Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
ps4MEL/ps4_pthread.h
ShadPKG / ps4MEL / ps4_pthread.h
1/*
2 * ╔═══════════════════════════════════════════════════════════════════════════╗
3 * ║ PS4 PTHREAD STUBS - HEADER ║
4 * ╠═══════════════════════════════════════════════════════════════════════════╣
5 * ║ Emulates scePthread* threading primitives for PS4 compatibility. ║
6 * ╚═══════════════════════════════════════════════════════════════════════════╝
7 */
8 
9#pragma once
10 
11#include <cstdint>
12 
13/*
14 * ┌─────────────────────────────────────────────────────────────────┐
15 * │ THREAD TYPES │
16 * └─────────────────────────────────────────────────────────────────┘
17 */
18 
19typedef void *ScePthread;
20typedef void *ScePthreadAttr;
21typedef void *ScePthreadMutex;
22typedef void *ScePthreadMutexattr;
23typedef void *ScePthreadCond;
24typedef void *ScePthreadCondattr;
25typedef void *ScePthreadRwlock;
26typedef void *ScePthreadRwlockattr;
27 
28/*
29 * ┌─────────────────────────────────────────────────────────────────┐
30 * │ THREAD CONSTANTS │
31 * └─────────────────────────────────────────────────────────────────┘
32 */
33 
34#define SCE_PTHREAD_MUTEX_INITIALIZER nullptr
35#define SCE_PTHREAD_COND_INITIALIZER nullptr
36#define SCE_PTHREAD_RWLOCK_INITIALIZER nullptr
37 
38// Mutex types
39#define SCE_PTHREAD_MUTEX_ERRORCHECK 1
40#define SCE_PTHREAD_MUTEX_RECURSIVE 2
41#define SCE_PTHREAD_MUTEX_NORMAL 3
42#define SCE_PTHREAD_MUTEX_ADAPTIVE_NP 4
43 
44// Thread priorities
45#define SCE_KERNEL_PRIO_FIFO_DEFAULT 700
46#define SCE_KERNEL_PRIO_FIFO_HIGHEST 256
47#define SCE_KERNEL_PRIO_FIFO_LOWEST 767
48 
49/*
50 * ┌─────────────────────────────────────────────────────────────────┐
51 * │ THREAD FUNCTIONS │
52 * └─────────────────────────────────────────────────────────────────┘
53 */
54 
55extern "C" {
56 
57// ═══════════════════════════════════════════════════════════════════
58// THREAD LIFECYCLE
59// ═══════════════════════════════════════════════════════════════════
60int32_t scePthreadCreate(ScePthread *thread, const ScePthreadAttr *attr,
61 void *(*entry)(void *), void *arg, const char *name);
62int32_t scePthreadJoin(ScePthread thread, void **retval);
63void scePthreadExit(void *retval);
64ScePthread scePthreadSelf();
65int32_t scePthreadCancel(ScePthread thread);
66int32_t scePthreadDetach(ScePthread thread);
67 
68// ═══════════════════════════════════════════════════════════════════
69// THREAD ATTRIBUTES
70// ═══════════════════════════════════════════════════════════════════
71int32_t scePthreadAttrInit(ScePthreadAttr *attr);
72int32_t scePthreadAttrDestroy(ScePthreadAttr *attr);
73int32_t scePthreadAttrSetdetachstate(ScePthreadAttr *attr, int32_t state);
74int32_t scePthreadAttrSetstacksize(ScePthreadAttr *attr, uint64_t size);
75int32_t scePthreadAttrSetschedparam(ScePthreadAttr *attr, const void *param);
76 
77// ═══════════════════════════════════════════════════════════════════
78// MUTEX
79// ═══════════════════════════════════════════════════════════════════
80int32_t scePthreadMutexInit(ScePthreadMutex *mutex,
81 const ScePthreadMutexattr *attr, const char *name);
82int32_t scePthreadMutexDestroy(ScePthreadMutex *mutex);
83int32_t scePthreadMutexLock(ScePthreadMutex *mutex);
84int32_t scePthreadMutexTrylock(ScePthreadMutex *mutex);
85int32_t scePthreadMutexUnlock(ScePthreadMutex *mutex);
86int32_t scePthreadMutexattrInit(ScePthreadMutexattr *attr);
87int32_t scePthreadMutexattrDestroy(ScePthreadMutexattr *attr);
88int32_t scePthreadMutexattrSettype(ScePthreadMutexattr *attr, int32_t type);
89 
90// ═══════════════════════════════════════════════════════════════════
91// CONDITION VARIABLE
92// ═══════════════════════════════════════════════════════════════════
93int32_t scePthreadCondInit(ScePthreadCond *cond, const ScePthreadCondattr *attr,
94 const char *name);
95int32_t scePthreadCondDestroy(ScePthreadCond *cond);
96int32_t scePthreadCondSignal(ScePthreadCond *cond);
97int32_t scePthreadCondBroadcast(ScePthreadCond *cond);
98int32_t scePthreadCondWait(ScePthreadCond *cond, ScePthreadMutex *mutex);
99int32_t scePthreadCondTimedwait(ScePthreadCond *cond, ScePthreadMutex *mutex,
100 uint32_t usec);
101 
102// ═══════════════════════════════════════════════════════════════════
103// READ-WRITE LOCK
104// ═══════════════════════════════════════════════════════════════════
105int32_t scePthreadRwlockInit(ScePthreadRwlock *rwlock,
106 const ScePthreadRwlockattr *attr,
107 const char *name);
108int32_t scePthreadRwlockDestroy(ScePthreadRwlock *rwlock);
109int32_t scePthreadRwlockRdlock(ScePthreadRwlock *rwlock);
110int32_t scePthreadRwlockWrlock(ScePthreadRwlock *rwlock);
111int32_t scePthreadRwlockUnlock(ScePthreadRwlock *rwlock);
112 
113// ═══════════════════════════════════════════════════════════════════
114// THREAD-SPECIFIC DATA
115// ═══════════════════════════════════════════════════════════════════
116int32_t scePthreadKeyCreate(uint32_t *key, void (*destructor)(void *));
117int32_t scePthreadKeyDelete(uint32_t key);
118void *scePthreadGetspecific(uint32_t key);
119int32_t scePthreadSetspecific(uint32_t key, const void *value);
120 
121// ═══════════════════════════════════════════════════════════════════
122// ONCE
123// ═══════════════════════════════════════════════════════════════════
124int32_t scePthreadOnce(void *once_control, void (*init_routine)());
125 
126// ═══════════════════════════════════════════════════════════════════
127// YIELD
128// ═══════════════════════════════════════════════════════════════════
129int32_t scePthreadYield();
130 
131} // extern "C"
132