Skip to content

Add native SM and CSRNG IPC transport - #171

Open
b4f8abbb24dbf56a7d0280f296e16eeb wants to merge 1 commit into
seedds:mainfrom
b4f8abbb24dbf56a7d0280f296e16eeb:feature/native-service-ipc
Open

b4f8abbb24dbf56a7d0280f296e16eeb wants to merge 1 commit into
seedds:mainfrom
b4f8abbb24dbf56a7d0280f296e16eeb:feature/native-service-ipc

Conversation

@b4f8abbb24dbf56a7d0280f296e16eeb

Copy link
Copy Markdown
Contributor

Summary

Add a shared, checked HIPC/CMIF backend for the service manager (sm:) and random-number service (csrng).

  • Implement native ConnectToNamedPort, synchronous requests through the current IPC buffer or an explicit user buffer, and service-owned handle closure.
  • Support SM client registration/service lookup, CSRNG output buffers, and the required pointer-buffer control request.
  • Route the existing HIPC compatibility adapters through the same generation-tagged session owner, preserving their olsc:u behavior.
  • Validate packet extents, descriptor arithmetic, response capacity and writable guest-memory ranges before side effects. Keep backing stable through writes and reject unsupported requests explicitly.

Why this helps

Today, missing service transport is worked around by intercepting individual C++ SDK exports using hardcoded mangled names. For example, hle_os.c contains an HLE_FORCE entry for:

_ZN2nn6crypto36GenerateCryptographicallyRandomBytesEPvm

That is nn::crypto::GenerateCryptographicallyRandomBytes(void *, size_t). Its original SDK implementation opens csrng through sm:; placeholder kernel-service responses currently prevent that path from working, so the host replaces the whole SDK function.

This PR implements the lower-level path: connect to sm:, register the client, acquire a CSRNG session, send command 0 with an output buffer, and return a valid CMIF response. Once the original SDK call is validated through that path, the long-name HLE_FORCE entry and its replacement wrapper can be removed, leaving the SDK's own implementation in place.

The same approach provides a route to retire the nine named HIPC adapter hooks. Concrete examples include:

  • _ZN2nn2sf4hipc20ConnectToHipcServiceEPNS_3svc6HandleEPKc
  • _ZN2nn2sf4hipc6client22QueryPointerBufferSizeEPtNS_3svc6HandleE
  • _ZN2nn2sf4hipc6client16DuplicateSessionEPNS_3svc6HandleES4_
  • _ZN2nn2sf4hipc15SendSyncRequestENS_3svc6HandleEPvm

Instead of recognizing each SDK function by its mangled name, the host handles the service protocol those functions use. This makes the implementation reusable across compatible SDK callers and gives new services one common transport and handle lifecycle.

The existing hooks remain installed in this PR. Retirement is a follow-up after verifying the original SDK request, control, domain and duplicate-session paths; the shared backend and cross-route tests make that migration possible.

Validation

CI passes:

  • Native ARM64 IPC tests under normal, ASan, UBSan, TSan and combined ASan/UBSan configurations.
  • Independent wire-format, malformed-packet, handle reuse/duplication/concurrency, output-canary and transactional-failure tests.
  • Production SVC dispatch and adapter/native handle cross-use fixtures, with 4 KiB and 16 KiB memory coverage across local and native runs.
  • Mac host linking for three profiles, existing host/CPU graphics tests, 72 tool tests and all graphics-test compilation.
  • iOS source compilation and a full unsigned app compile/link with synthetic resources.

Original SDK/game execution through this transport remains the next validation step.

Protocol references

The implementation is original code checked against libnx HIPC/CMIF layouts, SM requests, CSRNG requests, and Atmosphère's SM compatibility handling.

Implement checked HIPC/CMIF parsing, owned generation-tagged sessions and native synchronous SVC dispatch for the bounded service-manager and random-number service path. Route existing HIPC compatibility adapters through the same backend while preserving olsc responses and retaining the entropy takeover pending original-SDK validation.

Validate guest memory and hold backing stable through writes. Add independent wire, malformed-packet, handle-lifetime and production-dispatch fixtures, including 4 KiB and 16 KiB backing.
@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) docs Documentation labels Nov 3, 2026
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 12, 2026
…rmanent loss, so the sound comes back on the return' (seedds#171) from FrenklinFish/BananaNative:android-audio-focus into android

Reviewed-on: https://git.eden-emu.dev/moceure/BananaNative/pulls/171
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 12, 2026
…e-43only

seedds#163's Speedhack setting takes field 21 of the profile row (skipLayersOf,
Profile.skipLayers); the 4:3 variants move to field 22.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 12, 2026
…settings, Ocarina of Time on Qualcomm

- Game language: Polish (pl) and Thai (th), from SDK 21's own settings table (sdk+0xc62b5c in Ocarina of Time lists pt-BR, pl, th); the launcher list, the host's DM_LANG mapping and GetAvailableLanguageCodes. Ocarina of Time (`0400486024DEC000`) carries EUpl messages, Donkey Kong Bananza (`040074A01BF12000`) 1.1 EUpl and THth.
- Launcher: one full page per game with tabs Performance (Picture, Speed, Advanced), Game (options, Game language, Controls), Saves and Storage; rows wrap and say what they do; profile options keep their description and say when they need Prepare again.
- Recommended settings per game and phone (game.tsv recommend rows, Recommend.java): a card with Recommended / Custom and tags on the rows; facts from GLES at launcher start before the first readiness check. Ocarina of Time on Qualcomm: system driver, Performance preset, Full vegetation off.
- Resolution presets (res_preset, scene_output rows) and Scene resolution overlays from a game's own dynamic resolution palette (scene_res.py, DM_ROMFS_OVERLAY).
- Qualcomm's own driver: mesh draws through compute by default (full Ocarina of Time foliage; DM_VK_MESH=1 keeps native mesh shading).
- Mesh draws through compute: a draw takes its own record's entry, and prewarm drops mesh / pixel pairings that do not feed each other (see-through on Adreno 830, black-line flicker on Turnip, issue seedds#180).
- Texture serial map: probes past tombstones, live and tombstone counts apart (the table no longer grows with every serial ever registered).
- pack_android.py: a profile with a selected shader set builds that set on the Mac and Windows (issue seedds#178).
- PRs seedds#150, seedds#151, seedds#171 (FrenklinFish) and seedds#156, seedds#163 (Omnicrash) were merged on Forgejo before this update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant