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