[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC v2 2/7] x86emul/test: factor out emul_test_make_stack_executable
It will be used by emulator fuzzing target. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- Cc: Jan Beulich <jbeulich@xxxxxxxx> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/tests/x86_emulator/test_x86_emulator.c | 12 ++---------- tools/tests/x86_emulator/x86_emulate.c | 22 ++++++++++++++++++++++ tools/tests/x86_emulator/x86_emulate.h | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tools/tests/x86_emulator/test_x86_emulator.c b/tools/tests/x86_emulator/test_x86_emulator.c index eed8a0d..0d80bff 100644 --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -23,8 +23,6 @@ static const struct { #endif }; -#define MMAP_SZ 16384 - /* EFLAGS bit definitions. */ #define EFLG_OF (1<<11) #define EFLG_DF (1<<10) @@ -234,7 +232,6 @@ int main(int argc, char **argv) struct cpu_user_regs regs; char *instr; unsigned int *res, i, j; - unsigned long sp; bool stack_exec; int rc; #ifndef __x86_64__ @@ -258,13 +255,8 @@ int main(int argc, char **argv) } instr = (char *)res + 0x100; -#ifdef __x86_64__ - asm ("movq %%rsp, %0" : "=g" (sp)); -#else - asm ("movl %%esp, %0" : "=g" (sp)); -#endif - stack_exec = mprotect((void *)(sp & -0x1000L) - (MMAP_SZ - 0x1000), - MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0; + stack_exec = emul_test_make_stack_executable(); + if ( !stack_exec ) printf("Warning: Stack could not be made executable (%d).\n", errno); diff --git a/tools/tests/x86_emulator/x86_emulate.c b/tools/tests/x86_emulator/x86_emulate.c index 66c2464..78e6380 100644 --- a/tools/tests/x86_emulator/x86_emulate.c +++ b/tools/tests/x86_emulator/x86_emulate.c @@ -1,5 +1,7 @@ #include "x86_emulate.h" +#include <sys/mman.h> + #define EFER_SCE (1 << 0) #define EFER_LMA (1 << 10) @@ -18,4 +20,24 @@ #define get_stub(stb) ((void *)((stb).addr = (uintptr_t)(stb).buf)) #define put_stub(stb) +bool emul_test_make_stack_executable(void) +{ + unsigned long sp; + bool stack_exec; + + /* + * Mark the entire stack executable so that the stub executions + * don't fault + */ +#ifdef __x86_64__ + asm ("movq %%rsp, %0" : "=g" (sp)); +#else + asm ("movl %%esp, %0" : "=g" (sp)); +#endif + + stack_exec = mprotect((void *)(sp & -0x1000L) - (MMAP_SZ - 0x1000), + MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0; + return stack_exec; +} + #include "x86_emulate/x86_emulate.c" diff --git a/tools/tests/x86_emulator/x86_emulate.h b/tools/tests/x86_emulator/x86_emulate.h index 1981326..a9b874c 100644 --- a/tools/tests/x86_emulator/x86_emulate.h +++ b/tools/tests/x86_emulator/x86_emulate.h @@ -33,4 +33,7 @@ #define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63)) +#define MMAP_SZ 16384 +bool emul_test_make_stack_executable(void); + #include "x86_emulate/x86_emulate.h" -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |