libctru  v2.3.1
svc.h
Go to the documentation of this file.
1 /**
2  * @file svc.h
3  * @brief Syscall wrappers.
4  */
5 #pragma once
6 
7 #include "types.h"
8 
9 /// Pseudo handle for the current process
10 #define CUR_PROCESS_HANDLE 0xFFFF8001
11 
12 ///@name Memory management
13 ///@{
14 
15 /**
16  * @brief @ref svcControlMemory operation flags
17  *
18  * The lowest 8 bits are the operation
19  */
20 typedef enum {
21  MEMOP_FREE = 1, ///< Memory un-mapping
22  MEMOP_RESERVE = 2, ///< Reserve memory
23  MEMOP_ALLOC = 3, ///< Memory mapping
24  MEMOP_MAP = 4, ///< Mirror mapping
25  MEMOP_UNMAP = 5, ///< Mirror unmapping
26  MEMOP_PROT = 6, ///< Change protection
27 
28  MEMOP_REGION_APP = 0x100, ///< APPLICATION memory region.
29  MEMOP_REGION_SYSTEM = 0x200, ///< SYSTEM memory region.
30  MEMOP_REGION_BASE = 0x300, ///< BASE memory region.
31 
32  MEMOP_OP_MASK = 0xFF, ///< Operation bitmask.
33  MEMOP_REGION_MASK = 0xF00, ///< Region bitmask.
34  MEMOP_LINEAR_FLAG = 0x10000, ///< Flag for linear memory operations
35 
36  MEMOP_ALLOC_LINEAR = MEMOP_LINEAR_FLAG | MEMOP_ALLOC, ///< Allocates linear memory.
37 } MemOp;
38 
39 /// The state of a memory block.
40 typedef enum {
41  MEMSTATE_FREE = 0, ///< Free memory
42  MEMSTATE_RESERVED = 1, ///< Reserved memory
43  MEMSTATE_IO = 2, ///< I/O memory
44  MEMSTATE_STATIC = 3, ///< Static memory
45  MEMSTATE_CODE = 4, ///< Code memory
46  MEMSTATE_PRIVATE = 5, ///< Private memory
47  MEMSTATE_SHARED = 6, ///< Shared memory
48  MEMSTATE_CONTINUOUS = 7, ///< Continuous memory
49  MEMSTATE_ALIASED = 8, ///< Aliased memory
50  MEMSTATE_ALIAS = 9, ///< Alias memory
51  MEMSTATE_ALIASCODE = 10, ///< Aliased code memory
52  MEMSTATE_LOCKED = 11, ///< Locked memory
53 } MemState;
54 
55 /// Memory permission flags
56 typedef enum {
57  MEMPERM_READ = 1, ///< Readable
58  MEMPERM_WRITE = 2, ///< Writable
59  MEMPERM_EXECUTE = 4, ///< Executable
60  MEMPERM_READWRITE = MEMPERM_READ | MEMPERM_WRITE, ///< Readable and writable
61  MEMPERM_READEXECUTE = MEMPERM_READ | MEMPERM_EXECUTE, ///< Readable and executable
62  MEMPERM_DONTCARE = 0x10000000, ///< Don't care
63 } MemPerm;
64 
65 /// Memory regions.
66 typedef enum
67 {
68  MEMREGION_ALL = 0, ///< All regions.
69  MEMREGION_APPLICATION = 1, ///< APPLICATION memory.
70  MEMREGION_SYSTEM = 2, ///< SYSTEM memory.
71  MEMREGION_BASE = 3, ///< BASE memory.
72 } MemRegion;
73 
74 /// Memory information.
75 typedef struct {
76  u32 base_addr; ///< Base address.
77  u32 size; ///< Size.
78  u32 perm; ///< Memory permissions. See @ref MemPerm
79  u32 state; ///< Memory state. See @ref MemState
80 } MemInfo;
81 
82 /// Memory page information.
83 typedef struct {
84  u32 flags; ///< Page flags.
85 } PageInfo;
86 
87 /// Arbitration modes.
88 typedef enum {
89  ARBITRATION_SIGNAL = 0, ///< Signal #value threads for wake-up.
90  ARBITRATION_WAIT_IF_LESS_THAN = 1, ///< If the memory at the address is strictly lower than #value, then wait for signal.
91  ARBITRATION_DECREMENT_AND_WAIT_IF_LESS_THAN = 2, ///< If the memory at the address is strictly lower than #value, then decrement it and wait for signal.
92  ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT = 3, ///< If the memory at the address is strictly lower than #value, then wait for signal or timeout.
93  ARBITRATION_DECREMENT_AND_WAIT_IF_LESS_THAN_TIMEOUT = 4, ///< If the memory at the address is strictly lower than #value, then decrement it and wait for signal or timeout.
95 
96 /// Special value to signal all the threads
97 #define ARBITRATION_SIGNAL_ALL (-1)
98 
99 ///@}
100 
101 ///@name Multithreading
102 ///@{
103 
104 /// Reset types (for use with events and timers)
105 typedef enum {
106  RESET_ONESHOT = 0, ///< When the primitive is signaled, it will wake up exactly one thread and will clear itself automatically.
107  RESET_STICKY = 1, ///< When the primitive is signaled, it will wake up all threads and it won't clear itself automatically.
108  RESET_PULSE = 2, ///< Only meaningful for timers: same as ONESHOT but it will periodically signal the timer instead of just once.
109 } ResetType;
110 
111 /// Types of thread info.
112 typedef enum {
113  THREADINFO_TYPE_UNKNOWN ///< Unknown.
115 
116 /// Types of resource limit
117 typedef enum {
118  RESLIMIT_PRIORITY = 0, ///< Thread priority
119  RESLIMIT_COMMIT = 1, ///< Quantity of allocatable memory
120  RESLIMIT_THREAD = 2, ///< Number of threads
121  RESLIMIT_EVENT = 3, ///< Number of events
122  RESLIMIT_MUTEX = 4, ///< Number of mutexes
123  RESLIMIT_SEMAPHORE = 5, ///< Number of semaphores
124  RESLIMIT_TIMER = 6, ///< Number of timers
125  RESLIMIT_SHAREDMEMORY = 7, ///< Number of shared memory objects, see @ref svcCreateMemoryBlock
126  RESLIMIT_ADDRESSARBITER = 8, ///< Number of address arbiters
127  RESLIMIT_CPUTIME = 9, ///< CPU time. Value expressed in percentage regular until it reaches 90.
128 
129  RESLIMIT_BIT = BIT(31), ///< Forces enum size to be 32 bits
131 
132 /// Pseudo handle for the current thread
133 #define CUR_THREAD_HANDLE 0xFFFF8000
134 
135 ///@}
136 
137 ///@name Device drivers
138 ///@{
139 
140 /// DMA transfer state.
141 typedef enum {
142  DMASTATE_STARTING = 0, ///< DMA transfer involving at least one device is starting and has not reached DMAWFP yet.
143  DMASTATE_WFP_DST = 1, ///< DMA channel is in WFP state for the destination device (2nd loop iteration onwards).
144  DMASTATE_WFP_SRC = 2, ///< DMA channel is in WFP state for the source device (2nd loop iteration onwards).
145  DMASTATE_RUNNING = 3, ///< DMA transfer is running.
146  DMASTATE_DONE = 4, ///< DMA transfer is done.
147 } DmaState;
148 
149 /// Configuration flags for \ref DmaConfig.
150 enum {
151  DMACFG_SRC_IS_DEVICE = BIT(0), ///< DMA source is a device/peripheral. Address will not auto-increment.
152  DMACFG_DST_IS_DEVICE = BIT(1), ///< DMA destination is a device/peripheral. Address will not auto-increment.
153  DMACFG_WAIT_AVAILABLE = BIT(2), ///< Make \ref svcStartInterProcessDma wait for the channel to be unlocked.
154  DMACFG_KEEP_LOCKED = BIT(3), ///< Keep the channel locked after the transfer. Required for \ref svcRestartDma.
155  DMACFG_USE_SRC_CONFIG = BIT(6), ///< Use the provided source device configuration even if the DMA source is not a device.
156  DMACFG_USE_DST_CONFIG = BIT(7), ///< Use the provided destination device configuration even if the DMA destination is not a device.
157 };
158 
159 /// Configuration flags for \ref svcRestartDma.
160 enum {
161  DMARST_UNLOCK = BIT(0), ///< Unlock the channel after transfer.
162  DMARST_RESUME_DEVICE = BIT(1), ///< Replace DMAFLUSHP instructions by NOP (they may not be regenerated even if this flag is not set).
163 };
164 
165 /**
166  * @brief Device configuration structure, part of \ref DmaConfig.
167  * @note
168  * - if (and only if) src/dst is a device, then src/dst won't be auto-incremented.
169  * - the kernel uses DMAMOV instead of DMAADNH, when having to decrement (possibly working around an erratum);
170  * this forces all loops to be unrolled -- you need to keep that in mind when using negative increments, as the kernel
171  * uses a limit of 100 DMA instruction bytes per channel.
172  */
173 typedef struct {
174  s8 deviceId; ///< DMA device ID.
175  s8 allowedAlignments; ///< Mask of allowed access alignments (8, 4, 2, 1).
176  s16 burstSize; ///< Number of bytes transferred in a burst loop. Can be 0 (in which case the max allowed alignment is used as unit).
177  s16 transferSize; ///< Number of bytes transferred in a "transfer" loop (made of burst loops).
178  s16 burstStride; ///< Burst loop stride, can be <= 0.
179  s16 transferStride; ///< "Transfer" loop stride, can be <= 0.
181 
182 /// Configuration stucture for \ref svcStartInterProcessDma.
183 typedef struct {
184  s8 channelId; ///< Channel ID (Arm11: 0-7, Arm9: 0-1). Use -1 to auto-assign to a free channel (Arm11: 3-7, Arm9: 0-1).
185  s8 endianSwapSize; ///< Endian swap size (can be 0).
186  u8 flags; ///< DMACFG_* flags.
187  u8 _padding;
188  DmaDeviceConfig srcCfg; ///< Source device configuration, read if \ref DMACFG_SRC_IS_DEVICE and/or \ref DMACFG_USE_SRC_CONFIG are set.
189  DmaDeviceConfig dstCfg; ///< Destination device configuration, read if \ref DMACFG_SRC_IS_DEVICE and/or \ref DMACFG_USE_SRC_CONFIG are set.
190 } DmaConfig;
191 
192 ///@}
193 
194 ///@name Debugging
195 ///@{
196 
197 /// Operations for \ref svcControlPerformanceCounter
198 typedef enum {
199  PERFCOUNTEROP_ENABLE = 0, ///< Enable and lock perfmon. functionality.
200  PERFCOUNTEROP_DISABLE = 1, ///< Disable and forcibly unlock perfmon. functionality.
201  PERFCOUNTEROP_GET_VALUE = 2, ///< Get the value of a counter register.
202  PERFCOUNTEROP_SET_VALUE = 3, ///< Set the value of a counter register.
203  PERFCOUNTEROP_GET_OVERFLOW_FLAGS = 4, ///< Get the overflow flags for all CP15 and SCU counters.
204  PERFCOUNTEROP_RESET = 5, ///< Reset the value and/or overflow flags of selected counters.
205  PERFCOUNTEROP_GET_EVENT = 6, ///< Get the event ID associated to a particular counter.
206  PERFCOUNTEROP_SET_EVENT = 7, ///< Set the event ID associated to a paritcular counter.
207  PERFCOUNTEROP_SET_VIRTUAL_COUNTER_ENABLED = 8, ///< (Dis)allow the kernel to track counter overflows and to use 64-bit counter values.
209 
210 /// Performance counter register IDs (CP15 and SCU).
211 typedef enum
212 {
213  // CP15 registers:
214  PERFCOUNTERREG_CORE_BASE = 0,
215  PERFCOUNTERREG_CORE_COUNT_REG_0 = PERFCOUNTERREG_CORE_BASE, ///< CP15 PMN0.
218 
219  // SCU registers
220  PERFCOUNTERREG_SCU_BASE = 0x10,
221  PERFCOUNTERREG_SCU_0 = PERFCOUNTERREG_SCU_BASE, ///< SCU MN0.
222  PERFCOUNTERREG_SCU_1, ///< SCU MN1.
223  PERFCOUNTERREG_SCU_2, ///< SCU MN2.
224  PERFCOUNTERREG_SCU_3, ///< SCU MN3.
225  PERFCOUNTERREG_SCU_4, ///< SCU MN4. Prod-N3DS only. IRQ line missing.
226  PERFCOUNTERREG_SCU_5, ///< SCU MN5. Prod-N3DS only. IRQ line missing.
227  PERFCOUNTERREG_SCU_6, ///< SCU MN6. Prod-N3DS only. IRQ line missing.
228  PERFCOUNTERREG_SCU_7, ///< SCU MN7. Prod-N3DS only. IRQ line missing.
230 
231 /**
232  * @brief Performance counter event IDs (CP15 or SCU).
233  *
234  * @note Refer to:
235  * - CP15: https://developer.arm.com/documentation/ddi0360/e/control-coprocessor-cp15/register-descriptions/c15--performance-monitor-control-register--pmnc-
236  * - SCU: https://developer.arm.com/documentation/ddi0360/e/mpcore-private-memory-region/about-the-mpcore-private-memory-region/performance-monitor-event-registers
237  */
238 typedef enum
239 {
240  // Core events:
241  PERFCOUNTEREVT_CORE_BASE = 0x0,
242  PERFCOUNTEREVT_CORE_INST_CACHE_MISS = PERFCOUNTEREVT_CORE_BASE,
243  PERFCOUNTEREVT_CORE_STALL_BY_LACK_OF_INST,
244  PERFCOUNTEREVT_CORE_STALL_BY_DATA_HAZARD,
245  PERFCOUNTEREVT_CORE_INST_MICRO_TLB_MISS,
246  PERFCOUNTEREVT_CORE_DATA_MICRO_TLB_MISS,
247  PERFCOUNTEREVT_CORE_BRANCH_INST,
248  PERFCOUNTEREVT_CORE_BRANCH_NOT_PREDICTED,
249  PERFCOUNTEREVT_CORE_BRANCH_MISS_PREDICTED,
250  PERFCOUNTEREVT_CORE_INST_EXECUTED,
251  PERFCOUNTEREVT_CORE_FOLDED_INST_EXECUTED,
252  PERFCOUNTEREVT_CORE_DATA_CACHE_READ,
253  PERFCOUNTEREVT_CORE_DATA_CACHE_READ_MISS,
254  PERFCOUNTEREVT_CORE_DATA_CACHE_WRITE,
255  PERFCOUNTEREVT_CORE_DATA_CACHE_WRITE_MISS,
256  PERFCOUNTEREVT_CORE_DATA_CACHE_LINE_EVICTION,
257  PERFCOUNTEREVT_CORE_PC_CHANGED,
258  PERFCOUNTEREVT_CORE_MAIN_TLB_MISS,
259  PERFCOUNTEREVT_CORE_EXTERNAL_REQUEST,
260  PERFCOUNTEREVT_CORE_STALL_BY_LSU_FULL,
261  PERFCOUNTEREVT_CORE_STORE_BUFFER_DRAIN,
262  PERFCOUNTEREVT_CORE_MERGE_IN_STORE_BUFFER,
263  PERFCOUNTEREVT_CORE_CYCLE_COUNT = PERFCOUNTEREVT_CORE_BASE + 0xFF, ///< One cycle elapsed.
264  PERFCOUNTEREVT_CORE_CYCLE_COUNT_64 = PERFCOUNTEREVT_CORE_BASE + 0xFFF, ///< 64 cycles elapsed.
265 
266 
267  PERFCOUNTEREVT_SCU_BASE = 0x1000,
268  PERFCOUNTEREVT_SCU_DISABLED = PERFCOUNTEREVT_SCU_BASE,
269  PERFCOUNTEREVT_SCU_LINEFILL_MISS_FROM_CORE0,
270  PERFCOUNTEREVT_SCU_LINEFILL_MISS_FROM_CORE1,
271  PERFCOUNTEREVT_SCU_LINEFILL_MISS_FROM_CORE2,
272  PERFCOUNTEREVT_SCU_LINEFILL_MISS_FROM_CORE3,
273  PERFCOUNTEREVT_SCU_LINEFILL_HIT_FROM_CORE0,
274  PERFCOUNTEREVT_SCU_LINEFILL_HIT_FROM_CORE1,
275  PERFCOUNTEREVT_SCU_LINEFILL_HIT_FROM_CORE2,
276  PERFCOUNTEREVT_SCU_LINEFILL_HIT_FROM_CORE3,
277  PERFCOUNTEREVT_SCU_LINE_MISSING_FROM_CORE0,
278  PERFCOUNTEREVT_SCU_LINE_MISSING_FROM_CORE1,
279  PERFCOUNTEREVT_SCU_LINE_MISSING_FROM_CORE2,
280  PERFCOUNTEREVT_SCU_LINE_MISSING_FROM_CORE3,
281  PERFCOUNTEREVT_SCU_LINE_MIGRATION,
282  PERFCOUNTEREVT_SCU_READ_BUSY_PORT0,
283  PERFCOUNTEREVT_SCU_READ_BUSY_PORT1,
284  PERFCOUNTEREVT_SCU_WRITE_BUSY_PORT0,
285  PERFCOUNTEREVT_SCU_WRITE_BUSY_PORT1,
286  PERFCOUNTEREVT_SCU_EXTERNAL_READ,
287  PERFCOUNTEREVT_SCU_EXTERNAL_WRITE,
288  PERFCOUNTEREVT_SCU_CYCLE_COUNT = PERFCOUNTEREVT_SCU_BASE + 0x1F,
290 
291 /// Event relating to the attachment of a process.
292 typedef struct {
293  u64 program_id; ///< ID of the program.
294  char process_name[8]; ///< Name of the process.
295  u32 process_id; ///< ID of the process.
296  u32 other_flags; ///< Always 0
298 
299 /// Reasons for an exit process event.
300 typedef enum {
301  EXITPROCESS_EVENT_EXIT = 0, ///< Process exited either normally or due to an uncaught exception.
302  EXITPROCESS_EVENT_TERMINATE = 1, ///< Process has been terminated by @ref svcTerminateProcess.
303  EXITPROCESS_EVENT_DEBUG_TERMINATE = 2, ///< Process has been terminated by @ref svcTerminateDebugProcess.
305 
306 /// Event relating to the exiting of a process.
307 typedef struct {
308  ExitProcessEventReason reason; ///< Reason for exiting. See @ref ExitProcessEventReason
310 
311 /// Event relating to the attachment of a thread.
312 typedef struct {
313  u32 creator_thread_id; ///< ID of the creating thread.
314  u32 thread_local_storage; ///< Thread local storage.
315  u32 entry_point; ///< Entry point of the thread.
317 
318 /// Reasons for an exit thread event.
319 typedef enum {
320  EXITTHREAD_EVENT_EXIT = 0, ///< Thread exited.
321  EXITTHREAD_EVENT_TERMINATE = 1, ///< Thread terminated.
322  EXITTHREAD_EVENT_EXIT_PROCESS = 2, ///< Process exited either normally or due to an uncaught exception.
323  EXITTHREAD_EVENT_TERMINATE_PROCESS = 3, ///< Process has been terminated by @ref svcTerminateProcess.
325 
326 /// Event relating to the exiting of a thread.
327 typedef struct {
328  ExitThreadEventReason reason; ///< Reason for exiting. See @ref ExitThreadEventReason
330 
331 /// Reasons for a user break.
332 typedef enum {
333  USERBREAK_PANIC = 0, ///< Panic.
334  USERBREAK_ASSERT = 1, ///< Assertion failed.
335  USERBREAK_USER = 2, ///< User related.
336  USERBREAK_LOAD_RO = 3, ///< Load RO.
337  USERBREAK_UNLOAD_RO = 4, ///< Unload RO.
338 } UserBreakType;
339 
340 /// Reasons for an exception event.
341 typedef enum {
342  EXCEVENT_UNDEFINED_INSTRUCTION = 0, ///< Undefined instruction.
343  EXCEVENT_PREFETCH_ABORT = 1, ///< Prefetch abort.
344  EXCEVENT_DATA_ABORT = 2, ///< Data abort (other than the below kind).
345  EXCEVENT_UNALIGNED_DATA_ACCESS = 3, ///< Unaligned data access.
346  EXCEVENT_ATTACH_BREAK = 4, ///< Attached break.
347  EXCEVENT_STOP_POINT = 5, ///< Stop point reached.
348  EXCEVENT_USER_BREAK = 6, ///< User break occurred.
349  EXCEVENT_DEBUGGER_BREAK = 7, ///< Debugger break occurred.
350  EXCEVENT_UNDEFINED_SYSCALL = 8, ///< Undefined syscall.
352 
353 /// Event relating to fault exceptions (CPU exceptions other than stop points and undefined syscalls).
354 typedef struct {
355  u32 fault_information; ///< FAR (for DATA ABORT / UNALIGNED DATA ACCESS), attempted syscall or 0
357 
358 /// Stop point types
359 typedef enum {
360  STOPPOINT_SVC_FF = 0, ///< See @ref SVC_STOP_POINT.
361  STOPPOINT_BREAKPOINT = 1, ///< Breakpoint.
362  STOPPOINT_WATCHPOINT = 2, ///< Watchpoint.
363 } StopPointType;
364 
365 /// Event relating to stop points
366 typedef struct {
367  StopPointType type; ///< Stop point type, see @ref StopPointType.
368  u32 fault_information; ///< FAR for Watchpoints, otherwise 0.
370 
371 /// Event relating to @ref svcBreak
372 typedef struct {
373  UserBreakType type; ///< User break type, see @ref UserBreakType.
374  u32 croInfo; ///< For LOAD_RO and UNLOAD_RO.
375  u32 croInfoSize; ///< For LOAD_RO and UNLOAD_RO.
377 
378 /// Event relating to @ref svcBreakDebugProcess
379 typedef struct {
380  s32 thread_ids[4]; ///< IDs of the attached process's threads that were running on each core at the time of the @ref svcBreakDebugProcess call, or -1 (only the first 2 values are meaningful on O3DS).
382 
383 /// Event relating to exceptions.
384 typedef struct {
385  ExceptionEventType type; ///< Type of event. See @ref ExceptionEventType.
386  u32 address; ///< Address of the exception.
387  union {
388  FaultExceptionEvent fault; ///< Fault exception event data.
389  StopPointExceptionEvent stop_point; ///< Stop point exception event data.
390  UserBreakExceptionEvent user_break; ///< User break exception event data.
391  DebuggerBreakExceptionEvent debugger_break; ///< Debugger break exception event data
392  };
394 
395 /// Event relating to the scheduler.
396 typedef struct {
397  u64 clock_tick; ///< Clock tick that the event occurred.
399 
400 /// Event relating to syscalls.
401 typedef struct {
402  u64 clock_tick; ///< Clock tick that the event occurred.
403  u32 syscall; ///< Syscall sent/received.
405 
406 /// Event relating to debug output.
407 typedef struct {
408  u32 string_addr; ///< Address of the outputted string.
409  u32 string_size; ///< Size of the outputted string.
411 
412 /// Event relating to the mapping of memory.
413 typedef struct {
414  u32 mapped_addr; ///< Mapped address.
415  u32 mapped_size; ///< Mapped size.
416  MemPerm memperm; ///< Memory permissions. See @ref MemPerm.
417  MemState memstate; ///< Memory state. See @ref MemState.
418 } MapEvent;
419 
420 /// Debug event type.
421 typedef enum {
422  DBGEVENT_ATTACH_PROCESS = 0, ///< Process attached event.
423  DBGEVENT_ATTACH_THREAD = 1, ///< Thread attached event.
424  DBGEVENT_EXIT_THREAD = 2, ///< Thread exit event.
425  DBGEVENT_EXIT_PROCESS = 3, ///< Process exit event.
426  DBGEVENT_EXCEPTION = 4, ///< Exception event.
427  DBGEVENT_DLL_LOAD = 5, ///< DLL load event.
428  DBGEVENT_DLL_UNLOAD = 6, ///< DLL unload event.
429  DBGEVENT_SCHEDULE_IN = 7, ///< Schedule in event.
430  DBGEVENT_SCHEDULE_OUT = 8, ///< Schedule out event.
431  DBGEVENT_SYSCALL_IN = 9, ///< Syscall in event.
432  DBGEVENT_SYSCALL_OUT = 10, ///< Syscall out event.
433  DBGEVENT_OUTPUT_STRING = 11, ///< Output string event.
434  DBGEVENT_MAP = 12, ///< Map event.
436 
437 /// Information about a debug event.
438 typedef struct {
439  DebugEventType type; ///< Type of event. See @ref DebugEventType
440  u32 thread_id; ///< ID of the thread.
441  u32 flags; ///< Flags. Bit0 means that @ref svcContinueDebugEvent needs to be called for this event (except for EXIT PROCESS events, where this flag is disregarded).
442  u8 remnants[4]; ///< Always 0.
443  union {
444  AttachProcessEvent attach_process; ///< Process attachment event data.
445  AttachThreadEvent attach_thread; ///< Thread attachment event data.
446  ExitThreadEvent exit_thread; ///< Thread exit event data.
447  ExitProcessEvent exit_process; ///< Process exit event data.
448  ExceptionEvent exception; ///< Exception event data.
449  /* DLL_LOAD and DLL_UNLOAD do not seem to possess any event data */
450  ScheduleInOutEvent scheduler; ///< Schedule in/out event data.
451  SyscallInOutEvent syscall; ///< Syscall in/out event data.
452  OutputStringEvent output_string; ///< Output string event data.
453  MapEvent map; ///< Map event data.
454  };
456 
457 /// Debug flags for an attached process, set by @ref svcContinueDebugEvent
458 typedef enum {
459  DBG_INHIBIT_USER_CPU_EXCEPTION_HANDLERS = BIT(0), ///< Inhibit user-defined CPU exception handlers (including watchpoints and breakpoints, regardless of any @ref svcKernelSetState call).
460  DBG_SIGNAL_FAULT_EXCEPTION_EVENTS = BIT(1), ///< Signal fault exception events. See @ref FaultExceptionEvent.
461  DBG_SIGNAL_SCHEDULE_EVENTS = BIT(2), ///< Signal schedule in/out events. See @ref ScheduleInOutEvent.
462  DBG_SIGNAL_SYSCALL_EVENTS = BIT(3), ///< Signal syscall in/out events. See @ref SyscallInOutEvent.
463  DBG_SIGNAL_MAP_EVENTS = BIT(4), ///< Signal map events. See @ref MapEvent.
464 } DebugFlags;
465 
466 typedef struct {
467  CpuRegisters cpu_registers; ///< CPU registers.
468  FpuRegisters fpu_registers; ///< FPU registers.
469 } ThreadContext;
470 
471 /// Control flags for @ref svcGetDebugThreadContext and @ref svcSetDebugThreadContext
472 typedef enum {
473  THREADCONTEXT_CONTROL_CPU_GPRS = BIT(0), ///< Control r0-r12.
474  THREADCONTEXT_CONTROL_CPU_SPRS = BIT(1), ///< Control sp, lr, pc, cpsr.
475  THREADCONTEXT_CONTROL_FPU_GPRS = BIT(2), ///< Control d0-d15 (or s0-s31).
476  THREADCONTEXT_CONTROL_FPU_SPRS = BIT(3), ///< Control fpscr, fpexc.
477 
478  THREADCONTEXT_CONTROL_CPU_REGS = BIT(0) | BIT(1), ///< Control r0-r12, sp, lr, pc, cpsr.
479  THREADCONTEXT_CONTROL_FPU_REGS = BIT(2) | BIT(3), ///< Control d0-d15, fpscr, fpexc.
480 
481  THREADCONTEXT_CONTROL_ALL = BIT(0) | BIT(1) | BIT(2) | BIT(3), ///< Control all of the above.
483 
484 /// Thread parameter field for @ref svcGetDebugThreadParameter
485 typedef enum {
486  DBGTHREAD_PARAMETER_PRIORITY = 0, ///< Thread priority.
487  DBGTHREAD_PARAMETER_SCHEDULING_MASK_LOW = 1, ///< Low scheduling mask.
488  DBGTHREAD_PARAMETER_CPU_IDEAL = 2, ///< Ideal processor.
489  DBGTHREAD_PARAMETER_CPU_CREATOR = 3, ///< Processor that created the threod.
491 
492 ///@}
493 
494 ///@name Processes
495 ///@{
496 
497 /// Information on address space for process. All sizes are in pages (0x1000 bytes)
498 typedef struct {
499  u8 name[8]; ///< ASCII name of codeset
500  u16 version; ///< Version field of codeset (unused)
501  u16 padding[3]; ///< Padding
502  u32 text_addr; ///< .text start address
503  u32 text_size; ///< .text number of pages
504  u32 ro_addr; ///< .rodata start address
505  u32 ro_size; ///< .rodata number of pages
506  u32 rw_addr; ///< .data, .bss start address
507  u32 rw_size; ///< .data number of pages
508  u32 text_size_total; ///< total pages for .text (aligned)
509  u32 ro_size_total; ///< total pages for .rodata (aligned)
510  u32 rw_size_total; ///< total pages for .data, .bss (aligned)
511  u32 padding2; ///< Padding
512  u64 program_id; ///< Program ID
513 } CodeSetHeader;
514 
515 /// Information for the main thread of a process.
516 typedef struct
517 {
518  int priority; ///< Priority of the main thread.
519  u32 stack_size; ///< Size of the stack of the main thread.
520  int argc; ///< Unused on retail kernel.
521  u16* argv; ///< Unused on retail kernel.
522  u16* envp; ///< Unused on retail kernel.
523 } StartupInfo;
524 
525 ///@}
526 
527 /**
528  * @brief Gets the thread local storage buffer.
529  * @return The thread local storage buffer.
530  */
531 static inline void* getThreadLocalStorage(void)
532 {
533  void* ret;
534  __asm__ ("mrc p15, 0, %[data], c13, c0, 3" : [data] "=r" (ret));
535  return ret;
536 }
537 
538 /**
539  * @brief Gets the thread command buffer.
540  * @return The thread command buffer.
541  */
542 static inline u32* getThreadCommandBuffer(void)
543 {
544  return (u32*)((u8*)getThreadLocalStorage() + 0x80);
545 }
546 
547 /**
548  * @brief Gets the thread static buffer.
549  * @return The thread static buffer.
550  */
551 static inline u32* getThreadStaticBuffers(void)
552 {
553  return (u32*)((u8*)getThreadLocalStorage() + 0x180);
554 }
555 
556 ///@name Device drivers
557 ///@{
558 
559 /// Writes the default DMA device config that the kernel uses when DMACFG_*_IS_DEVICE and DMACFG_*_USE_CFG are not set
561 {
562  // Kernel uses this default instance if _IS_DEVICE and _USE_CFG are not set
563  *cfg = (DmaDeviceConfig) {
564  .deviceId = -1,
565  .allowedAlignments = 8 | 4 | 2 | 1,
566  .burstSize = 0x80,
567  .transferSize = 0,
568  .burstStride = 0x80,
569  .transferStride = 0,
570  };
571 }
572 
573 /// Initializes a \ref DmaConfig instance with sane defaults for RAM<>RAM tranfers
574 static inline void dmaConfigInitDefault(DmaConfig *cfg)
575 {
576  *cfg = (DmaConfig) {
577  .channelId = -1,
578  .endianSwapSize = 0,
579  .flags = DMACFG_WAIT_AVAILABLE,
580  ._padding = 0,
581  .srcCfg = {},
582  .dstCfg = {},
583  };
584 }
585 
586 ///@}
587 
588 ///@name Memory management
589 ///@{
590 /**
591  * @brief Controls memory mapping
592  * @param[out] addr_out The virtual address resulting from the operation. Usually the same as addr0.
593  * @param addr0 The virtual address to be used for the operation.
594  * @param addr1 The virtual address to be (un)mirrored by @p addr0 when using @ref MEMOP_MAP or @ref MEMOP_UNMAP.
595  * It has to be pointing to a RW memory.
596  * Use NULL if the operation is @ref MEMOP_FREE or @ref MEMOP_ALLOC.
597  * @param size The requested size for @ref MEMOP_ALLOC and @ref MEMOP_ALLOC_LINEAR.
598  * @param op Operation flags. See @ref MemOp.
599  * @param perm A combination of @ref MEMPERM_READ and @ref MEMPERM_WRITE. Using MEMPERM_EXECUTE will return an error.
600  * Value 0 is used when unmapping memory.
601  *
602  * If a memory is mapped for two or more addresses, you have to use MEMOP_UNMAP before being able to MEMOP_FREE it.
603  * MEMOP_MAP will fail if @p addr1 was already mapped to another address.
604  *
605  * More information is available at http://3dbrew.org/wiki/SVC#Memory_Mapping.
606  *
607  * @sa svcControlProcessMemory
608  */
609 Result svcControlMemory(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm);
610 
611 /**
612  * @brief Controls the memory mapping of a process
613  * @param addr0 The virtual address to map
614  * @param addr1 The virtual address to be mapped by @p addr0
615  * @param type Only operations @ref MEMOP_MAP, @ref MEMOP_UNMAP and @ref MEMOP_PROT are allowed.
616  *
617  * This is the only SVC which allows mapping executable memory.
618  * Using @ref MEMOP_PROT will change the memory permissions of an already mapped memory.
619  *
620  * @note The pseudo handle for the current process is not supported by this service call.
621  * @sa svcControlProcess
622  */
623 Result svcControlProcessMemory(Handle process, u32 addr0, u32 addr1, u32 size, u32 type, u32 perm);
624 
625 /**
626  * @brief Creates a block of shared memory
627  * @param[out] memblock Pointer to store the handle of the block
628  * @param addr Address of the memory to map, page-aligned. So its alignment must be 0x1000.
629  * @param size Size of the memory to map, a multiple of 0x1000.
630  * @param my_perm Memory permissions for the current process
631  * @param other_perm Memory permissions for the other processes
632  *
633  * @note The shared memory block, and its rights, are destroyed when the handle is closed.
634  */
635 Result svcCreateMemoryBlock(Handle* memblock, u32 addr, u32 size, MemPerm my_perm, MemPerm other_perm);
636 
637 /**
638  * @brief Maps a block of shared memory
639  * @param memblock Handle of the block
640  * @param addr Address of the memory to map, page-aligned. So its alignment must be 0x1000.
641  * @param my_perm Memory permissions for the current process
642  * @param other_perm Memory permissions for the other processes
643  *
644  * @note The shared memory block, and its rights, are destroyed when the handle is closed.
645  */
646 Result svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm);
647 
648 /**
649  * @brief Maps a block of process memory, starting from address 0x00100000.
650  * @param process Handle of the process.
651  * @param destAddress Address of the block of memory to map, in the current (destination) process.
652  * @param size Size of the block of memory to map (truncated to a multiple of 0x1000 bytes).
653  */
654 Result svcMapProcessMemory(Handle process, u32 destAddress, u32 size);
655 
656 /**
657  * @brief Unmaps a block of process memory, starting from address 0x00100000.
658  * @param process Handle of the process.
659  * @param destAddress Address of the block of memory to unmap, in the current (destination) process.
660  * @param size Size of the block of memory to unmap (truncated to a multiple of 0x1000 bytes).
661  */
662 Result svcUnmapProcessMemory(Handle process, u32 destAddress, u32 size);
663 
664 /**
665  * @brief Unmaps a block of shared memory
666  * @param memblock Handle of the block
667  * @param addr Address of the memory to unmap, page-aligned. So its alignment must be 0x1000.
668  */
670 
671 /**
672  * @brief Queries memory information.
673  * @param[out] info Pointer to output memory info to.
674  * @param out Pointer to output page info to.
675  * @param addr Virtual memory address to query.
676  */
678 
679 /**
680  * @brief Queries process memory information.
681  * @param[out] info Pointer to output memory info to.
682  * @param[out] out Pointer to output page info to.
683  * @param process Process to query memory from.
684  * @param addr Virtual memory address to query.
685  */
687 
688 ///@}
689 
690 
691 ///@name Process management
692 ///@{
693 /**
694  * @brief Gets the handle of a process.
695  * @param[out] process The handle of the process
696  * @param processId The ID of the process to open
697  */
698 Result svcOpenProcess(Handle* process, u32 processId);
699 
700 /// Exits the current process.
701 void svcExitProcess(void) __attribute__((noreturn));
702 
703 /**
704  * @brief Terminates a process.
705  * @param process Handle of the process to terminate.
706  */
708 
709 /**
710  * @brief Gets information about a process.
711  * @param[out] out Pointer to output process info to.
712  * @param process Handle of the process to get information about.
713  * @param type Type of information to retreieve.
714  */
715 Result svcGetProcessInfo(s64* out, Handle process, u32 type);
716 
717 /**
718  * @brief Gets the ID of a process.
719  * @param[out] out Pointer to output the process ID to.
720  * @param handle Handle of the process to get the ID of.
721  */
723 
724 /**
725  * @brief Gets a list of running processes.
726  * @param[out] processCount Pointer to output the process count to.
727  * @param[out] processIds Pointer to output the process IDs to.
728  * @param processIdMaxCount Maximum number of process IDs.
729  */
730 Result svcGetProcessList(s32* processCount, u32* processIds, s32 processIdMaxCount);
731 
732 /**
733  * @brief Gets a list of the threads of a process.
734  * @param[out] threadCount Pointer to output the thread count to.
735  * @param[out] threadIds Pointer to output the thread IDs to.
736  * @param threadIdMaxCount Maximum number of thread IDs.
737  * @param process Process handle to list the threads of.
738  */
739 Result svcGetThreadList(s32* threadCount, u32* threadIds, s32 threadIdMaxCount, Handle process);
740 
741 /**
742  * @brief Creates a port.
743  * @param[out] portServer Pointer to output the port server handle to.
744  * @param[out] portClient Pointer to output the port client handle to.
745  * @param name Name of the port.
746  * @param maxSessions Maximum number of sessions that can connect to the port.
747  */
748 Result svcCreatePort(Handle* portServer, Handle* portClient, const char* name, s32 maxSessions);
749 
750 /**
751  * @brief Connects to a port.
752  * @param[out] out Pointer to output the port handle to.
753  * @param portName Name of the port.
754  */
755 Result svcConnectToPort(volatile Handle* out, const char* portName);
756 
757 /**
758  * @brief Sets up virtual address space for a new process.
759  * @param[out] out Pointer to output the codeset handle to.
760  * @param info Codeset header, contains process name, titleId and segment info.
761  * @param textSegmentLma Address of executable segment in caller's address space.
762  * @param roSegmentLma Address of read-only segment in caller's address space.
763  * @param dataSegmentLma Address of read-write segment in caller's address space.
764  * @note On success, the provided segments are unmapped from the caller's address space.
765  */
766 Result svcCreateCodeSet(Handle* out, const CodeSetHeader* info, u32 textSegmentLma, u32 roSegmentLma, u32 dataSegmentLma);
767 
768 /**
769  * @brief Create a new process.
770  * @param[out] out Pointer to output the process handle to.
771  * @param codeset Codeset created for this process.
772  * @param arm11KernelCaps Arm11 Kernel Capabilities from exheader.
773  * @param numArm11KernelCaps Number of kernel capabilities.
774  */
775 Result svcCreateProcess(Handle* out, Handle codeset, const u32* arm11KernelCaps, s32 numArm11KernelCaps);
776 
777 /**
778  * @brief Gets a process's affinity mask.
779  * @param[out] affinitymask Pointer to store the affinity masks.
780  * @param process Handle of the process.
781  * @param processorcount Number of processors.
782  */
783 Result svcGetProcessAffinityMask(u8* affinitymask, Handle process, s32 processorcount);
784 
785 /**
786  * @brief Sets a process's affinity mask.
787  * @param process Handle of the process.
788  * @param affinitymask Pointer to retrieve the affinity masks from.
789  * @param processorcount Number of processors.
790  */
791 Result svcSetProcessAffinityMask(Handle process, const u8* affinitymask, s32 processorcount);
792 
793 /**
794  * Gets a process's ideal processor.
795  * @param[out] processorid Pointer to store the ID of the process's ideal processor.
796  * @param process Handle of the process.
797  */
799 
800 /**
801  * Sets a process's ideal processor.
802  * @param process Handle of the process.
803  * @param processorid ID of the process's ideal processor.
804  */
806 
807 /**
808  * Launches the main thread of the process.
809  * @param process Handle of the process.
810  * @param info Pointer to a StartupInfo structure describing information for the main thread.
811  */
812 Result svcRun(Handle process, const StartupInfo* info);
813 
814 ///@}
815 
816 ///@name Multithreading
817 ///@{
818 /**
819  * @brief Creates a new thread.
820  * @param[out] thread The thread handle
821  * @param entrypoint The function that will be called first upon thread creation
822  * @param arg The argument passed to @p entrypoint
823  * @param stack_top The top of the thread's stack. Must be 0x8 bytes mem-aligned.
824  * @param thread_priority Low values gives the thread higher priority.
825  * For userland apps, this has to be within the range [0x18;0x3F]
826  * @param processor_id The id of the processor the thread should be ran on. Those are labelled starting from 0.
827  * For old 3ds it has to be <2, and for new 3DS <4.
828  * Value -1 means all CPUs and -2 read from the Exheader.
829  *
830  * The processor with ID 1 is the system processor.
831  * To enable multi-threading on this core you need to call APT_SetAppCpuTimeLimit at least once with a non-zero value.
832  *
833  * Since a thread is considered as a waitable object, you can use @ref svcWaitSynchronization
834  * and @ref svcWaitSynchronizationN to join with it.
835  *
836  * @note The kernel will clear the @p stack_top's address low 3 bits to make sure it is 0x8-bytes aligned.
837  */
838 Result svcCreateThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stack_top, s32 thread_priority, s32 processor_id);
839 
840 /**
841  * @brief Gets the handle of a thread.
842  * @param[out] thread The handle of the thread
843  * @param process The ID of the process linked to the thread
844  */
845 Result svcOpenThread(Handle* thread,Handle process, u32 threadId);
846 
847 /**
848  * @brief Exits the current thread.
849  *
850  * This will trigger a state change and hence release all @ref svcWaitSynchronization operations.
851  * It means that you can join a thread by calling @code svcWaitSynchronization(threadHandle,yourtimeout); @endcode
852  */
853 void svcExitThread(void) __attribute__((noreturn));
854 
855 /**
856  * @brief Puts the current thread to sleep.
857  * @param ns The minimum number of nanoseconds to sleep for.
858  */
860 
861 /// Retrieves the priority of a thread.
863 
864 /**
865  * @brief Changes the priority of a thread
866  * @param prio For userland apps, this has to be within the range [0x18;0x3F]
867  *
868  * Low values gives the thread higher priority.
869  */
871 
872 /**
873  * @brief Gets a thread's affinity mask.
874  * @param[out] affinitymask Pointer to output the affinity masks to.
875  * @param thread Handle of the thread.
876  * @param processorcount Number of processors.
877  */
878 Result svcGetThreadAffinityMask(u8* affinitymask, Handle thread, s32 processorcount);
879 
880 /**
881  * @brief Sets a thread's affinity mask.
882  * @param thread Handle of the thread.
883  * @param affinitymask Pointer to retrieve the affinity masks from.
884  * @param processorcount Number of processors.
885  */
886 Result svcSetThreadAffinityMask(Handle thread, const u8* affinitymask, s32 processorcount);
887 
888 /**
889  * @brief Gets a thread's ideal processor.
890  * @param[out] processorid Pointer to output the ID of the thread's ideal processor to.
891  * @param thread Handle of the thread.
892  */
894 
895 /**
896  * Sets a thread's ideal processor.
897  * @param thread Handle of the thread.
898  * @param processorid ID of the thread's ideal processor.
899  */
901 
902 /**
903  * @brief Returns the ID of the processor the current thread is running on.
904  * @sa svcCreateThread
905  */
907 
908 /**
909  * @brief Gets the ID of a thread.
910  * @param[out] out Pointer to output the thread ID of the thread @p handle to.
911  * @param handle Handle of the thread.
912  */
914 
915 /**
916  * @brief Gets the resource limit set of a process.
917  * @param[out] resourceLimit Pointer to output the resource limit set handle to.
918  * @param process Process to get the resource limits of.
919  */
920 Result svcGetResourceLimit(Handle* resourceLimit, Handle process);
921 
922 /**
923  * @brief Gets the value limits of a resource limit set.
924  * @param[out] values Pointer to output the value limits to.
925  * @param resourceLimit Resource limit set to use.
926  * @param names Resource limit names to get the limits of.
927  * @param nameCount Number of resource limit names.
928  */
929 Result svcGetResourceLimitLimitValues(s64* values, Handle resourceLimit, ResourceLimitType* names, s32 nameCount);
930 
931 /**
932  * @brief Gets the values of a resource limit set.
933  * @param[out] values Pointer to output the values to.
934  * @param resourceLimit Resource limit set to use.
935  * @param names Resource limit names to get the values of.
936  * @param nameCount Number of resource limit names.
937  */
938 Result svcGetResourceLimitCurrentValues(s64* values, Handle resourceLimit, ResourceLimitType* names, s32 nameCount);
939 
940 /**
941  * @brief Sets the resource limit set of a process.
942  * @param process Process to set the resource limit set to.
943  * @param resourceLimit Resource limit set handle.
944  */
946 
947 /**
948  * @brief Creates a resource limit set.
949  * @param[out] resourceLimit Pointer to output the resource limit set handle to.
950  */
952 
953 /**
954  * @brief Sets the value limits of a resource limit set.
955  * @param resourceLimit Resource limit set to use.
956  * @param names Resource limit names to set the limits of.
957  * @param values Value limits to set. The high 32 bits of RESLIMIT_COMMIT are used to
958  set APPMEMALLOC in configuration memory, otherwise those bits are unused.
959  * @param nameCount Number of resource limit names.
960  */
961 Result svcSetResourceLimitValues(Handle resourceLimit, const ResourceLimitType* names, const s64* values, s32 nameCount);
962 
963 /**
964  * @brief Gets the process ID of a thread.
965  * @param[out] out Pointer to output the process ID of the thread @p handle to.
966  * @param handle Handle of the thread.
967  * @sa svcOpenProcess
968  */
970 
971 /**
972  * @brief Checks if a thread handle is valid.
973  * This requests always return an error when called, it only checks if the handle is a thread or not.
974  * @return 0xD8E007ED (BAD_ENUM) if the Handle is a Thread Handle
975  * @return 0xD8E007F7 (BAD_HANDLE) if it isn't.
976  */
978 ///@}
979 
980 
981 ///@name Synchronization
982 ///@{
983 /**
984  * @brief Creates a mutex.
985  * @param[out] mutex Pointer to output the handle of the created mutex to.
986  * @param initially_locked Whether the mutex should be initially locked.
987  */
988 Result svcCreateMutex(Handle* mutex, bool initially_locked);
989 
990 /**
991  * @brief Releases a mutex.
992  * @param handle Handle of the mutex.
993  */
995 
996 /**
997  * @brief Creates a semaphore.
998  * @param[out] semaphore Pointer to output the handle of the created semaphore to.
999  * @param initial_count Initial count of the semaphore.
1000  * @param max_count Maximum count of the semaphore.
1001  */
1002 Result svcCreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count);
1003 
1004 /**
1005  * @brief Releases a semaphore.
1006  * @param[out] count Pointer to output the current count of the semaphore to.
1007  * @param semaphore Handle of the semaphore.
1008  * @param release_count Number to increase the semaphore count by.
1009  */
1010 Result svcReleaseSemaphore(s32* count, Handle semaphore, s32 release_count);
1011 
1012 /**
1013  * @brief Creates an event handle.
1014  * @param[out] event Pointer to output the created event handle to.
1015  * @param reset_type Type of reset the event uses (RESET_ONESHOT/RESET_STICKY).
1016  */
1018 
1019 /**
1020  * @brief Signals an event.
1021  * @param handle Handle of the event to signal.
1022  */
1024 
1025 /**
1026  * @brief Clears an event.
1027  * @param handle Handle of the event to clear.
1028  */
1030 
1031 /**
1032  * @brief Waits for synchronization on a handle.
1033  * @param handle Handle to wait on.
1034  * @param nanoseconds Maximum nanoseconds to wait for.
1035  */
1037 
1038 /**
1039  * @brief Waits for synchronization on multiple handles.
1040  * @param[out] out Pointer to output the index of the synchronized handle to.
1041  * @param handles Handles to wait on.
1042  * @param handles_num Number of handles.
1043  * @param wait_all Whether to wait for synchronization on all handles.
1044  * @param nanoseconds Maximum nanoseconds to wait for.
1045  */
1046 Result svcWaitSynchronizationN(s32* out, const Handle* handles, s32 handles_num, bool wait_all, s64 nanoseconds);
1047 
1048 /**
1049  * @brief Creates an address arbiter
1050  * @param[out] mutex Pointer to output the handle of the created address arbiter to.
1051  * @sa svcArbitrateAddress
1052  */
1054 
1055 /**
1056  * @brief Arbitrate an address, can be used for synchronization
1057  * @param arbiter Handle of the arbiter
1058  * @param addr A pointer to a s32 value.
1059  * @param type Type of action to be performed by the arbiter
1060  * @param value Number of threads to signal if using @ref ARBITRATION_SIGNAL, or the value used for comparison.
1061  * @param timeout_ns Optional timeout in nanoseconds when using TIMEOUT actions, ignored otherwise. If not needed, use \ref svcArbitrateAddressNoTimeout instead.
1062  * @note Usage of this syscall entails an implicit Data Memory Barrier (dmb).
1063  * @warning Please use \ref syncArbitrateAddressWithTimeout instead.
1064  */
1065 Result svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 timeout_ns);
1066 
1067 /**
1068  * @brief Same as \ref svcArbitrateAddress but with the timeout_ns parameter undefined.
1069  * @param arbiter Handle of the arbiter
1070  * @param addr A pointer to a s32 value.
1071  * @param type Type of action to be performed by the arbiter
1072  * @param value Number of threads to signal if using @ref ARBITRATION_SIGNAL, or the value used for comparison.
1073  * @note Usage of this syscall entails an implicit Data Memory Barrier (dmb).
1074  * @warning Please use \ref syncArbitrateAddress instead.
1075  */
1077 
1078 /**
1079  * @brief Sends a synchronized request to a session handle.
1080  * @param session Handle of the session.
1081  */
1083 
1084 /**
1085  * @brief Connects to a port via a handle.
1086  * @param[out] clientSession Pointer to output the client session handle to.
1087  * @param clientPort Port client endpoint to connect to.
1088  */
1089 Result svcCreateSessionToPort(Handle* clientSession, Handle clientPort);
1090 
1091 /**
1092  * @brief Creates a linked pair of session endpoints.
1093  * @param[out] serverSession Pointer to output the created server endpoint handle to.
1094  * @param[out] clientSession Pointer to output the created client endpoint handle to.
1095  */
1096 Result svcCreateSession(Handle* serverSession, Handle* clientSession);
1097 
1098 /**
1099  * @brief Accepts a session.
1100  * @param[out] session Pointer to output the created session handle to.
1101  * @param port Handle of the port to accept a session from.
1102  */
1104 
1105 /**
1106  * @brief Replies to and receives a new request.
1107  * @param index Pointer to the index of the request.
1108  * @param handles Session handles to receive requests from.
1109  * @param handleCount Number of handles.
1110  * @param replyTarget Handle of the session to reply to.
1111  */
1112 Result svcReplyAndReceive(s32* index, const Handle* handles, s32 handleCount, Handle replyTarget);
1113 
1114 ///@}
1115 
1116 ///@name Time
1117 ///@{
1118 /**
1119  * @brief Creates a timer.
1120  * @param[out] timer Pointer to output the handle of the created timer to.
1121  * @param reset_type Type of reset to perform on the timer.
1122  */
1124 
1125 /**
1126  * @brief Sets a timer.
1127  * @param timer Handle of the timer to set.
1128  * @param initial Initial value of the timer.
1129  * @param interval Interval of the timer.
1130  */
1131 Result svcSetTimer(Handle timer, s64 initial, s64 interval);
1132 
1133 /**
1134  * @brief Cancels a timer.
1135  * @param timer Handle of the timer to cancel.
1136  */
1138 
1139 /**
1140  * @brief Clears a timer.
1141  * @param timer Handle of the timer to clear.
1142  */
1144 
1145 /**
1146  * @brief Gets the current system tick.
1147  * @return The current system tick.
1148  */
1150 ///@}
1151 
1152 ///@name System
1153 ///@{
1154 /**
1155  * @brief Closes a handle.
1156  * @param handle Handle to close.
1157  */
1159 
1160 /**
1161  * @brief Duplicates a handle.
1162  * @param[out] out Pointer to output the duplicated handle to.
1163  * @param original Handle to duplicate.
1164  */
1166 
1167 /**
1168  * @brief Gets a handle info.
1169  * @param[out] out Pointer to output the handle info to.
1170  * @param handle Handle to get the info for.
1171  * @param param Parameter clarifying the handle info type.
1172  */
1173 Result svcGetHandleInfo(s64* out, Handle handle, u32 param);
1174 
1175 /**
1176  * @brief Gets the system info.
1177  * @param[out] out Pointer to output the system info to.
1178  * @param type Type of system info to retrieve.
1179  * @param param Parameter clarifying the system info type.
1180  */
1181 Result svcGetSystemInfo(s64* out, u32 type, s32 param);
1182 
1183 /**
1184  * @brief Sets the current kernel state.
1185  * @param type Type of state to set (the other parameters depend on it).
1186  */
1188 ///@}
1189 
1190 ///@name Device drivers
1191 ///@{
1192 
1193 /**
1194  * @brief Binds an event or semaphore handle to an ARM11 interrupt.
1195  * @param interruptId Interrupt identfier (see https://www.3dbrew.org/wiki/ARM11_Interrupts).
1196  * @param eventOrSemaphore Event or semaphore handle to bind to the given interrupt.
1197  * @param priority Priority of the interrupt for the current process.
1198  * @param isManualClear Indicates whether the interrupt has to be manually cleared or not (= level-high active).
1199  */
1200 Result svcBindInterrupt(u32 interruptId, Handle eventOrSemaphore, s32 priority, bool isManualClear);
1201 
1202 /**
1203  * @brief Unbinds an event or semaphore handle from an ARM11 interrupt.
1204  * @param interruptId Interrupt identfier, see (see https://www.3dbrew.org/wiki/ARM11_Interrupts).
1205  * @param eventOrSemaphore Event or semaphore handle to unbind from the given interrupt.
1206  */
1207 Result svcUnbindInterrupt(u32 interruptId, Handle eventOrSemaphore);
1208 
1209 /**
1210  * @brief Invalidates a process's data cache.
1211  * @param process Handle of the process.
1212  * @param addr Address to invalidate.
1213  * @param size Size of the memory to invalidate.
1214  */
1216 
1217 /**
1218  * @brief Cleans a process's data cache.
1219  * @param process Handle of the process.
1220  * @param addr Address to clean.
1221  * @param size Size of the memory to clean.
1222  */
1224 
1225 /**
1226  * @brief Flushes (cleans and invalidates) a process's data cache.
1227  * @param process Handle of the process.
1228  * @param addr Address to flush.
1229  * @param size Size of the memory to flush.
1230  */
1232 
1233 /**
1234  * @brief Begins an inter-process DMA transfer.
1235  * @param[out] dma Pointer to output the handle of the DMA channel object to.
1236  * @param dstProcess Destination process handle.
1237  * @param dstAddr Address in the destination process to write data to.
1238  * @param srcProcess Source process handle.
1239  * @param srcAddr Address in the source to read data from.
1240  * @param size Size of the data to transfer.
1241  * @param cfg Configuration structure.
1242  * @note The handle is signaled when the transfer finishes.
1243  */
1244 Result svcStartInterProcessDma(Handle *dma, Handle dstProcess, u32 dstAddr, Handle srcProcess, u32 srcAddr, u32 size, const DmaConfig *cfg);
1245 
1246 /**
1247  * @brief Stops an inter-process DMA transfer.
1248  * @param dma Handle of the DMA channel object.
1249  */
1251 
1252 /**
1253  * @brief Gets the state of an inter-process DMA transfer.
1254  * @param[out] state Pointer to output the state of the DMA transfer to.
1255  * @param dma Handle of the DMA channel object.
1256  */
1258 
1259 /**
1260  * @brief Restarts a DMA transfer, using the same configuration as before.
1261  * @param[out] state Pointer to output the state of the DMA transfer to.
1262  * @param dma Handle of the DMA channel object.
1263  * @param dstAddr Address in the destination process to write data to.
1264  * @param srcAddr Address in the source to read data from.
1265  * @param size Size of the data to transfer.
1266  * @param flags Restart flags, \ref DMARST_UNLOCK and/or \ref DMARST_RESUME_DEVICE.
1267  * @note The first transfer has to be configured with \ref DMACFG_KEEP_LOCKED.
1268  */
1269 Result svcRestartDma(Handle dma, u32 dstAddr, u32 srcAddr, u32 size, s8 flags);
1270 
1271 /**
1272  * @brief Sets the GPU protection register to restrict the range of the GPU DMA. 11.3+ only.
1273  * @param useApplicationRestriction Whether to use the register value used for APPLICATION titles.
1274  */
1275 Result svcSetGpuProt(bool useApplicationRestriction);
1276 
1277 /**
1278  * @brief Enables or disables Wi-Fi. 11.4+ only.
1279  * @param enabled Whether to enable or disable Wi-Fi.
1280  */
1282 
1283 ///@}
1284 
1285 ///@name Debugging
1286 ///@{
1287 /**
1288  * @brief Breaks execution.
1289  * @param breakReason Reason for breaking.
1290  */
1291 void svcBreak(UserBreakType breakReason);
1292 
1293 /**
1294  * @brief Breaks execution (LOAD_RO and UNLOAD_RO).
1295  * @param breakReason Debug reason for breaking.
1296  * @param croInfo Library information.
1297  * @param croInfoSize Size of the above structure.
1298  */
1299 void svcBreakRO(UserBreakType breakReason, const void* croInfo, u32 croInfoSize) __asm__("svcBreak");
1300 
1301 /**
1302  * @brief Outputs a debug string.
1303  * @param str String to output.
1304  * @param length Length of the string to output, needs to be positive.
1305  */
1306 Result svcOutputDebugString(const char* str, s32 length);
1307 
1308 
1309 /**
1310  * @brief Controls performance monitoring on the CP15 interface and the SCU.
1311  * The meaning of the parameters depend on the operation.
1312  * @param[out] out Output.
1313  * @param op Operation, see details.
1314  * @param param1 First parameter.
1315  * @param param2 Second parameter.
1316  * @details The operations are the following:
1317  * - \ref PERFCOUNTEROP_ENABLE (void) -> void, tries to enable and lock perfmon. functionality.
1318  * - \ref PERFCOUNTEROP_DISABLE (void) -> void, disable and forcibly unlocks perfmon. functionality.
1319  * - \ref PERFCOUNTEROP_GET_VALUE (\ref PerfCounterRegister reg) -> u64, gets the value of a particular counter register.
1320  * - \ref PERFCOUNTEROP_SET_VALUE (\ref PerfCounterRegister reg, u64 value) -> void, sets the value of a particular counter register.
1321  * - \ref PERFCOUNTEROP_GET_OVERFLOW_FLAGS (void) -> u32, gets the overflow flags of all CP15 and SCU registers.
1322  * - Format is a bitfield of \ref PerfCounterRegister.
1323  * - \ref PERFCOUNTEROP_RESET (u32 valueResetMask, u32 overflowFlagResetMask) -> void, resets the value and/or
1324  * overflow flags of selected registers.
1325  * - Format is two bitfields of \ref PerfCounterRegister.
1326  * - \ref PERFCOUNTEROP_GET_EVENT (\ref PerfCounterRegister reg) -> \ref PerfCounterEvent, gets the event associated
1327  * to a particular counter register.
1328  * - \ref PERFCOUNTEROP_SET_EVENT (\ref PerfCounterRegister reg, \ref PerfCounterEvent) -> void, sets the event associated
1329  * to a particular counter register.
1330  * - \ref PERFCOUNTEROP_SET_VIRTUAL_COUNTER_ENABLED (bool enabled) -> void, (dis)allows the kernel to track counter overflows
1331  * and to use 64-bit counter values.
1332  */
1334 
1335 /**
1336  * @brief Creates a debug handle for an active process.
1337  * @param[out] debug Pointer to output the created debug handle to.
1338  * @param processId ID of the process to debug.
1339  */
1341 
1342 /**
1343  * @brief Breaks a debugged process.
1344  * @param debug Debug handle of the process.
1345  */
1347 
1348 /**
1349  * @brief Terminates a debugged process.
1350  * @param debug Debug handle of the process.
1351  */
1353 
1354 /**
1355  * @brief Gets the current debug event of a debugged process.
1356  * @param[out] info Pointer to output the debug event information to.
1357  * @param debug Debug handle of the process.
1358  */
1360 
1361 /**
1362  * @brief Continues the current debug event of a debugged process (not necessarily the same as @ref svcGetProcessDebugEvent).
1363  * @param debug Debug handle of the process.
1364  * @param flags Flags to continue with, see @ref DebugFlags.
1365  */
1367 
1368 /**
1369  * @brief Fetches the saved registers of a thread, either inactive or awaiting @ref svcContinueDebugEvent, belonging to a debugged process.
1370  * @param[out] context Values of the registers to fetch, see @ref ThreadContext.
1371  * @param debug Debug handle of the parent process.
1372  * @param threadId ID of the thread to fetch the saved registers of.
1373  * @param controlFlags Which registers to fetch, see @ref ThreadContextControlFlags.
1374  */
1376 
1377 /**
1378  * @brief Updates the saved registers of a thread, either inactive or awaiting @ref svcContinueDebugEvent, belonging to a debugged process.
1379  * @param debug Debug handle of the parent process.
1380  * @param threadId ID of the thread to update the saved registers of.
1381  * @param context Values of the registers to update, see @ref ThreadContext.
1382  * @param controlFlags Which registers to update, see @ref ThreadContextControlFlags.
1383  */
1385 
1386 /**
1387  * @brief Queries memory information of a debugged process.
1388  * @param[out] info Pointer to output memory info to.
1389  * @param[out] out Pointer to output page info to.
1390  * @param debug Debug handle of the process to query memory from.
1391  * @param addr Virtual memory address to query.
1392  */
1394 
1395 /**
1396  * @brief Reads from a debugged process's memory.
1397  * @param buffer Buffer to read data to.
1398  * @param debug Debug handle of the process.
1399  * @param addr Address to read from.
1400  * @param size Size of the memory to read.
1401  */
1402 Result svcReadProcessMemory(void* buffer, Handle debug, u32 addr, u32 size);
1403 
1404 /**
1405  * @brief Writes to a debugged process's memory.
1406  * @param debug Debug handle of the process.
1407  * @param buffer Buffer to write data from.
1408  * @param addr Address to write to.
1409  * @param size Size of the memory to write.
1410  */
1411 Result svcWriteProcessMemory(Handle debug, const void* buffer, u32 addr, u32 size);
1412 
1413 /**
1414  * @brief Sets an hardware breakpoint or watchpoint. This is an interface to the BRP/WRP registers, see http://infocenter.arm.com/help/topic/com.arm.doc.ddi0360f/CEGEBGFC.html .
1415  * @param registerId range 0..5 = breakpoints (BRP0-5), 0x100..0x101 = watchpoints (WRP0-1). The previous stop point for the register is disabled.
1416  * @param control Value of the control regiser.
1417  * @param value Value of the value register: either and address (if bit21 of control is clear) or the debug handle of a process to fetch the context ID of.
1418  */
1419 Result svcSetHardwareBreakPoint(s32 registerId, u32 control, u32 value);
1420 
1421 /**
1422  * @brief Gets a debugged thread's parameter.
1423  * @param[out] unused Unused.
1424  * @param[out] out Output value.
1425  * @param debug Debug handle of the process.
1426  * @param threadId ID of the thread
1427  * @param parameter Parameter to fetch, see @ref DebugThreadParameter.
1428  */
1429 Result svcGetDebugThreadParam(s64* unused, u32* out, Handle debug, u32 threadId, DebugThreadParameter parameter);
1430 
1431 ///@}
1432 
1433 /**
1434  * @brief Executes a function in supervisor mode.
1435  * @param callback Function to execute.
1436  */
1437 Result svcBackdoor(s32 (*callback)(void));
1438 
1439 /// Stop point, does nothing if the process is not attached (as opposed to 'bkpt' instructions)
1440 #define SVC_STOP_POINT __asm__ volatile("svc 0xFF");
__attribute__((warn_unused_result)) rbtree_node_t *rbtree_insert(rbtree_t *tree
Inserts a node into an rbtree.
Event relating to the attachment of a process.
Definition: svc.h:292
u32 other_flags
Always 0.
Definition: svc.h:296
u64 program_id
ID of the program.
Definition: svc.h:293
u32 process_id
ID of the process.
Definition: svc.h:295
Event relating to the attachment of a thread.
Definition: svc.h:312
u32 entry_point
Entry point of the thread.
Definition: svc.h:315
u32 creator_thread_id
ID of the creating thread.
Definition: svc.h:313
u32 thread_local_storage
Thread local storage.
Definition: svc.h:314
Information on address space for process. All sizes are in pages (0x1000 bytes)
Definition: svc.h:498
u32 text_size_total
total pages for .text (aligned)
Definition: svc.h:508
u32 text_addr
.text start address
Definition: svc.h:502
u32 ro_size
.rodata number of pages
Definition: svc.h:505
u32 rw_addr
.data, .bss start address
Definition: svc.h:506
u16 version
Version field of codeset (unused)
Definition: svc.h:500
u64 program_id
Program ID.
Definition: svc.h:512
u32 padding2
Padding.
Definition: svc.h:511
u32 ro_size_total
total pages for .rodata (aligned)
Definition: svc.h:509
u32 rw_size
.data number of pages
Definition: svc.h:507
u32 rw_size_total
total pages for .data, .bss (aligned)
Definition: svc.h:510
u32 text_size
.text number of pages
Definition: svc.h:503
u32 ro_addr
.rodata start address
Definition: svc.h:504
Structure representing CPU registers.
Definition: types.h:63
Information about a debug event.
Definition: svc.h:438
u32 flags
Flags. Bit0 means that svcContinueDebugEvent needs to be called for this event (except for EXIT PROCE...
Definition: svc.h:441
ExitProcessEvent exit_process
Process exit event data.
Definition: svc.h:447
SyscallInOutEvent syscall
Syscall in/out event data.
Definition: svc.h:451
ScheduleInOutEvent scheduler
Schedule in/out event data.
Definition: svc.h:450
u32 thread_id
ID of the thread.
Definition: svc.h:440
AttachThreadEvent attach_thread
Thread attachment event data.
Definition: svc.h:445
ExitThreadEvent exit_thread
Thread exit event data.
Definition: svc.h:446
AttachProcessEvent attach_process
Process attachment event data.
Definition: svc.h:444
OutputStringEvent output_string
Output string event data.
Definition: svc.h:452
ExceptionEvent exception
Exception event data.
Definition: svc.h:448
DebugEventType type
Type of event. See DebugEventType.
Definition: svc.h:439
MapEvent map
Map event data.
Definition: svc.h:453
Event relating to svcBreakDebugProcess.
Definition: svc.h:379
Configuration stucture for svcStartInterProcessDma.
Definition: svc.h:183
s8 channelId
Channel ID (Arm11: 0-7, Arm9: 0-1). Use -1 to auto-assign to a free channel (Arm11: 3-7,...
Definition: svc.h:184
s8 endianSwapSize
Endian swap size (can be 0).
Definition: svc.h:185
DmaDeviceConfig srcCfg
Source device configuration, read if DMACFG_SRC_IS_DEVICE and/or DMACFG_USE_SRC_CONFIG are set.
Definition: svc.h:188
u8 flags
DMACFG_* flags.
Definition: svc.h:186
DmaDeviceConfig dstCfg
Destination device configuration, read if DMACFG_SRC_IS_DEVICE and/or DMACFG_USE_SRC_CONFIG are set.
Definition: svc.h:189
Device configuration structure, part of DmaConfig.
Definition: svc.h:173
s16 burstStride
Burst loop stride, can be <= 0.
Definition: svc.h:178
s8 deviceId
DMA device ID.
Definition: svc.h:174
s16 transferStride
"Transfer" loop stride, can be <= 0.
Definition: svc.h:179
s16 burstSize
Number of bytes transferred in a burst loop. Can be 0 (in which case the max allowed alignment is use...
Definition: svc.h:176
s16 transferSize
Number of bytes transferred in a "transfer" loop (made of burst loops).
Definition: svc.h:177
s8 allowedAlignments
Mask of allowed access alignments (8, 4, 2, 1).
Definition: svc.h:175
Event relating to exceptions.
Definition: svc.h:384
ExceptionEventType type
Type of event. See ExceptionEventType.
Definition: svc.h:385
UserBreakExceptionEvent user_break
User break exception event data.
Definition: svc.h:390
u32 address
Address of the exception.
Definition: svc.h:386
FaultExceptionEvent fault
Fault exception event data.
Definition: svc.h:388
StopPointExceptionEvent stop_point
Stop point exception event data.
Definition: svc.h:389
DebuggerBreakExceptionEvent debugger_break
Debugger break exception event data.
Definition: svc.h:391
Event relating to the exiting of a process.
Definition: svc.h:307
ExitProcessEventReason reason
Reason for exiting. See ExitProcessEventReason.
Definition: svc.h:308
Event relating to the exiting of a thread.
Definition: svc.h:327
ExitThreadEventReason reason
Reason for exiting. See ExitThreadEventReason.
Definition: svc.h:328
Event relating to fault exceptions (CPU exceptions other than stop points and undefined syscalls).
Definition: svc.h:354
u32 fault_information
FAR (for DATA ABORT / UNALIGNED DATA ACCESS), attempted syscall or 0.
Definition: svc.h:355
Structure representing FPU registers.
Definition: types.h:72
Event relating to the mapping of memory.
Definition: svc.h:413
MemState memstate
Memory state. See MemState.
Definition: svc.h:417
u32 mapped_addr
Mapped address.
Definition: svc.h:414
MemPerm memperm
Memory permissions. See MemPerm.
Definition: svc.h:416
u32 mapped_size
Mapped size.
Definition: svc.h:415
Memory information.
Definition: svc.h:75
u32 base_addr
Base address.
Definition: svc.h:76
u32 state
Memory state. See MemState.
Definition: svc.h:79
u32 perm
Memory permissions. See MemPerm.
Definition: svc.h:78
u32 size
Size.
Definition: svc.h:77
Event relating to debug output.
Definition: svc.h:407
u32 string_size
Size of the outputted string.
Definition: svc.h:409
u32 string_addr
Address of the outputted string.
Definition: svc.h:408
Memory page information.
Definition: svc.h:83
u32 flags
Page flags.
Definition: svc.h:84
Event relating to the scheduler.
Definition: svc.h:396
u64 clock_tick
Clock tick that the event occurred.
Definition: svc.h:397
Information for the main thread of a process.
Definition: svc.h:517
u32 stack_size
Size of the stack of the main thread.
Definition: svc.h:519
u16 * envp
Unused on retail kernel.
Definition: svc.h:522
int priority
Priority of the main thread.
Definition: svc.h:518
int argc
Unused on retail kernel.
Definition: svc.h:520
u16 * argv
Unused on retail kernel.
Definition: svc.h:521
Event relating to stop points.
Definition: svc.h:366
StopPointType type
Stop point type, see StopPointType.
Definition: svc.h:367
u32 fault_information
FAR for Watchpoints, otherwise 0.
Definition: svc.h:368
Event relating to syscalls.
Definition: svc.h:401
u32 syscall
Syscall sent/received.
Definition: svc.h:403
u64 clock_tick
Clock tick that the event occurred.
Definition: svc.h:402
Definition: svc.h:466
CpuRegisters cpu_registers
CPU registers.
Definition: svc.h:467
FpuRegisters fpu_registers
FPU registers.
Definition: svc.h:468
Event relating to svcBreak.
Definition: svc.h:372
u32 croInfo
For LOAD_RO and UNLOAD_RO.
Definition: svc.h:374
UserBreakType type
User break type, see UserBreakType.
Definition: svc.h:373
u32 croInfoSize
For LOAD_RO and UNLOAD_RO.
Definition: svc.h:375
ArbitrationType
Arbitration modes.
Definition: svc.h:88
@ ARBITRATION_SIGNAL
Signal #value threads for wake-up.
Definition: svc.h:89
@ ARBITRATION_DECREMENT_AND_WAIT_IF_LESS_THAN
If the memory at the address is strictly lower than #value, then decrement it and wait for signal.
Definition: svc.h:91
@ ARBITRATION_WAIT_IF_LESS_THAN
If the memory at the address is strictly lower than #value, then wait for signal.
Definition: svc.h:90
@ ARBITRATION_DECREMENT_AND_WAIT_IF_LESS_THAN_TIMEOUT
If the memory at the address is strictly lower than #value, then decrement it and wait for signal or ...
Definition: svc.h:93
@ ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT
If the memory at the address is strictly lower than #value, then wait for signal or timeout.
Definition: svc.h:92
Result svcTerminateProcess(Handle process)
Terminates a process.
Result svcCreateTimer(Handle *timer, ResetType reset_type)
Creates a timer.
Result svcOpenProcess(Handle *process, u32 processId)
Gets the handle of a process.
Result svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm)
Maps a block of shared memory.
Result svcGetProcessInfo(s64 *out, Handle process, u32 type)
Gets information about a process.
Result svcCloseHandle(Handle handle)
Closes a handle.
ThreadInfoType
Types of thread info.
Definition: svc.h:112
@ THREADINFO_TYPE_UNKNOWN
Unknown.
Definition: svc.h:113
Result svcWriteProcessMemory(Handle debug, const void *buffer, u32 addr, u32 size)
Writes to a debugged process's memory.
Result svcWaitSynchronizationN(s32 *out, const Handle *handles, s32 handles_num, bool wait_all, s64 nanoseconds)
Waits for synchronization on multiple handles.
Result svcGetResourceLimitLimitValues(s64 *values, Handle resourceLimit, ResourceLimitType *names, s32 nameCount)
Gets the value limits of a resource limit set.
Result svcGetResourceLimitCurrentValues(s64 *values, Handle resourceLimit, ResourceLimitType *names, s32 nameCount)
Gets the values of a resource limit set.
ThreadContextControlFlags
Control flags for svcGetDebugThreadContext and svcSetDebugThreadContext.
Definition: svc.h:472
@ THREADCONTEXT_CONTROL_ALL
Control all of the above.
Definition: svc.h:481
@ THREADCONTEXT_CONTROL_FPU_GPRS
Control d0-d15 (or s0-s31).
Definition: svc.h:475
@ THREADCONTEXT_CONTROL_CPU_REGS
Control r0-r12, sp, lr, pc, cpsr.
Definition: svc.h:478
@ THREADCONTEXT_CONTROL_CPU_SPRS
Control sp, lr, pc, cpsr.
Definition: svc.h:474
@ THREADCONTEXT_CONTROL_CPU_GPRS
Control r0-r12.
Definition: svc.h:473
@ THREADCONTEXT_CONTROL_FPU_SPRS
Control fpscr, fpexc.
Definition: svc.h:476
@ THREADCONTEXT_CONTROL_FPU_REGS
Control d0-d15, fpscr, fpexc.
Definition: svc.h:479
Result svcOutputDebugString(const char *str, s32 length)
Outputs a debug string.
Result svcUnmapMemoryBlock(Handle memblock, u32 addr)
Unmaps a block of shared memory.
Result svcBackdoor(s32(*callback)(void))
Executes a function in supervisor mode.
Result svcDebugActiveProcess(Handle *debug, u32 processId)
Creates a debug handle for an active process.
UserBreakType
Reasons for a user break.
Definition: svc.h:332
@ USERBREAK_LOAD_RO
Load RO.
Definition: svc.h:336
@ USERBREAK_PANIC
Panic.
Definition: svc.h:333
@ USERBREAK_USER
User related.
Definition: svc.h:335
@ USERBREAK_UNLOAD_RO
Unload RO.
Definition: svc.h:337
@ USERBREAK_ASSERT
Assertion failed.
Definition: svc.h:334
Result svcRun(Handle process, const StartupInfo *info)
Launches the main thread of the process.
Result svcReleaseMutex(Handle handle)
Releases a mutex.
void svcExitThread(void) __attribute__((noreturn))
Exits the current thread.
static u32 * getThreadCommandBuffer(void)
Gets the thread command buffer.
Definition: svc.h:542
ExitProcessEventReason
Reasons for an exit process event.
Definition: svc.h:300
@ EXITPROCESS_EVENT_DEBUG_TERMINATE
Process has been terminated by svcTerminateDebugProcess.
Definition: svc.h:303
@ EXITPROCESS_EVENT_EXIT
Process exited either normally or due to an uncaught exception.
Definition: svc.h:301
@ EXITPROCESS_EVENT_TERMINATE
Process has been terminated by svcTerminateProcess.
Definition: svc.h:302
Result svcBindInterrupt(u32 interruptId, Handle eventOrSemaphore, s32 priority, bool isManualClear)
Binds an event or semaphore handle to an ARM11 interrupt.
Result svcDuplicateHandle(Handle *out, Handle original)
Duplicates a handle.
Result svcConnectToPort(volatile Handle *out, const char *portName)
Connects to a port.
PerfCounterOperation
Operations for svcControlPerformanceCounter.
Definition: svc.h:198
@ PERFCOUNTEROP_SET_EVENT
Set the event ID associated to a paritcular counter.
Definition: svc.h:206
@ PERFCOUNTEROP_ENABLE
Enable and lock perfmon. functionality.
Definition: svc.h:199
@ PERFCOUNTEROP_SET_VIRTUAL_COUNTER_ENABLED
(Dis)allow the kernel to track counter overflows and to use 64-bit counter values.
Definition: svc.h:207
@ PERFCOUNTEROP_SET_VALUE
Set the value of a counter register.
Definition: svc.h:202
@ PERFCOUNTEROP_GET_EVENT
Get the event ID associated to a particular counter.
Definition: svc.h:205
@ PERFCOUNTEROP_GET_OVERFLOW_FLAGS
Get the overflow flags for all CP15 and SCU counters.
Definition: svc.h:203
@ PERFCOUNTEROP_DISABLE
Disable and forcibly unlock perfmon. functionality.
Definition: svc.h:200
@ PERFCOUNTEROP_GET_VALUE
Get the value of a counter register.
Definition: svc.h:201
@ PERFCOUNTEROP_RESET
Reset the value and/or overflow flags of selected counters.
Definition: svc.h:204
s32 svcGetProcessorID(void)
Returns the ID of the processor the current thread is running on.
Result svcClearTimer(Handle timer)
Clears a timer.
Result svcCreateSession(Handle *serverSession, Handle *clientSession)
Creates a linked pair of session endpoints.
u64 svcGetSystemTick(void)
Gets the current system tick.
DebugThreadParameter
Thread parameter field for svcGetDebugThreadParameter.
Definition: svc.h:485
@ DBGTHREAD_PARAMETER_SCHEDULING_MASK_LOW
Low scheduling mask.
Definition: svc.h:487
@ DBGTHREAD_PARAMETER_CPU_IDEAL
Ideal processor.
Definition: svc.h:488
@ DBGTHREAD_PARAMETER_CPU_CREATOR
Processor that created the threod.
Definition: svc.h:489
@ DBGTHREAD_PARAMETER_PRIORITY
Thread priority.
Definition: svc.h:486
Result svcSendSyncRequest(Handle session)
Sends a synchronized request to a session handle.
Result svcGetThreadList(s32 *threadCount, u32 *threadIds, s32 threadIdMaxCount, Handle process)
Gets a list of the threads of a process.
static void * getThreadLocalStorage(void)
Gets the thread local storage buffer.
Definition: svc.h:531
Result svcCreateThread(Handle *thread, ThreadFunc entrypoint, u32 arg, u32 *stack_top, s32 thread_priority, s32 processor_id)
Creates a new thread.
StopPointType
Stop point types.
Definition: svc.h:359
@ STOPPOINT_BREAKPOINT
Breakpoint.
Definition: svc.h:361
@ STOPPOINT_WATCHPOINT
Watchpoint.
Definition: svc.h:362
@ STOPPOINT_SVC_FF
See SVC_STOP_POINT.
Definition: svc.h:360
Result svcGetDebugThreadContext(ThreadContext *context, Handle debug, u32 threadId, ThreadContextControlFlags controlFlags)
Fetches the saved registers of a thread, either inactive or awaiting svcContinueDebugEvent,...
Result svcGetProcessId(u32 *out, Handle handle)
Gets the ID of a process.
Result svcGetProcessList(s32 *processCount, u32 *processIds, s32 processIdMaxCount)
Gets a list of running processes.
Result svcGetHandleInfo(s64 *out, Handle handle, u32 param)
Gets a handle info.
Result svcGetThreadAffinityMask(u8 *affinitymask, Handle thread, s32 processorcount)
Gets a thread's affinity mask.
Result svcWaitSynchronization(Handle handle, s64 nanoseconds)
Waits for synchronization on a handle.
Result svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 timeout_ns)
Arbitrate an address, can be used for synchronization.
void svcExitProcess(void) __attribute__((noreturn))
Exits the current process.
Result svcCreateSessionToPort(Handle *clientSession, Handle clientPort)
Connects to a port via a handle.
Result svcGetSystemInfo(s64 *out, u32 type, s32 param)
Gets the system info.
Result svcSetWifiEnabled(bool enabled)
Enables or disables Wi-Fi.
Result svcControlPerformanceCounter(u64 *out, PerfCounterOperation op, u32 param1, u64 param2)
Controls performance monitoring on the CP15 interface and the SCU.
Result svcCreateMemoryBlock(Handle *memblock, u32 addr, u32 size, MemPerm my_perm, MemPerm other_perm)
Creates a block of shared memory.
Result svcGetThreadInfo(s64 *out, Handle thread, ThreadInfoType type)
Checks if a thread handle is valid.
Result svcGetThreadPriority(s32 *out, Handle handle)
Retrieves the priority of a thread.
PerfCounterEvent
Performance counter event IDs (CP15 or SCU).
Definition: svc.h:239
@ PERFCOUNTEREVT_CORE_CYCLE_COUNT
One cycle elapsed.
Definition: svc.h:263
@ PERFCOUNTEREVT_CORE_CYCLE_COUNT_64
64 cycles elapsed.
Definition: svc.h:264
Result svcCreateSemaphore(Handle *semaphore, s32 initial_count, s32 max_count)
Creates a semaphore.
void svcBreakRO(UserBreakType breakReason, const void *croInfo, u32 croInfoSize) __asm__("svcBreak")
Breaks execution (LOAD_RO and UNLOAD_RO).
Result svcContinueDebugEvent(Handle debug, DebugFlags flags)
Continues the current debug event of a debugged process (not necessarily the same as svcGetProcessDeb...
Result svcSetResourceLimitValues(Handle resourceLimit, const ResourceLimitType *names, const s64 *values, s32 nameCount)
Sets the value limits of a resource limit set.
Result svcQueryDebugProcessMemory(MemInfo *info, PageInfo *out, Handle debug, u32 addr)
Queries memory information of a debugged process.
void svcBreak(UserBreakType breakReason)
Breaks execution.
Result svcSetProcessResourceLimits(Handle process, Handle resourceLimit)
Sets the resource limit set of a process.
Result svcSetGpuProt(bool useApplicationRestriction)
Sets the GPU protection register to restrict the range of the GPU DMA.
MemOp
svcControlMemory operation flags
Definition: svc.h:20
@ MEMOP_FREE
Memory un-mapping.
Definition: svc.h:21
@ MEMOP_OP_MASK
Operation bitmask.
Definition: svc.h:32
@ MEMOP_PROT
Change protection.
Definition: svc.h:26
@ MEMOP_ALLOC
Memory mapping.
Definition: svc.h:23
@ MEMOP_LINEAR_FLAG
Flag for linear memory operations.
Definition: svc.h:34
@ MEMOP_REGION_BASE
BASE memory region.
Definition: svc.h:30
@ MEMOP_REGION_MASK
Region bitmask.
Definition: svc.h:33
@ MEMOP_RESERVE
Reserve memory.
Definition: svc.h:22
@ MEMOP_ALLOC_LINEAR
Allocates linear memory.
Definition: svc.h:36
@ MEMOP_MAP
Mirror mapping.
Definition: svc.h:24
@ MEMOP_REGION_APP
APPLICATION memory region.
Definition: svc.h:28
@ MEMOP_REGION_SYSTEM
SYSTEM memory region.
Definition: svc.h:29
@ MEMOP_UNMAP
Mirror unmapping.
Definition: svc.h:25
Result svcSetThreadAffinityMask(Handle thread, const u8 *affinitymask, s32 processorcount)
Sets a thread's affinity mask.
Result svcReadProcessMemory(void *buffer, Handle debug, u32 addr, u32 size)
Reads from a debugged process's memory.
Result svcSetProcessIdealProcessor(Handle process, s32 processorid)
Sets a process's ideal processor.
Result svcCreatePort(Handle *portServer, Handle *portClient, const char *name, s32 maxSessions)
Creates a port.
static u32 * getThreadStaticBuffers(void)
Gets the thread static buffer.
Definition: svc.h:551
Result svcControlMemory(u32 *addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm)
Controls memory mapping.
Result svcMapProcessMemory(Handle process, u32 destAddress, u32 size)
Maps a block of process memory, starting from address 0x00100000.
DebugFlags
Debug flags for an attached process, set by svcContinueDebugEvent.
Definition: svc.h:458
@ DBG_SIGNAL_SCHEDULE_EVENTS
Signal schedule in/out events. See ScheduleInOutEvent.
Definition: svc.h:461
@ DBG_SIGNAL_MAP_EVENTS
Signal map events. See MapEvent.
Definition: svc.h:463
@ DBG_SIGNAL_SYSCALL_EVENTS
Signal syscall in/out events. See SyscallInOutEvent.
Definition: svc.h:462
@ DBG_SIGNAL_FAULT_EXCEPTION_EVENTS
Signal fault exception events. See FaultExceptionEvent.
Definition: svc.h:460
@ DBG_INHIBIT_USER_CPU_EXCEPTION_HANDLERS
Inhibit user-defined CPU exception handlers (including watchpoints and breakpoints,...
Definition: svc.h:459
Result svcCancelTimer(Handle timer)
Cancels a timer.
DmaState
DMA transfer state.
Definition: svc.h:141
@ DMASTATE_WFP_SRC
DMA channel is in WFP state for the source device (2nd loop iteration onwards).
Definition: svc.h:144
@ DMASTATE_STARTING
DMA transfer involving at least one device is starting and has not reached DMAWFP yet.
Definition: svc.h:142
@ DMASTATE_WFP_DST
DMA channel is in WFP state for the destination device (2nd loop iteration onwards).
Definition: svc.h:143
@ DMASTATE_DONE
DMA transfer is done.
Definition: svc.h:146
@ DMASTATE_RUNNING
DMA transfer is running.
Definition: svc.h:145
Result svcArbitrateAddressNoTimeout(Handle arbiter, u32 addr, ArbitrationType type, s32 value)
Same as svcArbitrateAddress but with the timeout_ns parameter undefined.
Result svcCreateCodeSet(Handle *out, const CodeSetHeader *info, u32 textSegmentLma, u32 roSegmentLma, u32 dataSegmentLma)
Sets up virtual address space for a new process.
Result svcReleaseSemaphore(s32 *count, Handle semaphore, s32 release_count)
Releases a semaphore.
MemPerm
Memory permission flags.
Definition: svc.h:56
@ MEMPERM_DONTCARE
Don't care.
Definition: svc.h:62
@ MEMPERM_WRITE
Writable.
Definition: svc.h:58
@ MEMPERM_READWRITE
Readable and writable.
Definition: svc.h:60
@ MEMPERM_READ
Readable.
Definition: svc.h:57
@ MEMPERM_EXECUTE
Executable.
Definition: svc.h:59
@ MEMPERM_READEXECUTE
Readable and executable.
Definition: svc.h:61
MemState
The state of a memory block.
Definition: svc.h:40
@ MEMSTATE_ALIAS
Alias memory.
Definition: svc.h:50
@ MEMSTATE_CODE
Code memory.
Definition: svc.h:45
@ MEMSTATE_FREE
Free memory.
Definition: svc.h:41
@ MEMSTATE_SHARED
Shared memory.
Definition: svc.h:47
@ MEMSTATE_CONTINUOUS
Continuous memory.
Definition: svc.h:48
@ MEMSTATE_ALIASCODE
Aliased code memory.
Definition: svc.h:51
@ MEMSTATE_ALIASED
Aliased memory.
Definition: svc.h:49
@ MEMSTATE_PRIVATE
Private memory.
Definition: svc.h:46
@ MEMSTATE_IO
I/O memory.
Definition: svc.h:43
@ MEMSTATE_STATIC
Static memory.
Definition: svc.h:44
@ MEMSTATE_RESERVED
Reserved memory.
Definition: svc.h:42
@ MEMSTATE_LOCKED
Locked memory.
Definition: svc.h:52
Result svcGetThreadIdealProcessor(s32 *processorid, Handle thread)
Gets a thread's ideal processor.
Result svcBreakDebugProcess(Handle debug)
Breaks a debugged process.
Result svcGetResourceLimit(Handle *resourceLimit, Handle process)
Gets the resource limit set of a process.
Result svcQueryMemory(MemInfo *info, PageInfo *out, u32 addr)
Queries memory information.
Result svcCreateProcess(Handle *out, Handle codeset, const u32 *arm11KernelCaps, s32 numArm11KernelCaps)
Create a new process.
ExitThreadEventReason
Reasons for an exit thread event.
Definition: svc.h:319
@ EXITTHREAD_EVENT_EXIT_PROCESS
Process exited either normally or due to an uncaught exception.
Definition: svc.h:322
@ EXITTHREAD_EVENT_TERMINATE_PROCESS
Process has been terminated by svcTerminateProcess.
Definition: svc.h:323
@ EXITTHREAD_EVENT_TERMINATE
Thread terminated.
Definition: svc.h:321
@ EXITTHREAD_EVENT_EXIT
Thread exited.
Definition: svc.h:320
Result svcAcceptSession(Handle *session, Handle port)
Accepts a session.
Result svcGetThreadId(u32 *out, Handle handle)
Gets the ID of a thread.
@ DMACFG_SRC_IS_DEVICE
DMA source is a device/peripheral. Address will not auto-increment.
Definition: svc.h:151
@ DMACFG_USE_SRC_CONFIG
Use the provided source device configuration even if the DMA source is not a device.
Definition: svc.h:155
@ DMACFG_DST_IS_DEVICE
DMA destination is a device/peripheral. Address will not auto-increment.
Definition: svc.h:152
@ DMACFG_WAIT_AVAILABLE
Make svcStartInterProcessDma wait for the channel to be unlocked.
Definition: svc.h:153
@ DMACFG_USE_DST_CONFIG
Use the provided destination device configuration even if the DMA destination is not a device.
Definition: svc.h:156
@ DMACFG_KEEP_LOCKED
Keep the channel locked after the transfer. Required for svcRestartDma.
Definition: svc.h:154
Result svcQueryProcessMemory(MemInfo *info, PageInfo *out, Handle process, u32 addr)
Queries process memory information.
Result svcRestartDma(Handle dma, u32 dstAddr, u32 srcAddr, u32 size, s8 flags)
Restarts a DMA transfer, using the same configuration as before.
Result svcCreateAddressArbiter(Handle *arbiter)
Creates an address arbiter.
Result svcGetProcessIdealProcessor(s32 *processorid, Handle process)
Gets a process's ideal processor.
Result svcReplyAndReceive(s32 *index, const Handle *handles, s32 handleCount, Handle replyTarget)
Replies to and receives a new request.
Result svcUnmapProcessMemory(Handle process, u32 destAddress, u32 size)
Unmaps a block of process memory, starting from address 0x00100000.
DebugEventType
Debug event type.
Definition: svc.h:421
@ DBGEVENT_SCHEDULE_IN
Schedule in event.
Definition: svc.h:429
@ DBGEVENT_DLL_UNLOAD
DLL unload event.
Definition: svc.h:428
@ DBGEVENT_EXCEPTION
Exception event.
Definition: svc.h:426
@ DBGEVENT_EXIT_PROCESS
Process exit event.
Definition: svc.h:425
@ DBGEVENT_SYSCALL_IN
Syscall in event.
Definition: svc.h:431
@ DBGEVENT_SYSCALL_OUT
Syscall out event.
Definition: svc.h:432
@ DBGEVENT_SCHEDULE_OUT
Schedule out event.
Definition: svc.h:430
@ DBGEVENT_MAP
Map event.
Definition: svc.h:434
@ DBGEVENT_ATTACH_THREAD
Thread attached event.
Definition: svc.h:423
@ DBGEVENT_OUTPUT_STRING
Output string event.
Definition: svc.h:433
@ DBGEVENT_ATTACH_PROCESS
Process attached event.
Definition: svc.h:422
@ DBGEVENT_EXIT_THREAD
Thread exit event.
Definition: svc.h:424
@ DBGEVENT_DLL_LOAD
DLL load event.
Definition: svc.h:427
Result svcSetHardwareBreakPoint(s32 registerId, u32 control, u32 value)
Sets an hardware breakpoint or watchpoint.
Result svcSetTimer(Handle timer, s64 initial, s64 interval)
Sets a timer.
Result svcStoreProcessDataCache(Handle process, u32 addr, u32 size)
Cleans a process's data cache.
Result svcCreateResourceLimit(Handle *resourceLimit)
Creates a resource limit set.
ResourceLimitType
Types of resource limit.
Definition: svc.h:117
@ RESLIMIT_TIMER
Number of timers.
Definition: svc.h:124
@ RESLIMIT_SEMAPHORE
Number of semaphores.
Definition: svc.h:123
@ RESLIMIT_CPUTIME
CPU time. Value expressed in percentage regular until it reaches 90.
Definition: svc.h:127
@ RESLIMIT_COMMIT
Quantity of allocatable memory.
Definition: svc.h:119
@ RESLIMIT_EVENT
Number of events.
Definition: svc.h:121
@ RESLIMIT_BIT
Forces enum size to be 32 bits.
Definition: svc.h:129
@ RESLIMIT_ADDRESSARBITER
Number of address arbiters.
Definition: svc.h:126
@ RESLIMIT_MUTEX
Number of mutexes.
Definition: svc.h:122
@ RESLIMIT_THREAD
Number of threads.
Definition: svc.h:120
@ RESLIMIT_SHAREDMEMORY
Number of shared memory objects, see svcCreateMemoryBlock.
Definition: svc.h:125
@ RESLIMIT_PRIORITY
Thread priority.
Definition: svc.h:118
Result svcCreateEvent(Handle *event, ResetType reset_type)
Creates an event handle.
MemRegion
Memory regions.
Definition: svc.h:67
@ MEMREGION_SYSTEM
SYSTEM memory.
Definition: svc.h:70
@ MEMREGION_BASE
BASE memory.
Definition: svc.h:71
@ MEMREGION_ALL
All regions.
Definition: svc.h:68
@ MEMREGION_APPLICATION
APPLICATION memory.
Definition: svc.h:69
Result svcClearEvent(Handle handle)
Clears an event.
Result svcStopDma(Handle dma)
Stops an inter-process DMA transfer.
Result svcInvalidateProcessDataCache(Handle process, u32 addr, u32 size)
Invalidates a process's data cache.
static void dmaConfigInitDefault(DmaConfig *cfg)
Initializes a DmaConfig instance with sane defaults for RAM<>RAM tranfers.
Definition: svc.h:574
Result svcGetProcessIdOfThread(u32 *out, Handle handle)
Gets the process ID of a thread.
ExceptionEventType
Reasons for an exception event.
Definition: svc.h:341
@ EXCEVENT_UNDEFINED_SYSCALL
Undefined syscall.
Definition: svc.h:350
@ EXCEVENT_USER_BREAK
User break occurred.
Definition: svc.h:348
@ EXCEVENT_UNALIGNED_DATA_ACCESS
Unaligned data access.
Definition: svc.h:345
@ EXCEVENT_DEBUGGER_BREAK
Debugger break occurred.
Definition: svc.h:349
@ EXCEVENT_ATTACH_BREAK
Attached break.
Definition: svc.h:346
@ EXCEVENT_PREFETCH_ABORT
Prefetch abort.
Definition: svc.h:343
@ EXCEVENT_UNDEFINED_INSTRUCTION
Undefined instruction.
Definition: svc.h:342
@ EXCEVENT_DATA_ABORT
Data abort (other than the below kind).
Definition: svc.h:344
@ EXCEVENT_STOP_POINT
Stop point reached.
Definition: svc.h:347
@ DMARST_UNLOCK
Unlock the channel after transfer.
Definition: svc.h:161
@ DMARST_RESUME_DEVICE
Replace DMAFLUSHP instructions by NOP (they may not be regenerated even if this flag is not set).
Definition: svc.h:162
Result svcGetDebugThreadParam(s64 *unused, u32 *out, Handle debug, u32 threadId, DebugThreadParameter parameter)
Gets a debugged thread's parameter.
Result svcKernelSetState(u32 type,...)
Sets the current kernel state.
ResetType
Reset types (for use with events and timers)
Definition: svc.h:105
@ RESET_STICKY
When the primitive is signaled, it will wake up all threads and it won't clear itself automatically.
Definition: svc.h:107
@ RESET_ONESHOT
When the primitive is signaled, it will wake up exactly one thread and will clear itself automaticall...
Definition: svc.h:106
@ RESET_PULSE
Only meaningful for timers: same as ONESHOT but it will periodically signal the timer instead of just...
Definition: svc.h:108
void svcSleepThread(s64 ns)
Puts the current thread to sleep.
Result svcGetProcessDebugEvent(DebugEventInfo *info, Handle debug)
Gets the current debug event of a debugged process.
Result svcSetThreadIdealProcessor(Handle thread, s32 processorid)
Sets a thread's ideal processor.
Result svcSetThreadPriority(Handle thread, s32 prio)
Changes the priority of a thread.
Result svcGetProcessAffinityMask(u8 *affinitymask, Handle process, s32 processorcount)
Gets a process's affinity mask.
Result svcTerminateDebugProcess(Handle debug)
Terminates a debugged process.
Result svcOpenThread(Handle *thread, Handle process, u32 threadId)
Gets the handle of a thread.
Result svcSetDebugThreadContext(Handle debug, u32 threadId, ThreadContext *context, ThreadContextControlFlags controlFlags)
Updates the saved registers of a thread, either inactive or awaiting svcContinueDebugEvent,...
Result svcUnbindInterrupt(u32 interruptId, Handle eventOrSemaphore)
Unbinds an event or semaphore handle from an ARM11 interrupt.
Result svcSetProcessAffinityMask(Handle process, const u8 *affinitymask, s32 processorcount)
Sets a process's affinity mask.
PerfCounterRegister
Performance counter register IDs (CP15 and SCU).
Definition: svc.h:212
@ PERFCOUNTERREG_CORE_CYCLE_COUNTER
CP15 CCNT.
Definition: svc.h:217
@ PERFCOUNTERREG_CORE_COUNT_REG_1
CP15 PMN1.
Definition: svc.h:216
@ PERFCOUNTERREG_SCU_7
SCU MN7. Prod-N3DS only. IRQ line missing.
Definition: svc.h:228
@ PERFCOUNTERREG_SCU_6
SCU MN6. Prod-N3DS only. IRQ line missing.
Definition: svc.h:227
@ PERFCOUNTERREG_SCU_3
SCU MN3.
Definition: svc.h:224
@ PERFCOUNTERREG_SCU_5
SCU MN5. Prod-N3DS only. IRQ line missing.
Definition: svc.h:226
@ PERFCOUNTERREG_SCU_1
SCU MN1.
Definition: svc.h:222
@ PERFCOUNTERREG_SCU_2
SCU MN2.
Definition: svc.h:223
@ PERFCOUNTERREG_SCU_0
SCU MN0.
Definition: svc.h:221
@ PERFCOUNTERREG_CORE_COUNT_REG_0
CP15 PMN0.
Definition: svc.h:215
@ PERFCOUNTERREG_SCU_4
SCU MN4. Prod-N3DS only. IRQ line missing.
Definition: svc.h:225
Result svcSignalEvent(Handle handle)
Signals an event.
Result svcStartInterProcessDma(Handle *dma, Handle dstProcess, u32 dstAddr, Handle srcProcess, u32 srcAddr, u32 size, const DmaConfig *cfg)
Begins an inter-process DMA transfer.
Result svcFlushProcessDataCache(Handle process, u32 addr, u32 size)
Flushes (cleans and invalidates) a process's data cache.
Result svcCreateMutex(Handle *mutex, bool initially_locked)
Creates a mutex.
static void dmaDeviceConfigInitDefault(DmaDeviceConfig *cfg)
Writes the default DMA device config that the kernel uses when DMACFG_*_IS_DEVICE and DMACFG_*_USE_CF...
Definition: svc.h:560
Result svcControlProcessMemory(Handle process, u32 addr0, u32 addr1, u32 size, u32 type, u32 perm)
Controls the memory mapping of a process.
Result svcGetDmaState(DmaState *state, Handle dma)
Gets the state of an inter-process DMA transfer.
Various system types.
int64_t s64
64-bit signed integer
Definition: types.h:29
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:47
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
void(* ThreadFunc)(void *)
Thread entrypoint function.
Definition: types.h:43
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
int8_t s8
8-bit signed integer
Definition: types.h:26
int16_t s16
16-bit signed integer
Definition: types.h:27
u32 Handle
Resource handle.
Definition: types.h:41
s32 Result
Function result.
Definition: types.h:42
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
int32_t s32
32-bit signed integer
Definition: types.h:28
uint32_t u32
32-bit unsigned integer
Definition: types.h:23