Added support for forwarded ordinals in built-in dlls.

oldstable
Alexandre Julliard 1999-05-10 14:44:47 +00:00
parent df8ae8942e
commit 3eb441c7c4
4 changed files with 69 additions and 6 deletions

View File

@ -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 */

View File

@ -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;j<dll->descr->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) */

View File

@ -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.

View File

@ -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"