Skip to content

Commit

Permalink
DosFlatToSel() needs to save off registers.
Browse files Browse the repository at this point in the history
It's not syscall calling convention, and CSet/2 generates thunks that call
this function but expect %ecx to not be altered by it. Save off a bunch,
just in case.
  • Loading branch information
icculus committed Jan 4, 2018
1 parent aa06257 commit 185a983
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions native/doscalls.c
Expand Up @@ -657,13 +657,26 @@ ULONG _DosFlatToSel(PVOID ptr)
} // _DosFlatToSel

// DosFlatToSel() passes its argument in %eax, so a little asm to bridge that...
// Note that this isn't syscall calling conventions at all; CSet/2 generates
// thunking code that expects this function to preserve %ecx, so we'll just
// go ahead and save a bunch of stuff, just in case.
__asm__ (
".globl DosFlatToSel \n\t"
".type DosFlatToSel, @function \n\t"
"DosFlatToSel: \n\t"
" pushl %eax \n\t"
" pushl %ebx \n\t" // save off a bunch of stuff. Better safe than sorry.
" pushl %ecx \n\t"
" pushl %edx \n\t"
" pushl %edi \n\t"
" pushl %esi \n\t"
" pushl %eax \n\t" // the actual argument to DosFlatToSel.
" call _DosFlatToSel \n\t"
" addl $4, %esp \n\t"
" addl $4, %esp \n\t" // clear argument to DosFlatToSel.
" popl %esi \n\t"
" popl %edi \n\t"
" popl %edx \n\t" // save off a bunch of stuff.
" popl %ecx \n\t"
" popl %ebx \n\t"
" ret \n\t"
".size _DosFlatToSel, .-_DosFlatToSel \n\t"
);
Expand Down

0 comments on commit 185a983

Please sign in to comment.