diff options
Diffstat (limited to 'lib/vita')
-rw-r--r-- | lib/vita/execmem.c | 17 | ||||
-rwxr-xr-x | lib/vita/slab.c | 15 | ||||
-rwxr-xr-x | lib/vita/slab.h | 2 |
3 files changed, 23 insertions, 11 deletions
diff --git a/lib/vita/execmem.c b/lib/vita/execmem.c index 526b29b..84927d6 100644 --- a/lib/vita/execmem.c +++ b/lib/vita/execmem.c @@ -8,12 +8,15 @@ /** The size of each trampoline allocation. We use it for outro and optional * intro. Realistically, we do not use an intro. */ -#define SLAB_SIZE (TD_MAX_REWRITTEN_SIZE + 2 * MAX_JUMP_PATCH_SIZE) -#if (SLAB_SIZE % ARCH_MAX_CODE_ALIGNMENT != 0) +#define SLAB_ITEM_SIZE (TD_MAX_REWRITTEN_SIZE + 2 * MAX_JUMP_PATCH_SIZE) +#if (SLAB_ITEM_SIZE % ARCH_MAX_CODE_ALIGNMENT != 0) // if not aligned then substitute_hook_functions breaks! -#error SLAB_SIZE Must be aligned to ARCH_MAX_CODE_ALIGNMENT +#error SLAB_ITEM_SIZE Must be aligned to ARCH_MAX_CODE_ALIGNMENT #endif +/** Allow other files to use this constant. */ +const int g_exe_slab_item_size = SLAB_ITEM_SIZE; + /** * @file execmem.c * @@ -34,7 +37,7 @@ * @param[in] hint Unused * @param ptr_p The writable pointer * @param vma_p The executable pointer address - * @param size_p The size of the allocation. Always `SLAB_SIZE`. + * @param size_p The size of the allocation. Always `SLAB_ITEM_SIZE`. * @param opt A `tai_substitute_args_t` structure * @param[in] hint Unused * @@ -49,12 +52,11 @@ int execmem_alloc_unsealed(UNUSED uintptr_t hint, void **ptr_p, uintptr_t *vma_p * @brief Flushes icache * * @param ptr Unused - * @param[in] vma Pointer to flush * @param opt A `tai_substitute_args_t` structure * * @return `SUBSTITUTE_OK` */ -int execmem_seal(UNUSED void *ptr, uintptr_t vma, void *opt) { +int execmem_seal(UNUSED void *ptr, void *opt) { return SUBSTITUTE_OK; } @@ -62,10 +64,9 @@ int execmem_seal(UNUSED void *ptr, uintptr_t vma, void *opt) { * @brief Frees executable memory from slab allocator * * @param ptr The writable pointer - * @param[in] vma The executable address. Must match with ptr. * @param opt A `tai_substitute_args_t` structure */ -void execmem_free(void *ptr, uintptr_t vma, void *opt) { +void execmem_free(void *ptr, void *opt) { } /** diff --git a/lib/vita/slab.c b/lib/vita/slab.c index 0ca3529..91742a6 100755 --- a/lib/vita/slab.c +++ b/lib/vita/slab.c @@ -2,7 +2,6 @@ #include "slab.h" -#include <math.h> #include <stdint.h> #include <stddef.h> @@ -49,6 +48,18 @@ static int sce_exe_free(SceUID write_res, SceUID exe_res) { return 0; } +static inline uint32_t next_pow_2(uint32_t v) { + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + v += (v == 0); + return v; +} + void slab_init(struct slab_chain *const sch, const size_t itemsize, SceUID pid) { assert(sch != NULL); @@ -60,7 +71,7 @@ void slab_init(struct slab_chain *const sch, const size_t itemsize, SceUID pid) const size_t data_offset = offsetof(struct slab_header, data); const size_t least_slabsize = data_offset + 64 * sch->itemsize; - sch->slabsize = (size_t) 1 << (size_t) ceil(log2(least_slabsize)); + sch->slabsize = (size_t) next_pow_2(least_slabsize); sch->itemcount = 64; if (sch->slabsize - least_slabsize != 0) { diff --git a/lib/vita/slab.h b/lib/vita/slab.h index 942eb70..c8c5d9b 100755 --- a/lib/vita/slab.h +++ b/lib/vita/slab.h @@ -32,7 +32,7 @@ struct slab_chain { SceUID pid; }; -void slab_init(struct slab_chain *, size_t); +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 *); void slab_traverse(const struct slab_chain *, void (*)(const void *)); |