From 76ece8530abe582b2963af7d9dba408585b0f8b0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 20 Jan 2006 19:45:57 +0100 Subject: [PATCH] winebuild: Moved offset definitions to relay.c since they are only needed there. Hardcoded a couple of TEB offsets to support cross-compilation. --- tools/winebuild/build.h | 16 ---------------- tools/winebuild/relay.c | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h index ec4d9a98201..a445be93339 100644 --- a/tools/winebuild/build.h +++ b/tools/winebuild/build.h @@ -132,22 +132,6 @@ extern enum target_platform target_platform; #define FLAG_FORWARD 0x80 /* function is a forwarded name */ #define FLAG_EXT_LINK 0x100 /* function links to an external symbol */ - /* Offset of a structure field relative to the start of the struct */ -#define STRUCTOFFSET(type,field) ((int)&((type *)0)->field) - - /* Offset of register relative to the start of the CONTEXT struct */ -#define CONTEXTOFFSET(reg) STRUCTOFFSET(CONTEXT86,reg) - - /* Offset of register relative to the start of the STACK16FRAME struct */ -#define STACK16OFFSET(reg) STRUCTOFFSET(STACK16FRAME,reg) - - /* Offset of register relative to the start of the STACK32FRAME struct */ -#define STACK32OFFSET(reg) STRUCTOFFSET(STACK32FRAME,reg) - - /* Offset of the stack pointer relative to %fs:(0) */ -#define STACKOFFSET (STRUCTOFFSET(TEB,WOW32Reserved)) - - #define MAX_ORDINALS 65535 /* global functions */ diff --git a/tools/winebuild/relay.c b/tools/winebuild/relay.c index 5dbbe839f27..8d304d0ed03 100644 --- a/tools/winebuild/relay.c +++ b/tools/winebuild/relay.c @@ -32,6 +32,21 @@ #include "build.h" +/* offset of a structure field relative to the start of the struct */ +#define STRUCTOFFSET(type,field) ((int)FIELD_OFFSET(type,field)) + +/* offset of register relative to the start of the CONTEXT struct */ +#define CONTEXTOFFSET(reg) STRUCTOFFSET(CONTEXT86,reg) + +/* offset of register relative to the start of the STACK16FRAME struct */ +#define STACK16OFFSET(reg) STRUCTOFFSET(STACK16FRAME,reg) + +/* offset of register relative to the start of the STACK32FRAME struct */ +#define STACK32OFFSET(reg) STRUCTOFFSET(STACK32FRAME,reg) + +/* offset of the stack pointer relative to %fs:(0) */ +#define STACKOFFSET 0xc0 /* STRUCTOFFSET(TEB,WOW32Reserved) */ + /* fix this if the ntdll_thread_regs structure is changed */ #define GS_OFFSET 0x1b0 /* STRUCTOFFSET(TEB,SpareBytes1) + STRUCTOFFSET(ntdll_thread_regs,gs) */ @@ -182,7 +197,7 @@ static void BuildCallFrom16Core( FILE *outfile, int reg_func, int thunk ) fprintf( outfile, "\tpushl %%ds\n" ); fprintf( outfile, "\tpopl %%ss\n" ); fprintf( outfile, "\tmovl %%ebp, %%esp\n" ); - fprintf( outfile, "\taddl $%d, %%ebp\n", STRUCTOFFSET(STACK32FRAME, ebp) ); + fprintf( outfile, "\taddl $%d, %%ebp\n", STACK32OFFSET(ebp) ); /* At this point: @@ -294,7 +309,7 @@ static void BuildCallFrom16Core( FILE *outfile, int reg_func, int thunk ) if ( reg_func ) { fprintf( outfile, "\tleal -%d(%%ebp), %%ebx\n", - sizeof(CONTEXT) + STRUCTOFFSET(STACK32FRAME, ebp) ); + sizeof(CONTEXT) + STACK32OFFSET(ebp) ); /* Switch stack back */ fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 ); @@ -401,15 +416,15 @@ static void BuildCallTo16Core( FILE *outfile, int reg_func ) /* Setup exception frame */ fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STACKOFFSET ); fprintf( outfile, "\tpushl 16(%%ebp)\n" ); /* handler */ - fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) ); - fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) ); + fprintf( outfile, "\t.byte 0x64\n\tpushl (0)\n" ); + fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(0)\n" ); /* Call the actual CallTo16 routine (simulate a lcall) */ fprintf( outfile, "\tpushl %%cs\n" ); fprintf( outfile, "\tcall .L%s\n", name ); /* Remove exception frame */ - fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) ); + fprintf( outfile, "\t.byte 0x64\n\tpopl (0)\n" ); fprintf( outfile, "\taddl $4, %%esp\n" ); fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );