Difference between revisions of "NPDM"

From Nintendo Switch Brew
Jump to navigation Jump to search
(42 intermediate revisions by 12 users not shown)
Line 1: Line 1:
This is the Switch equivalent of 3DS exheader, [https://www.3dbrew.org/wiki/NCCH NCCH (Nintendo Content Containers Header)]. This is the file with extension ".npdm" in {Switch ExeFS}. The size of this file varies.
+
This is the Switch equivalent of 3DS [https://www.3dbrew.org/wiki/NCCH/Extended_Header exheader]. This is the file with extension ".npdm" in {Switch ExeFS}. The size of this file varies.
  
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 9: Line 9:
 
| 0x0
 
| 0x0
 
| 0x80
 
| 0x80
| META
+
| [[#META|META]]
 
|-
 
|-
 
| 0x80
 
| 0x80
 
| <Varies>
 
| <Varies>
| ACID
+
| [[#ACID|ACID]]
 
|-
 
|-
 
| <See META>
 
| <See META>
 
| <See META>
 
| <See META>
| ACI0
+
| [[#ACI0|ACI0]]
 
|}
 
|}
  
Line 29: Line 29:
 
| 0x0
 
| 0x0
 
| 0x4
 
| 0x4
| Magic "META".
+
| Magicnum "META"
 
|-
 
|-
 
| 0x4
 
| 0x4
|
 
|
 
|-
 
 
| 0x8
 
| 0x8
|
+
| Reserved
|
 
 
|-
 
|-
 
| 0xC
 
| 0xC
| 1
+
| 0x1
|  
+
| [[#Flags|Flags]]
 +
|-
 +
| 0xD
 +
| 0x1
 +
| Reserved
 
|-
 
|-
 
| 0xE
 
| 0xE
| 1
+
| 0x1
| MainThreadPrio
+
| [[#MainThreadPriority|MainThreadPriority]]
 
|-
 
|-
 
| 0xF
 
| 0xF
| 1
+
| 0x1
| DefaultCpuId
+
| MainThreadCoreNumber
 
|-
 
|-
 
| 0x10
 
| 0x10
|
+
| 0x4
|
+
| Reserved
 +
|-
 +
| 0x14
 +
| 0x4
 +
| [3.0.0+] [[#SystemResourceSize|SystemResourceSize]]
 
|-
 
|-
 
| 0x18
 
| 0x18
| 4
+
| 0x4
| ProcessCategory (0: regular title, 1: kernel built-in). Should be 0 here.
+
| [[#Version|Version]]
 
|-
 
|-
 
| 0x1C
 
| 0x1C
| 4
+
| 0x4
| MainStackSize
+
| [[#MainThreadStackSize|MainThreadStackSize]]
 
|-
 
|-
 
| 0x20
 
| 0x20
| ?
+
| 0x10
| Title name
+
| Name (usually/always "Application")
 +
|-
 +
| 0x30
 +
| 0x10
 +
| ProductCode (usually/always all zeroes)
 +
|-
 +
| 0x40
 +
| 0x30
 +
| Reserved
 
|-
 
|-
 
| 0x70
 
| 0x70
 
| 0x4
 
| 0x4
| [[#ACI0]] offset
+
| [[#ACI0|AciOffset]]
 
|-
 
|-
 
| 0x74
 
| 0x74
 
| 0x4
 
| 0x4
| [[#ACI0]] size
+
| [[#ACI0|AciSize]]
 
|-
 
|-
 
| 0x78
 
| 0x78
 
| 0x4
 
| 0x4
| [[#ACID]] offset
+
| [[#ACID|AcidOffset]]
 
|-
 
|-
 
| 0x7C
 
| 0x7C
 
| 0x4
 
| 0x4
| [[#ACID]] size
+
| [[#ACID|AcidSize]]
 +
|}
 +
 
 +
== Flags ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 0
 +
| Is64BitInstruction
 +
|-
 +
| 1-3
 +
| ProcessAddressSpace (0x00 = AddressSpace32Bit, 0x01 = AddressSpace64BitOld, 0x02 = AddressSpace32BitNoReserved, 0x03 = AddressSpace64Bit)
 +
|-
 +
| 4
 +
| OptimizeMemoryAllocation
 
|}
 
|}
 +
 +
== MainThreadPriority ==
 +
Ranges from 0 to 0x3F.
 +
 +
== SystemResourceSize ==
 +
This is the size of PersonalMmHeap. Maximum size as of 5.0.0 is 0x1FE00000.
 +
 +
== Version ==
 +
0 for all titles.
 +
 +
[8.1.0+] Now set to 1 for certain titles.
 +
 +
== MainThreadStackSize ==
 +
Must be aligned to 0x1000.
 +
 +
In non-nspwn scenarios, values of 0 can also rarely break in Horizon. This might be something auto-adapting or a security feature of some sort?
  
 
= ACID =
 
= ACID =
Line 91: Line 135:
 
! Description
 
! Description
 
|-
 
|-
| 0
+
| 0x0
 
| 0x100
 
| 0x100
| RSA-2048 signature, seems to verify the data starting at 0x100 with the size field from 0x204.
+
| RSA-2048 signature over the data starting at 0x100 with the size field from 0x204
 
|-
 
|-
 
| 0x100
 
| 0x100
 
| 0x100
 
| 0x100
| RSA-2048 public key, seems to be used for the second [[NCA_Format|NCA]] signature.
+
| RSA-2048 public key for the second [[NCA_Format|NCA]] signature
 
|-
 
|-
 
| 0x200
 
| 0x200
 
| 0x4
 
| 0x4
| Magic "ACID".
+
| Magicnum "ACID"
 
|-
 
|-
 
| 0x204
 
| 0x204
 
| 0x4
 
| 0x4
| s32 Size field used with the above signature(?).
+
| Size
 
|-
 
|-
 
| 0x208
 
| 0x208
 
| 0x4
 
| 0x4
| Zeroes
+
| Reserved
 
|-
 
|-
 
| 0x20C
 
| 0x20C
 
| 0x4
 
| 0x4
| Retail flag. Must be 1 on retail, on devunit 0 is also allowed.
+
| [[#Flags_2|Flags]]
 
|-
 
|-
 
| 0x210
 
| 0x210
 
| 0x8
 
| 0x8
| TitleIdRange_Min
+
| ProgramIdMin
 
|-
 
|-
 
| 0x218
 
| 0x218
 
| 0x8
 
| 0x8
| TitleIdRange_Max
+
| ProgramIdMax
 
|-
 
|-
 
| 0x220
 
| 0x220
 
| 0x4
 
| 0x4
| [[#FS Access Control]] offset
+
| [[#FsAccessControl|FsAccessControlOffset]]
 
|-
 
|-
 
| 0x224
 
| 0x224
 
| 0x4
 
| 0x4
| [[#FS Access Control]] size
+
| [[#FsAccessControl|FsAccessControlSize]]
 
|-
 
|-
 
| 0x228
 
| 0x228
 
| 0x4
 
| 0x4
| [[#Service Access Control]] offset
+
| [[#SrvAccessControl|SrvAccessControlOffset]]
 
|-
 
|-
 
| 0x22C
 
| 0x22C
 
| 0x4
 
| 0x4
| [[#Service Access Control]] size
+
| [[#SrvAccessControl|SrvAccessControlSize]]
 
|-
 
|-
 
| 0x230
 
| 0x230
| 4
+
| 0x4
| [[#Kernel Access Control]] offset
+
| [[#KernelCapability|KernelCapabilityOffset]]
 
|-
 
|-
 
| 0x234
 
| 0x234
| 4
+
| 0x4
| [[#Kernel Access Control]] size
+
| [[#KernelCapability|KernelCapabilitySize]]
 
|-
 
|-
 
| 0x238
 
| 0x238
 
| 0x8
 
| 0x8
| Padding
+
| Reserved
 +
|}
 +
 
 +
== Flags ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 0
 +
| ProductionFlag
 +
|-
 +
| 1
 +
| UnqualifiedApproval
 +
|-
 +
| 2-3
 +
| [5.0.0+ ] MemoryRegion (0 = Application, 1 = Applet, 2 = SecureSystem, 3 = NonSecureSystem)
 
|}
 
|}
 +
 +
MemoryRegion is set to Application for "starter" and NonSecureSystem for "nvservices".
  
 
= ACI0 =
 
= ACI0 =
Line 161: Line 223:
 
| 0x0
 
| 0x0
 
| 0x4
 
| 0x4
| Magic "ACI0".
+
| Magicnum "ACI0"
 
|-
 
|-
 
| 0x4
 
| 0x4
 
| 0xC
 
| 0xC
| Zeroes
+
| Reserved
 
|-
 
|-
 
| 0x10
 
| 0x10
 
| 0x8
 
| 0x8
| Title id
+
| ProgramId
 
|-
 
|-
 
| 0x18
 
| 0x18
 
| 0x8
 
| 0x8
| Padding
+
| Reserved
 
|-
 
|-
 
| 0x20
 
| 0x20
 
| 0x4
 
| 0x4
| [[#FS Access Header]] offset
+
| [[#FsAccessControl|FsAccessControlOffset]]
 
|-
 
|-
 
| 0x24
 
| 0x24
 
| 0x4
 
| 0x4
| [[#FS Access Header]] size
+
| [[#FsAccessControl|FsAccessControlSize]]
 
|-
 
|-
 
| 0x28
 
| 0x28
 
| 0x4
 
| 0x4
| [[#Service Access Control]] offset
+
| [[#SrvAccessControl|SrvAccessControlOffset]]
 
|-
 
|-
 
| 0x2C
 
| 0x2C
 
| 0x4
 
| 0x4
| [[#Service Access Control]] size
+
| [[#SrvAccessControl|SrvAccessControlSize]]
 
|-
 
|-
 
| 0x30
 
| 0x30
| 4
+
| 0x4
| [[#Kernel Access Control]] offset
+
| [[#KernelCapability|KernelCapabilityOffset]]
 
|-
 
|-
 
| 0x34
 
| 0x34
| 4
+
| 0x4
| [[#Kernel Access Control]] size
+
| [[#KernelCapability|KernelCapabilitySize]]
 
|-
 
|-
 
| 0x38
 
| 0x38
 
| 0x8
 
| 0x8
| Padding
+
| Reserved
 
|}
 
|}
  
= FS Access Header =
+
= FsAccessControl =
 
+
For [[#ACID|ACID]] this is a simple descriptor as follows:
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 214: Line 276:
 
| 0x0
 
| 0x0
 
| 0x1
 
| 0x1
| Version? Always 1. Must be non-zero.
+
| Version (always 1, must be non-zero)
 
|-
 
|-
 
| 0x1
 
| 0x1
Line 222: Line 284:
 
| 0x4
 
| 0x4
 
| 0x8
 
| 0x8
| Permissions bitmask
+
| [[#FsAccessFlag|FsAccessFlag]]
 
|-
 
|-
 
| 0xC
 
| 0xC
| 0x4
+
| 0x20
| Usually 0x1C
+
| Reserved
|-
 
| 0x10
 
| 0x4
 
| Usually 0x0
 
|-
 
| 0x14
 
| 0x4
 
| Usually 0x1C
 
|-
 
| 0x18
 
| 0x4
 
| Usually 0x0
 
|-
 
 
|}
 
|}
  
= FS Access Control =
+
For [[#ACI0|ACI0]] this embeds data as follows:
 
 
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 252: Line 300:
 
| 0x0
 
| 0x0
 
| 0x1
 
| 0x1
| Version? Always 1. Must be non-zero.
+
| Version (always 1, must be non-zero)
 
|-
 
|-
 
| 0x1
 
| 0x1
Line 260: Line 308:
 
| 0x4
 
| 0x4
 
| 0x8
 
| 0x8
| Permissions bitmask
+
| [[#FsAccessFlag|FsAccessFlag]]
 
|-
 
|-
 
| 0xC
 
| 0xC
| 0x20
+
| 0x4
| Usually all zeroes for applications
+
| ContentOwnerInfoOffset
 +
|-
 +
| 0x10
 +
| 0x4
 +
| ContentOwnerInfoSize
 +
|-
 +
| 0x14
 +
| 0x4
 +
| SaveDataOwnerInfoOffset
 +
|-
 +
| 0x18
 +
| 0x4
 +
| SaveDataOwnerInfoSize
 +
|-
 +
| 0x1C
 +
| 0x4
 +
| (Optional) Amount of content owner id's
 +
|-
 +
| 0x1C
 +
| 0x8 * Content Owner ID's
 +
| Content owner ID's as uint64's.
 +
|-
 +
| Variable
 +
| 0x4
 +
| Amount of save owner id's
 +
|-
 +
| Variable
 +
| 0x1 * Save data owner accessibilities (?)
 +
| Sets flags for what save data owners can do with other applications save data (?)
 +
|-
 +
| Variable (padded to nearest 4 bytes)
 +
| 0x8 * Amount of save owner ID's
 +
| Save data owner ID's
 
|}
 
|}
  
[[Filesystem_services#Permissions|Permissions]] bitmask:
+
== FsAccessFlag ==
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
! Bit
+
! Bits
 +
! Name
 
! Description
 
! Description
 
|-
 
|-
 
| 0
 
| 0
 +
| ApplicationInfo
 
| MountContent* is accessible when set.
 
| MountContent* is accessible when set.
 +
|-
 +
| 1
 +
| BootModeControl
 +
|
 +
|-
 +
| 2
 +
| Calibration
 +
|
 +
|-
 +
| 3
 +
| SystemSaveData
 +
|
 +
|-
 +
| 4
 +
| GameCard
 +
|
 +
|-
 +
| 5
 +
| SaveDataBackUp
 +
|
 +
|-
 +
| 6
 +
| SaveDataManagement
 +
|
 +
|-
 +
| 7
 +
| BisAllRaw
 +
|
 +
|-
 +
| 8
 +
| GameCardRaw
 +
|
 +
|-
 +
| 9
 +
| GameCardPrivate
 +
|
 +
|-
 +
| 10
 +
| SetTime
 +
|
 +
|-
 +
| 11
 +
| ContentManager
 +
|
 +
|-
 +
| 12
 +
| ImageManager
 +
|
 +
|-
 +
| 13
 +
| CreateSaveData
 +
|
 +
|-
 +
| 14
 +
| SystemSaveDataManagement
 +
|
 +
|-
 +
| 15
 +
| BisFileSystem
 +
|
 +
|-
 +
| 16
 +
| SystemUpdate
 +
|
 +
|-
 +
| 17
 +
| SaveDataMeta
 +
|
 +
|-
 +
| 18
 +
| DeviceSaveData
 +
|
 +
|-
 +
| 19
 +
| SettingsControl
 +
|
 +
|-
 +
| 20
 +
| SystemData
 +
|
 +
|-
 +
| 21
 +
| SdCard
 +
|
 +
|-
 +
| 22
 +
| Host
 +
|
 +
|-
 +
| 23
 +
| FillBis
 +
|
 +
|-
 +
| 24
 +
| CorruptSaveData
 +
|
 +
|-
 +
| 25
 +
| SaveDataForDebug
 +
|
 +
|-
 +
| 26
 +
| FormatSdCard
 +
|
 +
|-
 +
| 27
 +
| GetRightsId
 +
|
 +
|-
 +
| 28
 +
| RegisterExternalKey
 +
|
 +
|-
 +
| 29
 +
| RegisterUpdatePartition
 +
|
 +
|-
 +
| 30
 +
| SaveDataTransfer
 +
|
 +
|-
 +
| 31
 +
| DeviceDetection
 +
|
 +
|-
 +
| 32
 +
| AccessFailureResolution
 +
|
 +
|-
 +
| 33
 +
| SaveDataTransferVersion2
 +
|
 
|-
 
|-
 
| 34
 
| 34
| Enables access to [[Filesystem_services|Bis]] partitionID 27 and 28?
+
| RegisterProgramIndexMapInfo
 +
|
 +
|-
 +
| 35
 +
| CreateOwnSaveData
 +
|
 +
|-
 +
| 36-61
 +
| Reserved
 +
|
 +
|-
 +
| 62
 +
| Debug
 +
| See [[SPL_services#GetConfig|here]].
 
|-
 
|-
 
| 63
 
| 63
| Enables access to everything: all [[Filesystem_services#Permissions|permission-types]] which check a bitmask have this bit set.
+
| FullPermission
 +
| Enables access to everything: all [[Filesystem_services#Permissions|permission types]] which check a bitmask have this bit set.
 
|}
 
|}
  
For bit62 in permissions, see [[SPL_services#GetConfig|here]].
+
Controls the [[Filesystem_services#Permissions|filesystem permissions]].
  
 
Web-applets permissions:
 
Web-applets permissions:
Line 290: Line 518:
  
 
= Service Access Control =
 
= Service Access Control =
This is a list of [[Services_API|service]]-name strings which the title has access to, with the following structure:
+
{| class="wikitable" border="1"
  +0: control_byte
+
|-
  +1: {service-name without nul-terminator}
+
! Bits
 
+
! Description
Bitmask 0x0F in control_byte is the {length of the service-name without nul-terminator} - 1.
+
|-
 
+
| 0-2
Bitmask 0x80 in control_byte means service is allowed to be registered.
+
| Size (length of the service-name without null-terminator minus 1)
 +
|-
 +
| 7
 +
| IsServer (service is allowed to be registered)
 +
|-
 +
| Variable
 +
| Name
 +
|}
  
The service string can contain a wildcard <code>*</code> character.
+
This is a list of [[Services_API|service]]-name strings which the title has access to.
  
= Kernel Access Control =
+
The service name string starts after the first byte and supports the wildcard <code>*</code> character.
On Switch, descriptors are identified by pattern 01..11 in low bits.
 
  
 +
= KernelCapability =
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
 
! Pattern of lower bits
 
! Pattern of lower bits
 
! Lowest clear bitmask/bit
 
! Lowest clear bitmask/bit
! Type
+
! Description
! Fields
 
 
|-
 
|-
 
| <code>0bxxxxxxxxxxxx0111</code>
 
| <code>0bxxxxxxxxxxxx0111</code>
 
| Bit3
 
| Bit3
| KernelFlags
+
| [[#ThreadInfo]]
| Bit31-24: Highest allowed cpu id, bit23-16: Lowest allowed cpu id, bit15-10: Highest allowed thread prio, bit9-4: Lowest allowed thread prio
 
 
|-
 
|-
 
| <code>0bxxxxxxxxxxx01111</code>
 
| <code>0bxxxxxxxxxxx01111</code>
 
| Bit4
 
| Bit4
| SyscallMask
+
| [[#EnableSystemCalls]]
| Bits 29-31: Syscall mask table index; Bits 5-28: Mask
 
 
|-
 
|-
 
| <code>0bxxxxxxxxx0111111</code>
 
| <code>0bxxxxxxxxx0111111</code>
 
| Bit6
 
| Bit6
| MapIoOrNormalRange
+
| [[#MemoryMap]]
| Bits 7-30: Alternating start page and number of pages, bit31: Alternating read-only flag then MemoryAttribute 0x2001/0x42002 selector flag
 
 
|-
 
|-
 
| <code>0bxxxxxxxx01111111</code>
 
| <code>0bxxxxxxxx01111111</code>
 
| Bit7
 
| Bit7
| MapNormalPage (RW)
+
| [[#IoMemoryMap]]
| Bits 8-31: Page
+
|-
 +
| <code>0bxxxxx01111111111</code>
 +
| Bit10
 +
| [8.0.0+] [[#MemoryRegionMap]]
 
|-
 
|-
 
| <code>0bxxxx011111111111</code>
 
| <code>0bxxxx011111111111</code>
 
| Bit11
 
| Bit11
| InterruptPair
+
| [[#EnableInterrupts]]
| Bits 12-21: Irq0, bits 20-31: Irq1, 0x3FF means empty.
 
 
|-
 
|-
 
| <code>0bxx01111111111111</code>
 
| <code>0bxx01111111111111</code>
 
| Bit13
 
| Bit13
| ApplicationType
+
| [[#MiscParams]]
| Bit16-14: ApplicationType (0=sysmodule, 1=application, 2=applet), bit16 ignored. Parsed by [[Process Manager services]]. Defaults to 0 if descriptor doesn't exist. Can only run 1 application at a time.
 
 
|-
 
|-
 
| <code>0bx011111111111111</code>
 
| <code>0bx011111111111111</code>
 
| Bit14
 
| Bit14
| KernelReleaseVersion
+
| [[#KernelVersion]]
| Bits 15-X: Version. The raw descriptor is compared with 0x80000, when less than an error is returned. This is equivalent to comparing the bits starting at bit15 with 0x10. This enforces a minimum required version, not a maximum.
 
 
|-
 
|-
 
| <code>0b0111111111111111</code>
 
| <code>0b0111111111111111</code>
 
| Bit15
 
| Bit15
| HandleTableSize
+
| [[#HandleTableSize]]
| Bit25-16: Number of handles the table shall fit.
 
 
|-
 
|-
 
| <code>0b1111111111111111</code>
 
| <code>0b1111111111111111</code>
 
| Bit16
 
| Bit16
| DebugFlags
+
| [[#MiscFlags]]
| Bit17: can be debugged, bit18: can debug others
 
 
|-
 
|-
 
| All ones
 
| All ones
 
|  
 
|  
 
| Ignored
 
| Ignored
|
 
 
|}
 
|}
  
== Mapping restrictions ==
+
These descriptors are identified by pattern 01..11 in low bits.
 +
 
 +
== ThreadInfo ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 4-9
 +
| LowestPriority
 +
|-
 +
| 10-15
 +
| HighestPriority
 +
|-
 +
| 16-23
 +
| MinCoreNumber
 +
|-
 +
| 24-31
 +
| MaxCoreNumber
 +
|}
 +
 
 +
== EnableSystemCalls ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 5-28
 +
| SystemCallId
 +
|-
 +
| 29-31
 +
| Index
 +
|}
 +
 
 +
== MemoryMap ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 7-30
 +
| BeginAddress or Size
 +
|-
 +
| 31
 +
| IsRw or IsIo
 +
|}
 +
 
 +
MemoryMap entries are stored alternating between BeginAddress + IsRw and Size + IsIo.
 +
 
 +
=== Restrictions ===
 
The physaddr range 0x80060000-0x2000000000 is not allowed to be mapped as IO.
 
The physaddr range 0x80060000-0x2000000000 is not allowed to be mapped as IO.
 
The physaddr range 0x80000000-0x2000000000 is not allowed to be mapped as Normal.
 
The physaddr range 0x80000000-0x2000000000 is not allowed to be mapped as Normal.
  
[2.0.0+] The range for IO was changed into 0x80060000-0x81D3FFFF.
+
[2.0.0-4.1.0] The range for IO was changed into 0x80060000-0x81D3FFFF.
  
[2.0.0+] A blacklist was added for IO and Normal mappings:
+
[2.0.0-4.1.0] A blacklist was added for IO and Normal mappings:
 
* 0x50040000-0x50060000 (ARM, Interrupt Controller)
 
* 0x50040000-0x50060000 (ARM, Interrupt Controller)
 
* 0x6000F000 (Exception Vectors)
 
* 0x6000F000 (Exception Vectors)
Line 376: Line 653:
 
* 0x7001D000 (MC1)
 
* 0x7001D000 (MC1)
  
== Kernel versions ==
+
[5.0.0+] For IO, this blacklist was abandoned and instead two range checks were added. For Normal mappings it is still applied
 +
 
 +
== IoMemoryMap ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 8-31
 +
| BeginAddress
 +
|}
 +
 
 +
== MemoryRegionMap ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 11-16
 +
| RegionType0
 +
|-
 +
| 17
 +
| RegionIsReadOnly0
 +
|-
 +
| 18-23
 +
| RegionType1
 +
|-
 +
| 24
 +
| RegionIsReadOnly1
 +
|-
 +
| 25-30
 +
| RegionType2
 +
|-
 +
| 31
 +
| RegionIsReadOnly2
 +
|}
 +
 
 +
MemoryRegionMap is supported by the kernel but not by [[Loader_services|Loader]]. Thus, only initial processes may possess this capability.
 +
 
 +
== EnableInterrupts ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 12-21
 +
| InterruptNumber0
 +
|-
 +
| 22-31
 +
| InterruptNumber1
 +
|}
 +
 
 +
0x3FF means empty.
 +
 
 +
== MiscParams ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 14-16
 +
| ProgramType (0 = System, 1 = Application, 2 = Applet)
 +
|}
 +
 
 +
ProgramType is parsed by [[Process Manager services]]. Defaults to 0 if descriptor doesn't exist. Can only run 1 application at a time.
 +
 
 +
== KernelVersion ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 15-18
 +
| MinorVersion
 +
|-
 +
| 19-31
 +
| MajorVersion
 +
|}
 +
 
 +
This is compared with 0x80000, when less than an error is returned. This is equivalent to comparing the bits starting at bit15 with 0x10. This enforces a minimum required version, not a maximum.
 +
 
 +
=== Versions ===
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 388: Line 746:
 
|-
 
|-
 
| 3.0.2 || 7.4.0 || 3.0.0
 
| 3.0.2 || 7.4.0 || 3.0.0
 +
|-
 +
| 5.0.0 || 9.3.0 || 3.0.0
 
|}
 
|}
  
Bit31-19: Major version
+
== HandleTableSize ==
Bit18-15: Minor version
+
{| class="wikitable" border="1"
Bit14-0: Zeroes
+
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 16-25
 +
| HandleTableSize
 +
|}
 +
 
 +
== MiscFlags ==
 +
{| class="wikitable" border="1"
 +
|-
 +
! Bits
 +
! Description
 +
|-
 +
| 17
 +
| EnableDebug
 +
|-
 +
| 18
 +
| ForceDebug
 +
|}

Revision as of 20:21, 12 December 2019

This is the Switch equivalent of 3DS exheader. This is the file with extension ".npdm" in {Switch ExeFS}. The size of this file varies.

Offset Size Description
0x0 0x80 META
0x80 <Varies> ACID
<See META> <See META> ACI0

META

Offset Size Description
0x0 0x4 Magicnum "META"
0x4 0x8 Reserved
0xC 0x1 Flags
0xD 0x1 Reserved
0xE 0x1 MainThreadPriority
0xF 0x1 MainThreadCoreNumber
0x10 0x4 Reserved
0x14 0x4 [3.0.0+] SystemResourceSize
0x18 0x4 Version
0x1C 0x4 MainThreadStackSize
0x20 0x10 Name (usually/always "Application")
0x30 0x10 ProductCode (usually/always all zeroes)
0x40 0x30 Reserved
0x70 0x4 AciOffset
0x74 0x4 AciSize
0x78 0x4 AcidOffset
0x7C 0x4 AcidSize

Flags

Bits Description
0 Is64BitInstruction
1-3 ProcessAddressSpace (0x00 = AddressSpace32Bit, 0x01 = AddressSpace64BitOld, 0x02 = AddressSpace32BitNoReserved, 0x03 = AddressSpace64Bit)
4 OptimizeMemoryAllocation

MainThreadPriority

Ranges from 0 to 0x3F.

SystemResourceSize

This is the size of PersonalMmHeap. Maximum size as of 5.0.0 is 0x1FE00000.

Version

0 for all titles.

[8.1.0+] Now set to 1 for certain titles.

MainThreadStackSize

Must be aligned to 0x1000.

In non-nspwn scenarios, values of 0 can also rarely break in Horizon. This might be something auto-adapting or a security feature of some sort?

ACID

Offset Size Description
0x0 0x100 RSA-2048 signature over the data starting at 0x100 with the size field from 0x204
0x100 0x100 RSA-2048 public key for the second NCA signature
0x200 0x4 Magicnum "ACID"
0x204 0x4 Size
0x208 0x4 Reserved
0x20C 0x4 Flags
0x210 0x8 ProgramIdMin
0x218 0x8 ProgramIdMax
0x220 0x4 FsAccessControlOffset
0x224 0x4 FsAccessControlSize
0x228 0x4 SrvAccessControlOffset
0x22C 0x4 SrvAccessControlSize
0x230 0x4 KernelCapabilityOffset
0x234 0x4 KernelCapabilitySize
0x238 0x8 Reserved

Flags

Bits Description
0 ProductionFlag
1 UnqualifiedApproval
2-3 [5.0.0+ ] MemoryRegion (0 = Application, 1 = Applet, 2 = SecureSystem, 3 = NonSecureSystem)

MemoryRegion is set to Application for "starter" and NonSecureSystem for "nvservices".

ACI0

Offset Size Description
0x0 0x4 Magicnum "ACI0"
0x4 0xC Reserved
0x10 0x8 ProgramId
0x18 0x8 Reserved
0x20 0x4 FsAccessControlOffset
0x24 0x4 FsAccessControlSize
0x28 0x4 SrvAccessControlOffset
0x2C 0x4 SrvAccessControlSize
0x30 0x4 KernelCapabilityOffset
0x34 0x4 KernelCapabilitySize
0x38 0x8 Reserved

FsAccessControl

For ACID this is a simple descriptor as follows:

Offset Size Description
0x0 0x1 Version (always 1, must be non-zero)
0x1 0x3 Padding
0x4 0x8 FsAccessFlag
0xC 0x20 Reserved

For ACI0 this embeds data as follows:

Offset Size Description
0x0 0x1 Version (always 1, must be non-zero)
0x1 0x3 Padding
0x4 0x8 FsAccessFlag
0xC 0x4 ContentOwnerInfoOffset
0x10 0x4 ContentOwnerInfoSize
0x14 0x4 SaveDataOwnerInfoOffset
0x18 0x4 SaveDataOwnerInfoSize
0x1C 0x4 (Optional) Amount of content owner id's
0x1C 0x8 * Content Owner ID's Content owner ID's as uint64's.
Variable 0x4 Amount of save owner id's
Variable 0x1 * Save data owner accessibilities (?) Sets flags for what save data owners can do with other applications save data (?)
Variable (padded to nearest 4 bytes) 0x8 * Amount of save owner ID's Save data owner ID's

FsAccessFlag

Bits Name Description
0 ApplicationInfo MountContent* is accessible when set.
1 BootModeControl
2 Calibration
3 SystemSaveData
4 GameCard
5 SaveDataBackUp
6 SaveDataManagement
7 BisAllRaw
8 GameCardRaw
9 GameCardPrivate
10 SetTime
11 ContentManager
12 ImageManager
13 CreateSaveData
14 SystemSaveDataManagement
15 BisFileSystem
16 SystemUpdate
17 SaveDataMeta
18 DeviceSaveData
19 SettingsControl
20 SystemData
21 SdCard
22 Host
23 FillBis
24 CorruptSaveData
25 SaveDataForDebug
26 FormatSdCard
27 GetRightsId
28 RegisterExternalKey
29 RegisterUpdatePartition
30 SaveDataTransfer
31 DeviceDetection
32 AccessFailureResolution
33 SaveDataTransferVersion2
34 RegisterProgramIndexMapInfo
35 CreateOwnSaveData
36-61 Reserved
62 Debug See here.
63 FullPermission Enables access to everything: all permission types which check a bitmask have this bit set.

Controls the filesystem permissions.

Web-applets permissions:

  • "LibAppletWeb" and "LibAppletOff" have same access control: bit0 and bit3 set, and bit62 set.
  • Rest of the web-applets: Same as above except bit0 isn't set.

Service Access Control

Bits Description
0-2 Size (length of the service-name without null-terminator minus 1)
7 IsServer (service is allowed to be registered)
Variable Name

This is a list of service-name strings which the title has access to.

The service name string starts after the first byte and supports the wildcard * character.

KernelCapability

Pattern of lower bits Lowest clear bitmask/bit Description
0bxxxxxxxxxxxx0111 Bit3 #ThreadInfo
0bxxxxxxxxxxx01111 Bit4 #EnableSystemCalls
0bxxxxxxxxx0111111 Bit6 #MemoryMap
0bxxxxxxxx01111111 Bit7 #IoMemoryMap
0bxxxxx01111111111 Bit10 [8.0.0+] #MemoryRegionMap
0bxxxx011111111111 Bit11 #EnableInterrupts
0bxx01111111111111 Bit13 #MiscParams
0bx011111111111111 Bit14 #KernelVersion
0b0111111111111111 Bit15 #HandleTableSize
0b1111111111111111 Bit16 #MiscFlags
All ones Ignored

These descriptors are identified by pattern 01..11 in low bits.

ThreadInfo

Bits Description
4-9 LowestPriority
10-15 HighestPriority
16-23 MinCoreNumber
24-31 MaxCoreNumber

EnableSystemCalls

Bits Description
5-28 SystemCallId
29-31 Index

MemoryMap

Bits Description
7-30 BeginAddress or Size
31 IsRw or IsIo

MemoryMap entries are stored alternating between BeginAddress + IsRw and Size + IsIo.

Restrictions

The physaddr range 0x80060000-0x2000000000 is not allowed to be mapped as IO. The physaddr range 0x80000000-0x2000000000 is not allowed to be mapped as Normal.

[2.0.0-4.1.0] The range for IO was changed into 0x80060000-0x81D3FFFF.

[2.0.0-4.1.0] A blacklist was added for IO and Normal mappings:

  • 0x50040000-0x50060000 (ARM, Interrupt Controller)
  • 0x6000F000 (Exception Vectors)
  • 0x6001DC00-0x6001E000 (IPATCH)
  • 0x7000E000 (RTC/PMC)
  • 0x70019000 (MC)
  • 0x7001C000 (MC0)
  • 0x7001D000 (MC1)

[5.0.0+] For IO, this blacklist was abandoned and instead two range checks were added. For Normal mappings it is still applied

IoMemoryMap

Bits Description
8-31 BeginAddress

MemoryRegionMap

Bits Description
11-16 RegionType0
17 RegionIsReadOnly0
18-23 RegionType1
24 RegionIsReadOnly1
25-30 RegionType2
31 RegionIsReadOnly2

MemoryRegionMap is supported by the kernel but not by Loader. Thus, only initial processes may possess this capability.

EnableInterrupts

Bits Description
12-21 InterruptNumber0
22-31 InterruptNumber1

0x3FF means empty.

MiscParams

Bits Description
14-16 ProgramType (0 = System, 1 = Application, 2 = Applet)

ProgramType is parsed by Process Manager services. Defaults to 0 if descriptor doesn't exist. Can only run 1 application at a time.

KernelVersion

Bits Description
15-18 MinorVersion
19-31 MajorVersion

This is compared with 0x80000, when less than an error is returned. This is equivalent to comparing the bits starting at bit15 with 0x10. This enforces a minimum required version, not a maximum.

Versions

Firmware Kernel Version Minimum Allowed
1.0.0 5.0.0 3.0.0
2.0.0 6.1.0 3.0.0
3.0.0 7.4.0 3.0.0
3.0.2 7.4.0 3.0.0
5.0.0 9.3.0 3.0.0

HandleTableSize

Bits Description
16-25 HandleTableSize

MiscFlags

Bits Description
17 EnableDebug
18 ForceDebug