2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* Spec file parser
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Martin von Loewis
|
2004-02-17 21:36:16 +01:00
|
|
|
* Copyright 1995, 1996, 1997, 2004 Alexandre Julliard
|
2000-06-23 22:15:35 +02:00
|
|
|
* Copyright 1997 Eric Youngdale
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
int current_line = 0;
|
|
|
|
|
|
|
|
static char ParseBuffer[512];
|
2001-02-15 22:27:06 +01:00
|
|
|
static char TokenBuffer[512];
|
2000-06-23 22:15:35 +02:00
|
|
|
static char *ParseNext = ParseBuffer;
|
|
|
|
static FILE *input_file;
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
static const char *separator_chars;
|
|
|
|
static const char *comment_chars;
|
|
|
|
|
2006-12-04 12:23:58 +01:00
|
|
|
/* valid characters in ordinal names */
|
2012-05-02 21:16:01 +02:00
|
|
|
static const char valid_ordname_chars[] = "/$:-_@?<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
2006-12-04 12:23:58 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
static const char * const TypeNames[TYPE_NBTYPES] =
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
"variable", /* TYPE_VARIABLE */
|
2000-06-23 22:15:35 +02:00
|
|
|
"pascal", /* TYPE_PASCAL */
|
|
|
|
"equate", /* TYPE_ABS */
|
|
|
|
"stub", /* TYPE_STUB */
|
|
|
|
"stdcall", /* TYPE_STDCALL */
|
|
|
|
"cdecl", /* TYPE_CDECL */
|
|
|
|
"varargs", /* TYPE_VARARGS */
|
2003-03-17 05:56:10 +01:00
|
|
|
"extern" /* TYPE_EXTERN */
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
static const char * const FlagNames[] =
|
|
|
|
{
|
|
|
|
"norelay", /* FLAG_NORELAY */
|
2002-07-28 19:54:31 +02:00
|
|
|
"noname", /* FLAG_NONAME */
|
2003-08-27 04:20:44 +02:00
|
|
|
"ret16", /* FLAG_RET16 */
|
2000-11-26 05:31:48 +01:00
|
|
|
"ret64", /* FLAG_RET64 */
|
2001-12-15 00:14:22 +01:00
|
|
|
"register", /* FLAG_REGISTER */
|
2003-07-28 21:19:48 +02:00
|
|
|
"private", /* FLAG_PRIVATE */
|
2007-10-26 12:47:40 +02:00
|
|
|
"ordinal", /* FLAG_ORDINAL */
|
2019-02-27 17:09:51 +01:00
|
|
|
"thiscall", /* FLAG_THISCALL */
|
2019-02-27 17:11:08 +01:00
|
|
|
"fastcall", /* FLAG_FASTCALL */
|
2000-11-26 05:31:48 +01:00
|
|
|
NULL
|
|
|
|
};
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2010-08-30 12:06:19 +02:00
|
|
|
static const char * const ArgNames[ARG_MAXARG + 1] =
|
|
|
|
{
|
|
|
|
"word", /* ARG_WORD */
|
|
|
|
"s_word", /* ARG_SWORD */
|
|
|
|
"segptr", /* ARG_SEGPTR */
|
|
|
|
"segstr", /* ARG_SEGSTR */
|
|
|
|
"long", /* ARG_LONG */
|
|
|
|
"ptr", /* ARG_PTR */
|
|
|
|
"str", /* ARG_STR */
|
|
|
|
"wstr", /* ARG_WSTR */
|
2010-08-30 12:40:53 +02:00
|
|
|
"int64", /* ARG_INT64 */
|
|
|
|
"int128", /* ARG_INT128 */
|
|
|
|
"float", /* ARG_FLOAT */
|
2010-08-30 12:06:19 +02:00
|
|
|
"double" /* ARG_DOUBLE */
|
|
|
|
};
|
|
|
|
|
2001-02-15 22:27:06 +01:00
|
|
|
static int IsNumberString(const char *s)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
while (*s) if (!isdigit(*s++)) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline int is_token_separator( char ch )
|
2000-11-26 05:31:48 +01:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
return strchr( separator_chars, ch ) != NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline int is_token_comment( char ch )
|
2004-02-17 21:36:16 +01:00
|
|
|
{
|
|
|
|
return strchr( comment_chars, ch ) != NULL;
|
2000-11-26 05:31:48 +01:00
|
|
|
}
|
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
/* get the next line from the input file, or return 0 if at eof */
|
|
|
|
static int get_next_line(void)
|
|
|
|
{
|
|
|
|
ParseNext = ParseBuffer;
|
|
|
|
current_line++;
|
|
|
|
return (fgets(ParseBuffer, sizeof(ParseBuffer), input_file) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * GetToken( int allow_eol )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2011-07-03 13:33:33 +02:00
|
|
|
char *p;
|
2001-02-15 22:27:06 +01:00
|
|
|
char *token = TokenBuffer;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* remove initial white space */
|
|
|
|
p = ParseNext;
|
|
|
|
while (isspace(*p)) p++;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (*p == '\\' && p[1] == '\n') /* line continuation */
|
|
|
|
{
|
|
|
|
if (!get_next_line())
|
|
|
|
{
|
|
|
|
if (!allow_eol) error( "Unexpected end of file\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
if ((*p == '\0') || is_token_comment(*p))
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
if (!allow_eol) error( "Declaration not terminated properly\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* Find end of token.
|
|
|
|
*/
|
2001-02-15 22:27:06 +01:00
|
|
|
if (is_token_separator(*p))
|
|
|
|
{
|
|
|
|
/* a separator is always a complete token */
|
|
|
|
*token++ = *p++;
|
|
|
|
}
|
|
|
|
else while (*p != '\0' && !is_token_separator(*p) && !isspace(*p))
|
|
|
|
{
|
|
|
|
if (*p == '\\') p++;
|
|
|
|
if (*p) *token++ = *p++;
|
|
|
|
}
|
|
|
|
*token = '\0';
|
2000-06-23 22:15:35 +02:00
|
|
|
ParseNext = p;
|
2001-02-15 22:27:06 +01:00
|
|
|
return TokenBuffer;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
static ORDDEF *add_entry_point( DLLSPEC *spec )
|
|
|
|
{
|
2009-02-24 18:02:15 +01:00
|
|
|
ORDDEF *ret;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->nb_entry_points == spec->alloc_entry_points)
|
|
|
|
{
|
|
|
|
spec->alloc_entry_points += 128;
|
|
|
|
spec->entry_points = xrealloc( spec->entry_points,
|
|
|
|
spec->alloc_entry_points * sizeof(*spec->entry_points) );
|
|
|
|
}
|
2009-02-24 18:02:15 +01:00
|
|
|
ret = &spec->entry_points[spec->nb_entry_points++];
|
|
|
|
memset( ret, 0, sizeof(*ret) );
|
|
|
|
return ret;
|
2004-02-11 07:41:01 +01:00
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_variable
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse a variable definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_variable( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
char *endptr;
|
2017-02-02 05:23:53 +01:00
|
|
|
unsigned int *value_array;
|
2000-06-23 22:15:35 +02:00
|
|
|
int n_values;
|
|
|
|
int value_array_size;
|
2003-03-17 01:02:11 +01:00
|
|
|
const char *token;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'variable' not supported in Win32, use 'extern' instead\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-17 01:02:11 +01:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
if (*token != '(')
|
|
|
|
{
|
|
|
|
error( "Expected '(' got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
n_values = 0;
|
|
|
|
value_array_size = 25;
|
|
|
|
value_array = xmalloc(sizeof(*value_array) * value_array_size);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
for (;;)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0)))
|
|
|
|
{
|
|
|
|
free( value_array );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token == ')')
|
|
|
|
break;
|
|
|
|
|
2017-02-02 05:23:53 +01:00
|
|
|
value_array[n_values++] = strtoul(token, &endptr, 0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (n_values == value_array_size)
|
|
|
|
{
|
|
|
|
value_array_size += 25;
|
2002-06-01 01:06:46 +02:00
|
|
|
value_array = xrealloc(value_array,
|
2000-06-23 22:15:35 +02:00
|
|
|
sizeof(*value_array) * value_array_size);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
if (endptr == NULL || *endptr != '\0')
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Expected number value, got '%s'\n", token );
|
|
|
|
free( value_array );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
odp->u.var.n_values = n_values;
|
|
|
|
odp->u.var.values = xrealloc(value_array, sizeof(*value_array) * n_values);
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2011-05-03 12:49:15 +02:00
|
|
|
* parse_spec_arguments
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2011-05-03 12:49:15 +02:00
|
|
|
* Parse the arguments of an entry point.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2011-05-03 12:49:15 +02:00
|
|
|
static int parse_spec_arguments( ORDDEF *odp, DLLSPEC *spec, int optional )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2010-08-30 12:06:19 +02:00
|
|
|
unsigned int i, arg;
|
2009-12-28 22:42:58 +01:00
|
|
|
int is_win32 = (spec->type == SPEC_WIN32) || (odp->flags & FLAG_EXPORT32);
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2011-05-03 12:49:15 +02:00
|
|
|
if (!(token = GetToken( optional ))) return optional;
|
2003-03-18 06:30:54 +01:00
|
|
|
if (*token != '(')
|
|
|
|
{
|
|
|
|
error( "Expected '(' got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2010-08-30 12:06:19 +02:00
|
|
|
odp->u.func.nb_args = 0;
|
|
|
|
for (i = 0; i < MAX_ARGUMENTS; i++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) return 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token == ')')
|
|
|
|
break;
|
|
|
|
|
2010-08-30 12:06:19 +02:00
|
|
|
for (arg = 0; arg <= ARG_MAXARG; arg++)
|
|
|
|
if (!strcmp( ArgNames[arg], token )) break;
|
|
|
|
|
|
|
|
if (arg > ARG_MAXARG)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Unknown argument type '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-30 12:06:19 +02:00
|
|
|
if (is_win32) switch (arg)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2010-08-30 12:06:19 +02:00
|
|
|
case ARG_WORD:
|
|
|
|
case ARG_SWORD:
|
|
|
|
case ARG_SEGPTR:
|
|
|
|
case ARG_SEGSTR:
|
|
|
|
error( "Argument type '%s' only allowed for Win16\n", token );
|
|
|
|
return 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2010-08-30 12:06:19 +02:00
|
|
|
odp->u.func.args[i] = arg;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2010-08-30 12:06:19 +02:00
|
|
|
if (*token != ')')
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Too many arguments\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2010-08-30 12:06:19 +02:00
|
|
|
odp->u.func.nb_args = i;
|
2019-02-27 17:09:51 +01:00
|
|
|
if (odp->flags & FLAG_THISCALL)
|
2010-08-24 19:29:51 +02:00
|
|
|
{
|
2019-02-27 17:09:51 +01:00
|
|
|
if (odp->type != TYPE_STDCALL)
|
|
|
|
{
|
|
|
|
error( "A thiscall function must use the stdcall convention\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!i || odp->u.func.args[0] != ARG_PTR)
|
|
|
|
{
|
|
|
|
error( "First argument of a thiscall function must be a pointer\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-24 19:29:51 +02:00
|
|
|
}
|
2019-02-27 17:11:08 +01:00
|
|
|
if (odp->flags & FLAG_FASTCALL)
|
|
|
|
{
|
|
|
|
if (odp->type != TYPE_STDCALL)
|
|
|
|
{
|
|
|
|
error( "A fastcall function must use the stdcall convention\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!i || (odp->u.func.args[0] != ARG_PTR && odp->u.func.args[0] != ARG_LONG))
|
|
|
|
{
|
|
|
|
error( "First argument of a fastcall function must be a pointer or integer\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (i > 1 && odp->u.func.args[1] != ARG_PTR && odp->u.func.args[1] != ARG_LONG)
|
|
|
|
{
|
|
|
|
error( "Second argument of a fastcall function must be a pointer or integer\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2011-05-03 12:49:15 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_spec_export
|
|
|
|
*
|
|
|
|
* Parse an exported function definition in a .spec file.
|
|
|
|
*/
|
|
|
|
static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token;
|
|
|
|
int is_win32 = (spec->type == SPEC_WIN32) || (odp->flags & FLAG_EXPORT32);
|
|
|
|
|
|
|
|
if (!is_win32 && odp->type == TYPE_STDCALL)
|
|
|
|
{
|
|
|
|
error( "'stdcall' not supported for Win16\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (is_win32 && odp->type == TYPE_PASCAL)
|
|
|
|
{
|
|
|
|
error( "'pascal' not supported for Win32\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_spec_arguments( odp, spec, 0 )) return 0;
|
|
|
|
|
|
|
|
if (odp->type == TYPE_VARARGS)
|
|
|
|
odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */
|
2003-03-18 06:30:54 +01:00
|
|
|
|
2019-02-27 17:09:51 +01:00
|
|
|
if (target_cpu != CPU_x86)
|
2019-02-27 17:11:08 +01:00
|
|
|
odp->flags &= ~(FLAG_THISCALL | FLAG_FASTCALL);
|
2019-02-27 17:09:51 +01:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(1)))
|
2002-12-15 02:22:40 +01:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
{
|
|
|
|
error( "Missing handler name for anonymous function\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
odp->link_name = xstrdup( odp->name );
|
2002-12-15 02:22:40 +01:00
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->link_name = xstrdup( token );
|
|
|
|
if (strchr( odp->link_name, '.' ))
|
|
|
|
{
|
2009-12-28 22:42:58 +01:00
|
|
|
if (!is_win32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Forwarded functions not supported for Win16\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
odp->flags |= FLAG_FORWARD;
|
|
|
|
}
|
|
|
|
}
|
2019-02-27 17:11:08 +01:00
|
|
|
if ((odp->flags & (FLAG_THISCALL | FLAG_FASTCALL)) && !(odp->flags & FLAG_FORWARD))
|
2010-08-24 15:20:00 +02:00
|
|
|
{
|
2019-02-27 17:11:08 +01:00
|
|
|
char *link_name = strmake( "__%s_%s", (odp->flags & FLAG_THISCALL) ? "thiscall" : "fastcall",
|
|
|
|
odp->link_name );
|
2010-08-24 15:20:00 +02:00
|
|
|
free( odp->link_name );
|
|
|
|
odp->link_name = link_name;
|
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_equate
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an 'equate' definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_equate( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
char *endptr;
|
2003-03-18 06:30:54 +01:00
|
|
|
int value;
|
|
|
|
const char *token;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'equate' not supported for Win32\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
value = strtol(token, &endptr, 0);
|
|
|
|
if (endptr == NULL || *endptr != '\0')
|
|
|
|
{
|
|
|
|
error( "Expected number value, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2005-09-21 13:10:54 +02:00
|
|
|
if (value < -0x8000 || value > 0xffff)
|
|
|
|
{
|
|
|
|
error( "Value %d for absolute symbol doesn't fit in 16 bits\n", value );
|
|
|
|
value = 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->u.abs.value = value;
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_stub
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse a 'stub' definition in a .spec file
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_stub( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2011-05-03 12:49:15 +02:00
|
|
|
odp->u.func.nb_args = -1;
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup("");
|
2010-09-15 19:45:04 +02:00
|
|
|
/* don't bother generating stubs for Winelib */
|
|
|
|
if (odp->flags & FLAG_CPU_MASK)
|
2015-06-14 23:24:06 +02:00
|
|
|
odp->flags &= FLAG_CPU(CPU_x86) | FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM) | FLAG_CPU(CPU_ARM64);
|
2010-09-15 19:45:04 +02:00
|
|
|
else
|
2015-06-14 23:24:06 +02:00
|
|
|
odp->flags |= FLAG_CPU(CPU_x86) | FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM) | FLAG_CPU(CPU_ARM64);
|
2011-05-03 12:49:15 +02:00
|
|
|
|
|
|
|
return parse_spec_arguments( odp, spec, 1 );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_extern
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an 'extern' definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_extern( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
const char *token;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN16)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'extern' not supported for Win16, use 'variable' instead\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(1)))
|
|
|
|
{
|
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
{
|
|
|
|
error( "Missing handler name for anonymous extern\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
odp->link_name = xstrdup( odp->name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->link_name = xstrdup( token );
|
|
|
|
if (strchr( odp->link_name, '.' )) odp->flags |= FLAG_FORWARD;
|
|
|
|
}
|
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_flags
|
2000-11-26 05:31:48 +01:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse the optional flags for an entry point in a .spec file.
|
2000-11-26 05:31:48 +01:00
|
|
|
*/
|
2009-12-28 22:42:58 +01:00
|
|
|
static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
|
2000-11-26 05:31:48 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-11-26 05:31:48 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) break;
|
2008-12-08 17:07:50 +01:00
|
|
|
if (!strncmp( token, "arch=", 5))
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
2008-12-08 17:07:50 +01:00
|
|
|
char *args = xstrdup( token + 5 );
|
|
|
|
char *cpu_name = strtok( args, "," );
|
|
|
|
while (cpu_name)
|
|
|
|
{
|
2009-08-24 12:49:07 +02:00
|
|
|
if (!strcmp( cpu_name, "win32" ))
|
2009-12-28 22:42:58 +01:00
|
|
|
{
|
|
|
|
if (spec->type == SPEC_WIN32)
|
|
|
|
odp->flags |= FLAG_CPU_WIN32;
|
|
|
|
else
|
|
|
|
odp->flags |= FLAG_EXPORT32;
|
|
|
|
}
|
2009-08-24 12:49:07 +02:00
|
|
|
else if (!strcmp( cpu_name, "win64" ))
|
|
|
|
odp->flags |= FLAG_CPU_WIN64;
|
|
|
|
else
|
2008-12-08 17:07:50 +01:00
|
|
|
{
|
2015-03-04 09:25:06 +01:00
|
|
|
int cpu = get_cpu_from_name( cpu_name );
|
2009-08-24 12:49:07 +02:00
|
|
|
if (cpu == -1)
|
|
|
|
{
|
|
|
|
error( "Unknown architecture '%s'\n", cpu_name );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
odp->flags |= FLAG_CPU( cpu );
|
2008-12-08 17:07:50 +01:00
|
|
|
}
|
|
|
|
cpu_name = strtok( NULL, "," );
|
|
|
|
}
|
|
|
|
free( args );
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "i386" )) /* backwards compatibility */
|
|
|
|
{
|
|
|
|
odp->flags |= FLAG_CPU(CPU_x86);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; FlagNames[i]; i++)
|
|
|
|
if (!strcmp( FlagNames[i], token )) break;
|
|
|
|
if (!FlagNames[i])
|
|
|
|
{
|
|
|
|
error( "Unknown flag '%s'\n", token );
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-07-26 10:42:48 +02:00
|
|
|
switch (1 << i)
|
|
|
|
{
|
|
|
|
case FLAG_RET16:
|
|
|
|
case FLAG_REGISTER:
|
|
|
|
if (spec->type == SPEC_WIN32)
|
|
|
|
error( "Flag '%s' is not supported in Win32\n", FlagNames[i] );
|
|
|
|
break;
|
|
|
|
case FLAG_RET64:
|
2019-02-27 17:09:51 +01:00
|
|
|
case FLAG_THISCALL:
|
2019-02-27 17:11:08 +01:00
|
|
|
case FLAG_FASTCALL:
|
2017-07-26 10:42:48 +02:00
|
|
|
if (spec->type == SPEC_WIN16)
|
|
|
|
error( "Flag '%s' is not supported in Win16\n", FlagNames[i] );
|
|
|
|
break;
|
|
|
|
}
|
2008-12-08 17:07:50 +01:00
|
|
|
odp->flags |= 1 << i;
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2003-03-18 06:30:54 +01:00
|
|
|
} while (token && *token == '-');
|
2000-11-26 05:31:48 +01:00
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_ordinal
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an ordinal definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2006-12-04 12:23:58 +01:00
|
|
|
size_t len;
|
2004-02-11 07:41:01 +01:00
|
|
|
ORDDEF *odp = add_entry_point( spec );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
|
|
|
|
if (TypeNames[odp->type] && !strcmp( token, TypeNames[odp->type] ))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (odp->type >= TYPE_NBTYPES)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
2019-02-27 17:09:51 +01:00
|
|
|
if (!strcmp( token, "thiscall" )) /* for backwards compatibility */
|
|
|
|
{
|
|
|
|
odp->type = TYPE_STDCALL;
|
|
|
|
odp->flags |= FLAG_THISCALL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error( "Expected type after ordinal, found '%s' instead\n", token );
|
|
|
|
goto error;
|
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) goto error;
|
2009-12-28 22:42:58 +01:00
|
|
|
if (*token == '-' && !(token = parse_spec_flags( spec, odp ))) goto error;
|
|
|
|
|
|
|
|
if (ordinal == -1 && spec->type != SPEC_WIN32 && !(odp->flags & FLAG_EXPORT32))
|
|
|
|
{
|
|
|
|
error( "'@' ordinals not supported for Win16\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->name = xstrdup( token );
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->lineno = current_line;
|
|
|
|
odp->ordinal = ordinal;
|
|
|
|
|
2006-12-04 12:23:58 +01:00
|
|
|
len = strspn( odp->name, valid_ordname_chars );
|
|
|
|
if (len < strlen( odp->name ))
|
|
|
|
{
|
|
|
|
error( "Character '%c' is not allowed in exported name '%s'\n", odp->name[len], odp->name );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
switch(odp->type)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
case TYPE_VARIABLE:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_variable( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_PASCAL:
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
case TYPE_CDECL:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_export( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_ABS:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_equate( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_STUB:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_stub( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_EXTERN:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_extern( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( 0 );
|
|
|
|
}
|
|
|
|
|
2008-12-08 17:07:50 +01:00
|
|
|
if ((odp->flags & FLAG_CPU_MASK) && !(odp->flags & FLAG_CPU(target_cpu)))
|
2000-11-26 05:31:48 +01:00
|
|
|
{
|
2008-12-08 17:07:50 +01:00
|
|
|
/* ignore this entry point */
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->nb_entry_points--;
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-11-26 05:31:48 +01:00
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
if (ordinal != -1)
|
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!ordinal)
|
|
|
|
{
|
|
|
|
error( "Ordinal 0 is not valid\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (ordinal >= MAX_ORDINALS)
|
|
|
|
{
|
|
|
|
error( "Ordinal number %d too large\n", ordinal );
|
|
|
|
goto error;
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (ordinal > spec->limit) spec->limit = ordinal;
|
|
|
|
if (ordinal < spec->base) spec->base = ordinal;
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->ordinal = ordinal;
|
|
|
|
}
|
|
|
|
|
2004-08-27 21:40:53 +02:00
|
|
|
if (odp->type == TYPE_STDCALL && !(odp->flags & FLAG_PRIVATE))
|
|
|
|
{
|
|
|
|
if (!strcmp( odp->name, "DllRegisterServer" ) ||
|
|
|
|
!strcmp( odp->name, "DllUnregisterServer" ) ||
|
2015-07-15 08:57:51 +02:00
|
|
|
!strcmp( odp->name, "DllMain" ) ||
|
2004-08-27 21:40:53 +02:00
|
|
|
!strcmp( odp->name, "DllGetClassObject" ) ||
|
2005-08-09 12:24:05 +02:00
|
|
|
!strcmp( odp->name, "DllGetVersion" ) ||
|
|
|
|
!strcmp( odp->name, "DllInstall" ) ||
|
2004-08-27 21:40:53 +02:00
|
|
|
!strcmp( odp->name, "DllCanUnloadNow" ))
|
|
|
|
{
|
|
|
|
warning( "Function %s should be marked private\n", odp->name );
|
2005-08-09 12:24:05 +02:00
|
|
|
if (strcmp( odp->name, odp->link_name ))
|
|
|
|
warning( "Function %s should not use a different internal name (%s)\n",
|
|
|
|
odp->name, odp->link_name );
|
2004-08-27 21:40:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 12:47:40 +02:00
|
|
|
if (!strcmp( odp->name, "@" ) || odp->flags & (FLAG_NONAME | FLAG_ORDINAL))
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
if (ordinal == -1)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
2007-10-26 12:47:40 +02:00
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
error( "Nameless function needs an explicit ordinal number\n" );
|
|
|
|
else
|
|
|
|
error( "Function imported by ordinal needs an explicit ordinal number\n" );
|
2003-03-18 06:30:54 +01:00
|
|
|
goto error;
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type != SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Nameless functions not supported for Win16\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
2007-10-26 12:47:40 +02:00
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
{
|
|
|
|
free( odp->name );
|
|
|
|
odp->name = NULL;
|
|
|
|
}
|
|
|
|
else if (!(odp->flags & FLAG_ORDINAL)) /* -ordinal only affects the import library */
|
|
|
|
{
|
|
|
|
odp->export_name = odp->name;
|
|
|
|
odp->name = NULL;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->nb_entry_points--;
|
2003-03-18 06:30:54 +01:00
|
|
|
free( odp->name );
|
|
|
|
return 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-19 16:44:28 +02:00
|
|
|
static int name_compare( const void *ptr1, const void *ptr2 )
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2005-09-19 16:44:28 +02:00
|
|
|
const ORDDEF *odp1 = *(const ORDDEF * const *)ptr1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF * const *)ptr2;
|
|
|
|
const char *name1 = odp1->name ? odp1->name : odp1->export_name;
|
|
|
|
const char *name2 = odp2->name ? odp2->name : odp2->export_name;
|
|
|
|
return strcmp( name1, name2 );
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-11 07:41:01 +01:00
|
|
|
* assign_names
|
2000-11-12 04:45:55 +01:00
|
|
|
*
|
2004-02-11 07:41:01 +01:00
|
|
|
* Build the name array and catch duplicates.
|
2000-11-12 04:45:55 +01:00
|
|
|
*/
|
2004-02-11 07:41:01 +01:00
|
|
|
static void assign_names( DLLSPEC *spec )
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2005-09-19 16:44:28 +02:00
|
|
|
int i, j, nb_exp_names = 0;
|
|
|
|
ORDDEF **all_names;
|
2004-02-11 07:41:01 +01:00
|
|
|
|
|
|
|
spec->nb_names = 0;
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
if (spec->entry_points[i].name) spec->nb_names++;
|
2005-09-19 16:44:28 +02:00
|
|
|
else if (spec->entry_points[i].export_name) nb_exp_names++;
|
2000-11-12 04:45:55 +01:00
|
|
|
|
2005-09-19 16:44:28 +02:00
|
|
|
if (!spec->nb_names && !nb_exp_names) return;
|
|
|
|
|
|
|
|
/* check for duplicates */
|
|
|
|
|
|
|
|
all_names = xmalloc( (spec->nb_names + nb_exp_names) * sizeof(all_names[0]) );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = j = 0; i < spec->nb_entry_points; i++)
|
2005-09-19 16:44:28 +02:00
|
|
|
if (spec->entry_points[i].name || spec->entry_points[i].export_name)
|
|
|
|
all_names[j++] = &spec->entry_points[i];
|
2000-11-12 04:45:55 +01:00
|
|
|
|
2005-09-19 16:44:28 +02:00
|
|
|
qsort( all_names, j, sizeof(all_names[0]), name_compare );
|
2000-11-12 04:45:55 +01:00
|
|
|
|
2005-09-19 16:44:28 +02:00
|
|
|
for (i = 0; i < j - 1; i++)
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2005-09-19 16:44:28 +02:00
|
|
|
const char *name1 = all_names[i]->name ? all_names[i]->name : all_names[i]->export_name;
|
|
|
|
const char *name2 = all_names[i+1]->name ? all_names[i+1]->name : all_names[i+1]->export_name;
|
2009-12-28 22:42:58 +01:00
|
|
|
if (!strcmp( name1, name2 ) &&
|
|
|
|
!((all_names[i]->flags ^ all_names[i+1]->flags) & FLAG_EXPORT32))
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2005-09-19 16:44:28 +02:00
|
|
|
current_line = max( all_names[i]->lineno, all_names[i+1]->lineno );
|
2003-03-18 06:30:54 +01:00
|
|
|
error( "'%s' redefined\n%s:%d: First defined here\n",
|
2005-09-19 16:44:28 +02:00
|
|
|
name1, input_file_name,
|
|
|
|
min( all_names[i]->lineno, all_names[i+1]->lineno ) );
|
2004-02-11 07:41:01 +01:00
|
|
|
}
|
|
|
|
}
|
2005-09-19 16:44:28 +02:00
|
|
|
free( all_names );
|
|
|
|
|
|
|
|
if (spec->nb_names)
|
|
|
|
{
|
|
|
|
spec->names = xmalloc( spec->nb_names * sizeof(spec->names[0]) );
|
|
|
|
for (i = j = 0; i < spec->nb_entry_points; i++)
|
|
|
|
if (spec->entry_points[i].name) spec->names[j++] = &spec->entry_points[i];
|
|
|
|
|
|
|
|
/* sort the list of names */
|
|
|
|
qsort( spec->names, spec->nb_names, sizeof(spec->names[0]), name_compare );
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* assign_ordinals
|
|
|
|
*
|
|
|
|
* Build the ordinal array.
|
|
|
|
*/
|
|
|
|
static void assign_ordinals( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i, count, ordinal;
|
|
|
|
|
|
|
|
/* start assigning from base, or from 1 if no ordinal defined yet */
|
2005-08-29 17:15:42 +02:00
|
|
|
|
|
|
|
spec->base = MAX_ORDINALS;
|
|
|
|
spec->limit = 0;
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ordinal = spec->entry_points[i].ordinal;
|
|
|
|
if (ordinal == -1) continue;
|
|
|
|
if (ordinal > spec->limit) spec->limit = ordinal;
|
|
|
|
if (ordinal < spec->base) spec->base = ordinal;
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->base == MAX_ORDINALS) spec->base = 1;
|
|
|
|
if (spec->limit < spec->base) spec->limit = spec->base;
|
|
|
|
|
|
|
|
count = max( spec->limit + 1, spec->base + spec->nb_entry_points );
|
|
|
|
spec->ordinals = xmalloc( count * sizeof(spec->ordinals[0]) );
|
|
|
|
memset( spec->ordinals, 0, count * sizeof(spec->ordinals[0]) );
|
|
|
|
|
|
|
|
/* fill in all explicitly specified ordinals */
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ordinal = spec->entry_points[i].ordinal;
|
|
|
|
if (ordinal == -1) continue;
|
|
|
|
if (spec->ordinals[ordinal])
|
|
|
|
{
|
|
|
|
current_line = max( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno );
|
|
|
|
error( "ordinal %d redefined\n%s:%d: First defined here\n",
|
|
|
|
ordinal, input_file_name,
|
|
|
|
min( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno ) );
|
|
|
|
}
|
|
|
|
else spec->ordinals[ordinal] = &spec->entry_points[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now assign ordinals to the rest */
|
2005-06-23 18:46:20 +02:00
|
|
|
for (i = 0, ordinal = spec->base; i < spec->nb_entry_points; i++)
|
2004-02-11 07:41:01 +01:00
|
|
|
{
|
2005-06-23 18:46:20 +02:00
|
|
|
if (spec->entry_points[i].ordinal != -1) continue;
|
2004-02-11 07:41:01 +01:00
|
|
|
while (spec->ordinals[ordinal]) ordinal++;
|
|
|
|
if (ordinal >= MAX_ORDINALS)
|
|
|
|
{
|
2005-06-23 18:46:20 +02:00
|
|
|
current_line = spec->entry_points[i].lineno;
|
2004-02-11 07:41:01 +01:00
|
|
|
fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
2005-06-23 18:46:20 +02:00
|
|
|
spec->entry_points[i].ordinal = ordinal;
|
|
|
|
spec->ordinals[ordinal] = &spec->entry_points[i];
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (ordinal > spec->limit) spec->limit = ordinal;
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-24 18:02:15 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* add_16bit_exports
|
|
|
|
*
|
|
|
|
* Add the necessary exports to the 32-bit counterpart of a 16-bit module.
|
|
|
|
*/
|
|
|
|
void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 )
|
|
|
|
{
|
2009-12-28 22:42:58 +01:00
|
|
|
int i;
|
2009-02-24 18:02:15 +01:00
|
|
|
ORDDEF *odp;
|
|
|
|
|
2009-12-30 12:32:17 +01:00
|
|
|
spec32->file_name = xstrdup( spec16->file_name );
|
|
|
|
if (spec16->characteristics & IMAGE_FILE_DLL)
|
|
|
|
{
|
|
|
|
spec32->characteristics = IMAGE_FILE_DLL;
|
|
|
|
spec32->init_func = xstrdup( "__wine_spec_dll_entry" );
|
|
|
|
}
|
|
|
|
|
2009-02-24 18:02:15 +01:00
|
|
|
/* add an export for the NE module */
|
|
|
|
|
|
|
|
odp = add_entry_point( spec32 );
|
|
|
|
odp->type = TYPE_EXTERN;
|
2009-12-28 22:42:58 +01:00
|
|
|
odp->flags = FLAG_PRIVATE;
|
2009-02-24 18:02:15 +01:00
|
|
|
odp->name = xstrdup( "__wine_spec_dos_header" );
|
|
|
|
odp->lineno = 0;
|
|
|
|
odp->ordinal = 1;
|
|
|
|
odp->link_name = xstrdup( ".L__wine_spec_dos_header" );
|
|
|
|
|
2009-03-04 14:08:23 +01:00
|
|
|
if (spec16->main_module)
|
|
|
|
{
|
|
|
|
odp = add_entry_point( spec32 );
|
|
|
|
odp->type = TYPE_EXTERN;
|
2009-12-28 22:42:58 +01:00
|
|
|
odp->flags = FLAG_PRIVATE;
|
2009-03-04 14:08:23 +01:00
|
|
|
odp->name = xstrdup( "__wine_spec_main_module" );
|
|
|
|
odp->lineno = 0;
|
|
|
|
odp->ordinal = 2;
|
|
|
|
odp->link_name = xstrdup( ".L__wine_spec_main_module" );
|
|
|
|
}
|
|
|
|
|
2009-12-28 22:42:58 +01:00
|
|
|
/* add the explicit win32 exports */
|
|
|
|
|
|
|
|
for (i = 1; i <= spec16->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp16 = spec16->ordinals[i];
|
|
|
|
|
|
|
|
if (!odp16 || !odp16->name) continue;
|
|
|
|
if (!(odp16->flags & FLAG_EXPORT32)) continue;
|
|
|
|
|
|
|
|
odp = add_entry_point( spec32 );
|
|
|
|
odp->flags = odp16->flags & ~FLAG_EXPORT32;
|
|
|
|
odp->type = odp16->type;
|
|
|
|
odp->name = xstrdup( odp16->name );
|
|
|
|
odp->lineno = odp16->lineno;
|
|
|
|
odp->ordinal = -1;
|
|
|
|
odp->link_name = xstrdup( odp16->link_name );
|
2010-08-30 12:06:19 +02:00
|
|
|
odp->u.func.nb_args = odp16->u.func.nb_args;
|
2011-05-03 12:49:15 +02:00
|
|
|
if (odp->u.func.nb_args > 0) memcpy( odp->u.func.args, odp16->u.func.args,
|
|
|
|
odp->u.func.nb_args * sizeof(odp->u.func.args[0]) );
|
2009-12-28 22:42:58 +01:00
|
|
|
}
|
|
|
|
|
2009-02-24 18:02:15 +01:00
|
|
|
assign_names( spec32 );
|
|
|
|
assign_ordinals( spec32 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_file
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
int parse_spec_file( FILE *file, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
input_file = file;
|
2002-08-28 00:32:01 +02:00
|
|
|
current_line = 0;
|
2002-06-21 21:15:45 +02:00
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
comment_chars = "#;";
|
|
|
|
separator_chars = "()-";
|
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
while (get_next_line())
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(1))) continue;
|
2002-12-08 00:54:12 +01:00
|
|
|
if (strcmp(token, "@") == 0)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_ordinal( -1, spec )) continue;
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
|
|
|
else if (IsNumberString(token))
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_ordinal( atoi(token), spec )) continue;
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error( "Expected ordinal declaration, got '%s'\n", token );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
current_line = 0; /* no longer parsing the input file */
|
2004-02-11 07:41:01 +01:00
|
|
|
assign_names( spec );
|
|
|
|
assign_ordinals( spec );
|
2003-03-18 06:30:54 +01:00
|
|
|
return !nb_errors;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2002-05-14 22:54:58 +02:00
|
|
|
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_library
|
|
|
|
*
|
|
|
|
* Parse a LIBRARY declaration in a .def file.
|
|
|
|
*/
|
|
|
|
static int parse_def_library( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token = GetToken(1);
|
|
|
|
|
|
|
|
if (!token) return 1;
|
|
|
|
if (strcmp( token, "BASE" ))
|
|
|
|
{
|
|
|
|
free( spec->file_name );
|
|
|
|
spec->file_name = xstrdup( token );
|
|
|
|
if (!(token = GetToken(1))) return 1;
|
|
|
|
}
|
|
|
|
if (strcmp( token, "BASE" ))
|
|
|
|
{
|
|
|
|
error( "Expected library name or BASE= declaration, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
if (strcmp( token, "=" ))
|
|
|
|
{
|
|
|
|
error( "Expected '=' after BASE, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
/* FIXME: do something with base address */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_stack_heap_size
|
|
|
|
*
|
|
|
|
* Parse a STACKSIZE or HEAPSIZE declaration in a .def file.
|
|
|
|
*/
|
|
|
|
static int parse_def_stack_heap_size( int is_stack, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token = GetToken(0);
|
|
|
|
char *end;
|
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
if (!token) return 0;
|
|
|
|
size = strtoul( token, &end, 0 );
|
|
|
|
if (*end)
|
|
|
|
{
|
|
|
|
error( "Invalid number '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (is_stack) spec->stack_size = size / 1024;
|
|
|
|
else spec->heap_size = size / 1024;
|
|
|
|
if (!(token = GetToken(1))) return 1;
|
|
|
|
if (strcmp( token, "," ))
|
|
|
|
{
|
|
|
|
error( "Expected ',' after size, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
/* FIXME: do something with reserve size */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_export
|
|
|
|
*
|
|
|
|
* Parse an export declaration in a .def file.
|
|
|
|
*/
|
|
|
|
static int parse_def_export( char *name, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i, args;
|
|
|
|
const char *token = GetToken(1);
|
|
|
|
ORDDEF *odp = add_entry_point( spec );
|
|
|
|
|
|
|
|
odp->lineno = current_line;
|
|
|
|
odp->ordinal = -1;
|
|
|
|
odp->name = name;
|
|
|
|
args = remove_stdcall_decoration( odp->name );
|
2010-08-30 12:06:19 +02:00
|
|
|
if (args == -1)
|
|
|
|
{
|
|
|
|
odp->type = TYPE_CDECL;
|
|
|
|
args = 0;
|
|
|
|
}
|
2004-02-17 21:36:16 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->type = TYPE_STDCALL;
|
2005-09-08 13:35:19 +02:00
|
|
|
args /= get_ptr_size();
|
2010-08-30 12:06:19 +02:00
|
|
|
if (args >= MAX_ARGUMENTS)
|
2004-02-17 21:36:16 +01:00
|
|
|
{
|
|
|
|
error( "Too many arguments in stdcall function '%s'\n", odp->name );
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-30 12:06:19 +02:00
|
|
|
for (i = 0; i < args; i++) odp->u.func.args[i] = ARG_LONG;
|
2004-02-17 21:36:16 +01:00
|
|
|
}
|
2010-08-30 12:06:19 +02:00
|
|
|
odp->u.func.nb_args = args;
|
2004-02-17 21:36:16 +01:00
|
|
|
|
|
|
|
/* check for optional internal name */
|
|
|
|
|
|
|
|
if (token && !strcmp( token, "=" ))
|
|
|
|
{
|
|
|
|
if (!(token = GetToken(0))) goto error;
|
|
|
|
odp->link_name = xstrdup( token );
|
|
|
|
remove_stdcall_decoration( odp->link_name );
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
2004-11-21 16:39:51 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->link_name = xstrdup( name );
|
|
|
|
}
|
2004-02-17 21:36:16 +01:00
|
|
|
|
|
|
|
/* check for optional ordinal */
|
|
|
|
|
|
|
|
if (token && token[0] == '@')
|
|
|
|
{
|
|
|
|
int ordinal;
|
|
|
|
|
|
|
|
if (!IsNumberString( token+1 ))
|
|
|
|
{
|
|
|
|
error( "Expected number after '@', got '%s'\n", token+1 );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ordinal = atoi( token+1 );
|
|
|
|
if (!ordinal)
|
|
|
|
{
|
|
|
|
error( "Ordinal 0 is not valid\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (ordinal >= MAX_ORDINALS)
|
|
|
|
{
|
|
|
|
error( "Ordinal number %d too large\n", ordinal );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
odp->ordinal = ordinal;
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for other optional keywords */
|
|
|
|
|
2009-12-28 23:23:54 +01:00
|
|
|
while (token)
|
2004-02-17 21:36:16 +01:00
|
|
|
{
|
2009-12-28 23:23:54 +01:00
|
|
|
if (!strcmp( token, "NONAME" ))
|
2004-02-17 21:36:16 +01:00
|
|
|
{
|
2009-12-28 23:23:54 +01:00
|
|
|
if (odp->ordinal == -1)
|
|
|
|
{
|
|
|
|
error( "NONAME requires an ordinal\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
odp->export_name = odp->name;
|
|
|
|
odp->name = NULL;
|
|
|
|
odp->flags |= FLAG_NONAME;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "PRIVATE" ))
|
|
|
|
{
|
|
|
|
odp->flags |= FLAG_PRIVATE;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "DATA" ))
|
|
|
|
{
|
|
|
|
odp->type = TYPE_EXTERN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error( "Garbage text '%s' found at end of export declaration\n", token );
|
2004-02-17 21:36:16 +01:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
|
|
|
spec->nb_entry_points--;
|
|
|
|
free( odp->name );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_file
|
|
|
|
*
|
|
|
|
* Parse a .def file.
|
|
|
|
*/
|
|
|
|
int parse_def_file( FILE *file, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token;
|
|
|
|
int in_exports = 0;
|
|
|
|
|
|
|
|
input_file = file;
|
|
|
|
current_line = 0;
|
|
|
|
|
|
|
|
comment_chars = ";";
|
|
|
|
separator_chars = ",=";
|
|
|
|
|
|
|
|
while (get_next_line())
|
|
|
|
{
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
|
|
|
|
if (!strcmp( token, "LIBRARY" ) || !strcmp( token, "NAME" ))
|
|
|
|
{
|
|
|
|
if (!parse_def_library( spec )) continue;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "STACKSIZE" ))
|
|
|
|
{
|
|
|
|
if (!parse_def_stack_heap_size( 1, spec )) continue;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "HEAPSIZE" ))
|
|
|
|
{
|
|
|
|
if (!parse_def_stack_heap_size( 0, spec )) continue;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "EXPORTS" ))
|
|
|
|
{
|
|
|
|
in_exports = 1;
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "IMPORTS" ))
|
|
|
|
{
|
|
|
|
in_exports = 0;
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "SECTIONS" ))
|
|
|
|
{
|
|
|
|
in_exports = 0;
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_exports) continue; /* ignore this line */
|
|
|
|
if (!parse_def_export( xstrdup(token), spec )) continue;
|
|
|
|
|
|
|
|
end_of_line:
|
|
|
|
if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
|
|
|
|
}
|
|
|
|
|
|
|
|
current_line = 0; /* no longer parsing the input file */
|
|
|
|
assign_names( spec );
|
|
|
|
assign_ordinals( spec );
|
|
|
|
return !nb_errors;
|
|
|
|
}
|