Avoid excessive heap memory reallocation when generating EMF
[wine] / tools / winebuild / build.h
1 /*
2  * Copyright 1993 Robert J. Amstadt
3  * Copyright 1995 Martin von Loewis
4  * Copyright 1995, 1996, 1997 Alexandre Julliard
5  * Copyright 1997 Eric Youngdale
6  * Copyright 1999 Ulrich Weigand
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef __WINE_BUILD_H
24 #define __WINE_BUILD_H
25
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 typedef enum
35 {
36     TYPE_VARIABLE,     /* variable */
37     TYPE_PASCAL,       /* pascal function (Win16) */
38     TYPE_ABS,          /* absolute value (Win16) */
39     TYPE_STUB,         /* unimplemented stub */
40     TYPE_STDCALL,      /* stdcall function (Win32) */
41     TYPE_CDECL,        /* cdecl function (Win32) */
42     TYPE_VARARGS,      /* varargs function (Win32) */
43     TYPE_EXTERN,       /* external symbol (Win32) */
44     TYPE_NBTYPES
45 } ORD_TYPE;
46
47 typedef enum
48 {
49     SPEC_WIN16,
50     SPEC_WIN32
51 } SPEC_TYPE;
52
53 typedef enum
54 {
55     SPEC_MODE_DLL,
56     SPEC_MODE_GUIEXE,
57     SPEC_MODE_CUIEXE,
58     SPEC_MODE_GUIEXE_UNICODE,
59     SPEC_MODE_CUIEXE_UNICODE
60 } SPEC_MODE;
61
62 typedef struct
63 {
64     int n_values;
65     int *values;
66 } ORD_VARIABLE;
67
68 typedef struct
69 {
70     int  n_args;
71     char arg_types[21];
72 } ORD_FUNCTION;
73
74 typedef struct
75 {
76     int value;
77 } ORD_ABS;
78
79 typedef struct
80 {
81     ORD_TYPE    type;
82     int         ordinal;
83     int         offset;
84     int         lineno;
85     int         flags;
86     char       *name;         /* public name of this function */
87     char       *link_name;    /* name of the C symbol to link to */
88     char       *export_name;  /* name exported under for noname exports */
89     union
90     {
91         ORD_VARIABLE   var;
92         ORD_FUNCTION   func;
93         ORD_ABS        abs;
94     } u;
95 } ORDDEF;
96
97 /* entry point flags */
98 #define FLAG_NORELAY   0x01  /* don't use relay debugging for this function */
99 #define FLAG_NONAME    0x02  /* don't import function by name */
100 #define FLAG_RET16     0x04  /* function returns a 16-bit value */
101 #define FLAG_RET64     0x08  /* function returns a 64-bit value */
102 #define FLAG_I386      0x10  /* function is i386 only */
103 #define FLAG_REGISTER  0x20  /* use register calling convention */
104 #define FLAG_INTERRUPT 0x40  /* function is an interrupt handler */
105 #define FLAG_PRIVATE   0x80  /* function is private (cannot be imported) */
106
107 #define FLAG_FORWARD   0x100 /* function is a forwarded name */
108
109   /* Offset of a structure field relative to the start of the struct */
110 #define STRUCTOFFSET(type,field) ((int)&((type *)0)->field)
111
112   /* Offset of register relative to the start of the CONTEXT struct */
113 #define CONTEXTOFFSET(reg)  STRUCTOFFSET(CONTEXT86,reg)
114
115   /* Offset of register relative to the start of the STACK16FRAME struct */
116 #define STACK16OFFSET(reg)  STRUCTOFFSET(STACK16FRAME,reg)
117
118   /* Offset of register relative to the start of the STACK32FRAME struct */
119 #define STACK32OFFSET(reg)  STRUCTOFFSET(STACK32FRAME,reg)
120
121   /* Offset of the stack pointer relative to %fs:(0) */
122 #define STACKOFFSET (STRUCTOFFSET(TEB,cur_stack))
123
124
125 #define MAX_ORDINALS  65535
126
127 /* global functions */
128
129 #ifndef __GNUC__
130 #define __attribute__(X)
131 #endif
132
133 extern void *xmalloc (size_t size);
134 extern void *xrealloc (void *ptr, size_t size);
135 extern char *xstrdup( const char *str );
136 extern char *strupper(char *s);
137 extern void fatal_error( const char *msg, ... )
138    __attribute__ ((__format__ (__printf__, 1, 2)));
139 extern void fatal_perror( const char *msg, ... )
140    __attribute__ ((__format__ (__printf__, 1, 2)));
141 extern void error( const char *msg, ... )
142    __attribute__ ((__format__ (__printf__, 1, 2)));
143 extern void warning( const char *msg, ... )
144    __attribute__ ((__format__ (__printf__, 1, 2)));
145 extern void output_standard_file_header( FILE *outfile );
146 extern FILE *open_input_file( const char *srcdir, const char *name );
147 extern void close_input_file( FILE *file );
148 extern void dump_bytes( FILE *outfile, const unsigned char *data, int len,
149                         const char *label, int constant );
150 extern const char *make_c_identifier( const char *str );
151 extern int get_alignment(int alignBoundary);
152
153 extern void add_import_dll( const char *name, int delay );
154 extern void add_ignore_symbol( const char *name );
155 extern void read_undef_symbols( char **argv );
156 extern int resolve_imports( void );
157 extern int output_imports( FILE *outfile );
158 extern int load_res32_file( const char *name );
159 extern int output_resources( FILE *outfile );
160 extern void load_res16_file( const char *name );
161 extern int output_res16_data( FILE *outfile );
162 extern int output_res16_directory( unsigned char *buffer );
163 extern void output_dll_init( FILE *outfile, const char *constructor, const char *destructor );
164 extern int parse_debug_channels( const char *srcdir, const char *filename );
165
166 extern void BuildRelays16( FILE *outfile );
167 extern void BuildRelays32( FILE *outfile );
168 extern void BuildSpec16File( FILE *outfile );
169 extern void BuildSpec32File( FILE *outfile );
170 extern void BuildDef32File( FILE *outfile );
171 extern void BuildDebugFile( FILE *outfile, const char *srcdir, char **argv );
172 extern int ParseTopLevel( FILE *file );
173
174 /* global variables */
175
176 extern int current_line;
177 extern int nb_entry_points;
178 extern int nb_names;
179 extern int Base;
180 extern int Limit;
181 extern int DLLHeapSize;
182 extern int UsePIC;
183 extern int debugging;
184 extern int stack_size;
185 extern int nb_debug_channels;
186 extern int nb_lib_paths;
187 extern int nb_errors;
188 extern int display_warnings;
189 extern int kill_at;
190
191 extern char *owner_name;
192 extern char *dll_name;
193 extern char *dll_file_name;
194 extern const char *init_func;
195 extern char *input_file_name;
196 extern const char *output_file_name;
197 extern char **debug_channels;
198 extern char **lib_path;
199
200 extern ORDDEF *EntryPoints[MAX_ORDINALS];
201 extern ORDDEF *Ordinals[MAX_ORDINALS];
202 extern ORDDEF *Names[MAX_ORDINALS];
203 extern SPEC_MODE SpecMode;
204 extern SPEC_TYPE SpecType;
205
206 #endif  /* __WINE_BUILD_H */