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