libnx
Data Structures | Macros | Enumerations
svc.h File Reference

Wrappers for kernel syscalls. More...

#include "../types.h"

Go to the source code of this file.

Data Structures

struct  MemoryInfo
 Memory information structure. More...
 
struct  SecmonArgs
 Secure monitor arguments. More...
 

Macros

#define CUR_PROCESS_HANDLE   0xFFFF8001
 Pseudo handle for the current process.
 
#define CUR_THREAD_HANDLE   0xFFFF8000
 Pseudo handle for the current thread.
 

Enumerations

enum  MemoryType {
  MemType_Unmapped =0x00,
  MemType_Io =0x01,
  MemType_Normal =0x02,
  MemType_CodeStatic =0x03,
  MemType_CodeMutable =0x04,
  MemType_Heap =0x05,
  MemType_SharedMem =0x06,
  MemType_WeirdMappedMem =0x07,
  MemType_ModuleCodeStatic =0x08,
  MemType_ModuleCodeMutable =0x09,
  MemType_IpcBuffer0 =0x0A,
  MemType_MappedMemory =0x0B,
  MemType_ThreadLocal =0x0C,
  MemType_TransferMemIsolated =0x0D,
  MemType_TransferMem =0x0E,
  MemType_ProcessMem =0x0F,
  MemType_Reserved =0x10,
  MemType_IpcBuffer1 =0x11,
  MemType_IpcBuffer3 =0x12,
  MemType_KernelStack =0x13,
  MemType_JitReadOnly =0x14,
  MemType_JitWritable =0x15
}
 Memory type enumeration (lower 8 bits of MemoryState) More...
 
enum  MemoryState {
  MemState_Type =0xFF,
  MemState_PermChangeAllowed =(1U<<( 8 )),
  MemState_ForceRwByDebugSyscalls =(1U<<( 9 )),
  MemState_IpcSendAllowed_Type0 =(1U<<( 10 )),
  MemState_IpcSendAllowed_Type3 =(1U<<( 11 )),
  MemState_IpcSendAllowed_Type1 =(1U<<( 12 )),
  MemState_ProcessPermChangeAllowed =(1U<<( 14 )),
  MemState_MapAllowed =(1U<<( 15 )),
  MemState_UnmapProcessCodeMemAllowed =(1U<<( 16 )),
  MemState_TransferMemAllowed =(1U<<( 17 )),
  MemState_QueryPAddrAllowed =(1U<<( 18 )),
  MemState_MapDeviceAllowed =(1U<<( 19 )),
  MemState_MapDeviceAlignedAllowed =(1U<<( 20 )),
  MemState_IpcBufferAllowed =(1U<<( 21 )),
  MemState_IsPoolAllocated =(1U<<( 22 )),
  MemState_IsRefCounted =MemState_IsPoolAllocated,
  MemState_MapProcessAllowed =(1U<<( 23 )),
  MemState_AttrChangeAllowed =(1U<<( 24 )),
  MemState_JitMemAllowed =(1U<<( 25 ))
}
 Memory state bitmasks. More...
 
enum  MemoryAttribute {
  MemAttr_IsBorrowed =(1U<<( 0 )),
  MemAttr_IsIpcMapped =(1U<<( 1 )),
  MemAttr_IsDeviceMapped =(1U<<( 2 )),
  MemAttr_IsUncached =(1U<<( 3 ))
}
 Memory attribute bitmasks. More...
 
enum  Permission {
  Perm_None = 0,
  Perm_R = (1U<<( 0 )),
  Perm_W = (1U<<( 1 )),
  Perm_X = (1U<<( 2 )),
  Perm_Rw = Perm_R | Perm_W,
  Perm_Rx = Perm_R | Perm_X,
  Perm_DontCare = (1U<<( 28 ))
}
 Memory permission bitmasks. More...
 
enum  JitMapOperation {
  JitMapOperation_MapOwner =0,
  JitMapOperation_MapSlave =1,
  JitMapOperation_UnmapOwner =2,
  JitMapOperation_UnmapSlave =3
}
 JIT mapping operations. More...
 
enum  LimitableResource {
  LimitableResource_Memory =0,
  LimitableResource_Threads =1,
  LimitableResource_Events =2,
  LimitableResource_TransferMemories =3,
  LimitableResource_Sessions =4
}
 Limitable Resources. More...
 
enum  ProcessInfoType { ProcessInfoType_ProcessState =0 }
 Process Information. More...
 
enum  ProcessState {
  ProcessState_Created =0,
  ProcessState_DebugAttached =1,
  ProcessState_DebugDetached =2,
  ProcessState_Crashed =3,
  ProcessState_Running =4,
  ProcessState_Exiting =5,
  ProcessState_Exited =6,
  ProcessState_DebugSuspended =7
}
 Process States. More...
 

Functions

Memory management
Result svcSetHeapSize (void **out_addr, u64 size)
 Set the process heap to a given size. More...
 
Result svcSetMemoryPermission (void *addr, u64 size, u32 perm)
 Set the memory permissions of a (page-aligned) range of memory. More...
 
Result svcSetMemoryAttribute (void *addr, u64 size, u32 val0, u32 val1)
 Set the memory attributes of a (page-aligned) range of memory. More...
 
Result svcMapMemory (void *dst_addr, void *src_addr, u64 size)
 Maps a memory range into a different range. More...
 
Result svcUnmapMemory (void *dst_addr, void *src_addr, u64 size)
 Unmaps a region that was previously mapped with svcMapMemory. More...
 
Result svcQueryMemory (MemoryInfo *meminfo_ptr, u32 *pageinfo, u64 addr)
 Query information about an address. More...
 
