Commit bba76eed authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Switch stacks in CALL32_Init().

parent ed490031
...@@ -17,7 +17,7 @@ extern void MAIN_ParseModeOption( char *arg ); ...@@ -17,7 +17,7 @@ extern void MAIN_ParseModeOption( char *arg );
extern BOOL RELAY_Init(void); extern BOOL RELAY_Init(void);
extern int RELAY_ShowDebugmsgRelay(const char *func); extern int RELAY_ShowDebugmsgRelay(const char *func);
extern void* CALL32_Init(void); extern void CALL32_Init( void *func, void *target, void *stack );
extern BOOL THUNK_Init(void); extern BOOL THUNK_Init(void);
......
...@@ -158,13 +158,14 @@ int main( int argc, char *argv[] ) ...@@ -158,13 +158,14 @@ int main( int argc, char *argv[] )
if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1; if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
if ( !TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE ) ) return 1; if ( !TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE ) ) return 1;
/* Initialize CALL32 routines */
/* This needs to be done just before switching stacks */
IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
/* Switch to initial task */ /* Switch to initial task */
CURRENT_STACK16->frame32->retaddr = (DWORD)MAIN_EmulatorRun; PostEvent16( PROCESS_Current()->task );
TASK_StartTask( PROCESS_Current()->task ); TASK_Reschedule();
MSG( "main: Should never happen: returned from TASK_StartTask()\n" );
/* Switch stacks and jump to MAIN_EmulatorRun */
CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun,
THREAD_Current()->teb.stack_top );
MSG( "main: Should never happen: returned from CALL32_Init()\n" );
return 0; return 0;
} }
...@@ -2488,11 +2488,20 @@ static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx ) ...@@ -2488,11 +2488,20 @@ static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx )
* *
* The pointer to the function can be retrieved by calling CALL32_Init, * The pointer to the function can be retrieved by calling CALL32_Init,
* which also takes care of saving the current 32-bit stack pointer. * which also takes care of saving the current 32-bit stack pointer.
* Furthermore, CALL32_Init switches to a new stack and jumps to the
* specified target address.
* *
* NOTE: The CALL32_LargeStack routine may be recursively entered by the * NOTE: The CALL32_LargeStack routine may be recursively entered by the
* same thread, but not concurrently entered by several threads. * same thread, but not concurrently entered by several threads.
* *
* Stack layout: * Stack layout of CALL32_Init:
*
* (esp+12) new stack address
* (esp+8) target address
* (esp+4) pointer to variable to receive CALL32_LargeStack address
* (esp) ret addr
*
* Stack layout of CALL32_LargeStack:
* ... ... * ... ...
* (ebp+12) arg * (ebp+12) arg
* (ebp+8) func * (ebp+8) func
...@@ -2510,9 +2519,13 @@ static void BuildCallTo32LargeStack( FILE *outfile ) ...@@ -2510,9 +2519,13 @@ static void BuildCallTo32LargeStack( FILE *outfile )
fprintf( outfile, "\t.globl " PREFIX "CALL32_Init\n" ); fprintf( outfile, "\t.globl " PREFIX "CALL32_Init\n" );
fprintf( outfile, "\t.type " PREFIX "CALL32_Init,@function\n" ); fprintf( outfile, "\t.type " PREFIX "CALL32_Init,@function\n" );
fprintf( outfile, PREFIX "CALL32_Init:\n" ); fprintf( outfile, PREFIX "CALL32_Init:\n" );
fprintf( outfile, "\tleal -256(%%esp),%%eax\n" ); fprintf( outfile, "\tmovl %%esp,CALL32_Original32_esp\n" );
fprintf( outfile, "\tmovl %%eax,CALL32_Original32_esp\n" ); fprintf( outfile, "\tpopl %%eax\n" );
fprintf( outfile, "\tmovl $CALL32_LargeStack,%%eax\n" ); fprintf( outfile, "\tpopl %%eax\n" );
fprintf( outfile, "\tmovl $CALL32_LargeStack,(%%eax)\n" );
fprintf( outfile, "\tpopl %%eax\n" );
fprintf( outfile, "\tpopl %%esp\n" );
fprintf( outfile, "\tpushl %%eax\n" );
fprintf( outfile, "\tret\n" ); fprintf( outfile, "\tret\n" );
/* Function header */ /* Function header */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment