mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
x86emul/test: factor out emul_test_make_stack_executable
It will be used by emulator fuzzing target. Signed-off-by: Wei Liu <wei.liu2@citrix.com> Acked-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
1 parent
4f62f31d25
commit
1105f057f5
3 files changed
+25
-10
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -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,22 @@
|
||||
#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;
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
return mprotect((void *)(sp & -0x1000L) - (MMAP_SZ - 0x1000),
|
||||
MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
|
||||
}
|
||||
|
||||
#include "x86_emulate/x86_emulate.c"
|
||||
@@ -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"
|
||||