NS and APT Services

NS and APT Services

The NS (Nintendo User Interface Shell) system module is the first module launched from a CTR-NAND title after the FIRM processes are loaded (also see Bootloader). This module is launched by the pm process, with the titleID loaded from NS state(hard-coded TID initialized during applet TID-array initialization). NS first launches ErrDisp, then the menu. On retail the menu TID is loaded from NS state, while on dev/debug the menu TID is loaded from config. On dev-units if the menu TID block doesn’t exist in config, NS will attempt to launch the alternate menu instead. The TID of the launched menu is then written to ACTIVEMENUTID. NS uses pm:app to launch titles.

NS will not trigger the fatal-error screen when launching the regular/alternate menu fails.

Like home menu NS is constantly running while the system is in 3DS-mode. When attempting to return to home-menu when the home-menu process isn’t running(like when the process terminated/crashed), NS will trigger a fatal error.

Alternate menu #

When launching the regular menu fails, NS will then attempt to launch the alternate menu. This title could be used as a recovery process, however it’s normally not used after the factory.

At the factory for all 3DS systems, Test Menu is installed with this TID. On retail this title is eventually deleted during Factory Setup.

Auto-boot #

After loading FIRM params and prior to launching ErrDisp/Home Menu, NS handles auto-booting titles. The same code called by APT:Reboot is used for launching FIRM here. When the UPDATEFLAG is set, NS will launch SAFE_MODE_FIRM with the application titleID set to the System Updater titleID for this region. When the UPDATEFLAG is not set, NS can auto-boot the following titles as well if 0x1FF80016 bit0 is set.

When bit1 and bit2 are value zero in 0x1FF80016, NS will launch the title specified by the FIRM parameters if the title-info is set. This FIRM launch is done after launching ErrDisp and Home Menu. Otherwise when 0x1FF80016 is value 2 and the output u8 from PTMSYSM command 0x08140000 is value 0, NS will boot the title specified from the TWL TLNC block from FIRMparams+0x300. This is the same TLNC block which DSi titles wrote to RAM+0x300 for launching other titles via the launcher title. When handling the TLNC block, NS will boot the 3DS System Settings title when the TLNC titleID is the DSi System Settings titleID(the region field in the TLNC TID is not checked/used). When the TLNC titleID is not System Settings, NS will convert the input DSi titleID-high to the 3DS TWL titleID-high(tidhigh = (TLNCtidhigh & 0x7FFF) | 0x48000), then launch TWL_FIRM to run the title. NS does not support launching from gamecard via TLNC.

NS Workaround #

A “ns_workaround” was added in NS to workaround the flaw added with 5.0.0-11. When NS is loading before launching any ARM11 processes and certain Configuration Memory fields are set, NS will launch AM then use command AM:InstallNATIVEFIRM. NS will then execute the code called by APT:StartNewestHomeMenu, the code related to APT:PrepareToStartNewestHomeMenu is not executed here.

NS will only execute this code-path when 0x1FF80016 is value zero, when KERNEL_VERSIONMAJOR is value 2, and when KERNEL_VERSIONMINOR is less than 35. Therefore, this code-path is only executed when the running NATIVE_FIRM version is prior to 5.0.0-11.

NS Service “ns:s” #

Command HeaderAvailable since system versionDescription
0x000100C01.0.0-0 - 2.0.0-2LaunchFIRM
0x000200C01.0.0-0 - 2.0.0-2LaunchTitle
0x000300001.0.0-0 - 2.0.0-2TerminateApplication
0x000400401.0.0-0 - 2.0.0-2TerminateProcess
0x000500C01.0.0-0 - 2.0.0-2LaunchApplicationFIRM
0x000600421.0.0-0 - 2.0.0-2SetWirelessRebootInfo
0x000700421.0.0-0 - 2.0.0-2CardUpdateInitialize
0x000800001.0.0-0 - 2.0.0-2CardUpdateShutdown
0x000900001.0.0-0 - 2.0.0-2Gamecard system update related.
0x000A00001.0.0-0 - 2.0.0-2Gamecard system update related.
0x000B00001.0.0-0 - 2.0.0-2Gamecard system update related.
0x000C00001.0.0-0 - 2.0.0-2Gamecard system update related.
0x000D01401.0.0-0 - 2.0.0-2SetTWLBannerHMAC
0x000E00001.0.0-0 - 2.0.0-2ShutdownAsync
0x000F00001.0.0-0 - 2.0.0-2This calls APT:AppletUtility with fixed input params.
0x001001801.0.0-0 - 2.0.0-2RebootSystem
0x001101001.0.0-0 - 2.0.0-2TerminateTitle
0x001200C0?SetApplicationCpuTimeLimit
0x00130000??
0x00140042??
0x00150140?LaunchApplication
0x001600008.0.0-18RebootSystemClean

