diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-24 00:48:40 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 7212ea877ed85d3b85af90c902639df44fc493f2 (patch) | |
tree | c76d73e9882a832f82cef977efb6fb26fb0e4984 /executor | |
parent | d6f368a3f400fea3e89280262a8147e7ce5d855c (diff) |
Add exported variable (only functions for now), export main func, start execution from main func
Diffstat (limited to 'executor')
-rw-r--r-- | executor/executor.h | 3 | ||||
-rw-r--r-- | executor/x86_64/asm.c | 4 | ||||
-rw-r--r-- | executor/x86_64/asm.h | 2 | ||||
-rw-r--r-- | executor/x86_64/executor.c | 9 |
4 files changed, 12 insertions, 6 deletions
diff --git a/executor/executor.h b/executor/executor.h index 979784b..df6c0d8 100644 --- a/executor/executor.h +++ b/executor/executor.h @@ -18,7 +18,8 @@ typedef struct amal_executor amal_executor; CHECK_RESULT int amal_executor_init(amal_executor **self); void amal_executor_deinit(amal_executor *self); -CHECK_RESULT int amal_executor_run(amal_executor *self); +CHECK_RESULT int amal_executor_run(amal_executor *self, u32 offset); +u32 amal_exec_get_code_offset(amal_executor *self); /* These functions are called for every file in the program. Every file has its own list of strings, intermediates, functions and external functions */ CHECK_RESULT int amal_executor_instructions_start(amal_executor *self, u16 num_functions); diff --git a/executor/x86_64/asm.c b/executor/x86_64/asm.c index c741f15..f2bb801 100644 --- a/executor/x86_64/asm.c +++ b/executor/x86_64/asm.c @@ -210,7 +210,7 @@ static void asm_print_code_hex(Asm *self) { } #endif -int asm_execute(Asm *self) { +int asm_execute(Asm *self, u32 offset) { void (*func)(); if(mprotect(self->code, self->allocated_size, PROT_READ | PROT_EXEC) != 0) return -errno; @@ -218,7 +218,7 @@ int asm_execute(Asm *self) { /*asm_print_code_hex(self);*/ /* TODO: Verify if this is valid on all platforms. According to ISO C standard it isn't? */ - *(void**)(&func) = self->code; + *(void**)(&func) = self->code + offset; func(); return 0; } diff --git a/executor/x86_64/asm.h b/executor/x86_64/asm.h index 51f2d84..ace1ecf 100644 --- a/executor/x86_64/asm.h +++ b/executor/x86_64/asm.h @@ -49,7 +49,7 @@ void asm_deinit(Asm *self); usize asm_get_size(Asm *self); -CHECK_RESULT int asm_execute(Asm *self); +CHECK_RESULT int asm_execute(Asm *self, u32 offset); CHECK_RESULT int asm_nop(Asm *self); diff --git a/executor/x86_64/executor.c b/executor/x86_64/executor.c index fbe227a..335790a 100644 --- a/executor/x86_64/executor.c +++ b/executor/x86_64/executor.c @@ -64,9 +64,14 @@ void amal_executor_deinit(amal_executor *self) { am_free(impl); } -int amal_executor_run(amal_executor *self) { +int amal_executor_run(amal_executor *self, u32 offset) { IMPL - return asm_execute(&impl->asm); + return asm_execute(&impl->asm, offset); +} + +u32 amal_exec_get_code_offset(amal_executor *self) { + IMPL + return asm_get_size(&impl->asm); } int amal_executor_instructions_start(amal_executor *self, u16 num_functions) { |