Result svcMapPhysicalMemory (void *address, u64 size)
 Maps new heap memory at the desired address. More...
 
Result svcUnmapPhysicalMemory (void *address, u64 size)
 Undoes the effects of svcMapPhysicalMemory. More...
 
Result svcMapPhysicalMemoryUnsafe (void *address, u64 size)
 Maps unsafe memory (usable for GPU DMA) for a system module at the desired address. More...
 
Result svcUnmapPhysicalMemoryUnsafe (void *address, u64 size)
 Undoes the effects of svcMapPhysicalMemoryUnsafe. More...
 
Result svcSetUnsafeLimit (u64 size)
 Sets the system-wide limit for unsafe memory mappable using svcMapPhysicalMemoryUnsafe. More...
 
Result svcSetProcessMemoryPermission (Handle proc, u64 addr, u64 size, u32 perm)
 Sets the memory permissions for the specified memory with the supplied process handle. More...
 
Result svcMapProcessMemory (void *dst, Handle proc, u64 src, u64 size)
 Maps the src address from the supplied process handle into the current process. More...
 
Result svcUnmapProcessMemory (void *dst, Handle proc, u64 src, u64 size)
 Undoes the effects of svcMapProcessMemory. More...
 
Result svcMapProcessCodeMemory (Handle proc, u64 dst, u64 src, u64 size)
 Maps normal heap in a certain process as executable code (used when loading NROs). More...
 
Result svcUnmapProcessCodeMemory (Handle proc, u64 dst, u64 src, u64 size)
 Undoes the effects of svcMapProcessCodeMemory. More...
 
Process and thread management
void svcExitProcess (void)
 Exits the current process. More...
 
Result svcCreateThread (Handle *out, void *entry, void *arg, void *stack_top, int prio, int cpuid)
 Creates a thread. More...
 
Result svcStartThread (Handle handle)
 Starts a freshly created thread. More...
 
void svcExitThread (void)
 Exits the current thread. More...
 
Result svcSleepThread (u64 nano)
 Sleeps the current thread for the specified amount of time. More...
 
Result svcGetThreadPriority (u32 *priority, Handle handle)
 Gets a thread's priority. More...
 
Result svcSetThreadPriority (Handle handle, u32 priority)
 Sets a thread's priority. More...
 
u32 svcGetCurrentProcessorNumber (void)
 Gets the current processor's number. More...
 
Result svcGetProcessId (u64 *processID, Handle handle)
 Gets the PID associated with a process. More...
 
Result svcGetThreadId (u64 *threadID, Handle handle)
 Gets the TID associated with a process. More...
 
Result svcSetThreadActivity (Handle thread, bool paused)
 Configures the pause/unpause status of a thread. More...
 
Result svcGetProcessList (u32 *num_out, u64 *pids_out, u32 max_pids)
 Retrieves a list of all running processes. More...
 
Result svcCreateProcess (Handle *out, void *proc_info, u32 *caps, u64 cap_num)
 Creates a new process. More...
 
Result svcStartProcess (Handle proc, s32 main_prio, s32 default_cpu, u32 stack_size)
 Starts executing a freshly created process. More...
 
Result svcTerminateProcess (Handle proc)
 Terminates a running process. More...
 
Result svcGetProcessInfo (u64 *out, Handle proc, ProcessInfoType which)
 Gets a ProcessInfoType for a process. More...
 
Synchronization
Result svcSignalEvent (Handle handle)
 Sets an event's signalled status. More...
 
Result svcClearEvent (Handle handle)
 Clears an event's signalled status. More...
 
Result svcResetSignal (Handle handle)
 Resets a signal. More...
 
Result svcWaitSynchronization (s32 *index, const Handle *handles, s32 handleCount, u64 timeout)
 Waits on one or more synchronization objects, optionally with a timeout. More...
 
static Result svcWaitSynchronizationSingle (Handle handle, u64 timeout)
 Waits on a single synchronization object, optionally with a timeout. More...
 
Result svcCancelSynchronization (Handle thread)
 Waits a svcWaitSynchronization operation being done on a synchronization object in another thread. More...
 
Result svcArbitrateLock (u32 wait_tag, u32 *tag_location, u32 self_tag)
 Arbitrates a mutex lock operation in userspace. More...
 
Result svcArbitrateUnlock (u32 *tag_location)
 Arbitrates a mutex unlock operation in userspace. More...
 
Result svcWaitProcessWideKeyAtomic (u32 *key, u32 *tag_location, u32 self_tag, u64 timeout)
 Performs a condition variable wait operation in userspace. More...
 
Result svcSignalProcessWideKey (u32 *key, s32 num)
 Performs a condition variable wake-up operation in userspace. More...
 
Result svcCreateEvent (Handle *server_handle, Handle *client_handle)
 Creates a system event. More...
 
Inter-process memory sharing
Result svcMapSharedMemory (Handle handle, void *addr, size_t size, u32 perm)
 Maps a block of shared memory. More...
 
Result svcUnmapSharedMemory (Handle handle, void *addr, size_t size)
 Unmaps a block of shared memory. More...
 
Result svcCreateTransferMemory (Handle *out, void *addr, size_t size, u32 perm)
 Creates a block of transfer memory. More...
 
Result svcCreateSharedMemory (Handle *out, size_t size, u32 local_perm, u32 other_perm)
 Creates a block of shared memory. More...
 
Result svcMapTransferMemory (Handle tmem_handle, void *addr, size_t size, u32 perm)
 Maps a block of transfer memory. More...
 