The maximum sessions that can be used with this service is two, therefore only two processes can use this service at the same time.

NS Power Service “ns:p” #

Command HeaderDescription
0x00010040RebootSystem
0x00020000ShutdownAsync

This was added with 3.0.0-5. The PTM sysmodule connects to this service, and syncs whenever ptm:s GetShellState() changes.

NS Service “ns:c” #

Command HeaderDescription
0x00010100LockSpecialContent
0x00020100UnlockSpecialContent

This was added with 5.0.0-11. It is used by the Instruction Manual applet, and is likely related to triggering SD/Game Card removal errors when ejecting the media the manual is stored on.

APT Services #

Command HeaderAvailable since system versionAccessible with APT:UAccessible with APT:ADescription
0x00010040YesYesGetLockHandle
0x00020080See here.See here.Initialize
0x00030040YesYesEnable
0x00040040YesYesFinalize
0x00050040YesYesGetAppletManInfo
0x00060040Yes (AppID != 0x300)YesGetAppletInfo
0x00070000YesYesGetLastSignaledAppletId
0x00080000YesYesCountRegisteredApplet
0x00090040YesYesIsRegistered
0x000A0040YesYesGetAttribute
0x000B0040YesYesInquireNotification
0x000C0104YesYesSendParameter
0x000D0080YesYesReceiveParameter
0x000E0080YesYesGlanceParameter
0x000F0100YesYesCancelParameter
0x001000C2YesYesDebugFunc
0x001100C0YesYesMapProgramIdForDebug
0x00120040YesYesSetHomeMenuAppletIdForDebug
0x00130000YesYesGetPreparationState
0x00140040YesYesSetPreparationState
0x00150140NoNoPrepareToStartApplication
0x00160040YesYesPreloadLibraryApplet
0x00170040YesYesFinishPreloadingLibraryApplet
0x00180040YesYesPrepareToStartLibraryApplet
0x00190040YesYesPrepareToStartSystemApplet
0x001A0000YesYesPrepareToStartNewestHomeMenu
0x001B00C4YesYesStartApplication
0x001C0000YesYesWakeupApplication
0x001D0000YesYesCancelApplication
0x001E0084YesYesStartLibraryApplet
0x001F0084YesYesStartSystemApplet
0x00200044YesYesStartNewestHomeMenu
0x00210000NoNoOrderToCloseApplication
0x00220040YesYesPrepareToCloseApplication
0x00230040YesYesPrepareToJumpToApplication
0x00240044YesYesJumpToApplication
0x002500C0YesYesPrepareToCloseLibraryApplet
0x00260000YesYesPrepareToCloseSystemApplet
0x00270044YesYesCloseApplication
0x00280044YesYesCloseLibraryApplet
0x00290044YesYesCloseSystemApplet
0x002A0000YesYesOrderToCloseSystemApplet
0x002B0000YesYesPrepareToJumpToHomeMenu
0x002C0044YesYesJumpToHomeMenu
0x002D0000YesYesPrepareToLeaveHomeMenu
0x002E0044YesYesLeaveHomeMenu
0x002F0040YesYesPrepareToLeaveResidentApplet
0x00300044YesYesLeaveResidentApplet
0x00310100YesYesPrepareToDoApplicationJump
0x00320084YesYesDoApplicationJump
0x00330000YesYesGetProgramIdOnApplicationJump
0x00340084YesYesSendDeliverArg
0x00350080YesYesReceiveDeliverArg
0x00360040YesYesLoadSysMenuArg
0x00370042YesYesStoreSysMenuArg
0x00380040YesYesPreloadResidentApplet
0x00390040YesYesPrepareToStartResidentApplet
0x003A0044YesYesStartResidentApplet
0x003B0040YesYesCancelLibraryApplet
0x003C0042YesYesSendDspSleep
0x003D0042YesYesSendDspWakeUp
0x003E0080YesYesReplySleepQuery
0x003F0040YesYesReplySleepNotificationComplete
0x00400042YesYesSendCaptureBufferInfo
0x00410040YesYesReceiveCaptureBufferInfo
0x00420080YesYesSleepSystem
0x00430040YesYesNotifyToWait
0x00440000YesYesGetSharedFont
0x00450040YesYesGetWirelessRebootInfo
0x00460104YesYesWrap
0x00470104YesYesUnwrap
0x00480100NoNoGetProgramInfo
0x00490180NoNoReboot
0x004A0040YesYesGetCaptureInfo
0x004B00C2YesYesAppletUtility
0x004C0000YesYesSetFatalErrDispMode
0x004D0080YesYesGetAppletProgramInfo
0x004E0000YesYesHardwareResetAsync
0x004F00802.2.0-XYesYesSetApplicationCpuTimeLimit
0x005000402.2.0-XYesYesGetApplicationCpuTimeLimit
0x005100803.0.0-5YesYesGetStartupArgument
0x005201044.0.0-7YesYesWrap1
0x005301044.0.0-7YesYesUnwrap1
0x005400405.0.0-11YesYesTakes an unknown parameter, outputs a result code and media type.
0x005500407.0.0-13YesYesSetScreenCapturePostPermission
0x005600007.0.0-13YesYesGetScreenCapturePostPermission
0x005700447.0.0-13YesYesWakeupApplication2
0x005800027.0.0-13YesYesGetProgramID
0x010100008.0.0-18YesYesGetTargetPlatform
0x010200008.0.0-18YesYesCheckNew3DS
0x010300008.0.0-18YesYesGetApplicationRunningMode
0x010400008.0.0-18YesYesIsStandardMemoryLayout
0x0105010010.4.0-29YesYesIsTitleAllowed

