aboutsummaryrefslogtreecommitdiff
path: root/lib/vita/slab.h
diff options
context:
space:
mode:
authorYifan Lu2016-10-08 22:41:57 -0700
committerYifan Lu2016-10-08 22:44:43 -0700
commitabf235858588a5943cd9f532a5f1757e2baab80b (patch)
tree96640eefa1c3494f85cff520e49dc6c5c46d9905 /lib/vita/slab.h
parentAdded support for platform specific aux data to execmem (diff)
downloadsubstitute-abf235858588a5943cd9f532a5f1757e2baab80b.tar.gz
Added slab allocator for trampoline in Vita platform
Added support for smaller (non-page) allocations for trampoline
Diffstat (limited to 'lib/vita/slab.h')
-rwxr-xr-xlib/vita/slab.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/vita/slab.h b/lib/vita/slab.h
new file mode 100755
index 0000000..942eb70
--- /dev/null
+++ b/lib/vita/slab.h
@@ -0,0 +1,39 @@
+/* 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);
+void *slab_alloc(struct slab_chain *, uintptr_t *);
+void slab_free(struct slab_chain *, const void *);
+void slab_traverse(const struct slab_chain *, void (*)(const void *));
+void slab_destroy(const struct slab_chain *);