Result svcUnmapTransferMemory (Handle tmem_handle, void *addr, size_t size)
 Unmaps a block of transfer memory. More...
 
Miscellaneous
Result svcCloseHandle (Handle handle)
 Closes a handle, decrementing the reference count of the corresponding kernel object. More...
 
u64 svcGetSystemTick (void)
 Gets the current system tick. More...
 
Result svcBreak (u32 breakReason, u64 inval1, u64 inval2)
 Breaks execution. More...
 
Result svcGetInfo (u64 *out, u64 id0, Handle handle, u64 id1)
 Retrieves information about the system, or a certain kernel object. More...
 
Result svcGetSystemInfo (u64 *out, u64 id0, Handle handle, u64 id1)
 Retrieves privileged information about the system, or a certain kernel object. More...
 
Inter-process communication (IPC)
Result svcConnectToNamedPort (Handle *session, const char *name)
 Connects to a registered named port. More...
 
Result svcSendSyncRequest (Handle session)
 Sends an IPC synchronization request to a session. More...
 
Result svcSendSyncRequestWithUserBuffer (void *usrBuffer, u64 size, Handle session)
 Sends an IPC synchronization request to a session from an user allocated buffer. More...
 
Result svcSendAsyncRequestWithUserBuffer (Handle *handle, void *usrBuffer, u64 size, Handle session)
 Sends an IPC synchronization request to a session from an user allocated buffer (asynchronous version). More...
 
Result svcCreateSession (Handle *server_handle, Handle *client_handle, u32 unk0, u64 unk1)
 Creates an IPC session. More...
 
Result svcAcceptSession (Handle *session_handle, Handle port_handle)
 Accepts an IPC session. More...
 
Result svcReplyAndReceive (s32 *index, const Handle *handles, s32 handleCount, Handle replyTarget, u64 timeout)
 Performs IPC input/output. More...
 
Result svcReplyAndReceiveWithUserBuffer (s32 *index, void *usrBuffer, u64 size, const Handle *handles, s32 handleCount, Handle replyTarget, u64 timeout)
 Performs IPC input/output from an user allocated buffer. More...
 
Result svcCreatePort (Handle *portServer, Handle *portClient, s32 max_sessions, bool is_light, const char *name)
 Creates a port. More...
 
Result svcManageNamedPort (Handle *portServer, const char *name, s32 maxSessions)
 Manages a named port. More...
 
Result svcConnectToPort (Handle *session, Handle port)
 Manages a named port. More...
 
Debugging
Result svcOutputDebugString (const char *str, u64 size)
 Outputs debug text, if used during debugging. More...
 
Result svcDebugActiveProcess (Handle *debug, u64 processID)
 Debugs an active process. More...
 
Result svcBreakDebugProcess (Handle debug)
 Breaks an active debugging session. More...
 
Result svcGetDebugEvent (u8 *event_out, Handle *debug)
 Gets an incoming debug event from a debugging session. More...
 
Result svcContinueDebugEvent (Handle debug, u32 flags, u64 unk)
 Continues a debugging session. More...
 
Result svcGetDebugThreadContext (u8 *out, Handle debug, u64 threadID, u32 flags)
 Gets the context of a thread in a debugging session. More...
 
Result svcQueryDebugProcessMemory (MemoryInfo *meminfo_ptr, u32 *pageinfo, Handle debug, u64 addr)
 Queries memory information from a process that is being debugged. More...
 
Result svcReadDebugProcessMemory (void *buffer, Handle debug, u64 addr, u64 size)
 Reads memory from a process that is being debugged. More...
 
Result svcWriteDebugProcessMemory (Handle debug, void *buffer, u64 addr, u64 size)
 Writes to memory in a process that is being debugged. More...
 
Resource Limit Management
Result svcGetResourceLimitLimitValue (u64 *out, Handle reslimit_h, LimitableResource which)
 Gets the maximum value a LimitableResource can have, for a Resource Limit handle. More...
 
Result svcGetResourceLimitCurrentValue (u64 *out, Handle reslimit_h, LimitableResource which)
 Gets the maximum value a LimitableResource can have, for a Resource Limit handle. More...
 
Result svcCreateResourceLimit (Handle *out)
 Creates a new Resource Limit handle. More...
 
Result svcSetResourceLimitLimitValue (Handle reslimit, LimitableResource which, u64 value)
 Sets the value for a LimitableResource for a Resource Limit handle. More...
 
Just-in-time (JIT) compilation support
Result svcCreateJitMemory (Handle *jit_handle, void *src_addr, u64 size)
 Creates JIT memory in the caller's address space [4.0.0+]. More...
 
Result svcMapJitMemory (Handle jit_handle, JitMapOperation op, void *dst_addr, u64 size, u64 perm)
 Maps JIT memory in the caller's address space [4.0.0+]. More...
 
Device memory-mapped I/O (MMIO)
Result svcReadWriteRegister (u32 *outVal, u64 regAddr, u32 rwMask, u32 inVal)
 Reads/writes a protected MMIO register. More...
 
Result svcCreateInterruptEvent (Handle *handle, u64 irqNum, u32 flag)
 Creates an event and binds it to a specific hardware interrupt. More...
 
Result svcQueryPhysicalAddress (u64 out[3], u64 virtaddr)
 Queries information about a certain virtual address, including its physical address. More...
 
Result svcQueryIoMapping (u64 *virtaddr, u64 physaddr, u64 size)
 Returns a virtual address mapped to a given IO range. More...
 
I/O memory management unit (IOMMU)
Result svcCreateDeviceAddressSpace (Handle *handle, u64 dev_addr, u64 dev_size)
 Creates a virtual address space for binding device address spaces. More...
 
