Skip to content

[hle] Read the Switch 2 TIPC forms of sm's RegisterService and UnregisterService - #2589

Open
VIGO-VI wants to merge 2 commits into
scarletnx:mainfrom
VIGO-VI:vigo/sm/tipc-space
Open

VIGO-VI wants to merge 2 commits into
scarletnx:mainfrom
VIGO-VI:vigo/sm/tipc-space

Conversation

@VIGO-VI

@VIGO-VI VIGO-VI commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

sm's TIPC clients send RegisterService and UnregisterService with a service space ahead of the name on a Switch 2, 20 and 12 bytes, and RegisterService puts max_sessions before is_light, where the CMIF form has is_light first. sm.swipc declares the CMIF layout only, so the generated dispatcher read the wrong fields. CI, run 44756692206 with main merged: every job passed, Windows (x86-64 and aarch64), Android, Recompiler, Linux AppImage (x86-64, with the native and sanitizer suites, and aarch64) and macOS. This pull request is ready for review.

Part of #2224.

sm.c gets a dispatcher of its own. For those two TIPC commands it reads the 16 and 20 byte RegisterService forms and the 8 and 12 byte UnregisterService forms. Any other raw size, and any buffer, X descriptor, C list or handle, is answered as a request the command cannot take, as the SDK's TIPC command format checks the message's counts against the command's. The runtime serves one service space, so a space is logged and otherwise ignored, as the SM proxy of the public CFW does. The CMIF forms stay the generated dispatcher's, and the results are unchanged (NotAllowed for a registration, NotRegistered or NotAllowed for an unregistration).

The layouts are Atmosphère's UserService::RegisterService(OutMoveHandle, ServiceName, u32 max_sessions, bool is_light) and UnregisterService(ServiceName) serialized by its TIPC command format, and libounce's SM client with the space first.

Testing:

  • sm_service passes with 144 checks. It drives the dispatcher with both TIPC forms and checks the name, max_sessions and is_light it decodes, that a wrong size and each descriptor or handle are refused, and that a name sm refuses is InvalidServiceName in either form.
  • Swapping the two fields to the CMIF order fails the test.
  • runtime_architecture passes with the dispatcher in the file's save-state table.
  • sm_service passes under ASan and UBSan with leak detection (build/san, SNX_TEST_SANITIZERS=ON).

Not tested:

  • A client that sends these forms. The three Switch 2 games installed here send RegisterClient and GetServiceHandle only in the runs made here (31 requests over the three, none for RegisterService or UnregisterService), so their logs prove the other commands and no regression, not these forms. The layouts come from the reference's serialization.

Part of #2224.

  • No keys, dumps, game files or saves in the commits or the description.
  • A new file starts with SPDX-License-Identifier: GPL-3.0-or-later and the project's copyright line.
  • Code ported from another project keeps its copyright lines, names where it came from and is listed in docs/CREDITS.md.

…sterService

sm's TIPC clients on a Switch 2 send RegisterService and UnregisterService
with a service space ahead of the name, 20 and 12 bytes, and
RegisterService puts max_sessions before is_light, where CMIF has
is_light first. sm.swipc declares the CMIF layout only, so the generated
dispatcher read the wrong fields.

sm.c gets a dispatcher of its own. For those two TIPC commands it reads
the 16 and 20 byte RegisterService forms and the 8 and 12 byte
UnregisterService forms, and refuses any other size, buffer, X
descriptor, C list or handle, as the SDK's TIPC command format does. The
runtime serves one service space, so the space is logged and otherwise
ignored. The CMIF forms stay the generated dispatcher's. The dispatcher
joins the file's save-state table.

Verified with sm_service (144 checks), which drives the dispatcher with
both forms and checks the name, max_sessions and is_light it decodes, and
that a wrong size or a descriptor is refused. runtime_architecture passes
with the new save-state entry.
@VIGO-VI VIGO-VI changed the title [hle] Read the Switch 2 TIPC forms of sms RegisterService and UnregisterService [hle] Read the Switch 2 TIPC forms of sm's RegisterService and UnregisterService Nov 20, 2026
@VIGO-VI
VIGO-VI marked this pull request as ready for review November 20, 2026 15:45
@xinitrcn1
xinitrcn1 self-requested a review November 20, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants