8 #include <psp2kern/types.h> 9 #include <psp2kern/kernel/sysmem.h> 10 #include <psp2kern/kernel/threadmgr.h> 12 #include "taihen_internal.h" 23 #define MAP_POOL_SIZE 1024 26 extern const size_t g_exe_slab_item_size;
29 static SceUID g_map_pool;
39 SceKernelMemPoolCreateOpt opt;
40 memset(&opt, 0,
sizeof(opt));
41 opt.size =
sizeof(opt);
43 g_map_pool = sceKernelMemPoolCreate(
"tai_maps", MAP_POOL_SIZE, &opt);
57 sceKernelMemPoolDestroy(g_map_pool);
77 map->
lock = sceKernelCreateMutexForKernel(
"tai_map", SCE_KERNEL_MUTEX_ATTR_RECURSIVE, 0, NULL);
78 for (
int i = 0; i < nbuckets; i++) {
90 sceKernelDeleteMutexForKernel(map->
lock);
91 sceKernelMemPoolFree(g_map_pool, map);
124 sceKernelLockMutexForKernel(map->
lock, 1, NULL);
126 while (*item != NULL && (*item)->
pid < patch->
pid) {
127 item = &(*item)->
next;
129 if (*item != NULL && (*item)->
pid == patch->
pid) {
134 proc = sceKernelMemPoolAlloc(g_map_pool,
sizeof(
tai_proc_t));
138 slab_init(&proc->
slab, g_exe_slab_item_size, patch->
pid);
145 while (*cur != NULL) {
156 }
else if (patch->
addr < tmp->
addr) {
177 sceKernelUnlockMutexForKernel(map->
lock, 1);
208 sceKernelLockMutexForKernel(map->
lock, 1, NULL);
210 while (*cur != NULL && (*cur)->
pid < pid) {
213 if (*cur != NULL && (*cur)->
pid == pid) {
217 slab_destroy(&tmp->
slab);
218 sceKernelMemPoolFree(g_map_pool, tmp);
220 sceKernelUnlockMutexForKernel(map->
lock, 1);
221 return *head != NULL;
241 sceKernelLockMutexForKernel(map->
lock, 1, NULL);
243 while (*proc != NULL && (*proc)->
pid < patch->
pid) {
244 proc = &(*proc)->
next;
246 if (*proc != NULL && (*proc)->
pid == patch->
pid) {
247 cur = &(*proc)->head;
248 while (*cur != NULL && *cur != patch) {
256 if (*proc != NULL && (*proc)->
head == NULL) {
258 next = (*proc)->
next;
259 slab_destroy(&(*proc)->slab);
260 sceKernelMemPoolFree(g_map_pool, *proc);
263 sceKernelUnlockMutexForKernel(map->
lock, 1);
SceUID lock
Mutex for accessing buckets.
tai_proc_map_t * proc_map_alloc(int nbuckets)
Allocates a new map.
struct _tai_proc * next
Next process in this map bucket.
void proc_map_deinit(void)
Cleans up the map system.
The actual map in memory.
size_t size
Size of the patch.
struct _tai_patch * next
Next patch in the linked list for this process.
uintptr_t addr
Address being patched.
Internal data for a process.
int proc_map_remove(tai_proc_map_t *map, tai_patch_t *patch)
Remove a single patch from the map.
void proc_map_free(tai_proc_map_t *map)
Frees a map.
tai_proc_t * buckets[]
Buckets.
A patch containing either a hook chain or an injection.
struct slab_chain * slab
Slab chain for this process (copied from the owner tai_proc_t)
int proc_map_remove_all_pid(tai_proc_map_t *map, SceUID pid, tai_patch_t **head)
Removes every patch associated with a given pid from the map.
int nbuckets
Number of buckets set by proc_map_alloc
SceUID pid
Process owning this object.
struct slab_chain slab
A slab allocator associated with this process.
SceUID pid
Process ID (the key in the map)
tai_patch_t * head
Linked list of patches for this process.
int proc_map_try_insert(tai_proc_map_t *map, tai_patch_t *patch, tai_patch_t **existing)
Inserts into the map if no overlap or get patch that completely overlaps.
int proc_map_init(void)
Initializes the map system.