Result svcAttachDeviceAddressSpace (u64 device, Handle handle)
 Attaches a device address space to a device. More...
 
Result svcDetachDeviceAddressSpace (u64 device, Handle handle)
 Detaches a device address space from a device. More...
 
Result svcMapDeviceAddressSpaceByForce (Handle handle, Handle proc_handle, u64 map_addr, u64 dev_size, u64 dev_addr, u32 perm)
 Maps an attached device address space to an userspace address. More...
 
Result svcMapDeviceAddressSpaceAligned (Handle handle, Handle proc_handle, u64 map_addr, u64 dev_size, u64 dev_addr, u32 perm)
 Maps an attached device address space to an userspace address. More...
 
Result svcUnmapDeviceAddressSpace (Handle handle, Handle proc_handle, u64 map_addr, u64 map_size, u64 dev_addr)
 Unmaps an attached device address space from an userspace address. More...
 
( ͡° ͜ʖ ͡°)
u64 svcCallSecureMonitor (SecmonArgs *regs)
 Calls a secure monitor function (TrustZone, EL3). More...
 

Detailed Description

Wrappers for kernel syscalls.

Enumeration Type Documentation

JIT mapping operations.

Enumerator
JitMapOperation_MapOwner 

Map owner.

JitMapOperation_MapSlave 

Map slave.

JitMapOperation_UnmapOwner 

Unmap owner.

JitMapOperation_UnmapSlave 

Unmap slave.

Limitable Resources.

Enumerator
LimitableResource_Memory 

How much memory can a process map.

LimitableResource_Threads 

How many threads can a process spawn.

LimitableResource_Events 

How many events can a process have.

LimitableResource_TransferMemories 

How many transfer memories can a process make.

LimitableResource_Sessions 

How many sessions can a process own.

Memory attribute bitmasks.

Enumerator
MemAttr_IsBorrowed 

Is borrowed memory.

MemAttr_IsIpcMapped 

Is IPC mapped (when IpcRefCount > 0).

MemAttr_IsDeviceMapped 

Is device mapped (when DeviceRefCount > 0).

MemAttr_IsUncached 

Is uncached.

Memory state bitmasks.

Enumerator
MemState_Type 

Type field (see MemoryType).

MemState_PermChangeAllowed 

Permission change allowed.

MemState_ForceRwByDebugSyscalls 

Force read/writable by debug syscalls.

MemState_IpcSendAllowed_Type0 

IPC type 0 send allowed.

MemState_IpcSendAllowed_Type3 

IPC type 3 send allowed.

MemState_IpcSendAllowed_Type1 

IPC type 1 send allowed.

MemState_ProcessPermChangeAllowed 

Process permission change allowed.

MemState_MapAllowed 

Map allowed.

MemState_UnmapProcessCodeMemAllowed 

Unmap process code memory allowed.

MemState_TransferMemAllowed 

Transfer memory allowed.

MemState_QueryPAddrAllowed 

Query physical address allowed.

MemState_MapDeviceAllowed 

Map device allowed (svcMapDeviceAddressSpace and svcMapDeviceAddressSpaceByForce).

MemState_MapDeviceAlignedAllowed 

Map device aligned allowed.

MemState_IpcBufferAllowed 

IPC buffer allowed.

MemState_IsPoolAllocated 

Is pool allocated.

MemState_IsRefCounted 

Alias for MemState_IsPoolAllocated.

MemState_MapProcessAllowed 

Map process allowed.

MemState_AttrChangeAllowed 

Attribute change allowed.

MemState_JitMemAllowed 

JIT memory allowed.

enum MemoryType

Memory type enumeration (lower 8 bits of MemoryState)

Enumerator
MemType_Unmapped 

Unmapped memory.

MemType_Io 

Mapped by kernel capability parsing in svcCreateProcess.

MemType_Normal 

Mapped by kernel capability parsing in svcCreateProcess.

MemType_CodeStatic 

Mapped during svcCreateProcess.

MemType_CodeMutable 

Transition from MemType_CodeStatic performed by svcSetProcessMemoryPermission.

MemType_Heap 

Mapped using svcSetHeapSize.

MemType_SharedMem 

Mapped using svcMapSharedMemory.

MemType_WeirdMappedMem 

Mapped using svcMapMemory.

MemType_ModuleCodeStatic 

Mapped using svcMapProcessCodeMemory.

MemType_ModuleCodeMutable 

Transition from MemType_ModuleCodeStatic performed by svcSetProcessMemoryPermission.

MemType_IpcBuffer0 

IPC buffers with descriptor flags=0.

MemType_MappedMemory 

Mapped using svcMapMemory.

MemType_ThreadLocal 

Mapped during svcCreateThread.

MemType_TransferMemIsolated 

Mapped using svcMapTransferMemory when the owning process has perm=0.

MemType_TransferMem 

Mapped using svcMapTransferMemory when the owning process has perm!=0.

MemType_ProcessMem 

Mapped using svcMapProcessMemory.

MemType_Reserved 

Reserved.

MemType_IpcBuffer1 

IPC buffers with descriptor flags=1.

MemType_IpcBuffer3 

IPC buffers with descriptor flags=3.

MemType_KernelStack 

Mapped in kernel during svcCreateThread.

MemType_JitReadOnly 

Mapped in kernel during svcMapJitMemory.

MemType_JitWritable 

Mapped in kernel during svcMapJitMemory.

enum Permission

Memory permission bitmasks.

Enumerator
Perm_None 

No permissions.

Perm_R 

Read permission.

Perm_W 

Write permission.

