From 3eb441c7c46896dd7212ddf97c84ffdd18be7899 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 10 May 1999 14:44:47 +0000 Subject: [PATCH] Added support for forwarded ordinals in built-in dlls. --- include/builtin32.h | 1 + relay32/builtin32.c | 21 +++++++++++++++++---- tools/build-spec.txt | 11 +++++++++++ tools/build.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/include/builtin32.h b/include/builtin32.h index 3b263d68e4b..25055dc55b8 100644 --- a/include/builtin32.h +++ b/include/builtin32.h @@ -15,6 +15,7 @@ typedef struct int base; /* Ordinal base */ int nb_funcs; /* Number of functions */ int nb_names; /* Number of function names */ + int fwd_size; /* Total size of forward names */ const ENTRYPOINT32 *functions; /* Pointer to function table */ const char * const *names; /* Pointer to names table */ const unsigned short *ordinals; /* Pointer to ordinals table */ diff --git a/relay32/builtin32.c b/relay32/builtin32.c index eaee98844b1..bd705c19d3a 100644 --- a/relay32/builtin32.c +++ b/relay32/builtin32.c @@ -161,6 +161,7 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll ) IMAGE_EXPORT_DIRECTORY *exp; LPVOID *funcs; LPSTR *names; + LPSTR pfwd; DEBUG_ENTRY_POINT *debug; INT i, size; BYTE *addr; @@ -172,7 +173,8 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll ) + 2 * sizeof(IMAGE_SECTION_HEADER) + sizeof(IMAGE_EXPORT_DIRECTORY) + dll->descr->nb_funcs * sizeof(LPVOID) - + dll->descr->nb_names * sizeof(LPSTR)); + + dll->descr->nb_names * sizeof(LPSTR) + + dll->descr->fwd_size); #ifdef __i386__ if (WARN_ON(relay) || TRACE_ON(relay)) size += dll->descr->nb_funcs * sizeof(DEBUG_ENTRY_POINT); @@ -185,7 +187,8 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll ) exp = (IMAGE_EXPORT_DIRECTORY *)(sec + 2); funcs = (LPVOID *)(exp + 1); names = (LPSTR *)(funcs + dll->descr->nb_funcs); - debug = (DEBUG_ENTRY_POINT *)(names + dll->descr->nb_names); + pfwd = (LPSTR)(names + dll->descr->nb_names); + debug = (DEBUG_ENTRY_POINT *)(pfwd + dll->descr->fwd_size); /* Build the DOS and NT headers */ @@ -221,7 +224,8 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll ) dir->VirtualAddress = (BYTE *)exp - addr; dir->Size = sizeof(*exp) + dll->descr->nb_funcs * sizeof(LPVOID) - + dll->descr->nb_names * sizeof(LPSTR); + + dll->descr->nb_names * sizeof(LPSTR) + + dll->descr->fwd_size; /* Build the exports section */ @@ -298,7 +302,15 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll ) int j; if (!dll->descr->functions[i]) continue; - *funcs = (LPVOID)((BYTE *)dll->descr->functions[i] - addr); + + if (args == 0xfd) /* forward func */ + { + strcpy( pfwd, (LPSTR)dll->descr->functions[i] ); + *funcs = (LPVOID)((BYTE *)pfwd - addr); + pfwd += strlen(pfwd) + 1; + } + else *funcs = (LPVOID)((BYTE *)dll->descr->functions[i] - addr); + #ifdef __i386__ if (!(WARN_ON(relay) || TRACE_ON(relay))) continue; for (j=0;jdescr->nb_names;j++) @@ -322,6 +334,7 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll ) debug->args = 0; *funcs = (LPVOID)((BYTE *)debug - addr); break; + case 0xfd: /* forward */ case 0xff: /* stub or extern */ break; default: /* normal function (stdcall or cdecl) */ diff --git a/tools/build-spec.txt b/tools/build-spec.txt index cf796214c25..bb35b6e457f 100644 --- a/tools/build-spec.txt +++ b/tools/build-spec.txt @@ -16,6 +16,8 @@ ORDINAL return EXPORTNAME ARGLENGTH RETVALUE ORDINAL extern EXPORTNAME SYMBOLNAME +ORDINAL forward EXPORTNAME SYMBOLNAME + # COMMENT_TEXT -------------------- @@ -127,3 +129,12 @@ Extern ordinals: (variable or function); "EXPORTNAME" will point to the symbol "SYMBOLNAME" that must be defined in C code. This type only works with Win32. + +Forwarded ordinals: +=================== + + This type defines an entry that is forwarded to another entry +point (kind of a symbolic link). "EXPORTNAME" will forward to the +entry point "SYMBOLNAME" that must be of the form "DLL.Function". This +type only works with Win32. + diff --git a/tools/build.c b/tools/build.c index f8789f014c0..69d1114e694 100644 --- a/tools/build.c +++ b/tools/build.c @@ -54,6 +54,7 @@ typedef enum TYPE_CDECL, /* cdecl function (Win32) */ TYPE_VARARGS, /* varargs function (Win32) */ TYPE_EXTERN, /* external symbol (Win32) */ + TYPE_FORWARD, /* forwarded function (Win32) */ TYPE_NBTYPES } ORD_TYPE; @@ -72,7 +73,8 @@ static const char * const TypeNames[TYPE_NBTYPES] = "stdcall", /* TYPE_STDCALL */ "cdecl", /* TYPE_CDECL */ "varargs", /* TYPE_VARARGS */ - "extern" /* TYPE_EXTERN */ + "extern", /* TYPE_EXTERN */ + "forward" /* TYPE_FORWARD */ }; #define MAX_ORDINALS 2048 @@ -122,6 +124,11 @@ typedef struct char link_name[80]; } ORD_EXTERN; +typedef struct +{ + char link_name[80]; +} ORD_FORWARD; + typedef struct { ORD_TYPE type; @@ -136,6 +143,7 @@ typedef struct ORD_ABS abs; ORD_VARARGS vargs; ORD_EXTERN ext; + ORD_FORWARD fwd; } u; } ORDDEF; @@ -584,6 +592,24 @@ static int ParseExtern( ORDDEF *odp ) } +/******************************************************************* + * ParseForward + * + * Parse a 'forward' definition. + */ +static int ParseForward( ORDDEF *odp ) +{ + if (SpecType == SPEC_WIN16) + { + fprintf( stderr, "%s:%d: 'forward' not supported for Win16\n", + SpecName, Line ); + return -1; + } + strcpy( odp->u.fwd.link_name, GetToken() ); + return 0; +} + + /******************************************************************* * ParseOrdinal * @@ -651,6 +677,8 @@ static int ParseOrdinal(int ordinal) return ParseVarargs( odp ); case TYPE_EXTERN: return ParseExtern( odp ); + case TYPE_FORWARD: + return ParseForward( odp ); default: fprintf( stderr, "Should not happen\n" ); return -1; @@ -987,7 +1015,7 @@ static int BuildModule16( FILE *outfile, int max_code_offset, static int BuildSpec32File( char * specfile, FILE *outfile ) { ORDDEF *odp; - int i, nb_names; + int i, nb_names, fwd_size = 0; fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n", specfile ); @@ -1046,6 +1074,9 @@ static int BuildSpec32File( char * specfile, FILE *outfile ) case TYPE_CDECL: fprintf( outfile, "extern void %s();\n", odp->u.func.link_name ); break; + case TYPE_FORWARD: + fwd_size += strlen(odp->u.fwd.link_name) + 1; + break; case TYPE_INVALID: case TYPE_STUB: break; @@ -1085,6 +1116,9 @@ static int BuildSpec32File( char * specfile, FILE *outfile ) case TYPE_STUB: fprintf( outfile, " __stub_%d", i ); break; + case TYPE_FORWARD: + fprintf( outfile, " (ENTRYPOINT32)\"%s\"", odp->u.fwd.link_name ); + break; default: return -1; } @@ -1149,6 +1183,9 @@ static int BuildSpec32File( char * specfile, FILE *outfile ) case TYPE_CDECL: args = 0x80 | (unsigned char)strlen(odp->u.func.arg_types); break; + case TYPE_FORWARD: + args = 0xfd; + break; case TYPE_REGISTER: args = 0xfe; break; @@ -1169,6 +1206,7 @@ static int BuildSpec32File( char * specfile, FILE *outfile ) fprintf( outfile, " %d,\n", Base ); fprintf( outfile, " %d,\n", Limit - Base + 1 ); fprintf( outfile, " %d,\n", nb_names ); + fprintf( outfile, " %d,\n", (fwd_size + 3) & ~3 ); fprintf( outfile, " Functions,\n" " FuncNames,\n"