psp/sys/kernel/
thread.rs

1//! ThreadMan Thread Manager Library
2//!
3//! Library imports for the kernel threading library.
4//!
5//! Note: Some of the structures, types, and definitions in this file were
6//! extrapolated from symbolic debugging information found in the Japanese
7//! version of Puzzle Bobble.
8
9use super::SceUid;
10use crate::eabi::i6;
11use core::ffi::c_void;
12
13/// Structure to hold the psp profiler register values
14#[repr(C)]
15#[derive(Debug, Copy, Clone)]
16pub struct DebugProfilerRegs {
17    pub enable: u32,
18    pub systemck: u32,
19    pub cpuck: u32,
20    pub internal: u32,
21    pub memory: u32,
22    pub copz: u32,
23    pub vfpu: u32,
24    pub sleep: u32,
25    pub bus_access: u32,
26    pub uncached_load: u32,
27    pub uncached_store: u32,
28    pub cached_load: u32,
29    pub cached_store: u32,
30    pub i_miss: u32,
31    pub d_miss: u32,
32    pub d_writeback: u32,
33    pub cop0_inst: u32,
34    pub fpu_inst: u32,
35    pub vfpu_inst: u32,
36    pub local_bus: u32,
37}
38
39/// 64-bit system clock type.
40#[repr(C)]
41#[derive(Debug, Copy, Clone)]
42pub struct SceKernelSysClock {
43    pub low: u32,
44    pub hi: u32,
45}
46
47pub type SceKernelThreadEntry = unsafe extern "C" fn(args: usize, argp: *mut c_void) -> i32;
48
49/// Additional options used when creating threads.
50#[repr(C)]
51#[derive(Debug, Copy, Clone)]
52pub struct SceKernelThreadOptParam {
53    /// Size of the `SceKernelThreadOptParam` structure.
54    pub size: usize,
55
56    /// UID of the memory block (?) allocated for the thread's stack.
57    pub stack_mpid: SceUid,
58}
59
60bitflags::bitflags! {
61    /// Attributes for threads.
62    #[repr(transparent)]
63    pub struct ThreadAttributes: u32 {
64        /// Enable VFPU access for the thread.
65        const VFPU = 0x00004000;
66
67        /// Start the thread in user mode (done automatically if the thread
68        /// creating it is in user mode).
69        const USER = 0x80000000;
70
71        /// Thread is part of the USB/WLAN API.
72        const USBWLAN = 0xa0000000;
73
74        /// Thread is part of the VSH API.
75        const VSH = 0xc0000000;
76
77        /// Allow using scratchpad memory for a thread, NOT USABLE ON V1.0
78        const SCRATCH_SRAM = 0x00008000;
79
80        /// Disables filling the stack with `0xFF` on creation.
81        const NO_FILLSTACK = 0x00100000;
82
83        /// Clear the stack when the thread is deleted.
84        const CLEAR_STACK = 0x00200000;
85    }
86}
87
88bitflags::bitflags! {
89    /// Event flag creation attributes.
90    #[repr(transparent)]
91    pub struct EventFlagAttributes: u32 {
92        /// Allow the event flag to be waited upon by multiple threads.
93        const WAIT_MULTIPLE = 0x200;
94    }
95}
96
97bitflags::bitflags! {
98    /// Event flag wait types
99    #[repr(transparent)]
100    pub struct EventFlagWaitTypes: u32 {
101        /// Wait for all bits in the pattern to be set
102        const AND = 0;
103        /// Wait for one or more bits in the pattern to be set
104        const OR  = 1;
105        /// Clear the wait pattern when it matches
106        const CLEAR = 0x20;
107    }
108}
109
110/// Structure to hold the status information for a thread
111/// @see sceKernelReferThreadStatus
112#[repr(C)]
113#[derive(Debug, Copy, Clone)]
114pub struct SceKernelThreadInfo {
115    /// Size of the structure
116    pub size: usize,
117    /// Null terminated name of the thread
118    pub name: [u8; 32],
119    /// Thread attributes
120    pub attr: u32,
121    /// Thread status
122    pub status: i32,
123    /// Thread entry point
124    pub entry: SceKernelThreadEntry,
125    /// Thread stack pointer
126    pub stack: *mut c_void,
127    /// Thread stack size
128    pub stack_size: i32,
129    /// Pointer to the gp
130    pub gp_reg: *mut c_void,
131    /// Initial priority
132    pub init_priority: i32,
133    /// Current priority
134    pub current_priority: i32,
135    /// Wait type
136    pub wait_type: i32,
137    /// Wait ID
138    pub wait_id: SceUid,
139    /// Wakeup count
140    pub wakeup_count: i32,
141    /// Exit status of the thread
142    pub exit_status: i32,
143    /// Number of clock cycles run
144    pub run_clocks: SceKernelSysClock,
145    /// Interrupt preemption count
146    pub intr_preempt_count: u32,
147    /// Thread preemption count
148    pub thread_preempt_count: u32,
149    /// Release count
150    pub release_count: u32,
151}
152
153/// Statistics about a running thread. See `sceKernelReferThreadRunStatus`.
154#[repr(C)]
155#[derive(Debug, Copy, Clone)]
156pub struct SceKernelThreadRunStatus {
157    pub size: usize,
158    pub status: i32,
159    pub current_priority: i32,
160    pub wait_type: i32,
161    pub wait_id: i32,
162    pub wakeup_count: i32,
163    pub run_clocks: SceKernelSysClock,
164    pub intr_preempt_count: u32,
165    pub thread_preempt_count: u32,
166    pub release_count: u32,
167}
168
169/// Additional options used when creating semaphores.
170#[repr(C)]
171#[derive(Debug, Copy, Clone)]
172pub struct SceKernelSemaOptParam {
173    /// Size of the `SceKernelSemaOptParam` structure.
174    pub size: usize,
175}
176
177/// Current state of a semaphore. See `sceKernelReferSemaStatus`.
178#[repr(C)]
179#[derive(Debug, Copy, Clone)]
180pub struct SceKernelSemaInfo {
181    /// Size of the `SceKernelSemaInfo` structure.
182    pub size: usize,
183    /// Null terminated name of the semaphore.
184    pub name: [u8; 32],
185    /// Attributes.
186    pub attr: u32,
187    /// The initial count the semaphore was created with.
188    pub init_count: i32,
189    /// The current count.
190    pub current_count: i32,
191    /// The maximum count.
192    pub max_count: i32,
193    /// The number of threads waiting on the semaphore.
194    pub num_wait_threads: i32,
195}
196
197/// Structure to hold the event flag information.
198#[repr(C)]
199#[derive(Debug, Copy, Clone)]
200pub struct SceKernelEventFlagInfo {
201    pub size: usize,
202    pub name: [u8; 32],
203    pub attr: u32,
204    pub init_pattern: u32,
205    pub current_pattern: u32,
206    pub num_wait_threads: i32,
207}
208
209#[repr(C)]
210#[derive(Debug, Copy, Clone)]
211pub struct SceKernelEventFlagOptParam {
212    /// Size of the `SceKernelEventFlagOptParam` structure?
213    pub size: usize,
214}
215
216/// Additional options used when creating messageboxes.
217#[repr(C)]
218#[derive(Debug, Copy, Clone)]
219pub struct SceKernelMbxOptParam {
220    /// Size of the `SceKernelMbxOptParam` structure.
221    pub size: usize,
222}
223
224/// Current state of a messagebox. See `sceKernelReferMbxStatus`.
225#[repr(C)]
226#[derive(Debug, Copy, Clone)]
227pub struct SceKernelMbxInfo {
228    /// Size of the `SceKernelMbxInfo` structure.
229    pub size: usize,
230    /// Null terminated name of the messagebox.
231    pub name: [u8; 32usize],
232    /// Attributes.
233    pub attr: u32,
234    /// The number of threads waiting on the messagebox.
235    pub num_wait_threads: i32,
236    /// Number of messages currently in the messagebox.
237    pub num_messages: i32,
238    /// The message currently at the head of the queue.
239    pub first_message: *mut c_void,
240}
241
242pub type SceKernelVTimerHandler = unsafe extern "C" fn(
243    uid: SceUid,
244    arg1: *mut SceKernelSysClock,
245    arg2: *mut SceKernelSysClock,
246    arg3: *mut c_void,
247) -> u32;
248
249pub type SceKernelVTimerHandlerWide =
250    unsafe extern "C" fn(uid: SceUid, arg1: i64, arg2: i64, arg3: *mut c_void) -> u32;
251
252#[repr(C)]
253#[derive(Debug, Copy, Clone)]
254pub struct SceKernelVTimerInfo {
255    /// Size of the `SceKernelVTimerInfo` structure?
256    pub size: usize,
257    pub name: [u8; 32],
258    pub active: i32,
259    pub base: SceKernelSysClock,
260    pub current: SceKernelSysClock,
261    pub schedule: SceKernelSysClock,
262    pub handler: SceKernelVTimerHandler,
263    pub common: *mut c_void,
264}
265
266// TODO: Is this ok? What if the thread has no event handler registered?
267pub type SceKernelThreadEventHandler =
268    unsafe extern "C" fn(mask: i32, thid: SceUid, common: *mut c_void) -> i32;
269
270/// Struct for event handler info
271#[repr(C)]
272#[derive(Debug, Copy, Clone)]
273pub struct SceKernelThreadEventHandlerInfo {
274    pub size: usize,
275    pub name: [u8; 32],
276    pub thread_id: SceUid,
277    pub mask: i32,
278    // TODO: Make this option?
279    pub handler: SceKernelThreadEventHandler,
280    pub common: *mut c_void,
281}
282
283/// Prototype for alarm handlers.
284pub type SceKernelAlarmHandler = unsafe extern "C" fn(common: *mut c_void) -> u32;
285
286/// Struct containing alarm info
287#[repr(C)]
288#[derive(Debug, Copy, Clone)]
289pub struct SceKernelAlarmInfo {
290    /// Size of the structure (should be set before calling `sceKernelReferAlarmStatus`).
291    pub size: usize,
292    pub schedule: SceKernelSysClock,
293    /// Pointer to the alarm handler
294    pub handler: SceKernelAlarmHandler,
295    /// Common pointer argument
296    pub common: *mut c_void,
297}
298
299/// Threadman types.
300#[repr(u32)]
301#[derive(Debug, Copy, Clone)]
302pub enum SceKernelIdListType {
303    Thread = 1,
304    Semaphore = 2,
305    EventFlag = 3,
306    Mbox = 4,
307    Vpl = 5,
308    Fpl = 6,
309    Mpipe = 7,
310    Callback = 8,
311    ThreadEventHandler = 9,
312    Alarm = 10,
313    VTimer = 11,
314    SleepThread = 64,
315    DelayThread = 65,
316    SuspendThread = 66,
317    DormantThread = 67,
318}
319
320/// Structure to contain the system status returned by `sceKernelReferSystemStatus`.
321#[repr(C)]
322#[derive(Debug, Copy, Clone)]
323pub struct SceKernelSystemStatus {
324    /// Size of the structure (should be set prior to the call).
325    pub size: usize,
326    /// The status?
327    pub status: u32,
328    /// The number of cpu clocks in the idle thread
329    pub idle_clocks: SceKernelSysClock,
330    /// Number of times we resumed from idle
331    pub comes_out_of_idle_count: u32,
332    /// Number of thread context switches
333    pub thread_switch_count: u32,
334    /// Number of vfpu switches ?
335    pub vfpu_switch_count: u32,
336}
337
338/// Message Pipe status info
339#[repr(C)]
340#[derive(Debug, Copy, Clone)]
341pub struct SceKernelMppInfo {
342    pub size: usize,
343    pub name: [u8; 32],
344    pub attr: u32,
345    pub buf_size: i32,
346    pub free_size: i32,
347    pub num_send_wait_threads: i32,
348    pub num_receive_wait_threads: i32,
349}
350
351#[repr(C)]
352#[derive(Debug, Copy, Clone)]
353pub struct SceKernelVplOptParam {
354    /// Size of the `SceKernelVplOptParam` structure?
355    pub size: usize,
356}
357
358/// Variable pool status info
359#[repr(C)]
360#[derive(Debug, Copy, Clone)]
361pub struct SceKernelVplInfo {
362    /// Size of the `SceKernelVplInfo` structure?
363    pub size: usize,
364    pub name: [u8; 32],
365    pub attr: u32,
366    pub pool_size: i32,
367    pub free_size: i32,
368    pub num_wait_threads: i32,
369}
370
371#[repr(C)]
372#[derive(Debug, Copy, Clone)]
373pub struct SceKernelFplOptParam {
374    /// Size of the `SceKernelFplOptParam` structure?
375    pub size: usize,
376}
377
378/// Fixed pool status information
379#[repr(C)]
380#[derive(Debug, Copy, Clone)]
381pub struct SceKernelFplInfo {
382    pub size: usize,
383    pub name: [u8; 32usize],
384    pub attr: u32,
385    pub block_size: i32,
386    pub num_blocks: i32,
387    pub free_blocks: i32,
388    pub num_wait_threads: i32,
389}
390
391#[repr(C)]
392#[derive(Debug, Copy, Clone)]
393pub struct SceKernelVTimerOptParam {
394    /// Size of the `SceKernelVTimerOptParam` structure?
395    pub size: usize,
396}
397
398/// Callback function prototype
399pub type SceKernelCallbackFunction =
400    unsafe extern "C" fn(arg1: i32, arg2: i32, arg: *mut c_void) -> i32;
401
402/// Structure to hold the status information for a callback
403#[repr(C)]
404#[derive(Debug, Copy, Clone)]
405pub struct SceKernelCallbackInfo {
406    /// Size of the structure (i.e. `sizeof::<SceKernelCallbackInfo>()`)
407    pub size: usize,
408    /// The name given to the callback
409    pub name: [u8; 32usize],
410    /// The thread id associated with the callback
411    pub thread_id: SceUid,
412    /// Pointer to the callback function
413    pub callback: SceKernelCallbackFunction,
414    /// User supplied argument for the callback
415    pub common: *mut c_void,
416    /// Unknown
417    pub notify_count: i32,
418    /// Unknown
419    pub notify_arg: i32,
420}
421
422#[repr(C)]
423#[derive(Debug, Copy, Clone)]
424pub struct SceKernelLwMutexWork {
425    /// Count
426    pub lock_count: i32,
427    /// Locking thread
428    pub lock_thread: SceUid,
429    /// Attributes
430    pub attr: i32,
431    /// Number of waiting threads
432    pub num_wait_threads: i32,
433    /// UID
434    pub uid: SceUid,
435    /// Padding
436    pub pad: [i32; 3],
437}
438
439psp_extern! {
440    #![name = "ThreadManForUser"]
441    #![flags = 0x4001]
442    #![version = (0x00, 0x00)]
443
444    #[psp(0x57CF62DD)]
445    /// Get the type of a threadman uid
446    ///
447    /// # Parameters
448    ///
449    /// - `uid`: The uid to get the type from
450    ///
451    /// # Return Value
452    ///
453    /// The type, < 0 on error
454    pub fn sceKernelGetThreadmanIdType(uid: SceUid) -> SceKernelIdListType;
455
456    #[psp(0x446D8DE6, i6)]
457    /// Create a thread.
458    ///
459    /// This function does not directly run a thread, it simply returns a thread
460    /// ID which can be used as a handle to start the thread later. See
461    /// `sceKernelStartThread`.
462    ///
463    /// # Parameters
464    ///
465    /// - `name`: An arbitrary thread name.
466    /// - `entry`: The thread function to run when started.
467    /// - `init_priority`: The initial priority of the thread. Less if higher priority.
468    /// - `stack_size`: The size of the initial stack.
469    /// - `attr`: The thread attributes, zero or more of `ThreadAttributes`.
470    /// - `option`: Additional options specified by `SceKernelThreadOptParam`.
471    ///
472    /// # Return Value
473    ///
474    /// UID of the created thread, or an error code.
475    pub fn sceKernelCreateThread(
476        name: *const u8,
477        entry: SceKernelThreadEntry,
478        init_priority: i32,
479        stack_size: i32,
480        attr: ThreadAttributes,
481        option: *mut SceKernelThreadOptParam,
482    ) -> SceUid;
483
484    #[psp(0x9FA03CD3)]
485    /// Delate a thread
486    ///
487    /// # Parameters
488    ///
489    /// - `thid`: UID of the thread to be deleted.
490    ///
491    /// # Return Value
492    ///
493    /// < 0 on error.
494    pub fn sceKernelDeleteThread(thid: SceUid) -> i32;
495
496    #[psp(0xF475845D)]
497    /// Start a created thread.
498    ///
499    /// # Parameters
500    ///
501    /// - `id`: Thread id from sceKernelCreateThread
502    /// - `arg_len`: Length of the data pointed to by argp, in bytes
503    /// - `argp`: Pointer to the arguments.
504    pub fn sceKernelStartThread(
505        id: SceUid,
506        arg_len: usize,
507        arg_p: *mut c_void,
508    ) -> i32;
509
510    #[psp(0xAA73C935)]
511    /// Exit a thread
512    ///
513    /// # Parameters
514    ///
515    /// - `status`: Exit status.
516    pub fn sceKernelExitThread(status: i32) -> i32;
517
518    #[psp(0x809CE29B)]
519    /// Exit a thread and delete itself.
520    ///
521    /// # Parameters
522    ///
523    /// - `status`: Exit status
524    pub fn sceKernelExitDeleteThread(status: i32) -> i32;
525
526    #[psp(0x616403BA)]
527    /// Terminate a thread.
528    ///
529    /// # Parameters
530    ///
531    /// - `thid`: UID of the thread to terminate.
532    ///
533    /// # Return Value
534    ///
535    /// Success if >= 0, an error if < 0.
536    pub fn sceKernelTerminateThread(thid: SceUid) -> i32;
537
538    #[psp(0x383F7BCC)]
539    /// Terminate and delete a thread.
540    ///
541    /// # Parameters
542    ///
543    /// - `thid`: UID of the thread to terminate and delete.
544    ///
545    /// # Return Value
546    ///
547    /// Success if >= 0, an error if < 0.
548    pub fn sceKernelTerminateDeleteThread(thid: SceUid) -> i32;
549
550    #[psp(0x3AD58B8C)]
551    /// Suspend the dispatch thread
552    ///
553    /// # Return Value
554    ///
555    /// The current state of the dispatch thread, < 0 on error
556    pub fn sceKernelSuspendDispatchThread() -> i32;
557
558    #[psp(0x27E22EC2)]
559    /// Resume the dispatch thread
560    ///
561    /// # Parameters
562    ///
563    /// - `state`: The state of the dispatch thread
564    ///   (from `sceKernelSuspendDispatchThread`)
565    ///
566    /// # Return Value
567    ///
568    /// 0 on success, < 0 on error
569    pub fn sceKernelResumeDispatchThread(state: i32) -> i32;
570
571    #[psp(0x9ACE131E)]
572    /// Sleep thread
573    ///
574    /// # Return Value
575    ///
576    /// < 0 on error.
577    pub fn sceKernelSleepThread() -> i32;
578
579    #[psp(0x82826F70)]
580    /// Sleep thread but service any callbacks as necessary.
581    ///
582    /// Once all callbacks have been setup call this function.
583    pub fn sceKernelSleepThreadCB() -> i32;
584
585    #[psp(0xD59EAD2F)]
586    /// Wake a thread previously put into the sleep state.
587    ///
588    /// # Parameters
589    ///
590    /// - `thid`: UID of the thread to wake.
591    ///
592    /// # Return Value
593    ///
594    /// Success if >= 0, an error if < 0.
595    pub fn sceKernelWakeupThread(thid: SceUid) -> i32;
596
597    #[psp(0xFCCFAD26)]
598    /// Cancel a thread that was to be woken with `sceKernelWakeupThread`.
599    ///
600    /// # Parameters
601    ///
602    /// - `thid`: UID of the thread to cancel.
603    ///
604    /// # Return Value
605    ///
606    /// Success if >= 0, an error if < 0.
607    pub fn sceKernelCancelWakeupThread(thid: SceUid) -> i32;
608
609    #[psp(0x9944F31F)]
610    /// Suspend a thread.
611    ///
612    /// # Parameters
613    ///
614    /// - `thid`: UID of the thread to suspend.
615    ///
616    /// # Return Value
617    ///
618    /// Success if >= 0, an error if < 0.
619    pub fn sceKernelSuspendThread(thid: SceUid) -> i32;
620
621    #[psp(0x75156E8F)]
622    /// Resume a thread previously put into a suspended state with `sceKernelSuspendThread`.
623    ///
624    /// # Parameters
625    ///
626    /// - `thid`: UID of the thread to resume.
627    ///
628    /// # Return Value
629    ///
630    /// Success if >= 0, an error if < 0.
631    pub fn sceKernelResumeThread(thid: SceUid) -> i32;
632
633    #[psp(0x278C0DF5)]
634    /// Wait until a thread has ended.
635    ///
636    /// # Parameters
637    ///
638    /// - `thid`: Id of the thread to wait for.
639    /// - `timeout`: Timeout in microseconds (assumed).
640    ///
641    /// # Return Value
642    ///
643    /// < 0 on error.
644    pub fn sceKernelWaitThreadEnd(thid: SceUid, timeout: *mut u32) -> i32;
645
646    #[psp(0x840E8133)]
647    /// Wait until a thread has ended and handle callbacks if necessary.
648    ///
649    /// # Parameters
650    ///
651    /// - `thid`: Id of the thread to wait for.
652    /// - `timeout`: Timeout in microseconds (assumed).
653    ///
654    /// # Return Value
655    ///
656    /// < 0 on error.
657    pub fn sceKernelWaitThreadEndCB(thid: SceUid, timeout: *mut u32) -> i32;
658
659    #[psp(0xCEADEB47)]
660    /// Delay the current thread by a specified number of microseconds
661    ///
662    /// # Parameters
663    ///
664    /// - `delay`: Delay in microseconds.
665    ///
666    pub fn sceKernelDelayThread(delay: u32) -> i32;
667
668    #[psp(0x68DA9E36)]
669    /// Delay the current thread by a specified number of microseconds and handle any callbacks.
670    ///
671    /// # Parameters
672    ///
673    /// - `delay`: Delay in microseconds.
674    ///
675    pub fn sceKernelDelayThreadCB(delay: u32) -> i32;
676
677    #[psp(0xBD123D9E)]
678    /// Delay the current thread by a specified number of sysclocks
679    ///
680    /// # Parameters
681    ///
682    /// - `delay`: Delay in sysclocks
683    ///
684    /// # Return Value
685    ///
686    /// 0 on success, < 0 on error
687    pub fn sceKernelDelaySysClockThread(delay: *mut SceKernelSysClock) -> i32;
688
689    #[psp(0x1181E963)]
690    /// Delay the current thread by a specified number of sysclocks handling callbacks
691    ///
692    /// # Parameters
693    ///
694    /// - `delay`: Delay in sysclocks
695    ///
696    /// # Return Value
697    ///
698    /// 0 on success, < 0 on error
699    ///
700    pub fn sceKernelDelaySysClockThreadCB(delay: *mut SceKernelSysClock) -> i32;
701
702    #[psp(0xEA748E31)]
703    /// Modify the attributes of the current thread.
704    ///
705    /// # Parameters
706    ///
707    /// - `unknown`: Set to 0.
708    /// - `attr`: The thread attributes to modify.  One of `ThreadAttributes`.
709    ///
710    /// # Return Value
711    ///
712    /// < 0 on error.
713    pub fn sceKernelChangeCurrentThreadAttr(
714        unknown: i32,
715        attr: ThreadAttributes,
716    ) -> i32;
717
718    #[psp(0x71BC9871)]
719    /// Change the threads current priority.
720    ///
721    /// # Parameters
722    ///
723    /// - `thid`: The ID of the thread (from `sceKernelCreateThread` or `sceKernelGetThreadId`)
724    /// - `priority`: The new priority (the lower the number the higher the priority)
725    ///
726    /// # Return Value
727    ///
728    /// 0 if successful, otherwise the error code.
729    pub fn sceKernelChangeThreadPriority(
730        thid: SceUid,
731        priority: i32,
732    ) -> i32;
733
734    #[psp(0x912354A7)]
735    /// Rotate thread ready queue at a set priority
736    ///
737    /// # Parameters
738    ///
739    /// - `priority`: The priority of the queue
740    ///
741    /// # Return Value
742    ///
743    /// 0 on success, < 0 on error.
744    pub fn sceKernelRotateThreadReadyQueue(
745        priority: i32,
746    ) -> i32;
747
748    #[psp(0x2C34E053)]
749    /// Release a thread in the wait state.
750    ///
751    /// # Parameters
752    ///
753    /// - `thid`: The UID of the thread.
754    ///
755    /// # Return Value
756    ///
757    /// 0 on success, < 0 on error
758    pub fn sceKernelReleaseWaitThread(thid: SceUid) -> i32;
759
760    #[psp(0x293B45B8)]
761    /// Get the current thread Id
762    ///
763    /// # Return Value
764    ///
765    /// The thread id of the calling thread.
766    pub fn sceKernelGetThreadId() -> i32;
767
768    #[psp(0x94AA61EE)]
769    /// Get the current priority of the thread you are in.
770    ///
771    /// # Return Value
772    ///
773    /// The current thread priority
774    pub fn sceKernelGetThreadCurrentPriority() -> i32;
775
776    #[psp(0x3B183E26)]
777    /// Get the exit status of a thread.
778    ///
779    /// # Parameters
780    ///
781    /// - `thid`: The UID of the thread to check.
782    ///
783    /// # Return Value
784    ///
785    /// The exit status
786    pub fn sceKernelGetThreadExitStatus(thid: SceUid) -> i32;
787
788    #[psp(0xD13BDE95)]
789    /// Check the thread stack?
790    ///
791    /// # Return Value
792    ///
793    /// Unknown.
794    pub fn sceKernelCheckThreadStack() -> i32;
795
796    #[psp(0x52089CA1)]
797    /// Get the free stack size for a thread.
798    ///
799    /// # Parameters
800    ///
801    /// - `thid`: The thread ID. Seem to take current thread if set to 0.
802    ///
803    /// # Return Value
804    ///
805    /// The free size.
806    pub fn sceKernelGetThreadStackFreeSize(thid: SceUid) -> i32;
807
808    #[psp(0x17C1684E)]
809    /// Get the status information for the specified thread.
810    ///
811    /// # Parameters
812    ///
813    /// - `thid`: Id of the thread to get status
814    /// - `info`: Pointer to the info structure to receive the data.
815    ///
816    ///   Note: The structures size field should be set to
817    ///   `core::mem::size_of(SceKernelThreadInfo)` before calling this function.
818    ///
819    /// # Return Value
820    ///
821    /// 0 if successful, otherwise the error code.
822    pub fn sceKernelReferThreadStatus(
823        thid: SceUid,
824        info: *mut SceKernelThreadInfo,
825    ) -> i32;
826
827    #[psp(0xFFC36A14)]
828    /// Retrive the runtime status of a thread.
829    ///
830    /// # Parameters
831    ///
832    /// - `thid`: UID of the thread to retrive status.
833    /// - `status`: Pointer to a `SceKernelThreadRunStatus` struct to receive the runtime status.
834    ///
835    /// # Return Value
836    ///
837    /// 0 if successful, otherwise the error code.
838    pub fn sceKernelReferThreadRunStatus(
839        thid: SceUid,
840        status: *mut SceKernelThreadRunStatus,
841    ) -> i32;
842
843    #[psp(0xD6DA4BA1)]
844    /// Creates a new semaphore
845    ///
846    /// # Parameters
847    ///
848    /// - `name`: Specifies the name of the sema
849    /// - `attr`: Sema attribute flags (normally set to 0)
850    /// - `init_val`: Sema initial value
851    /// - `max_val`: Sema maximum value
852    /// - `option`: Sema options (normally set to 0)
853    /// # Return Value
854    ///
855    /// A semaphore id
856    pub fn sceKernelCreateSema(
857        name: *const u8,
858        attr: u32,
859        init_val: i32,
860        max_val: i32,
861        option: *mut SceKernelSemaOptParam,
862    ) -> SceUid;
863
864    #[psp(0x28B6489C)]
865    /// Destroy a semaphore
866    ///
867    /// # Parameters
868    ///
869    /// - `sema_id`: The semaid returned from a previous create call.
870    ///
871    /// # Return Value
872    ///
873    /// Returns the value 0 if it's succesful otherwise -1
874    pub fn sceKernelDeleteSema(sema_id: SceUid) -> i32;
875
876    #[psp(0x3F53E640)]
877    /// Send a signal to a semaphore
878    ///
879    /// # Parameters
880    ///
881    /// - `sema_id`: The sema id returned from `sceKernelCreateSema`
882    /// - `signal`: The amount to signal the sema (i.e. if 2 then increment the sema by 2)
883    ///
884    /// # Return Value
885    ///
886    /// < 0 On error.
887    pub fn sceKernelSignalSema(
888        sema_id: SceUid,
889        signal: i32,
890    ) -> i32;
891
892    #[psp(0x4E3A1105)]
893    /// Lock a semaphore
894    ///
895    /// # Parameters
896    ///
897    /// - `sema_id`: The sema id returned from `sceKernelCreateSema`
898    /// - `signal`: The value to wait for (i.e. if 1 then wait till reaches a signal state of 1)
899    /// - `timeout`: Timeout in microseconds (assumed).
900    ///
901    /// # Return Value
902    ///
903    /// < 0 on error.
904    pub fn sceKernelWaitSema(
905        sema_id: SceUid,
906        signal: i32,
907        timeout: *mut u32,
908    ) -> i32;
909
910    #[psp(0x6D212BAC)]
911    /// Lock a semaphore a handle callbacks if necessary.
912    ///
913    /// # Parameters
914    ///
915    /// - `sema_id`: The sema id returned from `sceKernelCreateSema`
916    /// - `signal`: The value to wait for (i.e. if 1 then wait till reaches a signal state of 1)
917    /// - `timeout`: Timeout in microseconds (assumed).
918    ///
919    /// # Return Value
920    ///
921    /// < 0 on error.
922    pub fn sceKernelWaitSemaCB(
923        sema_id: SceUid,
924        signal: i32,
925        timeout: *mut u32,
926    ) -> i32;
927
928    #[psp(0x58B1F937)]
929    /// Poll a sempahore.
930    ///
931    /// # Parameters
932    ///
933    /// - `sema_id`: UID of the semaphore to poll.
934    /// - `signal`: The value to test for.
935    ///
936    /// # Return Value
937    ///
938    /// < 0 on error.
939    pub fn sceKernelPollSema(
940        sema_id: SceUid,
941        signal: i32,
942    ) -> i32;
943
944    #[psp(0xBC6FEBC5)]
945    /// Retrieve information about a semaphore.
946    ///
947    /// # Parameters
948    ///
949    /// - `sema_id`: UID of the semaphore to retrieve info for.
950    /// - `info`: Pointer to a `SceKernelSemaInfo` struct to receive the info.
951    ///
952    /// # Return Value
953    ///
954    /// < 0 on error.
955    pub fn sceKernelReferSemaStatus(
956        sema_id: SceUid,
957        info: *mut SceKernelSemaInfo,
958    ) -> i32;
959
960    #[psp(0x19CFF145)]
961    /// Create a lightweight mutex
962    ///
963    /// # Parameters
964    ///
965    /// - `mutex`: The pointer to the mutex
966    /// - `name`: The name of the lightweight mutex
967    /// - `attr`: Attributes of the lightweight mutex
968    /// TODO: what values does this take?
969    /// - `initial_count`: The inital value of the mutex
970    /// - `options`: Other options for the mutex
971    /// TODO: what values does this take?
972    ///
973    /// # Return Value
974    ///
975    /// 0 on success, otherwise an error code
976    pub fn sceKernelCreateLwMutex(
977        mutex: *mut SceKernelLwMutexWork,
978        name: *const u8,
979        attr: u32,
980        initial_count: i32,
981        options: *mut u32,
982    ) -> i32;
983
984    #[psp(0x60107536)]
985    /// Delete a lightweight mutex
986    ///
987    /// # Parameters
988    ///
989    /// - `mutex`: Pointer to a lightweight mutex structure.
990    ///
991    /// # Return Value
992    ///
993    /// 0 on success, otherwise an error code
994    pub fn sceKernelDeleteLwMutex(mutex: *mut SceKernelLwMutexWork) -> i32;
995
996    #[psp(0xDC692EE3)]
997    /// Tries to lock a lightweight mutex.
998    ///
999    /// This function is non-blocking. If the mutex is flagged as recursive, count can be >1. For more information, see http://linux.die.net/man/3/pthread_mutex_trylock
1000    ///
1001    /// # Parameters
1002    /// - `mutex`: Pointer to a lightweight mutex structure.
1003    /// - `count`: The lock counter increment.
1004    ///
1005    /// # Return Value
1006    /// SCE_ERROR_OK on success, otherwise SCE_ERROR_KERNEL_LWMUTEX_LOCKED on error.
1007    pub fn sceKernelTryLockLwMutex(
1008        mutex: *mut SceKernelLwMutexWork,
1009        count: i32,
1010    ) -> i32;
1011
1012    #[psp(0xBEA46419)]
1013    /// Locks a lightweight mutex.
1014    ///
1015    /// This function can be blocking if the mutex is already locked. If the mutex is flagged as recursive, count can be >1. For more information, see http://linux.die.net/man/3/pthread_mutex_lock
1016    ///
1017    /// # Parameters
1018    /// - `mutex`: Pointer to a lightweight mutex structure.
1019    /// - `count`: The lock counter increment.
1020    /// - `timeout`: The timeout to expire after if the mutex cannot be locked.
1021    ///
1022    /// # Return Value
1023    /// SCE_ERROR_OK on success, otherwise <0 on error.
1024    pub fn sceKernelLockLwMutex(
1025        mutex: *mut SceKernelLwMutexWork,
1026        count: i32,
1027        timeout: *mut u32,
1028    ) -> i32;
1029
1030    #[psp(0x1FC64E09)]
1031    /// Locks a lightweight mutex (callback).
1032    ///
1033    /// This function can be blocking if the mutex is already locked. If the mutex is flagged as recursive, count can be >1. For more information, see http://linux.die.net/man/3/pthread_mutex_lock
1034    ///
1035    /// # Parameters
1036    /// - `mutex`: Pointer to a lightweight mutex structure.
1037    /// - `count`: The lock counter increment.
1038    ///
1039    /// # Return Value
1040    /// SCE_ERROR_OK on success, otherwise <0 on error.
1041    pub fn sceKernelLockMutexCB(mutex: *mut SceKernelLwMutexWork, count: i32) -> i32;
1042
1043    #[psp(0x15B6446B)]
1044    /// Unlocks a lightweight mutex.
1045    ///
1046    /// This function is non-blocking. If the mutex is flagged as recursive, count can be >1. For more information, see http://linux.die.net/man/3/pthread_mutex_unlock
1047    ///
1048    /// # Parameters
1049    /// - `mutex`: Pointer to a lightweight mutex structure.
1050    /// - `count`: The lock counter decrement.
1051    ///
1052    /// # Return Value
1053    /// SCE_ERROR_OK on success, otherwise <0 on error.
1054    pub fn sceKernelUnlockLwMutex(
1055        mutex: *mut SceKernelLwMutexWork,
1056        count: i32,
1057    ) -> i32;
1058
1059    #[psp(0xC1734599)]
1060    /// TODO: Refers the lightweight mutex's status.
1061    ///
1062    /// # Parameters
1063    /// - `mutex`: Pointer to a lightweight mutex structure.
1064    /// - `addr`: Unknown.
1065    /// # Return Value
1066    /// Unknown, may be SCE_ERROR_OK on success and <0 on error.
1067    pub fn sceKernelReferLwMutexStatus(work_area: *mut SceKernelLwMutexWork, addr: *mut u32) -> i32;
1068
1069    #[psp(0x55C20A00)]
1070    /// Create an event flag.
1071    ///
1072    /// # Parameters
1073    ///
1074    /// - `name`: The name of the event flag.
1075    /// - `attr`: Attributes from `EventFlagAttributes`.
1076    /// - `bits`: Initial bit pattern.
1077    /// - `opt`: Options, set to null.
1078    ///
1079    /// # Return Value
1080    ///
1081    /// < 0 on error. >= 0 event flag id.
1082    pub fn sceKernelCreateEventFlag(
1083        name: *const u8,
1084        attr: EventFlagAttributes,
1085        bits: i32,
1086        opt: *mut SceKernelEventFlagOptParam,
1087    ) -> SceUid;
1088
1089    #[psp(0x1FB15A32)]
1090    /// Set an event flag bit pattern.
1091    ///
1092    /// # Parameters
1093    ///
1094    /// - `ev_id`: The event id returned by `sceKernelCreateEventFlag`.
1095    /// - `bits`: The bit pattern to set.
1096    ///
1097    /// # Return Value
1098    ///
1099    /// < 0 On error
1100    pub fn sceKernelSetEventFlag(ev_id: SceUid, bits: u32) -> i32;
1101
1102    #[psp(0x812346E4)]
1103    /// Clear a event flag bit pattern
1104    ///
1105    /// # Parameters
1106    ///
1107    /// - `ev_id`: The event id returned by `sceKernelCreateEventFlag`
1108    /// - `bits`: The bits to clean
1109    ///
1110    /// # Return Value
1111    ///
1112    /// < 0 on Error
1113    pub fn sceKernelClearEventFlag(ev_id: SceUid, bits: u32) -> i32;
1114
1115    #[psp(0x30FD48F0)]
1116    /// Poll an event flag for a given bit pattern.
1117    ///
1118    /// # Parameters
1119    ///
1120    /// - `ev_id`: The event id returned by `sceKernelCreateEventFlag`.
1121    /// - `bits`: The bit pattern to poll for.
1122    /// - `wait`: Wait type, one or more of `EventFlagWaitTypes` or'ed together
1123    /// - `out_bits`: The bit pattern that was matched.
1124    ///
1125    /// # Return Value
1126    ///
1127    /// < 0 On error
1128    pub fn sceKernelPollEventFlag(
1129        ev_id: SceUid,
1130        bits: u32,
1131        wait: EventFlagWaitTypes,
1132        out_bits: *mut u32,
1133    ) -> i32;
1134
1135    #[psp(0x402FCF22)]
1136    /// Wait for an event flag for a given bit pattern.
1137    ///
1138    /// # Parameters
1139    ///
1140    /// - `ev_id`: The event id returned by sceKernelCreateEventFlag.
1141    /// - `bits`: The bit pattern to poll for.
1142    /// - `wait`: Wait type, one or more of `EventFlagWaitTypes` or'ed together
1143    /// - `out_bits`: The bit pattern that was matched.
1144    /// - `timeout`: Timeout in microseconds
1145    ///
1146    /// # Return Value
1147    ///
1148    /// < 0 On error
1149    pub fn sceKernelWaitEventFlag(
1150        ev_id: SceUid,
1151        bits: u32,
1152        wait: EventFlagWaitTypes,
1153        out_bits: *mut u32,
1154        timeout: *mut u32,
1155    ) -> i32;
1156
1157    #[psp(0x328C546A)]
1158    /// Wait for an event flag for a given bit pattern with callback.
1159    ///
1160    /// # Parameters
1161    ///
1162    /// - `ev_id`: The event id returned by `sceKernelCreateEventFlag`.
1163    /// - `bits`: The bit pattern to poll for.
1164    /// - `wait`: Wait type, one or more of `EventFlagWaitTypes` or'ed together
1165    /// - `out_bits`: The bit pattern that was matched.
1166    /// - `timeout`: Timeout in microseconds
1167    /// # Return Value
1168    ///
1169    /// < 0 On error
1170    pub fn sceKernelWaitEventFlagCB(
1171        ev_id: SceUid,
1172        bits: u32,
1173        wait: EventFlagWaitTypes,
1174        out_bits: *mut u32,
1175        timeout: *mut u32,
1176    ) -> i32;
1177
1178    #[psp(0xEF9E4C70)]
1179    /// Delete an event flag
1180    ///
1181    /// # Parameters
1182    ///
1183    /// - `ev_id`: The event id returned by `sceKernelCreateEventFlag`.
1184    ///
1185    /// # Return Value
1186    ///
1187    /// < 0 On error
1188    pub fn sceKernelDeleteEventFlag(ev_id: SceUid) -> i32;
1189
1190    #[psp(0xA66B0120)]
1191    /// Get the status of an event flag.
1192    ///
1193    /// # Parameters
1194    ///
1195    /// - `event`: The UID of the event.
1196    /// - `status`: A pointer to a `SceKernelEventFlagInfo` structure.
1197    ///
1198    /// # Return Value
1199    ///
1200    /// < 0 on error.
1201    pub fn sceKernelReferEventFlagStatus(
1202        event: SceUid,
1203        status: *mut SceKernelEventFlagInfo,
1204    ) -> i32;
1205
1206    #[psp(0x8125221D)]
1207    /// Creates a new messagebox
1208    ///
1209    /// # Parameters
1210    ///
1211    /// - `name`: Specifies the name of the mbx
1212    /// - `attr`: Mbx attribute flags (normally set to 0)
1213    /// - `option`: Mbx options (normally set to null)
1214    ///
1215    /// # Return Value
1216    ///
1217    /// A messagebox id
1218    pub fn sceKernelCreateMbx(
1219        name: *const u8,
1220        attr: u32,
1221        option: *mut SceKernelMbxOptParam,
1222    ) -> SceUid;
1223
1224    #[psp(0x86255ADA)]
1225    /// Destroy a messagebox
1226    ///
1227    /// # Parameters
1228    ///
1229    /// - `mbx_id`: The mbxid returned from a previous create call.
1230    ///
1231    /// # Return Value
1232    ///
1233    /// Returns the value 0 if its succesful otherwise an error code
1234    pub fn sceKernelDeleteMbx(mbx_id: SceUid) -> i32;
1235
1236    #[psp(0xE9B3061E)]
1237    /// Send a message to a messagebox
1238    ///
1239    /// # Parameters
1240    ///
1241    /// - `mbx_id`: The mbx id returned from `sceKernelCreateMbx`
1242    /// - `message`: A message to be forwarded to the receiver.
1243    ///
1244    ///    Note: The start of the message should be the `SceKernelMsgPacket` structure, the rest
1245    ///    (???) *This documentation appears to have been unfinished*.
1246    ///
1247    /// # Return Value
1248    ///
1249    /// < 0 On error.
1250    pub fn sceKernelSendMbx(
1251        mbx_id: SceUid,
1252        message: *mut c_void,
1253    ) -> i32;
1254
1255    #[psp(0x18260574)]
1256    /// Wait for a message to arrive in a messagebox
1257    ///
1258    /// # Parameters
1259    ///
1260    /// - `mbx_id`: The mbx id returned from `sceKernelCreateMbx`
1261    /// - `message`: A pointer to where a pointer to the received message should be stored
1262    /// - `timeout`: Timeout in microseconds
1263    ///
1264    /// # Return Value
1265    ///
1266    /// < 0 on error.
1267    pub fn sceKernelReceiveMbx(
1268        mbx_id: SceUid,
1269        message: *mut *mut c_void,
1270        timeout: *mut u32,
1271    ) -> i32;
1272
1273    #[psp(0xF3986382)]
1274    /// Wait for a message to arrive in a messagebox and handle callbacks if necessary.
1275    ///
1276    /// # Parameters
1277    ///
1278    /// - `mbx_id`: The mbx id returned from `sceKernelCreateMbx`
1279    /// - `message`: A pointer to where a pointer to the received message should be stored
1280    /// - `timeout`: Timeout in microseconds
1281    ///
1282    /// # Return Value
1283    ///
1284    /// < 0 on error.
1285    pub fn sceKernelReceiveMbxCB(
1286        mbx_id: SceUid,
1287        message: *mut *mut c_void,
1288        timeout: *mut u32,
1289    ) -> i32;
1290
1291    #[psp(0x0D81716A)]
1292    /// Check if a message has arrived in a messagebox
1293    ///
1294    /// # Parameters
1295    ///
1296    /// - `mbx_id`: The mbx id returned from `sceKernelCreateMbx`
1297    /// - `message`: A pointer to where a pointer to the received message should be stored
1298    ///
1299    /// # Return Value
1300    ///
1301    /// < 0 on error (`SCE_KERNEL_ERROR_MBOX_NOMSG` if the mbx is empty).
1302    pub fn sceKernelPollMbx(
1303        mbx_id: SceUid,
1304        pmessage: *mut *mut c_void,
1305    ) -> i32;
1306
1307    #[psp(0x87D4DD36)]
1308    /// Abort all wait operations on a messagebox
1309    ///
1310    /// # Parameters
1311    ///
1312    /// - `mbx_id`: The mbx id returned from `sceKernelCreateMbx`
1313    /// - `num`: A pointer to where the number of threads which were waiting on
1314    ///    the mbx should be stored (null if you don't care)
1315    ///
1316    /// # Return Value
1317    ///
1318    /// < 0 on error
1319    pub fn sceKernelCancelReceiveMbx(
1320        mbx_id: SceUid,
1321        num: *mut i32,
1322    ) -> i32;
1323
1324    #[psp(0xA8E8C846)]
1325    /// Retrieve information about a messagebox.
1326    ///
1327    /// # Parameters
1328    ///
1329    /// - `mbx_id`: UID of the messagebox to retrieve info for.
1330    /// - `info`: Pointer to a `SceKernelMbxInfo` struct to receive the info.
1331    ///
1332    /// # Return Value
1333    ///
1334    /// < 0 on error.
1335    pub fn sceKernelReferMbxStatus(
1336        mbx_id: SceUid,
1337        info: *mut SceKernelMbxInfo,
1338    ) -> i32;
1339
1340    #[psp(0x6652B8CA)]
1341    /// Set an alarm.
1342    ///
1343    /// # Parameters
1344    ///
1345    /// - `clock`: The number of micro seconds till the alarm occurrs.
1346    /// - `handler`: Pointer to a `SceKernelAlarmHandler`
1347    /// - `common`: Common pointer for the alarm handler
1348    ///
1349    /// # Return Value
1350    ///
1351    /// A UID representing the created alarm, < 0 on error.
1352    pub fn sceKernelSetAlarm(
1353        clock: u32,
1354        handler: SceKernelAlarmHandler,
1355        common: *mut c_void,
1356    ) -> SceUid;
1357
1358    #[psp(0xB2C25152)]
1359    /// Set an alarm using a `SceKernelSysClock` structure for the time
1360    ///
1361    /// # Parameters
1362    ///
1363    /// - `clock`: Pointer to a `SceKernelSysClock` structure
1364    /// - `handler`: Pointer to a `SceKernelAlarmHandler`
1365    /// - `common`: Common pointer for the alarm handler.
1366    ///
1367    /// # Return Value
1368    ///
1369    /// A UID representing the created alarm, < 0 on error.
1370    pub fn sceKernelSetSysClockAlarm(
1371        clock: *mut SceKernelSysClock,
1372        handler: *mut SceKernelAlarmHandler,
1373        common: *mut c_void,
1374    ) -> SceUid;
1375
1376    #[psp(0x7E65B999)]
1377    /// Cancel a pending alarm.
1378    ///
1379    /// # Parameters
1380    ///
1381    /// - `alarm_id`: UID of the alarm to cancel.
1382    ///
1383    /// # Return Value
1384    ///
1385    /// 0 on success, < 0 on error.
1386    pub fn sceKernelCancelAlarm(alarm_id: SceUid) -> i32;
1387
1388    #[psp(0xDAA3F564)]
1389    /// Refer the status of a created alarm.
1390    ///
1391    /// # Parameters
1392    ///
1393    /// - `alarm_id`: UID of the alarm to get the info of
1394    /// - `info`: Pointer to a `SceKernelAlarmInfo` structure
1395    ///
1396    /// # Return Value
1397    ///
1398    /// 0 on success, < 0 on error.
1399    pub fn sceKernelReferAlarmStatus(
1400        alarm_id: SceUid,
1401        info: *mut SceKernelAlarmInfo,
1402    ) -> i32;
1403
1404    #[psp(0xE81CAF8F)]
1405    /// Create callback.
1406    ///
1407    /// # Parameters
1408    ///
1409    /// - `name`: A textual name for the callback.
1410    /// - `func`: A pointer to a function that will be called as the callback.
1411    /// - `arg`: Argument for the callback?
1412    ///
1413    /// # Return Value
1414    ///
1415    /// >= 0 A callback id which can be used in subsequent functions, < 0 an error.
1416    pub fn sceKernelCreateCallback(
1417        name: *const u8,
1418        func: SceKernelCallbackFunction,
1419        arg: *mut c_void,
1420    ) -> SceUid;
1421
1422    #[psp(0x730ED8BC)]
1423    /// Gets the status of a specified callback.
1424    ///
1425    /// # Parameters
1426    ///
1427    /// - `cb`: The UID of the callback to refer.
1428    /// - `status`: Pointer to a status structure. The size parameter should be
1429    ///   initialised before calling.
1430    ///
1431    /// # Return Value
1432    ///
1433    /// < 0 on error.
1434    pub fn sceKernelReferCallbackStatus(
1435        cb: SceUid,
1436        status: *mut SceKernelCallbackInfo,
1437    ) -> i32;
1438
1439    #[psp(0xEDBA5844)]
1440    /// Delete a callback
1441    ///
1442    /// # Parameters
1443    ///
1444    /// - `cb`: The UID of the specified callback
1445    ///
1446    /// # Return Value
1447    ///
1448    /// 0 on success, < 0 on error
1449    pub fn sceKernelDeleteCallback(cb: SceUid) -> i32;
1450
1451    #[psp(0xC11BA8C4)]
1452    /// Notify a callback
1453    ///
1454    /// # Parameters
1455    ///
1456    /// - `cb`: The UID of the specified callback
1457    /// - `arg2`: Passed as arg2 into the callback function
1458    ///
1459    /// # Return Value
1460    ///
1461    /// 0 on success, < 0 on error
1462    pub fn sceKernelNotifyCallback(
1463        cb: SceUid,
1464        arg2: i32,
1465    ) -> i32;
1466
1467    #[psp(0xBA4051D6)]
1468    /// Cancel a callback?
1469    ///
1470    /// # Parameters
1471    ///
1472    /// - `cb`: The UID of the specified callback
1473    ///
1474    /// # Return Value
1475    ///
1476    /// 0 on success, < 0 on error
1477    pub fn sceKernelCancelCallback(cb: SceUid) -> i32;
1478
1479    #[psp(0x2A3D44FF)]
1480    /// Get the callback count
1481    ///
1482    /// # Parameters
1483    ///
1484    /// - `cb`: The UID of the specified callback
1485    ///
1486    /// # Return Value
1487    ///
1488    /// The callback count, < 0 on error
1489    pub fn sceKernelGetCallbackCount(cb: SceUid) -> i32;
1490
1491    #[psp(0x349D6D6C)]
1492    /// Check callback?
1493    ///
1494    /// # Return Value
1495    ///
1496    /// TODO: Something or another
1497    pub fn sceKernelCheckCallback() -> i32;
1498
1499    #[psp(0x94416130)]
1500    /// Get a list of UIDs from threadman. Allows you to enumerate resources
1501    /// such as threads or semaphores.
1502    ///
1503    /// # Parameters
1504    ///
1505    /// - `type`: The type of resource to list, one of `SceKernelIdListType`.
1506    /// - `read_buf`: A pointer to a buffer to store the list.
1507    /// - `read_buf_size`: The size of the buffer in `SceUid` units.
1508    /// - `id_count`: Pointer to an integer in which to return the number of IDs in the list.
1509    ///
1510    /// # Return Value
1511    ///
1512    /// < 0 on error. Either 0 or the same as idcount on success.
1513    pub fn sceKernelGetThreadmanIdList(
1514        type_: SceKernelIdListType,
1515        read_buf: *mut SceUid,
1516        read_buf_size: i32,
1517        id_count: *mut i32,
1518    ) -> i32;
1519
1520    #[psp(0x627E6F3A)]
1521    /// Get the current system status.
1522    ///
1523    /// # Parameters
1524    ///
1525    /// - `status`: Pointer to a `SceKernelSystemStatus` structure.
1526    ///
1527    /// # Return Value
1528    ///
1529    /// < 0 on error.
1530    pub fn sceKernelReferSystemStatus(status: *mut SceKernelSystemStatus) -> i32;
1531
1532    #[psp(0x7C0DC2A0)]
1533    /// Create a message pipe
1534    ///
1535    /// # Parameters
1536    ///
1537    /// - `name`: Name of the pipe
1538    /// - `part`: ID of the memory partition
1539    /// - `attr`: Set to 0?
1540    /// - `unk1`: Unknown
1541    /// - `opt`: Message pipe options (set to null)
1542    ///
1543    /// # Return Value
1544    ///
1545    /// The UID of the created pipe, < 0 on error
1546    pub fn sceKernelCreateMsgPipe(
1547        name: *const u8,
1548        part: i32,
1549        attr: i32,
1550        unk1: *mut c_void,
1551        opt: *mut c_void,
1552    ) -> SceUid;
1553
1554    #[psp(0xF0B7DA1C)]
1555    /// Delete a message pipe
1556    ///
1557    /// # Parameters
1558    ///
1559    /// - `uid`: The UID of the pipe
1560    ///
1561    /// # Return Value
1562    ///
1563    /// 0 on success, < 0 on error
1564    pub fn sceKernelDeleteMsgPipe(uid: SceUid) -> i32;
1565
1566    #[psp(0x876DBFAD)]
1567    /// Send a message to a pipe
1568    ///
1569    /// # Parameters
1570    ///
1571    /// - `uid`: The UID of the pipe
1572    /// - `message`: Pointer to the message
1573    /// - `size`: Size of the message
1574    /// - `unk1`: Unknown
1575    /// - `unk2`: Unknown
1576    /// - `timeout`: Timeout for send
1577    ///
1578    /// # Return Value
1579    ///
1580    /// 0 on success, < 0 on error
1581    pub fn sceKernelSendMsgPipe(
1582        uid: SceUid,
1583        message: *mut c_void,
1584        size: u32,
1585        unk1: i32,
1586        unk2: *mut c_void,
1587        timeout: *mut u32,
1588    ) -> i32;
1589
1590    #[psp(0x7C41F2C2)]
1591    /// Send a message to a pipe (with callback)
1592    ///
1593    /// # Parameters
1594    ///
1595    /// - `uid`: The UID of the pipe
1596    /// - `message`: Pointer to the message
1597    /// - `size`: Size of the message
1598    /// - `unk1`: Unknown
1599    /// - `unk2`: Unknown
1600    /// - `timeout`: Timeout for send
1601    ///
1602    /// # Return Value
1603    ///
1604    /// 0 on success, < 0 on error
1605    pub fn sceKernelSendMsgPipeCB(
1606        uid: SceUid,
1607        message: *mut c_void,
1608        size: u32,
1609        unk1: i32,
1610        unk2: *mut c_void,
1611        timeout: *mut u32,
1612    ) -> i32;
1613
1614    #[psp(0x884C9F90)]
1615    /// Try to send a message to a pipe
1616    ///
1617    /// # Parameters
1618    ///
1619    /// - `uid`: The UID of the pipe
1620    /// - `message`: Pointer to the message
1621    /// - `size`: Size of the message
1622    /// - `unk1`: Unknown
1623    /// - `unk2`: Unknown
1624    ///
1625    /// # Return Value
1626    ///
1627    /// 0 on success, < 0 on error
1628    pub fn sceKernelTrySendMsgPipe(
1629        uid: SceUid,
1630        message: *mut c_void,
1631        size: u32,
1632        unk1: i32,
1633        unk2: *mut c_void,
1634    ) -> i32;
1635
1636    #[psp(0x74829B76)]
1637    /// Receive a message from a pipe
1638    ///
1639    /// # Parameters
1640    ///
1641    /// - `uid`: The UID of the pipe
1642    /// - `message`: Pointer to the message
1643    /// - `size`: Size of the message
1644    /// - `unk1`: Unknown
1645    /// - `unk2`: Unknown
1646    /// - `timeout`: Timeout for receive
1647    ///
1648    /// # Return Value
1649    ///
1650    /// 0 on success, < 0 on error
1651    pub fn sceKernelReceiveMsgPipe(
1652        uid: SceUid,
1653        message: *mut c_void,
1654        size: u32,
1655        unk1: i32,
1656        unk2: *mut c_void,
1657        timeout: *mut u32,
1658    ) -> i32;
1659
1660    #[psp(0xFBFA697D)]
1661    /// Receive a message from a pipe (with callback)
1662    ///
1663    /// # Parameters
1664    ///
1665    /// - `uid`: The UID of the pipe
1666    /// - `message`: Pointer to the message
1667    /// - `size`: Size of the message
1668    /// - `unk1`: Unknown
1669    /// - `unk2`: Unknown
1670    /// - `timeout`: Timeout for receive
1671    ///
1672    /// # Return Value
1673    ///
1674    /// 0 on success, < 0 on error
1675    pub fn sceKernelReceiveMsgPipeCB(
1676        uid: SceUid,
1677        message: *mut c_void,
1678        size: u32,
1679        unk1: i32,
1680        unk2: *mut c_void,
1681        timeout: *mut u32,
1682    ) -> i32;
1683
1684    #[psp(0xDF52098F)]
1685    /// Receive a message from a pipe
1686    ///
1687    /// # Parameters
1688    ///
1689    /// - `uid`: The UID of the pipe
1690    /// - `message`: Pointer to the message
1691    /// - `size`: Size of the message
1692    /// - `unk1`: Unknown
1693    /// - `unk2`: Unknown
1694    ///
1695    /// # Return Value
1696    ///
1697    /// 0 on success, < 0 on error
1698    pub fn sceKernelTryReceiveMsgPipe(
1699        uid: SceUid,
1700        message: *mut c_void,
1701        size: u32,
1702        unk1: i32,
1703        unk2: *mut c_void,
1704    ) -> i32;
1705
1706    #[psp(0x349B864D)]
1707    /// Cancel a message pipe
1708    ///
1709    /// # Parameters
1710    ///
1711    /// - `uid`: UID of the pipe to cancel
1712    /// - `send`: Receive number of sending threads?
1713    /// - `recv`: Receive number of receiving threads?
1714    ///
1715    /// # Return Value
1716    ///
1717    /// 0 on success, < 0 on error
1718    pub fn sceKernelCancelMsgPipe(
1719        uid: SceUid,
1720        send: *mut i32,
1721        recv: *mut i32,
1722    ) -> i32;
1723
1724    #[psp(0x33BE4024)]
1725    /// Get the status of a Message Pipe
1726    ///
1727    /// # Parameters
1728    ///
1729    /// - `uid`: The uid of the Message Pipe
1730    /// - `info`: Pointer to a `SceKernelMppInfo` structure
1731    ///
1732    /// # Return Value
1733    ///
1734    /// 0 on success, < 0 on error
1735    pub fn sceKernelReferMsgPipeStatus(
1736        uid: SceUid,
1737        info: *mut SceKernelMppInfo,
1738    ) -> i32;
1739
1740    #[psp(0x56C039B5)]
1741    /// Create a variable pool
1742    ///
1743    /// # Parameters
1744    ///
1745    /// - `name`: Name of the pool
1746    /// - `part`: The memory partition ID
1747    /// - `attr`: Attributes
1748    /// - `size`: Size of pool
1749    /// - `opt`: Options (can be set to null)
1750    ///
1751    /// # Return Value
1752    ///
1753    /// The UID of the created pool, < 0 on error.
1754    pub fn sceKernelCreateVpl(
1755        name: *const u8,
1756        part: i32,
1757        attr: i32,
1758        size: u32,
1759        opt: *mut SceKernelVplOptParam,
1760    ) -> SceUid;
1761
1762    #[psp(0x89B3D48C)]
1763    /// Delete a variable pool
1764    ///
1765    /// # Parameters
1766    ///
1767    /// - `uid`: The UID of the pool
1768    ///
1769    /// # Return Value
1770    ///
1771    /// 0 on success, < 0 on error
1772    pub fn sceKernelDeleteVpl(uid: SceUid) -> i32;
1773
1774    #[psp(0xBED27435)]
1775    /// Allocate from the pool
1776    ///
1777    /// # Parameters
1778    ///
1779    /// - `uid`: The UID of the pool
1780    /// - `size`: The size to allocate
1781    /// - `data`: Receives the address of the allocated data
1782    /// - `timeout`: Amount of time to wait for allocation?
1783    ///
1784    /// # Return Value
1785    ///
1786    /// 0 on success, < 0 on error
1787    pub fn sceKernelAllocateVpl(
1788        uid: SceUid,
1789        size: u32,
1790        data: *mut *mut c_void,
1791        timeout: *mut u32,
1792    ) -> i32;
1793
1794    #[psp(0xEC0A693F)]
1795    /// Allocate from the pool (with callback)
1796    ///
1797    /// # Parameters
1798    ///
1799    /// - `uid`: The UID of the pool
1800    /// - `size`: The size to allocate
1801    /// - `data`: Receives the address of the allocated data
1802    /// - `timeout`: Amount of time to wait for allocation?
1803    ///
1804    /// # Return Value
1805    ///
1806    /// 0 on success, < 0 on error
1807    pub fn sceKernelAllocateVplCB(
1808        uid: SceUid,
1809        size: u32,
1810        data: *mut *mut c_void,
1811        timeout: *mut u32,
1812    ) -> i32;
1813
1814    #[psp(0xAF36D708)]
1815    /// Try to allocate from the pool
1816    ///
1817    /// # Parameters
1818    ///
1819    /// - `uid`: The UID of the pool
1820    /// - `size`: The size to allocate
1821    /// - `data`: Receives the address of the allocated data
1822    ///
1823    /// # Return Value
1824    ///
1825    /// 0 on success, < 0 on error
1826    pub fn sceKernelTryAllocateVpl(
1827        uid: SceUid,
1828        size: u32,
1829        data: *mut *mut c_void,
1830    ) -> i32;
1831
1832    #[psp(0xB736E9FF)]
1833    /// Free a block
1834    ///
1835    /// # Parameters
1836    ///
1837    /// - `uid`: The UID of the pool
1838    /// - `data`: The data block to deallocate
1839    ///
1840    /// # Return Value
1841    ///
1842    /// 0 on success, < 0 on error
1843    pub fn sceKernelFreeVpl(
1844        uid: SceUid,
1845        data: *mut c_void,
1846    ) -> i32;
1847
1848    #[psp(0x1D371B8A)]
1849    /// Cancel a pool
1850    ///
1851    /// # Parameters
1852    ///
1853    /// - `uid`: The UID of the pool
1854    /// - `num`: Receives the number of waiting threads
1855    ///
1856    /// # Return Value
1857    ///
1858    /// 0 on success, < 0 on error
1859    pub fn sceKernelCancelVpl(
1860        uid: SceUid,
1861        num: *mut i32,
1862    ) -> i32;
1863
1864    #[psp(0x39810265)]
1865    /// Get the status of an VPL
1866    ///
1867    /// # Parameters
1868    ///
1869    /// - `uid`: The uid of the VPL
1870    /// - `info`: Pointer to a `SceKernelVplInfo` structure
1871    ///
1872    /// # Return Value
1873    ///
1874    /// 0 on success, < 0 on error
1875    pub fn sceKernelReferVplStatus(
1876        uid: SceUid,
1877        info: *mut SceKernelVplInfo,
1878    ) -> i32;
1879
1880    #[psp(0xC07BB470)]
1881    /// Create a fixed pool
1882    ///
1883    /// # Parameters
1884    ///
1885    /// - `name`: Name of the pool
1886    /// - `part`: The memory partition ID
1887    /// - `attr`: Attributes
1888    /// - `size`: Size of pool block
1889    /// - `blocks`: Number of blocks to allocate
1890    /// - `opt`: Options (can be set to null)
1891    ///
1892    /// # Return Value
1893    ///
1894    /// The UID of the created pool, < 0 on error.
1895    pub fn sceKernelCreateFpl(
1896        name: *const u8,
1897        part: i32,
1898        attr: i32,
1899        size: u32,
1900        blocks: u32,
1901        opt: *mut SceKernelFplOptParam,
1902    ) -> i32;
1903
1904    #[psp(0xED1410E0)]
1905    /// Delete a fixed pool
1906    ///
1907    /// # Parameters
1908    ///
1909    /// - `uid`: The UID of the pool
1910    ///
1911    /// # Return Value
1912    ///
1913    /// 0 on success, < 0 on error
1914    pub fn sceKernelDeleteFpl(uid: SceUid) -> i32;
1915
1916    #[psp(0xD979E9BF)]
1917    /// Allocate from the pool
1918    ///
1919    /// # Parameters
1920    ///
1921    /// - `uid`: The UID of the pool
1922    /// - `data`: Receives the address of the allocated data
1923    /// - `timeout`: Amount of time to wait for allocation?
1924    ///
1925    /// # Return Value
1926    ///
1927    /// 0 on success, < 0 on error
1928    pub fn sceKernelAllocateFpl(
1929        uid: SceUid,
1930        data: *mut *mut c_void,
1931        timeout: *mut u32,
1932    ) -> i32;
1933
1934    #[psp(0xE7282CB6)]
1935    /// Allocate from the pool (with callback)
1936    ///
1937    /// # Parameters
1938    ///
1939    /// - `uid`: The UID of the pool
1940    /// - `data`: Receives the address of the allocated data
1941    /// - `timeout`: Amount of time to wait for allocation?
1942    ///
1943    /// # Return Value
1944    ///
1945    /// 0 on success, < 0 on error
1946    pub fn sceKernelAllocateFplCB(
1947        uid: SceUid,
1948        data: *mut *mut c_void,
1949        timeout: *mut u32,
1950    ) -> i32;
1951
1952    #[psp(0x623AE665)]
1953    /// Try to allocate from the pool
1954    ///
1955    /// # Parameters
1956    ///
1957    /// - `uid`: The UID of the pool
1958    /// - `data`: Receives the address of the allocated data
1959    ///
1960    /// # Return Value
1961    ///
1962    /// 0 on success, < 0 on error
1963    pub fn sceKernelTryAllocateFpl(
1964        uid: SceUid,
1965        data: *mut *mut c_void,
1966    ) -> i32;
1967
1968    #[psp(0xF6414A71)]
1969    /// Free a block
1970    ///
1971    /// # Parameters
1972    ///
1973    /// - `uid`: The UID of the pool
1974    /// - `data`: The data block to deallocate
1975    ///
1976    /// # Return Value
1977    ///
1978    /// 0 on success, < 0 on error
1979    pub fn sceKernelFreeFpl(
1980        uid: SceUid,
1981        data: *mut c_void,
1982    ) -> i32;
1983
1984    #[psp(0xA8AA591F)]
1985    /// Cancel a pool
1986    ///
1987    /// # Parameters
1988    ///
1989    /// - `uid`: The UID of the pool
1990    /// - `pnum`: Receives the number of waiting threads
1991    ///
1992    /// # Return Value
1993    ///
1994    /// 0 on success, < 0 on error
1995    pub fn sceKernelCancelFpl(
1996        uid: SceUid,
1997        pnum: *mut i32,
1998    ) -> i32;
1999
2000    #[psp(0xD8199E4C)]
2001    /// Get the status of an FPL
2002    ///
2003    /// # Parameters
2004    ///
2005    /// - `uid`: The uid of the FPL
2006    /// - `info`: Pointer to a `SceKernelFplInfo` structure
2007    ///
2008    /// # Return Value
2009    ///
2010    /// 0 on success, < 0 on error
2011    pub fn sceKernelReferFplStatus(
2012        uid: SceUid,
2013        info: *mut SceKernelFplInfo,
2014    ) -> i32;
2015
2016    #[psp(0x110DEC9A)]
2017    /// Convert a number of microseconds to a `SceKernelSysClock` structure
2018    ///
2019    /// # Parameters
2020    ///
2021    /// - `usec`: Number of microseconds
2022    /// - `clock`: Pointer to a `SceKernelSysClock` structure
2023    ///
2024    /// # Return Value
2025    ///
2026    /// 0 on success, < 0 on error
2027    pub fn sceKernelUSec2SysClock(
2028        usec: u32,
2029        clock: *mut SceKernelSysClock,
2030    ) -> i32;
2031
2032    #[psp(0xC8CD158C)]
2033    /// Convert a number of microseconds to a wide time
2034    ///
2035    /// # Parameters
2036    ///
2037    /// - `usec`: Number of microseconds.
2038    ///
2039    /// # Return Value
2040    ///
2041    /// The time
2042    pub fn sceKernelUSec2SysClockWide(usec: u32) -> i64;
2043
2044    #[psp(0xBA6B92E2)]
2045    /// Convert a `SceKernelSysClock` structure to microseconds
2046    ///
2047    /// # Parameters
2048    ///
2049    /// - `clock`: Pointer to a `SceKernelSysClock` structure
2050    /// - `low`: Pointer to the low part of the time
2051    /// - `high`: Pointer to the high part of the time
2052    ///
2053    /// # Return Value
2054    ///
2055    /// 0 on success, < 0 on error
2056    pub fn sceKernelSysClock2USec(
2057        clock: *mut SceKernelSysClock,
2058        low: *mut u32,
2059        high: *mut u32,
2060    ) -> i32;
2061
2062    #[psp(0xE1619D7C)]
2063    /// Convert a wide time to microseconds
2064    ///
2065    /// # Parameters
2066    ///
2067    /// - `clock`: Wide time
2068    /// - `low`: Pointer to the low part of the time
2069    /// - `high`: Pointer to the high part of the time
2070    ///
2071    /// # Return Value
2072    ///
2073    /// 0 on success, < 0 on error
2074    pub fn sceKernelSysClock2USecWide(
2075        clock: i64,
2076        low: *mut u32,
2077        high: *mut u32,
2078    ) -> i32;
2079
2080    #[psp(0xDB738F35)]
2081    /// Get the system time
2082    ///
2083    /// # Parameters
2084    ///
2085    /// - `time`: Pointer to a `SceKernelSysClock` structure
2086    ///
2087    /// # Return Value
2088    ///
2089    /// 0 on success, < 0 on error
2090    pub fn sceKernelGetSystemTime(time: *mut SceKernelSysClock) -> i32;
2091
2092    #[psp(0x82BC5777)]
2093    /// Get the system time (wide version)
2094    ///
2095    /// # Return Value
2096    ///
2097    /// The system time
2098    pub fn sceKernelGetSystemTimeWide() -> i64;
2099
2100    #[psp(0x369ED59D)]
2101    /// Get the low 32bits of the current system time
2102    ///
2103    /// # Return Value
2104    ///
2105    /// The low 32bits of the system time
2106    pub fn sceKernelGetSystemTimeLow() -> u32;
2107
2108    #[psp(0x20FFF560)]
2109    /// Create a virtual timer
2110    ///
2111    /// # Parameters
2112    ///
2113    /// - `name`: Name for the timer.
2114    /// - `opt`: Pointer to an `SceKernelVTimerOptParam` (can be set to null)
2115    ///
2116    /// # Return Value
2117    ///
2118    /// The VTimer's UID or < 0 on error.
2119    pub fn sceKernelCreateVTimer(
2120        name: *const u8,
2121        opt: *mut SceKernelVTimerOptParam,
2122    ) -> SceUid;
2123
2124    #[psp(0x328F9E52)]
2125    /// Delete a virtual timer
2126    ///
2127    /// # Parameters
2128    ///
2129    /// - `uid`: The UID of the timer
2130    ///
2131    /// # Return Value
2132    ///
2133    /// < 0 on error.
2134    pub fn sceKernelDeleteVTimer(uid: SceUid) -> i32;
2135
2136    #[psp(0xB3A59970)]
2137    /// Get the timer base
2138    ///
2139    /// # Parameters
2140    ///
2141    /// - `uid`: UID of the vtimer
2142    /// - `base`: Pointer to a `SceKernelSysClock` structure
2143    ///
2144    /// # Return Value
2145    ///
2146    /// 0 on success, < 0 on error
2147    pub fn sceKernelGetVTimerBase(
2148        uid: SceUid,
2149        base: *mut SceKernelSysClock,
2150    ) -> i32;
2151
2152    #[psp(0xB7C18B77)]
2153    /// Get the timer base (wide format)
2154    ///
2155    /// # Parameters
2156    ///
2157    /// - `uid`: UID of the vtimer
2158    ///
2159    /// # Return Value
2160    ///
2161    /// The 64bit timer base
2162    pub fn sceKernelGetVTimerBaseWide(uid: SceUid) -> i64;
2163
2164    #[psp(0x034A921F)]
2165    /// Get the timer time
2166    ///
2167    /// # Parameters
2168    ///
2169    /// - `uid`: UID of the vtimer
2170    /// - `time`: Pointer to a `SceKernelSysClock` structure
2171    ///
2172    /// # Return Value
2173    ///
2174    /// 0 on success, < 0 on error
2175    pub fn sceKernelGetVTimerTime(
2176        uid: SceUid,
2177        time: *mut SceKernelSysClock,
2178    ) -> i32;
2179
2180    #[psp(0xC0B3FFD2)]
2181    /// Get the timer time (wide format)
2182    ///
2183    /// # Parameters
2184    ///
2185    /// - `uid`: UID of the vtimer
2186    ///
2187    /// # Return Value
2188    ///
2189    /// The 64bit timer time
2190    pub fn sceKernelGetVTimerTimeWide(uid: SceUid) -> i64;
2191
2192    #[psp(0x542AD630)]
2193    /// Set the timer time
2194    ///
2195    /// # Parameters
2196    ///
2197    /// - `uid`: UID of the vtimer
2198    /// - `time`: Pointer to a `SceKernelSysClock` structure
2199    ///
2200    /// # Return Value
2201    ///
2202    /// 0 on success, < 0 on error
2203    pub fn sceKernelSetVTimerTime(
2204        uid: SceUid,
2205        time: *mut SceKernelSysClock,
2206    ) -> i32;
2207
2208    #[psp(0xFB6425C3)]
2209    /// Set the timer time (wide format)
2210    ///
2211    /// # Parameters
2212    ///
2213    /// - `uid`: UID of the vtimer
2214    /// - `time`: Pointer to a `SceKernelSysClock` structure
2215    ///
2216    /// # Return Value
2217    ///
2218    /// Possibly the last time
2219    pub fn sceKernelSetVTimerTimeWide(uid: SceUid, time: i64) -> i64;
2220
2221    #[psp(0xC68D9437)]
2222    /// Start a virtual timer
2223    ///
2224    /// # Parameters
2225    ///
2226    /// - `uid`: The UID of the timer
2227    ///
2228    /// # Return Value
2229    ///
2230    /// < 0 on error
2231    pub fn sceKernelStartVTimer(uid: SceUid) -> i32;
2232
2233    #[psp(0xD0AEEE87)]
2234    /// Stop a virtual timer
2235    ///
2236    /// # Parameters
2237    ///
2238    /// - `uid`: The UID of the timer
2239    ///
2240    /// # Return Value
2241    ///
2242    /// < 0 on error
2243    pub fn sceKernelStopVTimer(uid: SceUid) -> i32;
2244
2245    #[psp(0xD8B299AE)]
2246    /// Set the timer handler
2247    ///
2248    /// # Parameters
2249    ///
2250    /// - `uid`: UID of the vtimer
2251    /// - `time`: Time to call the handler?
2252    /// - `handler`: The timer handler
2253    /// - `common`: Common pointer
2254    ///
2255    /// # Return Value
2256    ///
2257    /// 0 on success, < 0 on error
2258    pub fn sceKernelSetVTimerHandler(
2259        uid: SceUid,
2260        time: *mut SceKernelSysClock,
2261        handler: SceKernelVTimerHandler,
2262        common: *mut c_void,
2263    ) -> i32;
2264
2265    #[psp(0x53B00E9A)]
2266    /// Set the timer handler (wide mode)
2267    ///
2268    /// # Parameters
2269    ///
2270    /// - `uid`: UID of the vtimer
2271    /// - `time`: Time to call the handler?
2272    /// - `handler`: The timer handler
2273    /// - `common`: Common pointer
2274    ///
2275    /// # Return Value
2276    ///
2277    /// 0 on success, < 0 on error
2278    pub fn sceKernelSetVTimerHandlerWide(
2279        uid: SceUid,
2280        time: i64,
2281        handler: SceKernelVTimerHandlerWide,
2282        common: *mut c_void,
2283    ) -> i32;
2284
2285    #[psp(0xD2D615EF)]
2286    /// Cancel the timer handler
2287    ///
2288    /// # Parameters
2289    ///
2290    /// - `uid`: The UID of the vtimer
2291    ///
2292    /// # Return Value
2293    ///
2294    /// 0 on success, < 0 on error
2295    pub fn sceKernelCancelVTimerHandler(uid: SceUid) -> i32;
2296
2297    #[psp(0x5F32BEAA)]
2298    /// Get the status of a VTimer
2299    ///
2300    /// # Parameters
2301    ///
2302    /// - `uid`: The uid of the VTimer
2303    /// - `info`: Pointer to a `SceKernelVTimerInfo` structure
2304    ///
2305    /// # Return Value
2306    ///
2307    /// 0 on success, < 0 on error
2308    pub fn sceKernelReferVTimerStatus(
2309        uid: SceUid,
2310        info: *mut SceKernelVTimerInfo,
2311    ) -> i32;
2312
2313    #[psp(0x0C106E53)]
2314    /// Register a thread event handler
2315    ///
2316    /// # Parameters
2317    ///
2318    /// - `name`: Name for the thread event handler
2319    /// - `thread_id`: Thread ID to monitor
2320    /// - `mask`: Bit mask for what events to handle (only lowest 4 bits valid)
2321    /// - `handler`: Pointer to a `SceKernelThreadEventHandler` function
2322    /// - `common`: Common pointer
2323    ///
2324    /// # Return Value
2325    ///
2326    /// The UID of the create event handler, < 0 on error
2327    pub fn sceKernelRegisterThreadEventHandler(
2328        name: *const u8,
2329        thread_id: SceUid,
2330        mask: i32,
2331        handler: SceKernelThreadEventHandler,
2332        common: *mut c_void,
2333    ) -> SceUid;
2334
2335    #[psp(0x72F3C145)]
2336    /// Release a thread event handler.
2337    ///
2338    /// # Parameters
2339    ///
2340    /// - `uid`: The UID of the event handler
2341    ///
2342    /// # Return Value
2343    ///
2344    /// 0 on success, < 0 on error
2345    pub fn sceKernelReleaseThreadEventHandler(uid: SceUid) -> i32;
2346
2347    #[psp(0x369EEB6B)]
2348    /// Refer the status of an thread event handler
2349    ///
2350    /// # Parameters
2351    ///
2352    /// - `uid`: The UID of the event handler
2353    /// - `info`: Pointer to a `SceKernelThreadEventHandlerInfo` structure
2354    ///
2355    /// # Return Value
2356    ///
2357    /// 0 on success, < 0 on error
2358    pub fn sceKernelReferThreadEventHandlerStatus(
2359        uid: SceUid,
2360        info: *mut SceKernelThreadEventHandlerInfo,
2361    ) -> i32;
2362
2363    #[psp(0x64D4540E)]
2364    /// Get the thread profiler registers.
2365    ///
2366    /// # Return Value
2367    ///
2368    /// Pointer to the registers, null on error
2369    pub fn sceKernelReferThreadProfiler() -> *mut DebugProfilerRegs;
2370
2371    #[psp(0x8218B4DD)]
2372    /// Get the global profiler registers.
2373    ///
2374    /// # Return Value
2375    ///
2376    /// Pointer to the registers, null on error
2377    pub fn sceKernelReferGlobalProfiler() -> *mut DebugProfilerRegs;
2378}