Perm_X 

Execute permission.

Perm_Rw 

Read/write permissions.

Perm_Rx 

Read/execute permissions.

Perm_DontCare 

Don't care.

Process Information.

Enumerator
ProcessInfoType_ProcessState 

What state is a process in.

Process States.

Enumerator
ProcessState_Created 

Newly-created process.

ProcessState_DebugAttached 

Process attached to debugger.

ProcessState_DebugDetached 

Process detached from debugger.

ProcessState_Crashed 

Process that has just creashed.

ProcessState_Running 

Process executing normally.

ProcessState_Exiting 

Process has begun exiting.

ProcessState_Exited 

Process has finished exiting.

ProcessState_DebugSuspended 

Process execution suspended by debugger.

Function Documentation

Result svcAcceptSession ( Handle session_handle,
Handle  port_handle 
)

Accepts an IPC session.

Returns
Result code.
Note
Syscall number 0x41.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcArbitrateLock ( u32  wait_tag,
u32 tag_location,
u32  self_tag 
)

Arbitrates a mutex lock operation in userspace.

Returns
Result code.
Note
Syscall number 0x1A.
Result svcArbitrateUnlock ( u32 tag_location)

Arbitrates a mutex unlock operation in userspace.

Returns
Result code.
Note
Syscall number 0x1B.
Result svcAttachDeviceAddressSpace ( u64  device,
Handle  handle 
)

Attaches a device address space to a device.

Returns
Result code.
Note
Syscall number 0x57.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcBreak ( u32  breakReason,
u64  inval1,
u64  inval2 
)

Breaks execution.

Panic.

Parameters
[in]breakReasonBreak reason.
[in]inval1First break parameter.
[in]inval2Second break parameter.
Returns
Result code.
Note
Syscall number 0x26.
Result svcBreakDebugProcess ( Handle  debug)

Breaks an active debugging session.

Returns
Result code.
Note
Syscall number 0x61.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
u64 svcCallSecureMonitor ( SecmonArgs regs)

Calls a secure monitor function (TrustZone, EL3).

Parameters
regsArguments to pass to the secure monitor.
Returns
Return value from the secure monitor.
Note
Syscall number 0x7F.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCancelSynchronization ( Handle  thread)

Waits a svcWaitSynchronization operation being done on a synchronization object in another thread.

Returns
Result code.
Note
Syscall number 0x19.
Result svcClearEvent ( Handle  handle)

Clears an event's signalled status.

Returns
Result code.
Note
Syscall number 0x12.
Result svcCloseHandle ( Handle  handle)

Closes a handle, decrementing the reference count of the corresponding kernel object.

This might result in the kernel freeing the object.

Parameters
handleHandle to close.
Returns
Result code.
Note
Syscall number 0x16.
Result svcConnectToNamedPort ( Handle session,
const char *  name 
)

Connects to a registered named port.

Returns
Result code.
Note
Syscall number 0x1F.
Result svcConnectToPort ( Handle session,
Handle  port 
)

Manages a named port.

Returns
Result code.
Note
Syscall number 0x72.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcContinueDebugEvent ( Handle  debug,
u32  flags,
u64  unk 
)

Continues a debugging session.

Returns
Result code.
Note
Syscall number 0x64.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateDeviceAddressSpace ( Handle handle,
u64  dev_addr,
u64  dev_size 
)

Creates a virtual address space for binding device address spaces.

Returns
Result code.
Note
Syscall number 0x56.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateEvent ( Handle server_handle,
Handle client_handle 
)

Creates a system event.

Returns
Result code.
Note
Syscall number 0x45.
Result svcCreateInterruptEvent ( Handle handle,
u64  irqNum,
u32  flag 
)

Creates an event and binds it to a specific hardware interrupt.

Returns
Result code.
Note
Syscall number 0x53.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateJitMemory ( Handle jit_handle,
void *  src_addr,
u64  size 
)

Creates JIT memory in the caller's address space [4.0.0+].

Returns
Result code.
Note
Syscall number 0x4B.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreatePort ( Handle portServer,
Handle portClient,
s32  max_sessions,
bool  is_light,
const char *  name 
)

Creates a port.

Returns
Result code.
Note
Syscall number 0x70.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateProcess ( Handle out,
void *  proc_info,
u32 caps,
u64  cap_num 
)

Creates a new process.

Returns
Result code.
Note
Syscall number 0x79.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateResourceLimit ( Handle out)

Creates a new Resource Limit handle.

Returns
Result code.
Note
Syscall number 0x7D.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateSession ( Handle server_handle,
Handle client_handle,
u32  unk0,
u64  unk1 
)

Creates an IPC session.

Returns
Result code.
Note
Syscall number 0x40.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateSharedMemory ( Handle out,
size_t  size,
u32  local_perm,
u32  other_perm 
)

Creates a block of shared memory.

Returns
Result code.
Note
Syscall number 0x50.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcCreateThread ( Handle out,
void *  entry,
void *  arg,
void *  stack_top,
int  prio,
int  cpuid 
)

Creates a thread.

Returns
Result code.
Note
Syscall number 0x08.
Result svcCreateTransferMemory ( Handle out,
void *  addr,
size_t  size,
u32  perm 
)

Creates a block of transfer memory.

Returns
Result code.
Note
Syscall number 0x15.
Result svcDebugActiveProcess ( Handle debug,
u64  processID 
)

Debugs an active process.

Returns
Result code.
Note
Syscall number 0x60.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcDetachDeviceAddressSpace ( u64  device,
Handle  handle 
)

Detaches a device address space from a device.

Returns
Result code.
Note
Syscall number 0x58.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
void svcExitProcess ( void  )

Exits the current process.

Note
Syscall number 0x07.
void svcExitThread ( void  )

Exits the current thread.

Note
Syscall number 0x0A.
u32 svcGetCurrentProcessorNumber ( void  )

Gets the current processor's number.

Returns
The current processor's number.
Note
Syscall number 0x10.
Result svcGetDebugEvent ( u8 event_out,
Handle debug 
)

Gets an incoming debug event from a debugging session.

Returns
Result code.
Note
Syscall number 0x63.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcGetDebugThreadContext ( u8 out,
Handle  debug,
u64  threadID,
u32  flags 
)

Gets the context of a thread in a debugging session.

Returns
Result code.
Note
Syscall number 0x67.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcGetInfo ( u64 out,
u64  id0,
Handle  handle,
u64  id1 
)

Retrieves information about the system, or a certain kernel object.

Parameters
[out]outVariable to which store the information.
[in]id0First ID of the property to retrieve.
[in]handleHandle of the object to retrieve information from, or INVALID_HANDLE to retrieve information about the system.
[in]id1Second ID of the property to retrieve.
Returns
Result code.
Remarks
The full list of property IDs can be found on the switchbrew.org wiki.
Note
Syscall number 0x29.
Result svcGetProcessId ( u64 processID,
Handle  handle 
)

Gets the PID associated with a process.

Returns
Result code.
Note
Syscall number 0x24.
Result svcGetProcessInfo ( u64 out,
Handle  proc,
ProcessInfoType  which 
)

Gets a ProcessInfoType for a process.

Returns
Result code.
Note
Syscall number 0x7C.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcGetProcessList ( u32 num_out,
u64 pids_out,
u32  max_pids 
)

Retrieves a list of all running processes.

Returns
Result code.
Note
Syscall number 0x65.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcGetResourceLimitCurrentValue ( u64 out,
Handle  reslimit_h,
LimitableResource  which 
)

Gets the maximum value a LimitableResource can have, for a Resource Limit handle.

Returns
Result code.
Note
Syscall number 0x31.
Result svcGetResourceLimitLimitValue ( u64 out,
Handle  reslimit_h,
LimitableResource  which 
)

Gets the maximum value a LimitableResource can have, for a Resource Limit handle.

Returns
Result code.
Note
Syscall number 0x30.
Result svcGetSystemInfo ( u64 out,
u64  id0,
Handle  handle,
u64  id1 
)

Retrieves privileged information about the system, or a certain kernel object.

Parameters
[out]outVariable to which store the information.
[in]id0First ID of the property to retrieve.
[in]handleHandle of the object to retrieve information from, or INVALID_HANDLE to retrieve information about the system.
[in]id1Second ID of the property to retrieve.
Returns
Result code.
Remarks
The full list of property IDs can be found on the switchbrew.org wiki.
Note
Syscall number 0x6F.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
u64 svcGetSystemTick ( void  )

Gets the current system tick.

Returns
The current system tick.
Note
Syscall number 0x1E.
Result svcGetThreadId ( u64 threadID,
Handle  handle 
)

Gets the TID associated with a process.

Returns
Result code.
Note
Syscall number 0x25.
Result svcGetThreadPriority ( u32 priority,
Handle  handle 
)

Gets a thread's priority.

Returns
Result code.
Note
Syscall number 0x0C.
Result svcManageNamedPort ( Handle portServer,
const char *  name,
s32  maxSessions 
)

Manages a named port.

Returns
Result code.
Note
Syscall number 0x71.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapDeviceAddressSpaceAligned ( Handle  handle,
Handle  proc_handle,
u64  map_addr,
u64  dev_size,
u64  dev_addr,
u32  perm 
)

Maps an attached device address space to an userspace address.

Returns
Result code.
Remarks
The userspace destination address must have the MemState_MapDeviceAlignedAllowed bit set.
Note
Syscall number 0x5A.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapDeviceAddressSpaceByForce ( Handle  handle,
Handle  proc_handle,
u64  map_addr,
u64  dev_size,
u64  dev_addr,
u32  perm 
)

Maps an attached device address space to an userspace address.

Returns
Result code.
Remarks
The userspace destination address must have the MemState_MapDeviceAllowed bit set.
Note
Syscall number 0x59.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapJitMemory ( Handle  jit_handle,
JitMapOperation  op,
void *  dst_addr,
u64  size,
u64  perm 
)

Maps JIT memory in the caller's address space [4.0.0+].

Returns
Result code.
Note
Syscall number 0x4C.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapMemory ( void *  dst_addr,
void *  src_addr,
u64  size 
)

Maps a memory range into a different range.

Mainly used for adding guard pages around stack. Source range gets reprotected to Perm_None (it can no longer be accessed), and MemAttr_IsBorrowed is set in the source MemoryAttribute.

Parameters
[in]dst_addrDestination address.
[in]src_addrSource address.
[in]sizeSize of the range.
Returns
Result code.
Note
Syscall number 0x04.
Result svcMapPhysicalMemory ( void *  address,
u64  size 
)

Maps new heap memory at the desired address.

[3.0.0+]

Returns
Result code.
Note
Syscall number 0x2A.
Result svcMapPhysicalMemoryUnsafe ( void *  address,
u64  size 
)

Maps unsafe memory (usable for GPU DMA) for a system module at the desired address.

[5.0.0+]

Returns
Result code.
Note
Syscall number 0x48.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapProcessCodeMemory ( Handle  proc,
u64  dst,
u64  src,
u64  size 
)

Maps normal heap in a certain process as executable code (used when loading NROs).

Parameters
[in]procProcess handle (cannot be CUR_PROCESS_HANDLE).
[in]dstDestination mapping address.
[in]srcSource mapping address.
[in]sizeSize of the mapping.
Returns
Result code.
Note
Syscall number 0x77.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapProcessMemory ( void *  dst,
Handle  proc,
u64  src,
u64  size 
)

Maps the src address from the supplied process handle into the current process.

Parameters
[in]dstAddress to which map the memory in the current process.
[in]procProcess handle.
[in]srcSource mapping address.
[in]sizeSize of the memory.
Returns
Result code.
Remarks
This allows mapping code and rodata with RW- permission.
Note
Syscall number 0x74.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcMapSharedMemory ( Handle  handle,
void *  addr,
size_t  size,
u32  perm 
)

Maps a block of shared memory.

Returns
Result code.
Note
Syscall number 0x13.
Result svcMapTransferMemory ( Handle  tmem_handle,
void *  addr,
size_t  size,
u32  perm 
)

Maps a block of transfer memory.

Returns
Result code.
Note
Syscall number 0x51.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcOutputDebugString ( const char *  str,
u64  size 
)

Outputs debug text, if used during debugging.

Parameters
[in]strText to output.
[in]sizeSize of the text in bytes.
Returns
Result code.
Note
Syscall number 0x27.
Result svcQueryDebugProcessMemory ( MemoryInfo meminfo_ptr,
u32 pageinfo,
Handle  debug,
u64  addr 
)

Queries memory information from a process that is being debugged.

Returns
Result code.
Note
Syscall number 0x69.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcQueryIoMapping ( u64 virtaddr,
u64  physaddr,
u64  size 
)

Returns a virtual address mapped to a given IO range.

Returns
Result code.
Note
Syscall number 0x55.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcQueryMemory ( MemoryInfo meminfo_ptr,
u32 pageinfo,
u64  addr 
)

Query information about an address.

Will always fetch the lowest page-aligned mapping that contains the provided address.

Parameters
[out]meminfo_ptrMemoryInfo structure which will be filled in.
[out]page_infoPage information which will be filled in.
[in]addrAddress to query.
Returns
Result code.
Note
Syscall number 0x06.
Result svcQueryPhysicalAddress ( u64  out[3],
u64  virtaddr 
)

Queries information about a certain virtual address, including its physical address.

Returns
Result code.
Note
Syscall number 0x54.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcReadDebugProcessMemory ( void *  buffer,
Handle  debug,
u64  addr,
u64  size 
)

Reads memory from a process that is being debugged.

Returns
Result code.
Note
Syscall number 0x6A.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcReadWriteRegister ( u32 outVal,
u64  regAddr,
u32  rwMask,
u32  inVal 
)

Reads/writes a protected MMIO register.

Returns
Result code.
Note
Syscall number 0x4E.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcReplyAndReceive ( s32 index,
const Handle handles,
s32  handleCount,
Handle  replyTarget,
u64  timeout 
)

Performs IPC input/output.

Returns
Result code.
Note
Syscall number 0x43.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcReplyAndReceiveWithUserBuffer ( s32 index,
void *  usrBuffer,
u64  size,
const Handle handles,
s32  handleCount,
Handle  replyTarget,
u64  timeout 
)

Performs IPC input/output from an user allocated buffer.

Returns
Result code.
Note
Syscall number 0x44.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcResetSignal ( Handle  handle)

Resets a signal.

Returns
Result code.
Note
Syscall number 0x17.
Result svcSendAsyncRequestWithUserBuffer ( Handle handle,
void *  usrBuffer,
u64  size,
Handle  session 
)

Sends an IPC synchronization request to a session from an user allocated buffer (asynchronous version).

Returns
Result code.
Remarks
size must be allocated to 0x1000 bytes.
Note
Syscall number 0x23.
Result svcSendSyncRequest ( Handle  session)

Sends an IPC synchronization request to a session.

Returns
Result code.
Note
Syscall number 0x21.
Result svcSendSyncRequestWithUserBuffer ( void *  usrBuffer,
u64  size,
Handle  session 
)

Sends an IPC synchronization request to a session from an user allocated buffer.

Returns
Result code.
Remarks
size must be allocated to 0x1000 bytes.
Note
Syscall number 0x22.
Result svcSetHeapSize ( void **  out_addr,
u64  size 
)

Set the process heap to a given size.

It can both extend and shrink the heap.

Parameters
[out]out_addrVariable to which write the address of the heap (which is randomized and fixed by the kernel)
[in]sizeSize of the heap, must be a multiple of 0x2000000 and [2.0.0+] less than 0x18000000.
Returns
Result code.
Note
Syscall number 0x00.
Result svcSetMemoryAttribute ( void *  addr,
u64  size,
u32  val0,
u32  val1 
)

Set the memory attributes of a (page-aligned) range of memory.

Parameters
[in]addrStart address of the range.
[in]sizeSize of the range, in bytes.
[in]val0State0
[in]val1State1
Returns
Result code.
Remarks
See switchbrew.org Wiki for more details.
Note
Syscall number 0x02.
Result svcSetMemoryPermission ( void *  addr,
u64  size,
u32  perm 
)

Set the memory permissions of a (page-aligned) range of memory.

Parameters
[in]addrStart address of the range.
[in]sizeSize of the range, in bytes.
[in]permPermissions (see Permission).
Returns
Result code.
Remarks
Perm_X is not allowed. Setting write-only is not allowed either (Perm_W). This can be used to move back and forth between Perm_None, Perm_R and Perm_Rw.
Note
Syscall number 0x01.
Result svcSetProcessMemoryPermission ( Handle  proc,
u64  addr,
u64  size,
u32  perm 
)