These “APT:U” and “APT:S” NS services can handle launching titles/“applets”, these services handle signaling for home/power button as well. Only one session for either APT service can be open at a time, normally processes close the service handle immediately once finished using the service. The commands for APT:U and APT:S are exactly the same, however certain commands are only accessible with APT:S(NS module will call svcBreak when the command isn’t accessible).

Applets returning to home-menu first use commands APT:PrepareToJumpToHomeMenu and APT:JumpToHomeMenu, followed by these commands to launch home-menu: APT:PrepareToStartSystemApplet and APT:StartSystemApplet. APT:PrepareToStartSystemApplet and APT:StartSystemApplet are also used for launching the Internet Browser, the camera applet, etc.

Processes launch applications via home-menu, not directly with APT:PrepareToStartApplication and APT:StartApplication. Regular applications can’t directly launch applications since APT:StartApplication launches the process without terminating the currently running application.

APT:PrepareToDoApplicationJump and APT:DoApplicationJump are used by applications, for launching native/<non-NATIVE_FIRM> applications. These commands notify Home Menu that title launching needs done, Home Menu does the actual title launching via NS commands.

AppletAttr #

BitsDescription
0-2AppletPos
3Manually Acquire/Release GPU Rights
4Manually Acquire/Release DSP Rights
5?

DisplayBufferMode #

ValueDescription
0FORMAT_R8G8B8A8
1FORMAT_R8G8B8
2FORMAT_R5G6B5
3FORMAT_R5G5B5A1
4FORMAT_R4G4B4A4
0xFFFFFFFFFORMAT_UNIMPORTABLE

This is the same mapping as used for the GPU framebuffer color formats.

AppletPos #

ValueDescription
-1POS_NONE
0POS_APP
1POS_APPLIB
2POS_SYS
3POS_SYSLIB
4POS_RESIDENT

QueryReply #

ValueDescription
0REPLY_REJECT
1REPLY_ACCEPT
2REPLY_LATER

Notification #

ValueDescription
0NOTIFICATION_NONE
1NOTIFICATION_HOME_BUTTON_1
2NOTIFICATION_HOME_BUTTON_2
3NOTIFICATION_SLEEP_QUERY
4NOTIFICATION_SLEEP_CANCELED_BY_OPEN
5NOTIFICATION_SLEEP_ACCEPTED
6NOTIFICATION_SLEEP_AWAKE
7NOTIFICATION_SHUTDOWN
8NOTIFICATION_POWER_BUTTON_CLICK
9NOTIFICATION_POWER_BUTTON_CLEAR
10NOTIFICATION_TRY_SLEEP
11NOTIFICATION_ORDER_TO_CLOSE

Command #

ValueDescription
0COMMAND_NONE
1COMMAND_WAKEUP
2COMMAND_REQUEST
3COMMAND_RESPONSE
4COMMAND_EXIT
5COMMAND_MESSAGE
6COMMAND_HOME_BUTTON_SINGLE
7COMMAND_HOME_BUTTON_DOUBLE
8COMMAND_DSP_SLEEP
9COMMAND_DSP_WAKEUP
10COMMAND_WAKEUP_BY_EXIT
11COMMAND_WAKEUP_BY_PAUSE
12COMMAND_WAKEUP_BY_CANCEL
13COMMAND_WAKEUP_BY_CANCELALL
14COMMAND_WAKEUP_BY_POWER_BUTTON_CLICK
15COMMAND_WAKEUP_TO_JUMP_HOME
16COMMAND_REQUEST_FOR_SYS_APPLET
17COMMAND_WAKEUP_TO_LAUNCH_APPLICATION
0x41Unknown. Received by Home Menu during boot when the Home Menu process doesn’t terminate properly(svcExitProcess/crash).

AppletPreparationState #

ValueDescription
0NO_PREPARATION
1PREPARED_TO_LAUNCH_APP
2PREPARED_TO_CLOSE_APP
3PREPARED_TO_FORCE_TO_CLOSE_APP
4PREPARED_TO_PRELOAD_APPLIB
5PREPARED_TO_LAUNCH_APPLIB
6PREPARED_TO_CLOSE_APPLIB
7PREPARED_TO_LAUNCH_SYS
8PREPARED_TO_CLOSE_SYS
9PREPARED_TO_PRELOAD_SYSLIB
10PREPARED_TO_LAUNCH_SYSLIB
11PREPARED_TO_CLOSE_SYSLIB
12PREPARED_TO_LAUNCH_RESIDENT
13PREPARED_TO_LEAVE_RESIDENT
14PREPARED_TO_DO_HOMEMENU
15PREPARED_TO_LEAVE_HOMEMENU
16PREPARED_TO_START_RESIDENT
17PREPARED_TO_DO_APP_JUMP
18PREPARED_TO_FORCE_TO_CLOSE_SYS
19PREPARED_TO_LAUNCH_OTHER_SYS
20PREPARED_TO_JUMP_TO_APP

StartupArgumentType #

ValueDescription
0STARTUP_ARGUMENT_TYPE_OTHER_APP
1STARTUP_ARGUMENT_TYPE_RESTART
2STARTUP_ARGUMENT_TYPE_OTHER_MEDIA

CaptureBufferInfo #

OffsetSizeDescription
0x00x4u32, Size
0x40x1u8, 3D (0 = not 3D, 1 = 3D)
0x50x3Reserved
0x80x4Main Screen Left Offset
0xC0x4Main Screen Right Offset
0x100x4Main Screen DisplayBufferMode
0x140x4Sub Screen Left Offset
0x180x4Sub Screen Right Offset
0x1C0x4Sub Screen DisplayBufferMode

WirelessRebootInfo #

OffsetSizeDescription
0x00x6Host MAC address.
0x60x9WirelessRebootPassphrase
0xF0x1Uninitialized

This is setup by the dlplay system-application, before launching the DLP-child which can then use APT:GetWirelessRebootInfo. The MAC address and passphrase is used for connecting to the host by the DLP-child. See also here.

“APT:A” Service #

This was added with 7.0.0-X. Official apps built with the CTRSDK for system-version >= 7.0.0-X normally use the “APT:A” service instead of “APT:U”. Those processes also have “APT:A” instead of “APT:U” in the service-access-control. Unlike APT:U, APT:A can call APT:GetAppletInfo with applet ID 0x300.

Applets #

NS module does not verify that the input appID for the APT service cmds are correct for that type of command. For example, a process-launch of a SystemApplet via LibraryApplet commands works fine(minus the launched-process side of APT probably).

System Applets #

On Old3DS there could only be one applet here(Home Menu, Internet Browser, Friend-List, etc) with programID-high 00040030 running at a time. On Old3DS when directly launching one of these 00040030 applets with Home Menu, the Home Menu process will terminate once the process is launched. On Old3DS when returning to Home Menu from that launched process, the Home Menu process is launched again.

On New3DS the Home Menu process is still running/in-memory, while another system-applet is running. On New3DS it appears that the Home Menu process is terminated+relaunched, when another system-applet terminated without exiting with APT properly.

Library Applets #

Library applets can be launched by applications and regular applets. These library applets render to the screen(s) when running, etc. For example, this includes swkbd for text input. See the below appIDs in the 0x2XX range, the actual appID used is 0x4XX however.

Input data can be sent to the library applet via the NS parameter buffer, and/or with shared-memory with a shared-mem handle sent to the library applet. Output data from the library applet can be received by APT:ReceiveParameter, the library applet can also use the specified shared-mem for output too.

AppIDs #

AppIDDescription
0x101Home Menu (menu)
0x103Alternate Menu
0x110Camera applet ( CtrApp)
0x112Friends List applet ( friend)
0x113Game Notes applet (Cherry)
0x114Internet Browser (spider/SKATER)
0x115Instruction Manual applet
0x116Notifications applet (newslist)
0x117Miiverse applet (olv)
0x118Miiverse posting applet (solv3)
0x119Amiibo settings (cabinet)
0x201Software Keyboard (swkbd) (?)
0x202Mii Selector (appletEd) (?)
0x204Photo Selector (PNOTE_AP) (?)
0x205Sound Selector (SNOTE_AP) (?)
0x206Error Display ( error) (?)
0x207eShop applet ( mint) (?)
0x208Circle Pad Pro Calibrator ( extrapad) (?)
0x209Notepad (memolib) (?)
0x300Application
0x301eShop (tiger)
0x401Software Keyboard (swkbd)
0x402Mii Selector (appletEd)
0x404Photo Selector (PNOTE_AP)
0x405Sound Selector (SNOTE_AP)
0x406Error Display (error)
0x407eShop applet (mint)
0x408Circle Pad Pro Calibrator ( extrapad)
0x409Notepad (memolib)
0xF10ProgramID: 0004003000008900.
0xF11ProgramID: 000400000FFFFD00.
0xF12ProgramID: 000400000FFFFC00.
0xF13ProgramID: 000400000FFFFB00.
0xF14ProgramID: 000400000FFFF900.
0xF15ProgramID: 000400000FFFF800.
0xF16ProgramID: 000400000FFFF700.
0xF17ProgramID: 000400000FFFF600.
0xF18ProgramID: 000400000FFFF500.

These AppIDs are all for NAND titles, except for 0x300. AppIDs in the 0x1XX range are applets(programID-high 00040030), and the AppIDs in the 0x2XX range are “system libraries”(programID-high 00040030). The 0xFXX AppID range is for development NAND applications, these are not available for retail.

Note that at some point the total AppID entry count was changed from 28 to 27.

Category:Services