diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-04 21:16:34 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-04 21:16:34 +0300 |
| commit | 09f8df9f7e1166be48cdd6b1caba0f6771dd753e (patch) | |
| tree | 1cad6a2b118825e19432e2acf4e65c45e975ab60 /src/copyjit.c | |
| parent | c671d6612be0fb28eea498246c39bb5032afa872 (diff) | |
| download | copyjit-09f8df9f7e1166be48cdd6b1caba0f6771dd753e.tar.gz copyjit-09f8df9f7e1166be48cdd6b1caba0f6771dd753e.zip | |
add simple patching mechanism
Diffstat (limited to 'src/copyjit.c')
| -rw-r--r-- | src/copyjit.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/copyjit.c b/src/copyjit.c index 393c8e1..0de85d3 100644 --- a/src/copyjit.c +++ b/src/copyjit.c @@ -471,6 +471,23 @@ void compile_start(ctx_t *ctx) ctx->pc = ctx->buf; } +reloc_t compile_placeholder(ctx_t *ctx, compile_callback_t call) +{ + reloc_t r = {0}; + r.addr = call(ctx, 0); + + /* the immediate is the last sizeof(uintptr_t) bytes of the generated + * instruction + * (at least we assume, the user could've passed anything to our callback) */ + r.imm = ((uintptr_t *)ctx->pc) - 1; + return r; +} + +void compile_patch(reloc_t reloc, void *addr) +{ + *reloc.imm = (uintptr_t)addr; +} + void compile_finish(ctx_t *ctx) { __builtin___clear_cache(ctx->buf, ctx->buf + ctx->size); |
