Skip to content

Commit

Permalink
Keep copy of EFLAGS (should fix stability issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayFoxRox committed Nov 11, 2018
1 parent 393acd2 commit b15d6c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ Address CreateHlt() {

// Fill guest_registers
"mov guest_registers, %%esp\n"
"add $32, %%esp\n"
"add $36, %%esp\n"
"pushf\n"
"pusha\n"

// Move to host fs
Expand All @@ -456,6 +457,7 @@ Address CreateHlt() {
// Move to host space
"mov host_esp, %%esp\n"
"popa\n"
"popf\n"

"call return_to_host\n"
"continue:\n":);
Expand Down
2 changes: 2 additions & 0 deletions uc_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ uc_err uc_emu_start(uc_engine *uc, uint64_t begin, uint64_t until, uint64_t time
//"movl fs, 32([registers])"

// Make host backup
"pushf\n"
"pusha\n"
"mov %%esp, host_esp\n"

Expand All @@ -374,6 +375,7 @@ uc_err uc_emu_start(uc_engine *uc, uint64_t begin, uint64_t until, uint64_t time
// Load all registers
"mov guest_registers, %%esp\n"
"popa\n"
"popf\n"
"mov guest_registers_esp, %%esp\n"
//FIXME: Fixup ESP too

Expand Down
11 changes: 7 additions & 4 deletions uc_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ typedef struct {
uint32_t ecx; // +24
uint32_t eax; // +28

// Hack because we always do pusha and pushf in sequence
uint32_t eflags; // +32

// Extensions, can be re-ordered / added / removed, but assembly needs update
uint16_t fs; // +32
uint16_t pad; // +34
uint32_t eip; // +36
uint16_t fs; // +36
uint16_t pad; // +40
uint32_t eip; // +44

uint32_t fs_base; //+40
uint32_t fs_base; //+48

} Registers;

Expand Down

0 comments on commit b15d6c4

Please sign in to comment.