taiHEN  1.0
CFW framework for PS Vita
slab.h
1 /* ref: https://github.com/bbu/userland-slab-allocator */
2 
3 #ifndef __GNUC__
4 # error Can be compiled only with GCC.
5 #endif
6 
7 #pragma once
8 
9 #include <stdint.h>
10 #include <stddef.h>
11 #include <psp2kern/types.h>
12 
13 extern const size_t slab_pagesize;
14 
15 struct slab_header {
16  struct slab_header *prev, *next;
17  uint64_t slots;
18  uintptr_t refcount;
19  struct slab_header *page;
20  SceUID write_res;
21  SceUID exe_res;
22  uintptr_t exe_data;
23  uint8_t data[] __attribute__((aligned(sizeof(void *))));
24 };
25 
26 struct slab_chain {
27  size_t itemsize, itemcount;
28  size_t slabsize, pages_per_alloc;
29  uint64_t initial_slotmask, empty_slotmask;
30  uintptr_t alignment_mask;
31  struct slab_header *partial, *empty, *full;
32  SceUID pid;
33 };
34 
35 void slab_init(struct slab_chain *, size_t, SceUID);
36 void *slab_alloc(struct slab_chain *, uintptr_t *);
37 void slab_free(struct slab_chain *, const void *);
38 uintptr_t slab_getmirror(struct slab_chain *, const void *);
39 void slab_traverse(const struct slab_chain *, void (*)(const void *));
40 void slab_destroy(const struct slab_chain *);