Sets the memory permissions for the specified memory with the supplied process handle.

Parameters
[in]procProcess handle.
[in]addrAddress of the memory.
[in]sizeSize of the memory.
[in]permPermissions (see Permission).
Returns
Result code.
Remarks
This returns an error (0xD801) when perm is >0x5, hence -WX and RWX are not allowed.
Note
Syscall number 0x73.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcSetResourceLimitLimitValue ( Handle  reslimit,
LimitableResource  which,
u64  value 
)

Sets the value for a LimitableResource for a Resource Limit handle.

Returns
Result code.
Note
Syscall number 0x7E.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcSetThreadActivity ( Handle  thread,
bool  paused 
)

Configures the pause/unpause status of a thread.

Returns
Result code.
Note
Syscall number 0x32.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcSetThreadPriority ( Handle  handle,
u32  priority 
)

Sets a thread's priority.

Returns
Result code.
Note
Syscall number 0x0D.
Result svcSetUnsafeLimit ( u64  size)

Sets the system-wide limit for unsafe memory mappable using svcMapPhysicalMemoryUnsafe.

[5.0.0+]

Returns
Result code.
Note
Syscall number 0x4A.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcSignalEvent ( Handle  handle)

Sets an event's signalled status.

Returns
Result code.
Note
Syscall number 0x11.
Result svcSignalProcessWideKey ( u32 key,
s32  num 
)

Performs a condition variable wake-up operation in userspace.

Returns
Result code.
Note
Syscall number 0x1D.
Result svcSleepThread ( u64  nano)

Sleeps the current thread for the specified amount of time.

Returns
Result code.
Note
Syscall number 0x0B.
Result svcStartProcess ( Handle  proc,
s32  main_prio,
s32  default_cpu,
u32  stack_size 
)

Starts executing a freshly created process.

Returns
Result code.
Note
Syscall number 0x7A.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcStartThread ( Handle  handle)

Starts a freshly created thread.

Returns
Result code.
Note
Syscall number 0x09.
Result svcTerminateProcess ( Handle  proc)

Terminates a running process.

Returns
Result code.
Note
Syscall number 0x7B.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcUnmapDeviceAddressSpace ( Handle  handle,
Handle  proc_handle,
u64  map_addr,
u64  map_size,
u64  dev_addr 
)

Unmaps an attached device address space from an userspace address.

Returns
Result code.
Note
Syscall number 0x5C.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcUnmapMemory ( void *  dst_addr,
void *  src_addr,
u64  size 
)

Unmaps a region that was previously mapped with svcMapMemory.

Parameters
[in]dst_addrDestination address.
[in]src_addrSource address.
[in]sizeSize of the range.
Returns
Result code.
Note
Syscall number 0x05.
Result svcUnmapPhysicalMemory ( void *  address,
u64  size 
)

Undoes the effects of svcMapPhysicalMemory.

[3.0.0+]

Returns
Result code.
Note
Syscall number 0x2B.
Result svcUnmapPhysicalMemoryUnsafe ( void *  address,
u64  size 
)

Undoes the effects of svcMapPhysicalMemoryUnsafe.

[5.0.0+]

Returns
Result code.
Note
Syscall number 0x49.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcUnmapProcessCodeMemory ( Handle  proc,
u64  dst,
u64  src,
u64  size 
)

Undoes the effects of svcMapProcessCodeMemory.

Parameters
[in]procProcess handle (cannot be CUR_PROCESS_HANDLE).
[in]dstDestination mapping address.
[in]srcSource mapping address.
[in]sizeSize of the mapping.
Returns
Result code.
Note
Syscall number 0x78.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcUnmapProcessMemory ( void *  dst,
Handle  proc,
u64  src,
u64  size 
)

Undoes the effects of svcMapProcessMemory.

Parameters
[in]dstDestination mapping address
[in]procProcess handle.
[in]srcAddress of the memory in the process.
[in]sizeSize of the memory.
Returns
Result code.
Remarks
This allows mapping code and rodata with RW- permission.
Note
Syscall number 0x75.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcUnmapSharedMemory ( Handle  handle,
void *  addr,
size_t  size 
)

Unmaps a block of shared memory.

Returns
Result code.
Note
Syscall number 0x14.
Result svcUnmapTransferMemory ( Handle  tmem_handle,
void *  addr,
size_t  size 
)

Unmaps a block of transfer memory.

Returns
Result code.
Note
Syscall number 0x52.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.
Result svcWaitProcessWideKeyAtomic ( u32 key,
u32 tag_location,
u32  self_tag,
u64  timeout 
)

Performs a condition variable wait operation in userspace.

Returns
Result code.
Note
Syscall number 0x1C.
Result svcWaitSynchronization ( s32 index,
const Handle handles,
s32  handleCount,
u64  timeout 
)

Waits on one or more synchronization objects, optionally with a timeout.

Returns
Result code.
Note
Syscall number 0x18.
static Result svcWaitSynchronizationSingle ( Handle  handle,
u64  timeout 
)
inlinestatic

Waits on a single synchronization object, optionally with a timeout.

Returns
Result code.
Note
Wrapper for svcWaitSynchronization.
Result svcWriteDebugProcessMemory ( Handle  debug,
void *  buffer,
u64  addr,
u64  size 
)

Writes to memory in a process that is being debugged.

Returns
Result code.
Note
Syscall number 0x6B.
Warning
This is a privileged syscall. Use envIsSyscallHinted to check if it is available.