It will be used by emulator fuzzing target.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
#endif
};
-#define MMAP_SZ 16384
-
/* EFLAGS bit definitions. */
#define EFLG_OF (1<<11)
#define EFLG_DF (1<<10)
struct cpu_user_regs regs;
char *instr;
unsigned int *res, i, j;
- unsigned long sp;
bool stack_exec;
int rc;
#ifndef __x86_64__
}
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);
#include "x86_emulate.h"
+#include <sys/mman.h>
+
#define EFER_SCE (1 << 0)
#define EFER_LMA (1 << 10)
#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"
#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"