libnx
svc.h
Go to the documentation of this file.
1 /**
2  * @file svc.h
3  * @brief Wrappers for kernel syscalls.
4  * @copyright libnx Authors
5  */
6 #pragma once
7 #include "../types.h"
8 
9 /// Pseudo handle for the current process.
10 #define CUR_PROCESS_HANDLE 0xFFFF8001
11 
12 /// Pseudo handle for the current thread.
13 #define CUR_THREAD_HANDLE 0xFFFF8000
14 
15 /// Memory type enumeration (lower 8 bits of \ref MemoryState)
16 typedef enum {
17  MemType_Unmapped=0x00, ///< Unmapped memory.
18  MemType_Io=0x01, ///< Mapped by kernel capability parsing in \ref svcCreateProcess.
19  MemType_Normal=0x02, ///< Mapped by kernel capability parsing in \ref svcCreateProcess.
20  MemType_CodeStatic=0x03, ///< Mapped during \ref svcCreateProcess.
21  MemType_CodeMutable=0x04, ///< Transition from MemType_CodeStatic performed by \ref svcSetProcessMemoryPermission.
22  MemType_Heap=0x05, ///< Mapped using \ref svcSetHeapSize.
23  MemType_SharedMem=0x06, ///< Mapped using \ref svcMapSharedMemory.
24  MemType_WeirdMappedMem=0x07, ///< Mapped using \ref svcMapMemory.
25  MemType_ModuleCodeStatic=0x08, ///< Mapped using \ref svcMapProcessCodeMemory.
26  MemType_ModuleCodeMutable=0x09, ///< Transition from \ref MemType_ModuleCodeStatic performed by \ref svcSetProcessMemoryPermission.
27  MemType_IpcBuffer0=0x0A, ///< IPC buffers with descriptor flags=0.
28  MemType_MappedMemory=0x0B, ///< Mapped using \ref svcMapMemory.
29  MemType_ThreadLocal=0x0C, ///< Mapped during \ref svcCreateThread.
30  MemType_TransferMemIsolated=0x0D, ///< Mapped using \ref svcMapTransferMemory when the owning process has perm=0.
31  MemType_TransferMem=0x0E, ///< Mapped using \ref svcMapTransferMemory when the owning process has perm!=0.
32  MemType_ProcessMem=0x0F, ///< Mapped using \ref svcMapProcessMemory.
33  MemType_Reserved=0x10, ///< Reserved.
34  MemType_IpcBuffer1=0x11, ///< IPC buffers with descriptor flags=1.
35  MemType_IpcBuffer3=0x12, ///< IPC buffers with descriptor flags=3.
36  MemType_KernelStack=0x13, ///< Mapped in kernel during \ref svcCreateThread.
37  MemType_JitReadOnly=0x14, ///< Mapped in kernel during \ref svcMapJitMemory.
38  MemType_JitWritable=0x15, ///< Mapped in kernel during \ref svcMapJitMemory.
39 } MemoryType;
40 
41 /// Memory state bitmasks.
42 typedef enum {
43  MemState_Type=0xFF, ///< Type field (see \ref MemoryType).
44  MemState_PermChangeAllowed=BIT(8), ///< Permission change allowed.
45  MemState_ForceRwByDebugSyscalls=BIT(9), ///< Force read/writable by debug syscalls.
46  MemState_IpcSendAllowed_Type0=BIT(10), ///< IPC type 0 send allowed.
47  MemState_IpcSendAllowed_Type3=BIT(11), ///< IPC type 3 send allowed.
48  MemState_IpcSendAllowed_Type1=BIT(12), ///< IPC type 1 send allowed.
49  MemState_ProcessPermChangeAllowed=BIT(14), ///< Process permission change allowed.
50  MemState_MapAllowed=BIT(15), ///< Map allowed.
51  MemState_UnmapProcessCodeMemAllowed=BIT(16), ///< Unmap process code memory allowed.
52  MemState_TransferMemAllowed=BIT(17), ///< Transfer memory allowed.
53  MemState_QueryPAddrAllowed=BIT(18), ///< Query physical address allowed.
54  MemState_MapDeviceAllowed=BIT(19), ///< Map device allowed (\ref svcMapDeviceAddressSpace and \ref svcMapDeviceAddressSpaceByForce).
55  MemState_MapDeviceAlignedAllowed=BIT(20), ///< Map device aligned allowed.
56  MemState_IpcBufferAllowed=BIT(21), ///< IPC buffer allowed.
57  MemState_IsPoolAllocated=BIT(22), ///< Is pool allocated.
58  MemState_IsRefCounted=MemState_IsPoolAllocated, ///< Alias for \ref MemState_IsPoolAllocated.
59  MemState_MapProcessAllowed=BIT(23), ///< Map process allowed.
60  MemState_AttrChangeAllowed=BIT(24), ///< Attribute change allowed.
61  MemState_JitMemAllowed=BIT(25), ///< JIT memory allowed.
62 } MemoryState;
63 
64 /// Memory attribute bitmasks.
65 typedef enum {
66  MemAttr_IsBorrowed=BIT(0), ///< Is borrowed memory.
67  MemAttr_IsIpcMapped=BIT(1), ///< Is IPC mapped (when IpcRefCount > 0).
68  MemAttr_IsDeviceMapped=BIT(2), ///< Is device mapped (when DeviceRefCount > 0).
69  MemAttr_IsUncached=BIT(3), ///< Is uncached.
71 
72 /// Memory permission bitmasks.
73 typedef enum {
74  Perm_None = 0, ///< No permissions.
75  Perm_R = BIT(0), ///< Read permission.
76  Perm_W = BIT(1), ///< Write permission.
77  Perm_X = BIT(2), ///< Execute permission.
78  Perm_Rw = Perm_R | Perm_W, ///< Read/write permissions.
79  Perm_Rx = Perm_R | Perm_X, ///< Read/execute permissions.
80  Perm_DontCare = BIT(28), ///< Don't care
81 } Permission;
82 
83 /// Memory information structure.
84 typedef struct {
85  u64 addr; ///< Base address.
86  u64 size; ///< Size.
87  u32 type; ///< Memory type (see lower 8 bits of \ref MemoryState).
88  u32 attr; ///< Memory attributes (see \ref MemoryAttribute).
89  u32 perm; ///< Memory permissions (see \ref Permission).
90  u32 device_refcount; ///< Device reference count.
91  u32 ipc_refcount; ///< IPC reference count.
92  u32 padding; ///< Padding.
93 } MemoryInfo;
94 
95 /// Secure monitor arguments.
96 typedef struct {
97  u64 X[8]; ///< Values of X0 through X7.
99 
100 /// JIT mapping operations
101 typedef enum {
102  JitMapOperation_MapOwner=0, ///< Map owner.
103  JitMapOperation_MapSlave=1, ///< Map slave.
104  JitMapOperation_UnmapOwner=2, ///< Unmap owner.
105  JitMapOperation_UnmapSlave=3, ///< Unmap slave.
107 
108 /// Limitable Resources.
109 typedef enum {
110  LimitableResource_Memory=0, ///<How much memory can a process map.
111  LimitableResource_Threads=1, ///<How many threads can a process spawn.
112  LimitableResource_Events=2, ///<How many events can a process have.
113  LimitableResource_TransferMemories=3, ///<How many transfer memories can a process make.
114  LimitableResource_Sessions=4, ///<How many sessions can a process own.
116 
117 /// Process Information.
118 typedef enum {
119  ProcessInfoType_ProcessState=0, ///<What state is a process in.
121 
122 /// Process States.
123 typedef enum {
124  ProcessState_Created=0, ///<Newly-created process.
125  ProcessState_DebugAttached=1, ///<Process attached to debugger.
126  ProcessState_DebugDetached=2, ///<Process detached from debugger.
127  ProcessState_Crashed=3, ///<Process that has just creashed.
128  ProcessState_Running=4, ///<Process executing normally.
129  ProcessState_Exiting=5, ///<Process has begun exiting.
130  ProcessState_Exited=6, ///<Process has finished exiting.
131  ProcessState_DebugSuspended=7, ///<Process execution suspended by debugger.
132 } ProcessState;
133 
134 ///@name Memory management
135 ///@{
136 
137 /**
138  * @brief Set the process heap to a given size. It can both extend and shrink the heap.
139  * @param[out] out_addr Variable to which write the address of the heap (which is randomized and fixed by the kernel)
140  * @param[in] size Size of the heap, must be a multiple of 0x2000000 and [2.0.0+] less than 0x18000000.
141  * @return Result code.
142  * @note Syscall number 0x00.
143  */
144 Result svcSetHeapSize(void** out_addr, u64 size);
145 
146 /**
147  * @brief Set the memory permissions of a (page-aligned) range of memory.
148  * @param[in] addr Start address of the range.
149  * @param[in] size Size of the range, in bytes.
150  * @param[in] perm Permissions (see \ref Permission).
151  * @return Result code.
152  * @remark Perm_X is not allowed. Setting write-only is not allowed either (Perm_W).
153  * This can be used to move back and forth between Perm_None, Perm_R and Perm_Rw.
154  * @note Syscall number 0x01.
155  */
156 Result svcSetMemoryPermission(void* addr, u64 size, u32 perm);
157 
158 /**
159  * @brief Set the memory attributes of a (page-aligned) range of memory.
160  * @param[in] addr Start address of the range.
161  * @param[in] size Size of the range, in bytes.
162  * @param[in] val0 State0
163  * @param[in] val1 State1
164  * @return Result code.
165  * @remark See <a href="http://switchbrew.org/index.php?title=SVC#svcSetMemoryAttribute">switchbrew.org Wiki</a> for more details.
166  * @note Syscall number 0x02.
167  */
168 Result svcSetMemoryAttribute(void* addr, u64 size, u32 val0, u32 val1);
169 
170 /**
171  * @brief Maps a memory range into a different range. Mainly used for adding guard pages around stack.
172  * Source range gets reprotected to Perm_None (it can no longer be accessed), and \ref MemAttr_IsBorrowed is set in the source \ref MemoryAttribute.
173  * @param[in] dst_addr Destination address.
174  * @param[in] src_addr Source address.
175  * @param[in] size Size of the range.
176  * @return Result code.
177  * @note Syscall number 0x04.
178  */
179 Result svcMapMemory(void* dst_addr, void* src_addr, u64 size);
180 
181 /**
182  * @brief Unmaps a region that was previously mapped with \ref svcMapMemory.
183  * @param[in] dst_addr Destination address.
184  * @param[in] src_addr Source address.
185  * @param[in] size Size of the range.
186  * @return Result code.
187  * @note Syscall number 0x05.
188  */
189 Result svcUnmapMemory(void* dst_addr, void* src_addr, u64 size);
190 
191 /**
192  * @brief Query information about an address. Will always fetch the lowest page-aligned mapping that contains the provided address.
193  * @param[out] meminfo_ptr \ref MemoryInfo structure which will be filled in.
194  * @param[out] page_info Page information which will be filled in.
195  * @param[in] addr Address to query.
196  * @return Result code.
197  * @note Syscall number 0x06.
198  */
199 Result svcQueryMemory(MemoryInfo* meminfo_ptr, u32 *pageinfo, u64 addr);
200 
201 ///@}
202 
203 ///@name Process and thread management
204 ///@{
205 
206 /**
207  * @brief Exits the current process.
208  * @note Syscall number 0x07.
209  */
210 
211 void NORETURN svcExitProcess(void);
212 
213 /**
214  * @brief Creates a thread.
215  * @return Result code.
216  * @note Syscall number 0x08.
217  */
218 Result svcCreateThread(Handle* out, void* entry, void* arg, void* stack_top, int prio, int cpuid);
219 
220 /**
221  * @brief Starts a freshly created thread.
222  * @return Result code.
223  * @note Syscall number 0x09.
224  */
226 
227 /**
228  * @brief Exits the current thread.
229  * @note Syscall number 0x0A.
230  */
231 void NORETURN svcExitThread(void);
232 
233 /**
234  * @brief Sleeps the current thread for the specified amount of time.
235  * @return Result code.
236  * @note Syscall number 0x0B.
237  */
239 
240 /**
241  * @brief Gets a thread's priority.
242  * @return Result code.
243  * @note Syscall number 0x0C.
244  */
245 Result svcGetThreadPriority(u32* priority, Handle handle);
246 
247 /**
248  * @brief Sets a thread's priority.
249  * @return Result code.
250  * @note Syscall number 0x0D.
251  */
252 Result svcSetThreadPriority(Handle handle, u32 priority);
253 
254 /**
255  * @brief Gets the current processor's number.
256  * @return The current processor's number.
257  * @note Syscall number 0x10.
258  */
260 
261 ///@}
262 
263 ///@name Synchronization
264 ///@{
265 
266 /**
267  * @brief Sets an event's signalled status.
268  * @return Result code.
269  * @note Syscall number 0x11.
270  */
272 
273 /**
274  * @brief Clears an event's signalled status.
275  * @return Result code.
276  * @note Syscall number 0x12.
277  */
278 Result svcClearEvent(Handle handle);
279 
280 ///@}
281 
282 ///@name Inter-process memory sharing
283 ///@{
284 
285 /**
286  * @brief Maps a block of shared memory.
287  * @return Result code.
288  * @note Syscall number 0x13.
289  */
290 Result svcMapSharedMemory(Handle handle, void* addr, size_t size, u32 perm);
291 
292 /**
293  * @brief Unmaps a block of shared memory.
294  * @return Result code.
295  * @note Syscall number 0x14.
296  */
297 Result svcUnmapSharedMemory(Handle handle, void* addr, size_t size);
298 
299 /**
300  * @brief Creates a block of transfer memory.
301  * @return Result code.
302  * @note Syscall number 0x15.
303  */
304 Result svcCreateTransferMemory(Handle* out, void* addr, size_t size, u32 perm);
305 
306 ///@}
307 
308 ///@name Miscellaneous
309 ///@{
310 
311 /**
312  * @brief Closes a handle, decrementing the reference count of the corresponding kernel object.
313  * This might result in the kernel freeing the object.
314  * @param handle Handle to close.
315  * @return Result code.
316  * @note Syscall number 0x16.
317  */
319 
320 ///@}
321 
322 ///@name Synchronization
323 ///@{
324 
325 /**
326  * @brief Resets a signal.
327  * @return Result code.
328  * @note Syscall number 0x17.
329  */
331 
332 ///@}
333 
334 ///@name Synchronization
335 ///@{
336 
337 /**
338  * @brief Waits on one or more synchronization objects, optionally with a timeout.
339  * @return Result code.
340  * @note Syscall number 0x18.
341  */
342 Result svcWaitSynchronization(s32* index, const Handle* handles, s32 handleCount, u64 timeout);
343 
344 /**
345  * @brief Waits on a single synchronization object, optionally with a timeout.
346  * @return Result code.
347  * @note Wrapper for \ref svcWaitSynchronization.
348  */
349 static inline Result svcWaitSynchronizationSingle(Handle handle, u64 timeout) {
350  s32 tmp;
351  return svcWaitSynchronization(&tmp, &handle, 1, timeout);
352 }
353 
354 /**
355  * @brief Waits a \ref svcWaitSynchronization operation being done on a synchronization object in another thread.
356  * @return Result code.
357  * @note Syscall number 0x19.
358  */
360 
361 /**
362  * @brief Arbitrates a mutex lock operation in userspace.
363  * @return Result code.
364  * @note Syscall number 0x1A.
365  */
366 Result svcArbitrateLock(u32 wait_tag, u32* tag_location, u32 self_tag);
367 
368 /**
369  * @brief Arbitrates a mutex unlock operation in userspace.
370  * @return Result code.
371  * @note Syscall number 0x1B.
372  */
373 Result svcArbitrateUnlock(u32* tag_location);
374 
375 /**
376  * @brief Performs a condition variable wait operation in userspace.
377  * @return Result code.
378  * @note Syscall number 0x1C.
379  */
380 Result svcWaitProcessWideKeyAtomic(u32* key, u32* tag_location, u32 self_tag, u64 timeout);
381 
382 /**
383  * @brief Performs a condition variable wake-up operation in userspace.
384  * @return Result code.
385  * @note Syscall number 0x1D.
386  */
388 
389 ///@}
390 
391 ///@name Miscellaneous
392 ///@{
393 
394 /**
395  * @brief Gets the current system tick.
396  * @return The current system tick.
397  * @note Syscall number 0x1E.
398  */
399 u64 svcGetSystemTick(void);
400 
401 ///@}
402 
403 ///@name Inter-process communication (IPC)
404 ///@{
405 
406 /**
407  * @brief Connects to a registered named port.
408  * @return Result code.
409  * @note Syscall number 0x1F.
410  */
411 Result svcConnectToNamedPort(Handle* session, const char* name);
412 
413 /**
414  * @brief Sends an IPC synchronization request to a session.
415  * @return Result code.
416  * @note Syscall number 0x21.
417  */
419 
420 /**
421  * @brief Sends an IPC synchronization request to a session from an user allocated buffer.
422  * @return Result code.
423  * @remark size must be allocated to 0x1000 bytes.
424  * @note Syscall number 0x22.
425  */
426 Result svcSendSyncRequestWithUserBuffer(void* usrBuffer, u64 size, Handle session);
427 
428 /**
429  * @brief Sends an IPC synchronization request to a session from an user allocated buffer (asynchronous version).
430  * @return Result code.
431  * @remark size must be allocated to 0x1000 bytes.
432  * @note Syscall number 0x23.
433  */
434 Result svcSendAsyncRequestWithUserBuffer(Handle* handle, void* usrBuffer, u64 size, Handle session);
435 
436 ///@}
437 
438 ///@name Process and thread management
439 ///@{
440 
441 /**
442  * @brief Gets the PID associated with a process.
443  * @return Result code.
444  * @note Syscall number 0x24.
445  */
446 Result svcGetProcessId(u64 *processID, Handle handle);
447 
448 /**
449  * @brief Gets the TID associated with a process.
450  * @return Result code.
451  * @note Syscall number 0x25.
452  */
453 Result svcGetThreadId(u64 *threadID, Handle handle);
454 
455 ///@}
456 
457 ///@name Miscellaneous
458 ///@{
459 
460 /**
461  * @brief Breaks execution. Panic.
462  * @param[in] breakReason Break reason.
463  * @param[in] inval1 First break parameter.
464  * @param[in] inval2 Second break parameter.
465  * @return Result code.
466  * @note Syscall number 0x26.
467  */
468 Result svcBreak(u32 breakReason, u64 inval1, u64 inval2);
469 
470 ///@}
471 
472 ///@name Debugging
473 ///@{
474 
475 /**
476  * @brief Outputs debug text, if used during debugging.
477  * @param[in] str Text to output.
478  * @param[in] size Size of the text in bytes.
479  * @return Result code.
480  * @note Syscall number 0x27.
481  */
482 Result svcOutputDebugString(const char *str, u64 size);
483 
484 ///@}
485 
486 ///@name Miscellaneous
487 ///@{
488 
489 /**
490  * @brief Retrieves information about the system, or a certain kernel object.
491  * @param[out] out Variable to which store the information.
492  * @param[in] id0 First ID of the property to retrieve.
493  * @param[in] handle Handle of the object to retrieve information from, or \ref INVALID_HANDLE to retrieve information about the system.
494  * @param[in] id1 Second ID of the property to retrieve.
495  * @return Result code.
496  * @remark The full list of property IDs can be found on the <a href="http://switchbrew.org/index.php?title=SVC#svcGetInfo">switchbrew.org wiki</a>.
497  * @note Syscall number 0x29.
498  */
499 Result svcGetInfo(u64* out, u64 id0, Handle handle, u64 id1);
500 
501 ///@}
502 
503 ///@name Memory management
504 ///@{
505 
506 /**
507  * @brief Maps new heap memory at the desired address. [3.0.0+]
508  * @return Result code.
509  * @note Syscall number 0x2A.
510  */
511 Result svcMapPhysicalMemory(void *address, u64 size);
512 
513 /**
514  * @brief Undoes the effects of \ref svcMapPhysicalMemory. [3.0.0+]
515  * @return Result code.
516  * @note Syscall number 0x2B.
517  */
518 Result svcUnmapPhysicalMemory(void *address, u64 size);
519 
520 ///@}
521 
522 ///@name Process and thread management
523 ///@{
524 
525 /**
526  * @brief Configures the pause/unpause status of a thread.
527  * @return Result code.
528  * @note Syscall number 0x32.
529  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
530  */
531 Result svcSetThreadActivity(Handle thread, bool paused);
532 
533 ///@}
534 
535 ///@name Resource Limit Management
536 ///@{
537 
538 /**
539  * @brief Gets the maximum value a LimitableResource can have, for a Resource Limit handle.
540  * @return Result code.
541  * @note Syscall number 0x30.
542  */
544 
545 /**
546  * @brief Gets the maximum value a LimitableResource can have, for a Resource Limit handle.
547  * @return Result code.
548  * @note Syscall number 0x31.
549  */
551 
552 ///@}
553 
554 ///@name Inter-process communication (IPC)
555 ///@{
556 
557 /**
558  * @brief Creates an IPC session.
559  * @return Result code.
560  * @note Syscall number 0x40.
561  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
562  */
563 Result svcCreateSession(Handle *server_handle, Handle *client_handle, u32 unk0, u64 unk1);//unk* are normally 0?
564 
565 /**
566  * @brief Accepts an IPC session.
567  * @return Result code.
568  * @note Syscall number 0x41.
569  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
570  */
571 Result svcAcceptSession(Handle *session_handle, Handle port_handle);
572 
573 /**
574  * @brief Performs IPC input/output.
575  * @return Result code.
576  * @note Syscall number 0x43.
577  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
578  */
579 Result svcReplyAndReceive(s32* index, const Handle* handles, s32 handleCount, Handle replyTarget, u64 timeout);
580 
581 /**
582  * @brief Performs IPC input/output from an user allocated buffer.
583  * @return Result code.
584  * @note Syscall number 0x44.
585  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
586  */
587 Result svcReplyAndReceiveWithUserBuffer(s32* index, void* usrBuffer, u64 size, const Handle* handles, s32 handleCount, Handle replyTarget, u64 timeout);
588 
589 ///@}
590 
591 ///@name Synchronization
592 ///@{
593 
594 /**
595  * @brief Creates a system event.
596  * @return Result code.
597  * @note Syscall number 0x45.
598  */
599 Result svcCreateEvent(Handle* server_handle, Handle* client_handle);
600 
601 ///@}
602 
603 ///@name Memory management
604 ///@{
605 
606 /**
607  * @brief Maps unsafe memory (usable for GPU DMA) for a system module at the desired address. [5.0.0+]
608  * @return Result code.
609  * @note Syscall number 0x48.
610  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
611  */
612 Result svcMapPhysicalMemoryUnsafe(void *address, u64 size);
613 
614 /**
615  * @brief Undoes the effects of \ref svcMapPhysicalMemoryUnsafe. [5.0.0+]
616  * @return Result code.
617  * @note Syscall number 0x49.
618  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
619  */
620 Result svcUnmapPhysicalMemoryUnsafe(void *address, u64 size);
621 
622 /**
623  * @brief Sets the system-wide limit for unsafe memory mappable using \ref svcMapPhysicalMemoryUnsafe. [5.0.0+]
624  * @return Result code.
625  * @note Syscall number 0x4A.
626  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
627  */
629 
630 ///@}
631 
632 
633 ///@name Just-in-time (JIT) compilation support
634 ///@{
635 
636 /**
637  * @brief Creates JIT memory in the caller's address space [4.0.0+].
638  * @return Result code.
639  * @note Syscall number 0x4B.
640  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
641  */
642 Result svcCreateJitMemory(Handle* jit_handle, void* src_addr, u64 size);
643 
644 /**
645  * @brief Maps JIT memory in the caller's address space [4.0.0+].
646  * @return Result code.
647  * @note Syscall number 0x4C.
648  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
649  */
650 Result svcMapJitMemory(Handle jit_handle, JitMapOperation op, void* dst_addr, u64 size, u64 perm);
651 
652 ///@}
653 
654 ///@name Device memory-mapped I/O (MMIO)
655 ///@{
656 
657 /**
658  * @brief Reads/writes a protected MMIO register.
659  * @return Result code.
660  * @note Syscall number 0x4E.
661  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
662  */
663 Result svcReadWriteRegister(u32* outVal, u64 regAddr, u32 rwMask, u32 inVal);
664 
665 ///@}
666 
667 ///@name Inter-process memory sharing
668 ///@{
669 
670 /**
671  * @brief Creates a block of shared memory.
672  * @return Result code.
673  * @note Syscall number 0x50.
674  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
675  */
676 Result svcCreateSharedMemory(Handle* out, size_t size, u32 local_perm, u32 other_perm);
677 
678 /**
679  * @brief Maps a block of transfer memory.
680  * @return Result code.
681  * @note Syscall number 0x51.
682  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
683  */
684 Result svcMapTransferMemory(Handle tmem_handle, void* addr, size_t size, u32 perm);
685 
686 /**
687  * @brief Unmaps a block of transfer memory.
688  * @return Result code.
689  * @note Syscall number 0x52.
690  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
691  */
692 Result svcUnmapTransferMemory(Handle tmem_handle, void* addr, size_t size);
693 
694 ///@}
695 
696 ///@name Device memory-mapped I/O (MMIO)
697 ///@{
698 
699 /**
700  * @brief Creates an event and binds it to a specific hardware interrupt.
701  * @return Result code.
702  * @note Syscall number 0x53.
703  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
704  */
705 Result svcCreateInterruptEvent(Handle* handle, u64 irqNum, u32 flag);
706 
707 /**
708  * @brief Queries information about a certain virtual address, including its physical address.
709  * @return Result code.
710  * @note Syscall number 0x54.
711  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
712  */
713 Result svcQueryPhysicalAddress(u64 out[3], u64 virtaddr);
714 
715 /**
716  * @brief Returns a virtual address mapped to a given IO range.
717  * @return Result code.
718  * @note Syscall number 0x55.
719  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
720  */
721 Result svcQueryIoMapping(u64* virtaddr, u64 physaddr, u64 size);
722 
723 ///@}
724 
725 ///@name I/O memory management unit (IOMMU)
726 ///@{
727 
728 /**
729  * @brief Creates a virtual address space for binding device address spaces.
730  * @return Result code.
731  * @note Syscall number 0x56.
732  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
733  */
734 Result svcCreateDeviceAddressSpace(Handle *handle, u64 dev_addr, u64 dev_size);
735 
736 /**
737  * @brief Attaches a device address space to a device.
738  * @return Result code.
739  * @note Syscall number 0x57.
740  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
741  */
743 
744 /**
745  * @brief Detaches a device address space from a device.
746  * @return Result code.
747  * @note Syscall number 0x58.
748  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
749  */
751 
752 /**
753  * @brief Maps an attached device address space to an userspace address.
754  * @return Result code.
755  * @remark The userspace destination address must have the \ref MemState_MapDeviceAllowed bit set.
756  * @note Syscall number 0x59.
757  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
758  */
759 Result svcMapDeviceAddressSpaceByForce(Handle handle, Handle proc_handle, u64 map_addr, u64 dev_size, u64 dev_addr, u32 perm);
760 
761 /**
762  * @brief Maps an attached device address space to an userspace address.
763  * @return Result code.
764  * @remark The userspace destination address must have the \ref MemState_MapDeviceAlignedAllowed bit set.
765  * @note Syscall number 0x5A.
766  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
767  */
768 Result svcMapDeviceAddressSpaceAligned(Handle handle, Handle proc_handle, u64 map_addr, u64 dev_size, u64 dev_addr, u32 perm);
769 
770 /**
771  * @brief Unmaps an attached device address space from an userspace address.
772  * @return Result code.
773  * @note Syscall number 0x5C.
774  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
775  */
776 Result svcUnmapDeviceAddressSpace(Handle handle, Handle proc_handle, u64 map_addr, u64 map_size, u64 dev_addr);
777 
778 ///@}
779 
780 ///@name Debugging
781 ///@{
782 
783 /**
784  * @brief Debugs an active process.
785  * @return Result code.
786  * @note Syscall number 0x60.
787  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
788  */
789 Result svcDebugActiveProcess(Handle* debug, u64 processID);
790 
791 /**
792  * @brief Breaks an active debugging session.
793  * @return Result code.
794  * @note Syscall number 0x61.
795  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
796  */
798 
799 /**
800  * @brief Gets an incoming debug event from a debugging session.
801  * @return Result code.
802  * @note Syscall number 0x63.
803  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
804  */
805 Result svcGetDebugEvent(u8* event_out, Handle* debug);
806 
807 /**
808  * @brief Continues a debugging session.
809  * @return Result code.
810  * @note Syscall number 0x64.
811  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
812  */
813 Result svcContinueDebugEvent(Handle debug, u32 flags, u64 unk);
814 
815 /**
816  * @brief Gets the context of a thread in a debugging session.
817  * @return Result code.
818  * @note Syscall number 0x67.
819  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
820  */
821 Result svcGetDebugThreadContext(u8* out, Handle debug, u64 threadID, u32 flags);
822 
823 ///@}
824 
825 ///@name Process and thread management
826 ///@{
827 
828 /**
829  * @brief Retrieves a list of all running processes.
830  * @return Result code.
831  * @note Syscall number 0x65.
832  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
833  */
834 Result svcGetProcessList(u32 *num_out, u64 *pids_out, u32 max_pids);
835 
836 ///@}
837 
838 ///@name Debugging
839 ///@{
840 
841 /**
842  * @brief Queries memory information from a process that is being debugged.
843  * @return Result code.
844  * @note Syscall number 0x69.
845  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
846  */
847 Result svcQueryDebugProcessMemory(MemoryInfo* meminfo_ptr, u32* pageinfo, Handle debug, u64 addr);
848 
849 /**
850  * @brief Reads memory from a process that is being debugged.
851  * @return Result code.
852  * @note Syscall number 0x6A.
853  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
854  */
855 Result svcReadDebugProcessMemory(void* buffer, Handle debug, u64 addr, u64 size);
856 
857 /**
858  * @brief Writes to memory in a process that is being debugged.
859  * @return Result code.
860  * @note Syscall number 0x6B.
861  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
862  */
863 Result svcWriteDebugProcessMemory(Handle debug, void* buffer, u64 addr, u64 size);
864 
865 ///@}
866 
867 ///@name Miscellaneous
868 ///@{
869 
870 /**
871  * @brief Retrieves privileged information about the system, or a certain kernel object.
872  * @param[out] out Variable to which store the information.
873  * @param[in] id0 First ID of the property to retrieve.
874  * @param[in] handle Handle of the object to retrieve information from, or \ref INVALID_HANDLE to retrieve information about the system.
875  * @param[in] id1 Second ID of the property to retrieve.
876  * @return Result code.
877  * @remark The full list of property IDs can be found on the <a href="http://switchbrew.org/index.php?title=SVC#svcGetSystemInfo">switchbrew.org wiki</a>.
878  * @note Syscall number 0x6F.
879  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
880  */
881 Result svcGetSystemInfo(u64* out, u64 id0, Handle handle, u64 id1);
882 
883 ///@}
884 
885 ///@name Inter-process communication (IPC)
886 ///@{
887 
888 /**
889  * @brief Creates a port.
890  * @return Result code.
891  * @note Syscall number 0x70.
892  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
893  */
894 Result svcCreatePort(Handle* portServer, Handle *portClient, s32 max_sessions, bool is_light, const char* name);
895 
896 /**
897  * @brief Manages a named port.
898  * @return Result code.
899  * @note Syscall number 0x71.
900  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
901  */
902 Result svcManageNamedPort(Handle* portServer, const char* name, s32 maxSessions);
903 
904 /**
905  * @brief Manages a named port.
906  * @return Result code.
907  * @note Syscall number 0x72.
908  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
909  */
910 Result svcConnectToPort(Handle* session, Handle port);
911 
912 ///@}
913 
914 ///@name Memory management
915 ///@{
916 
917 /**
918  * @brief Sets the memory permissions for the specified memory with the supplied process handle.
919  * @param[in] proc Process handle.
920  * @param[in] addr Address of the memory.
921  * @param[in] size Size of the memory.
922  * @param[in] perm Permissions (see \ref Permission).
923  * @return Result code.
924  * @remark This returns an error (0xD801) when \p perm is >0x5, hence -WX and RWX are not allowed.
925  * @note Syscall number 0x73.
926  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
927  */
928 Result svcSetProcessMemoryPermission(Handle proc, u64 addr, u64 size, u32 perm);
929 
930 /**
931  * @brief Maps the src address from the supplied process handle into the current process.
932  * @param[in] dst Address to which map the memory in the current process.
933  * @param[in] proc Process handle.
934  * @param[in] src Source mapping address.
935  * @param[in] size Size of the memory.
936  * @return Result code.
937  * @remark This allows mapping code and rodata with RW- permission.
938  * @note Syscall number 0x74.
939  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
940  */
941 Result svcMapProcessMemory(void* dst, Handle proc, u64 src, u64 size);
942 
943 /**
944  * @brief Undoes the effects of \ref svcMapProcessMemory.
945  * @param[in] dst Destination mapping address
946  * @param[in] proc Process handle.
947  * @param[in] src Address of the memory in the process.
948  * @param[in] size Size of the memory.
949  * @return Result code.
950  * @remark This allows mapping code and rodata with RW- permission.
951  * @note Syscall number 0x75.
952  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
953  */
954 Result svcUnmapProcessMemory(void* dst, Handle proc, u64 src, u64 size);
955 
956 /**
957  * @brief Maps normal heap in a certain process as executable code (used when loading NROs).
958  * @param[in] proc Process handle (cannot be \ref CUR_PROCESS_HANDLE).
959  * @param[in] dst Destination mapping address.
960  * @param[in] src Source mapping address.
961  * @param[in] size Size of the mapping.
962  * @return Result code.
963  * @note Syscall number 0x77.
964  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
965  */
966 Result svcMapProcessCodeMemory(Handle proc, u64 dst, u64 src, u64 size);
967 
968 /**
969  * @brief Undoes the effects of \ref svcMapProcessCodeMemory.
970  * @param[in] proc Process handle (cannot be \ref CUR_PROCESS_HANDLE).
971  * @param[in] dst Destination mapping address.
972  * @param[in] src Source mapping address.
973  * @param[in] size Size of the mapping.
974  * @return Result code.
975  * @note Syscall number 0x78.
976  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
977  */
978 Result svcUnmapProcessCodeMemory(Handle proc, u64 dst, u64 src, u64 size);
979 
980 ///@}
981 
982 ///@name Process and thread management
983 ///@{
984 
985 /**
986  * @brief Creates a new process.
987  * @return Result code.
988  * @note Syscall number 0x79.
989  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
990  */
991 Result svcCreateProcess(Handle* out, void* proc_info, u32* caps, u64 cap_num);
992 
993 /**
994  * @brief Starts executing a freshly created process.
995  * @return Result code.
996  * @note Syscall number 0x7A.
997  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
998  */
999 Result svcStartProcess(Handle proc, s32 main_prio, s32 default_cpu, u32 stack_size);
1000 
1001 /**
1002  * @brief Terminates a running process.
1003  * @return Result code.
1004  * @note Syscall number 0x7B.
1005  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
1006  */
1008 
1009 /**
1010  * @brief Gets a \ref ProcessInfoType for a process.
1011  * @return Result code.
1012  * @note Syscall number 0x7C.
1013  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
1014  */
1016 
1017 ///@}
1018 
1019 ///@name Resource Limit Management
1020 ///@{
1021 
1022 /**
1023  * @brief Creates a new Resource Limit handle.
1024  * @return Result code.
1025  * @note Syscall number 0x7D.
1026  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
1027  */
1029 
1030 /**
1031  * @brief Sets the value for a \ref LimitableResource for a Resource Limit handle.
1032  * @return Result code.
1033  * @note Syscall number 0x7E.
1034  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
1035  */
1037 
1038 ///@}
1039 
1040 ///@name ( ͡° ͜ʖ ͡°)
1041 ///@{
1042 
1043 /**
1044  * @brief Calls a secure monitor function (TrustZone, EL3).
1045  * @param regs Arguments to pass to the secure monitor.
1046  * @return Return value from the secure monitor.
1047  * @note Syscall number 0x7F.
1048  * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
1049  */
1051 
1052 ///@}
u64 svcGetSystemTick(void)
Gets the current system tick.
How many events can a process have.
Definition: svc.h:112
void svcExitProcess(void)
Exits the current process.
Result svcConnectToNamedPort(Handle *session, const char *name)
Connects to a registered named port.
Unmap slave.
Definition: svc.h:105
Result svcMapTransferMemory(Handle tmem_handle, void *addr, size_t size, u32 perm)
Maps a block of transfer memory.
Result svcGetResourceLimitCurrentValue(u64 *out, Handle reslimit_h, LimitableResource which)
Gets the maximum value a LimitableResource can have, for a Resource Limit handle. ...
Result svcConnectToPort(Handle *session, Handle port)
Manages a named port.
Process has begun exiting.
Definition: svc.h:129
#define PACKED
Packs a struct (and other types?) so it won&#39;t include padding bytes.
Definition: types.h:56
Result svcSetProcessMemoryPermission(Handle proc, u64 addr, u64 size, u32 perm)
Sets the memory permissions for the specified memory with the supplied process handle.
Mapped using svcMapMemory.
Definition: svc.h:28
Result svcGetThreadPriority(u32 *priority, Handle handle)
Gets a thread&#39;s priority.
Result svcMapJitMemory(Handle jit_handle, JitMapOperation op, void *dst_addr, u64 size, u64 perm)
Maps JIT memory in the caller&#39;s address space [4.0.0+].
Mapped using svcMapProcessMemory.
Definition: svc.h:32
Is borrowed memory.
Definition: svc.h:66
Mapped using svcMapProcessCodeMemory.
Definition: svc.h:25
IPC buffer allowed.
Definition: svc.h:56
void svcExitThread(void)
Exits the current thread.
Execute permission.
Definition: svc.h:77
Result svcSetUnsafeLimit(u64 size)
Sets the system-wide limit for unsafe memory mappable using svcMapPhysicalMemoryUnsafe.
Result svcAcceptSession(Handle *session_handle, Handle port_handle)
Accepts an IPC session.
static Result svcWaitSynchronizationSingle(Handle handle, u64 timeout)
Waits on a single synchronization object, optionally with a timeout.
Definition: svc.h:349
Mapped by kernel capability parsing in svcCreateProcess.
Definition: svc.h:19
Permission change allowed.
Definition: svc.h:44
Process executing normally.
Definition: svc.h:128
Result svcMapPhysicalMemoryUnsafe(void *address, u64 size)
Maps unsafe memory (usable for GPU DMA) for a system module at the desired address.
Result svcMapPhysicalMemory(void *address, u64 size)
Maps new heap memory at the desired address.
Result svcManageNamedPort(Handle *portServer, const char *name, s32 maxSessions)
Manages a named port.
Permission
Memory permission bitmasks.
Definition: svc.h:73
u32 attr
Memory attributes (see MemoryAttribute).
Definition: svc.h:88
Map device allowed (svcMapDeviceAddressSpace and svcMapDeviceAddressSpaceByForce).
Definition: svc.h:54
Result svcDetachDeviceAddressSpace(u64 device, Handle handle)
Detaches a device address space from a device.
IPC buffers with descriptor flags=0.
Definition: svc.h:27
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.
u64 svcCallSecureMonitor(SecmonArgs *regs)
Calls a secure monitor function (TrustZone, EL3).
Result svcSignalProcessWideKey(u32 *key, s32 num)
Performs a condition variable wake-up operation in userspace.
MemoryAttribute
Memory attribute bitmasks.
Definition: svc.h:65
Result svcUnmapProcessCodeMemory(Handle proc, u64 dst, u64 src, u64 size)
Undoes the effects of svcMapProcessCodeMemory.
Result svcUnmapPhysicalMemoryUnsafe(void *address, u64 size)
Undoes the effects of svcMapPhysicalMemoryUnsafe.
Mapped in kernel during svcCreateThread.
Definition: svc.h:36
u32 type
Memory type (see lower 8 bits of MemoryState).
Definition: svc.h:87
Result svcQueryIoMapping(u64 *virtaddr, u64 physaddr, u64 size)
Returns a virtual address mapped to a given IO range.
Result svcUnmapProcessMemory(void *dst, Handle proc, u64 src, u64 size)
Undoes the effects of svcMapProcessMemory.
ProcessState
Process States.
Definition: svc.h:123
JitMapOperation
JIT mapping operations.
Definition: svc.h:101
IPC type 1 send allowed.
Definition: svc.h:48
u32 Handle
Kernel object handle.
Definition: types.h:45
Result svcUnmapSharedMemory(Handle handle, void *addr, size_t size)
Unmaps a block of shared memory.
Memory information structure.
Definition: svc.h:84
Result svcCreateDeviceAddressSpace(Handle *handle, u64 dev_addr, u64 dev_size)
Creates a virtual address space for binding device address spaces.
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.
Mapped by kernel capability parsing in svcCreateProcess.
Definition: svc.h:18
What state is a process in.
Definition: svc.h:119
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.
Result svcUnmapPhysicalMemory(void *address, u64 size)
Undoes the effects of svcMapPhysicalMemory.
u32 Result
Function error code result type.
Definition: types.h:46
Transfer memory allowed.
Definition: svc.h:52
Result svcWaitProcessWideKeyAtomic(u32 *key, u32 *tag_location, u32 self_tag, u64 timeout)
Performs a condition variable wait operation in userspace.
Result svcSignalEvent(Handle handle)
Sets an event&#39;s signalled status.
IPC type 3 send allowed.
Definition: svc.h:47
uint8_t u8
8-bit unsigned integer.
Definition: types.h:21
Result svcGetProcessList(u32 *num_out, u64 *pids_out, u32 max_pids)
Retrieves a list of all running processes.
Result svcArbitrateLock(u32 wait_tag, u32 *tag_location, u32 self_tag)
Arbitrates a mutex lock operation in userspace.
Result svcReadDebugProcessMemory(void *buffer, Handle debug, u64 addr, u64 size)
Reads memory from a process that is being debugged.
Result svcCreateResourceLimit(Handle *out)
Creates a new Resource Limit handle.
Result svcGetDebugThreadContext(u8 *out, Handle debug, u64 threadID, u32 flags)
Gets the context of a thread in a debugging session.
Result svcSetThreadPriority(Handle handle, u32 priority)
Sets a thread&#39;s priority.
uint64_t u64
64-bit unsigned integer.
Definition: types.h:24
Process that has just creashed.
Definition: svc.h:127
Result svcCreateSession(Handle *server_handle, Handle *client_handle, u32 unk0, u64 unk1)
Creates an IPC session.
Result svcGetInfo(u64 *out, u64 id0, Handle handle, u64 id1)
Retrieves information about the system, or a certain kernel object.
Read/execute permissions.
Definition: svc.h:79
MemoryType
Memory type enumeration (lower 8 bits of MemoryState)
Definition: svc.h:16
How many sessions can a process own.
Definition: svc.h:114
Don&#39;t care.
Definition: svc.h:80
Result svcGetDebugEvent(u8 *event_out, Handle *debug)
Gets an incoming debug event from a debugging session.
Map process allowed.
Definition: svc.h:59
Mapped using svcMapTransferMemory when the owning process has perm=0.
Definition: svc.h:30
Result svcSetMemoryAttribute(void *addr, u64 size, u32 val0, u32 val1)
Set the memory attributes of a (page-aligned) range of memory.
u32 device_refcount
Device reference count.
Definition: svc.h:90
uint32_t u32
32-bit unsigned integer.
Definition: types.h:23
Process permission change allowed.
Definition: svc.h:49
How much memory can a process map.
Definition: svc.h:110
Result svcResetSignal(Handle handle)
Resets a signal.
u32 ipc_refcount
IPC reference count.
Definition: svc.h:91
Result svcDebugActiveProcess(Handle *debug, u64 processID)
Debugs an active process.
Result svcStartThread(Handle handle)
Starts a freshly created thread.
u32 padding
Padding.
Definition: svc.h:92
Result svcCreateThread(Handle *out, void *entry, void *arg, void *stack_top, int prio, int cpuid)
Creates a thread.
No permissions.
Definition: svc.h:74
Mapped using svcMapMemory.
Definition: svc.h:24
Result svcCreateTransferMemory(Handle *out, void *addr, size_t size, u32 perm)
Creates a block of transfer memory.
Is pool allocated.
Definition: svc.h:57
Result svcMapProcessCodeMemory(Handle proc, u64 dst, u64 src, u64 size)
Maps normal heap in a certain process as executable code (used when loading NROs).
Result svcSleepThread(u64 nano)
Sleeps the current thread for the specified amount of time.
int32_t s32
32-bit signed integer.
Definition: types.h:29
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.
Read/write permissions.
Definition: svc.h:78
Result svcContinueDebugEvent(Handle debug, u32 flags, u64 unk)
Continues a debugging session.
Result svcMapProcessMemory(void *dst, Handle proc, u64 src, u64 size)
Maps the src address from the supplied process handle into the current process.
Process execution suspended by debugger.
Definition: svc.h:131
Result svcCancelSynchronization(Handle thread)
Waits a svcWaitSynchronization operation being done on a synchronization object in another thread...
Result svcStartProcess(Handle proc, s32 main_prio, s32 default_cpu, u32 stack_size)
Starts executing a freshly created process.
Mapped in kernel during svcMapJitMemory.
Definition: svc.h:37
Mapped using svcMapSharedMemory.
Definition: svc.h:23
Result svcWriteDebugProcessMemory(Handle debug, void *buffer, u64 addr, u64 size)
Writes to memory in a process that is being debugged.
Result svcClearEvent(Handle handle)
Clears an event&#39;s signalled status.
Process has finished exiting.
Definition: svc.h:130
Result svcQueryMemory(MemoryInfo *meminfo_ptr, u32 *pageinfo, u64 addr)
Query information about an address.
Result svcAttachDeviceAddressSpace(u64 device, Handle handle)
Attaches a device address space to a device.
How many threads can a process spawn.
Definition: svc.h:111
Result svcCreateJitMemory(Handle *jit_handle, void *src_addr, u64 size)
Creates JIT memory in the caller&#39;s address space [4.0.0+].
Reserved.
Definition: svc.h:33
u32 svcGetCurrentProcessorNumber(void)
Gets the current processor&#39;s number.
Secure monitor arguments.
Definition: svc.h:96
IPC buffers with descriptor flags=3.
Definition: svc.h:35
Unmap owner.
Definition: svc.h:104
Result svcTerminateProcess(Handle proc)
Terminates a running process.
Result svcSetThreadActivity(Handle thread, bool paused)
Configures the pause/unpause status of a thread.
Result svcUnmapTransferMemory(Handle tmem_handle, void *addr, size_t size)
Unmaps a block of transfer memory.
Result svcCreateSharedMemory(Handle *out, size_t size, u32 local_perm, u32 other_perm)
Creates a block of shared memory.
Process attached to debugger.
Definition: svc.h:125
JIT memory allowed.
Definition: svc.h:61
Is IPC mapped (when IpcRefCount > 0).
Definition: svc.h:67
Result svcWaitSynchronization(s32 *index, const Handle *handles, s32 handleCount, u64 timeout)
Waits on one or more synchronization objects, optionally with a timeout.
Result svcGetProcessId(u64 *processID, Handle handle)
Gets the PID associated with a process.
Result svcSetHeapSize(void **out_addr, u64 size)
Set the process heap to a given size.
Mapped during svcCreateProcess.
Definition: svc.h:20
Unmapped memory.
Definition: svc.h:17
IPC type 0 send allowed.
Definition: svc.h:46
Is uncached.
Definition: svc.h:69
Type field (see MemoryType).
Definition: svc.h:43
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:51
Result svcMapSharedMemory(Handle handle, void *addr, size_t size, u32 perm)
Maps a block of shared memory.
LimitableResource
Limitable Resources.
Definition: svc.h:109
Unmap process code memory allowed.
Definition: svc.h:51
Mapped using svcMapTransferMemory when the owning process has perm!=0.
Definition: svc.h:31
Attribute change allowed.
Definition: svc.h:60
Result svcGetProcessInfo(u64 *out, Handle proc, ProcessInfoType which)
Gets a ProcessInfoType for a process.
How many transfer memories can a process make.
Definition: svc.h:113
Mapped using svcSetHeapSize.
Definition: svc.h:22
Result svcBreak(u32 breakReason, u64 inval1, u64 inval2)
Breaks execution.
Result svcCreateInterruptEvent(Handle *handle, u64 irqNum, u32 flag)
Creates an event and binds it to a specific hardware interrupt.
Query physical address allowed.
Definition: svc.h:53
Result svcSetMemoryPermission(void *addr, u64 size, u32 perm)
Set the memory permissions of a (page-aligned) range of memory.
Is device mapped (when DeviceRefCount > 0).
Definition: svc.h:68
Result svcCreatePort(Handle *portServer, Handle *portClient, s32 max_sessions, bool is_light, const char *name)
Creates a port.
Map slave.
Definition: svc.h:103
Result svcBreakDebugProcess(Handle debug)
Breaks an active debugging session.
Newly-created process.
Definition: svc.h:124
Result svcQueryDebugProcessMemory(MemoryInfo *meminfo_ptr, u32 *pageinfo, Handle debug, u64 addr)
Queries memory information from a process that is being debugged.
IPC buffers with descriptor flags=1.
Definition: svc.h:34
Map owner.
Definition: svc.h:102
Result svcMapMemory(void *dst_addr, void *src_addr, u64 size)
Maps a memory range into a different range.
u32 perm
Memory permissions (see Permission).
Definition: svc.h:89
Result svcUnmapMemory(void *dst_addr, void *src_addr, u64 size)
Unmaps a region that was previously mapped with svcMapMemory.
Result svcReadWriteRegister(u32 *outVal, u64 regAddr, u32 rwMask, u32 inVal)
Reads/writes a protected MMIO register.
MemoryState
Memory state bitmasks.
Definition: svc.h:42
u64 size
Size.
Definition: svc.h:86
Process detached from debugger.
Definition: svc.h:126
Result svcArbitrateUnlock(u32 *tag_location)
Arbitrates a mutex unlock operation in userspace.
Force read/writable by debug syscalls.
Definition: svc.h:45
Alias for MemState_IsPoolAllocated.
Definition: svc.h:58
Result svcCloseHandle(Handle handle)
Closes a handle, decrementing the reference count of the corresponding kernel object.
Result svcCreateEvent(Handle *server_handle, Handle *client_handle)
Creates a system event.
Result svcOutputDebugString(const char *str, u64 size)
Outputs debug text, if used during debugging.
u64 addr
Base address.
Definition: svc.h:85
Result svcSendSyncRequest(Handle session)
Sends an IPC synchronization request to a session.
Result svcCreateProcess(Handle *out, void *proc_info, u32 *caps, u64 cap_num)
Creates a new process.
Result svcGetResourceLimitLimitValue(u64 *out, Handle reslimit_h, LimitableResource which)
Gets the maximum value a LimitableResource can have, for a Resource Limit handle. ...
Transition from MemType_CodeStatic performed by svcSetProcessMemoryPermission.
Definition: svc.h:21
Result svcGetThreadId(u64 *threadID, Handle handle)
Gets the TID associated with a process.
Result svcReplyAndReceive(s32 *index, const Handle *handles, s32 handleCount, Handle replyTarget, u64 timeout)
Performs IPC input/output.
Write permission.
Definition: svc.h:76
Mapped during svcCreateThread.
Definition: svc.h:29
Result svcSetResourceLimitLimitValue(Handle reslimit, LimitableResource which, u64 value)
Sets the value for a LimitableResource for a Resource Limit handle.
Result svcGetSystemInfo(u64 *out, u64 id0, Handle handle, u64 id1)
Retrieves privileged information about the system, or a certain kernel object.
Map allowed.
Definition: svc.h:50
Mapped in kernel during svcMapJitMemory.
Definition: svc.h:38
Result svcSendSyncRequestWithUserBuffer(void *usrBuffer, u64 size, Handle session)
Sends an IPC synchronization request to a session from an user allocated buffer.
Transition from MemType_ModuleCodeStatic performed by svcSetProcessMemoryPermission.
Definition: svc.h:26
Map device aligned allowed.
Definition: svc.h:55
Result svcQueryPhysicalAddress(u64 out[3], u64 virtaddr)
Queries information about a certain virtual address, including its physical address.
Read permission.
Definition: svc.h:75
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...
ProcessInfoType
Process Information.
Definition: svc.h:118