A tool for deriving PKG packet encryption keys for ps4 written in c++
| 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 | |
| 19 | typedef void *ScePthread; |
| 20 | typedef void *ScePthreadAttr; |
| 21 | typedef void *ScePthreadMutex; |
| 22 | typedef void *ScePthreadMutexattr; |
| 23 | typedef void *ScePthreadCond; |
| 24 | typedef void *ScePthreadCondattr; |
| 25 | typedef void *ScePthreadRwlock; |
| 26 | typedef 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 | |
| 55 | extern "C" { |
| 56 | |
| 57 | // ═══════════════════════════════════════════════════════════════════ |
| 58 | // THREAD LIFECYCLE |
| 59 | // ═══════════════════════════════════════════════════════════════════ |
| 60 | int32_t scePthreadCreate(ScePthread *thread, const ScePthreadAttr *attr, |
| 61 | void *(*entry)(void *), void *arg, const char *name); |
| 62 | int32_t scePthreadJoin(ScePthread thread, void **retval); |
| 63 | void scePthreadExit(void *retval); |
| 64 | ScePthread scePthreadSelf(); |
| 65 | int32_t scePthreadCancel(ScePthread thread); |
| 66 | int32_t scePthreadDetach(ScePthread thread); |
| 67 | |
| 68 | // ═══════════════════════════════════════════════════════════════════ |
| 69 | // THREAD ATTRIBUTES |
| 70 | // ═══════════════════════════════════════════════════════════════════ |
| 71 | int32_t scePthreadAttrInit(ScePthreadAttr *attr); |
| 72 | int32_t scePthreadAttrDestroy(ScePthreadAttr *attr); |
| 73 | int32_t scePthreadAttrSetdetachstate(ScePthreadAttr *attr, int32_t state); |
| 74 | int32_t scePthreadAttrSetstacksize(ScePthreadAttr *attr, uint64_t size); |
| 75 | int32_t scePthreadAttrSetschedparam(ScePthreadAttr *attr, const void *param); |
| 76 | |
| 77 | // ═══════════════════════════════════════════════════════════════════ |
| 78 | // MUTEX |
| 79 | // ═══════════════════════════════════════════════════════════════════ |
| 80 | int32_t scePthreadMutexInit(ScePthreadMutex *mutex, |
| 81 | const ScePthreadMutexattr *attr, const char *name); |
| 82 | int32_t scePthreadMutexDestroy(ScePthreadMutex *mutex); |
| 83 | int32_t scePthreadMutexLock(ScePthreadMutex *mutex); |
| 84 | int32_t scePthreadMutexTrylock(ScePthreadMutex *mutex); |
| 85 | int32_t scePthreadMutexUnlock(ScePthreadMutex *mutex); |
| 86 | int32_t scePthreadMutexattrInit(ScePthreadMutexattr *attr); |
| 87 | int32_t scePthreadMutexattrDestroy(ScePthreadMutexattr *attr); |
| 88 | int32_t scePthreadMutexattrSettype(ScePthreadMutexattr *attr, int32_t type); |
| 89 | |
| 90 | // ═══════════════════════════════════════════════════════════════════ |
| 91 | // CONDITION VARIABLE |
| 92 | // ═══════════════════════════════════════════════════════════════════ |
| 93 | int32_t scePthreadCondInit(ScePthreadCond *cond, const ScePthreadCondattr *attr, |
| 94 | const char *name); |
| 95 | int32_t scePthreadCondDestroy(ScePthreadCond *cond); |
| 96 | int32_t scePthreadCondSignal(ScePthreadCond *cond); |
| 97 | int32_t scePthreadCondBroadcast(ScePthreadCond *cond); |
| 98 | int32_t scePthreadCondWait(ScePthreadCond *cond, ScePthreadMutex *mutex); |
| 99 | int32_t scePthreadCondTimedwait(ScePthreadCond *cond, ScePthreadMutex *mutex, |
| 100 | uint32_t usec); |
| 101 | |
| 102 | // ═══════════════════════════════════════════════════════════════════ |
| 103 | // READ-WRITE LOCK |
| 104 | // ═══════════════════════════════════════════════════════════════════ |
| 105 | int32_t scePthreadRwlockInit(ScePthreadRwlock *rwlock, |
| 106 | const ScePthreadRwlockattr *attr, |
| 107 | const char *name); |
| 108 | int32_t scePthreadRwlockDestroy(ScePthreadRwlock *rwlock); |
| 109 | int32_t scePthreadRwlockRdlock(ScePthreadRwlock *rwlock); |
| 110 | int32_t scePthreadRwlockWrlock(ScePthreadRwlock *rwlock); |
| 111 | int32_t scePthreadRwlockUnlock(ScePthreadRwlock *rwlock); |
| 112 | |
| 113 | // ═══════════════════════════════════════════════════════════════════ |
| 114 | // THREAD-SPECIFIC DATA |
| 115 | // ═══════════════════════════════════════════════════════════════════ |
| 116 | int32_t scePthreadKeyCreate(uint32_t *key, void (*destructor)(void *)); |
| 117 | int32_t scePthreadKeyDelete(uint32_t key); |
| 118 | void *scePthreadGetspecific(uint32_t key); |
| 119 | int32_t scePthreadSetspecific(uint32_t key, const void *value); |
| 120 | |
| 121 | // ═══════════════════════════════════════════════════════════════════ |
| 122 | // ONCE |
| 123 | // ═══════════════════════════════════════════════════════════════════ |
| 124 | int32_t scePthreadOnce(void *once_control, void (*init_routine)()); |
| 125 | |
| 126 | // ═══════════════════════════════════════════════════════════════════ |
| 127 | // YIELD |
| 128 | // ═══════════════════════════════════════════════════════════════════ |
| 129 | int32_t scePthreadYield(); |
| 130 | |
| 131 | } // extern "C" |
| 132 |