Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winebuild/build.h
4389 views
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21
*/
22
23
#ifndef __WINE_BUILD_H
24
#define __WINE_BUILD_H
25
26
#include <stdio.h>
27
#include <stdlib.h>
28
#include "../tools.h"
29
30
typedef enum
31
{
32
TYPE_VARIABLE, /* variable */
33
TYPE_PASCAL, /* pascal function (Win16) */
34
TYPE_ABS, /* absolute value (Win16) */
35
TYPE_STUB, /* unimplemented stub */
36
TYPE_STDCALL, /* stdcall function (Win32) */
37
TYPE_CDECL, /* cdecl function (Win32) */
38
TYPE_VARARGS, /* varargs function (Win32) */
39
TYPE_EXTERN, /* external symbol (Win32) */
40
TYPE_NBTYPES
41
} ORD_TYPE;
42
43
typedef enum
44
{
45
SPEC_WIN16,
46
SPEC_WIN32
47
} SPEC_TYPE;
48
49
enum arg_type
50
{
51
ARG_WORD, /* 16-bit word */
52
ARG_SWORD, /* 16-bit signed word */
53
ARG_SEGPTR, /* segmented pointer */
54
ARG_SEGSTR, /* segmented pointer to Ansi string */
55
ARG_LONG, /* long */
56
ARG_PTR, /* pointer */
57
ARG_STR, /* pointer to Ansi string */
58
ARG_WSTR, /* pointer to Unicode string */
59
ARG_INT64, /* 64-bit integer */
60
ARG_INT128, /* 128-bit integer */
61
ARG_FLOAT, /* 32-bit float */
62
ARG_DOUBLE, /* 64-bit float */
63
ARG_MAXARG = ARG_DOUBLE
64
};
65
66
#define MAX_ARGUMENTS 32
67
68
typedef struct
69
{
70
int n_values;
71
unsigned int *values;
72
} ORD_VARIABLE;
73
74
typedef struct
75
{
76
int nb_args;
77
int args_str_offset;
78
enum arg_type args[MAX_ARGUMENTS];
79
} ORD_FUNCTION;
80
81
typedef struct
82
{
83
unsigned short value;
84
} ORD_ABS;
85
86
typedef struct
87
{
88
ORD_TYPE type;
89
int ordinal;
90
int hint;
91
int lineno;
92
int flags;
93
char *name; /* public name of this function */
94
char *link_name; /* name of the C symbol to link to */
95
char *export_name; /* name exported under for noname exports */
96
union
97
{
98
ORD_VARIABLE var;
99
ORD_FUNCTION func;
100
ORD_ABS abs;
101
} u;
102
} ORDDEF;
103
104
struct apiset_entry
105
{
106
unsigned int name_off;
107
unsigned int name_len;
108
unsigned int hash;
109
unsigned int hash_len;
110
unsigned int val_count;
111
struct apiset_value
112
{
113
unsigned int name_off;
114
unsigned int name_len;
115
unsigned int val_off;
116
unsigned int val_len;
117
} values[4];
118
};
119
120
struct apiset
121
{
122
unsigned int count;
123
unsigned int size;
124
struct apiset_entry *entries;
125
unsigned int str_pos;
126
unsigned int str_size;
127
char *strings;
128
};
129
130
static const unsigned int apiset_hash_factor = 31;
131
132
struct exports
133
{
134
int nb_entry_points; /* number of used entry points */
135
ORDDEF **entry_points; /* dll entry points */
136
int nb_names; /* number of entry points with names */
137
ORDDEF **names; /* array of entry point names (points into entry_points) */
138
int base; /* ordinal base */
139
int limit; /* ordinal limit */
140
ORDDEF **ordinals; /* array of dll ordinals (points into entry_points) */
141
};
142
143
typedef struct
144
{
145
char *src_name; /* file name of the source spec file */
146
char *file_name; /* file name of the dll */
147
char *dll_name; /* internal name of the dll */
148
char *c_name; /* internal name of the dll, as a C-compatible identifier */
149
char *init_func; /* initialization routine */
150
char *main_module; /* main Win32 module for Win16 specs */
151
SPEC_TYPE type; /* type of dll (Win16/Win32) */
152
int stack_size; /* exe stack size */
153
int heap_size; /* exe heap size */
154
int nb_entry_points; /* number of used entry points */
155
int alloc_entry_points; /* number of allocated entry points */
156
unsigned int nb_resources; /* number of resources */
157
int characteristics; /* characteristics for the PE header */
158
int dll_characteristics;/* DLL characteristics for the PE header */
159
int subsystem; /* subsystem id */
160
int subsystem_major; /* subsystem version major number */
161
int subsystem_minor; /* subsystem version minor number */
162
int unicode_app; /* default to unicode entry point */
163
ORDDEF *entry_points; /* spec entry points */
164
struct exports exports; /* dll exports */
165
struct exports native_exports; /* dll native exports */
166
struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
167
struct apiset apiset; /* list of defined api sets */
168
} DLLSPEC;
169
170
extern char *target_alias;
171
extern struct target target;
172
173
static inline unsigned int get_ptr_size(void)
174
{
175
return get_target_ptr_size( target );
176
}
177
178
static inline int is_pe(void)
179
{
180
return is_pe_target( target );
181
}
182
183
/* entry point flags */
184
#define FLAG_NORELAY 0x0001 /* don't use relay debugging for this function */
185
#define FLAG_NONAME 0x0002 /* don't export function by name */
186
#define FLAG_RET16 0x0004 /* function returns a 16-bit value */
187
#define FLAG_RET64 0x0008 /* function returns a 64-bit value */
188
#define FLAG_REGISTER 0x0010 /* use register calling convention */
189
#define FLAG_PRIVATE 0x0020 /* function is private (cannot be imported) */
190
#define FLAG_ORDINAL 0x0040 /* function should be imported by ordinal */
191
#define FLAG_THISCALL 0x0080 /* function uses thiscall calling convention */
192
#define FLAG_FASTCALL 0x0100 /* function uses fastcall calling convention */
193
#define FLAG_SYSCALL 0x0200 /* function is a system call */
194
#define FLAG_IMPORT 0x0400 /* export is imported from another module */
195
196
#define FLAG_FORWARD 0x1000 /* function is a forwarded name */
197
#define FLAG_EXT_LINK 0x2000 /* function links to an external symbol */
198
#define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
199
200
#define FLAG_CPU(cpu) (0x10000 << (cpu))
201
#define FLAG_CPU_MASK (FLAG_CPU_WIN32 | FLAG_CPU_WIN64)
202
#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64) | FLAG_CPU(CPU_ARM64EC))
203
#define FLAG_CPU_WIN32 (FLAG_CPU(CPU_i386) | FLAG_CPU(CPU_ARM))
204
205
#define MAX_ORDINALS 65535
206
207
/* some Windows constants */
208
209
#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* No relocation info */
210
#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
211
#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
212
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
213
#define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
214
#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
215
#define IMAGE_FILE_16BIT_MACHINE 0x0040
216
#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
217
#define IMAGE_FILE_32BIT_MACHINE 0x0100
218
#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
219
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
220
#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
221
#define IMAGE_FILE_SYSTEM 0x1000
222
#define IMAGE_FILE_DLL 0x2000
223
#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
224
#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
225
226
#define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
227
#define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020
228
#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040
229
#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080
230
#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
231
#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
232
#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
233
#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
234
#define IMAGE_DLLCHARACTERISTICS_APPCONTAINER 0x1000
235
#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
236
#define IMAGE_DLLCHARACTERISTICS_GUARD_CF 0x4000
237
#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
238
239
#define IMAGE_SUBSYSTEM_NATIVE 1
240
#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
241
#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
242
#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
243
244
/* global functions */
245
246
#ifndef DECLSPEC_NORETURN
247
# if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
248
# define DECLSPEC_NORETURN __declspec(noreturn)
249
# else
250
# define DECLSPEC_NORETURN __attribute__((noreturn))
251
# endif
252
#endif
253
extern char *strupper(char *s);
254
extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
255
__attribute__ ((__format__ (__printf__, 1, 2)));
256
extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
257
__attribute__ ((__format__ (__printf__, 1, 2)));
258
extern void error( const char *msg, ... )
259
__attribute__ ((__format__ (__printf__, 1, 2)));
260
extern void warning( const char *msg, ... )
261
__attribute__ ((__format__ (__printf__, 1, 2)));
262
extern int output( const char *format, ... )
263
__attribute__ ((__format__ (__printf__, 1, 2)));
264
extern void output_cfi( const char *format, ... )
265
__attribute__ ((__format__ (__printf__, 1, 2)));
266
extern void output_seh( const char *format, ... )
267
__attribute__ ((__format__ (__printf__, 1, 2)));
268
extern void output_rva( const char *format, ... )
269
__attribute__ ((__format__ (__printf__, 1, 2)));
270
extern void output_thunk_rva( int ordinal, const char *format, ... )
271
__attribute__ ((__format__ (__printf__, 2, 3)));
272
extern void spawn( struct strarray array );
273
extern struct strarray find_tool( const char *name, const char * const *names );
274
extern struct strarray find_link_tool(void);
275
extern struct strarray get_as_command(void);
276
extern struct strarray get_ld_command(void);
277
extern const char *get_nm_command(void);
278
extern void output_standard_file_header(void);
279
extern FILE *open_input_file( const char *srcdir, const char *name );
280
extern void close_input_file( FILE *file );
281
extern void open_output_file(void);
282
extern void close_output_file(void);
283
extern char *open_temp_output_file( const char *suffix );
284
extern void dump_bytes( const void *buffer, unsigned int size );
285
extern int remove_stdcall_decoration( char *name );
286
extern void assemble_file( const char *src_file, const char *obj_file );
287
extern DLLSPEC *alloc_dll_spec(void);
288
extern void free_dll_spec( DLLSPEC *spec );
289
extern char *make_c_identifier( const char *str );
290
extern const char *get_abi_name( const ORDDEF *odp, const char *name );
291
extern const char *get_link_name( const ORDDEF *odp );
292
extern int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) );
293
extern unsigned int get_section_alignment(void);
294
extern unsigned int get_args_size( const ORDDEF *odp );
295
extern const char *asm_name( const char *func );
296
extern const char *arm64_name( const char *func );
297
extern const char *asm_globl( const char *func );
298
extern const char *get_asm_ptr_keyword(void);
299
extern const char *get_asm_string_keyword(void);
300
extern const char *get_asm_export_section(void);
301
extern const char *get_asm_rodata_section(void);
302
extern const char *get_asm_rsrc_section(void);
303
extern const char *get_asm_string_section(void);
304
extern void output_function_header( const char *func, int global );
305
extern void output_function_size( const char *name );
306
extern void output_gnu_stack_note(void);
307
308
extern void add_delayed_import( const char *name );
309
extern void add_extra_ld_symbol( const char *name );
310
extern void add_spec_extra_ld_symbol( const char *name );
311
extern void read_undef_symbols( DLLSPEC *spec, struct strarray files );
312
extern void resolve_imports( DLLSPEC *spec );
313
extern int is_undefined( const char *name );
314
extern int has_imports(void);
315
extern int has_delay_imports(void);
316
extern void output_get_pc_thunk(void);
317
extern void output_module( DLLSPEC *spec );
318
extern void output_stubs( DLLSPEC *spec );
319
extern void output_imports( DLLSPEC *spec );
320
extern void output_import_lib( DLLSPEC *spec, struct strarray files );
321
extern void output_static_lib( const char *output_name, struct strarray files, int create );
322
extern void output_exports( DLLSPEC *spec );
323
extern int load_res32_file( const char *name, DLLSPEC *spec );
324
extern void output_resources( DLLSPEC *spec );
325
extern void output_bin_resources( DLLSPEC *spec, unsigned int start_rva );
326
extern void output_spec32_file( DLLSPEC *spec );
327
extern void output_fake_module( DLLSPEC *spec );
328
extern void output_data_module( DLLSPEC *spec );
329
extern void output_def_file( DLLSPEC *spec, struct exports *exports, int import_only );
330
extern void output_apiset_lib( DLLSPEC *spec, const struct apiset *apiset );
331
extern void load_res16_file( const char *name, DLLSPEC *spec );
332
extern void output_res16_data( DLLSPEC *spec );
333
extern void output_bin_res16_data( DLLSPEC *spec );
334
extern void output_res16_directory( DLLSPEC *spec );
335
extern void output_bin_res16_directory( DLLSPEC *spec, unsigned int data_offset );
336
extern void output_spec16_file( DLLSPEC *spec );
337
extern void output_fake_module16( DLLSPEC *spec16 );
338
extern void output_res_o_file( DLLSPEC *spec );
339
extern void output_asm_relays16(void);
340
extern void make_builtin_files( struct strarray files );
341
extern void fixup_constructors( struct strarray files );
342
343
extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
344
extern int parse_spec_file( FILE *file, DLLSPEC *spec );
345
extern int parse_def_file( FILE *file, DLLSPEC *spec );
346
347
/* buffer management */
348
349
extern int byte_swapped;
350
extern const char *input_buffer_filename;
351
extern const unsigned char *input_buffer;
352
extern size_t input_buffer_pos;
353
extern size_t input_buffer_size;
354
355
extern void init_input_buffer( const char *file );
356
extern unsigned char get_byte(void);
357
extern unsigned short get_word(void);
358
extern unsigned int get_dword(void);
359
extern void put_pword( unsigned int val );
360
361
/* global variables */
362
363
extern int current_line;
364
extern int UsePIC;
365
extern int nb_errors;
366
extern int display_warnings;
367
extern int kill_at;
368
extern int verbose;
369
extern int link_ext_symbols;
370
extern int force_pointer_size;
371
extern int unwind_tables;
372
extern int use_dlltool;
373
extern int use_msvcrt;
374
extern int native_arch;
375
extern int safe_seh;
376
extern int prefer_native;
377
extern int data_only;
378
379
extern char *input_file_name;
380
extern char *spec_file_name;
381
extern FILE *output_file;
382
extern const char *output_file_name;
383
384
extern struct strarray tools_path;
385
extern struct strarray as_command;
386
extern struct strarray cc_command;
387
extern struct strarray ld_command;
388
extern struct strarray nm_command;
389
extern char *cpu_option;
390
extern char *fpu_option;
391
extern char *arch_option;
392
extern int needs_get_pc_thunk;
393
394
#endif /* __WINE_BUILD_H */
395
396