blob: 526b29bac496a94e00a2b228b352caad26b998c5 (
plain) (
blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include "substitute.h"
#include "dis.h"
#include "execmem.h"
#include stringify(TARGET_DIR/jump-patch.h)
#include <psp2kern/kernel/sysmem.h>
#include "../../../taihen_internal.h"
/** 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)
// if not aligned then substitute_hook_functions breaks!
#error SLAB_SIZE Must be aligned to ARCH_MAX_CODE_ALIGNMENT
#endif
/**
* @file execmem.c
*
* @brief Functions for allocating executable memory and writing to RO
* memory.
*
* We only consider two arenas for allocating trampoline executable
* memory. One is shared in user space across all processes. The
* other is in kernel space for kernel hooks.
*/
/**
* @brief Allocate a slab of executable memory.
*
* Two pointers will be returned: the executable ro pointer and a
* writable pointer.
*
* @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 opt A `tai_substitute_args_t` structure
* @param[in] hint Unused
*
* @return `SUBSTITUTE_OK` or `SUBSTITUTE_ERR_VM` if out of memory
*/
int execmem_alloc_unsealed(UNUSED uintptr_t hint, void **ptr_p, uintptr_t *vma_p,
size_t *size_p, void *opt) {
return SUBSTITUTE_OK;
}
/**
* @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) {
return SUBSTITUTE_OK;
}
/**
* @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) {
}
/**
* @brief Write to executable process memory
*
* @param writes List of writes
* @param[in] nwrites Number of writes
* @param[in] callback Unused
* @param callback_ctx Unused
*
* @return `SUBSTITUTE_OK` or `SUBSTITUTE_ERR_VM` on failure
*/
int execmem_foreign_write_with_pc_patch(struct execmem_foreign_write *writes,
size_t nwrites,
UNUSED execmem_pc_patch_callback callback,
UNUSED void *callback_ctx) {
return 0;
}
|