Merge 14551:14980 from trunk
[reactos.git] / reactos / tools / winebuild / spec32.c
1 /*
2 * 32-bit spec files
3 *
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #include "config.h"
26
27 #include <assert.h>
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include <string.h>
31
32 #include "winglue.h"
33
34 #define EXCEPTION_WINE_STUB 0x80000100 /* stub entry point called */
35 #define EH_NONCONTINUABLE 0x01
36
37 #include "build.h"
38
39
40 #ifdef __APPLE__
41 # define __ASM_SKIP ".space"
42 #else
43 # define __ASM_SKIP ".skip"
44 #endif
45
46 static int string_compare( const void *ptr1, const void *ptr2 )
47 {
48 const char * const *str1 = ptr1;
49 const char * const *str2 = ptr2;
50 return strcmp( *str1, *str2 );
51 }
52
53
54 /*******************************************************************
55 * make_internal_name
56 *
57 * Generate an internal name for an entry point. Used for stubs etc.
58 */
59 static const char *make_internal_name( const ORDDEF *odp, DLLSPEC *spec, const char *prefix )
60 {
61 static char buffer[256];
62 if (odp->name || odp->export_name)
63 {
64 char *p;
65 sprintf( buffer, "__wine_%s_%s_%s", prefix, spec->file_name,
66 odp->name ? odp->name : odp->export_name );
67 /* make sure name is a legal C identifier */
68 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
69 if (!*p) return buffer;
70 }
71 sprintf( buffer, "__wine_%s_%s_%d", prefix, make_c_identifier(spec->file_name), odp->ordinal );
72 return buffer;
73 }
74
75 /*******************************************************************
76 * declare_weak_function
77 *
78 * Output a prototype for a weak function.
79 */
80 static void declare_weak_function( FILE *outfile, const char *ret_type, const char *name, const char *params)
81 {
82 fprintf( outfile, "#ifdef __GNUC__\n" );
83 fprintf( outfile, "# ifdef __APPLE__\n" );
84 fprintf( outfile, "extern %s %s(%s) __attribute__((weak_import));\n", ret_type, name, params );
85 fprintf( outfile, "static %s (*__wine_spec_weak_%s)(%s) = %s;\n", ret_type, name, params, name );
86 fprintf( outfile, "#define %s __wine_spec_weak_%s\n", name, name );
87 fprintf( outfile, "# else\n" );
88 fprintf( outfile, "extern %s %s(%s) __attribute__((weak));\n", ret_type, name, params );
89 fprintf( outfile, "# endif\n" );
90 fprintf( outfile, "#else\n" );
91 fprintf( outfile, "extern %s %s(%s);\n", ret_type, name, params );
92 fprintf( outfile, "static void __asm__dummy_%s(void)", name );
93 fprintf( outfile, " { asm(\".weak " __ASM_NAME("%s") "\"); }\n", name );
94 fprintf( outfile, "#endif\n\n" );
95 }
96
97
98 /*******************************************************************
99 * output_debug
100 *
101 * Output the debug channels.
102 */
103 static int output_debug( FILE *outfile )
104 {
105 int i;
106
107 if (!nb_debug_channels) return 0;
108 qsort( debug_channels, nb_debug_channels, sizeof(debug_channels[0]), string_compare );
109
110 for (i = 0; i < nb_debug_channels; i++)
111 fprintf( outfile, "char __wine_dbch_%s[] = \"\\003%s\";\n",
112 debug_channels[i], debug_channels[i] );
113
114 fprintf( outfile, "\nstatic char * const debug_channels[%d] =\n{\n", nb_debug_channels );
115 for (i = 0; i < nb_debug_channels; i++)
116 {
117 fprintf( outfile, " __wine_dbch_%s", debug_channels[i] );
118 if (i < nb_debug_channels - 1) fprintf( outfile, ",\n" );
119 }
120 fprintf( outfile, "\n};\n\n" );
121 fprintf( outfile, "static void *debug_registration;\n\n" );
122
123 return nb_debug_channels;
124 }
125
126
127 /*******************************************************************
128 * output_exports
129 *
130 * Output the export table for a Win32 module.
131 */
132 static int output_exports( FILE *outfile, int nr_exports, DLLSPEC *spec )
133 {
134 int i, fwd_size = 0, total_size = 0;
135
136 if (!nr_exports) return 0;
137
138 fprintf( outfile, "asm(\".data\\n\"\n" );
139 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
140 fprintf( outfile, " \"" __ASM_NAME("__wine_spec_exports") ":\\n\"\n" );
141
142 /* export directory header */
143
144 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* Characteristics */
145 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* TimeDateStamp */
146 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* MajorVersion/MinorVersion */
147 fprintf( outfile, " \"\\t.long __wine_spec_exp_names\\n\"\n" ); /* Name */
148 fprintf( outfile, " \"\\t.long %d\\n\"\n", spec->base ); /* Base */
149 fprintf( outfile, " \"\\t.long %d\\n\"\n", nr_exports ); /* NumberOfFunctions */
150 fprintf( outfile, " \"\\t.long %d\\n\"\n", spec->nb_names ); /* NumberOfNames */
151 fprintf( outfile, " \"\\t.long __wine_spec_exports_funcs\\n\"\n" ); /* AddressOfFunctions */
152 if (spec->nb_names)
153 {
154 fprintf( outfile, " \"\\t.long __wine_spec_exp_name_ptrs\\n\"\n" ); /* AddressOfNames */
155 fprintf( outfile, " \"\\t.long __wine_spec_exp_ordinals\\n\"\n" ); /* AddressOfNameOrdinals */
156 }
157 else
158 {
159 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* AddressOfNames */
160 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* AddressOfNameOrdinals */
161 }
162 total_size += 10 * sizeof(int);
163
164 /* output the function pointers */
165
166 fprintf( outfile, " \"__wine_spec_exports_funcs:\\n\"\n" );
167 for (i = spec->base; i <= spec->limit; i++)
168 {
169 ORDDEF *odp = spec->ordinals[i];
170 if (!odp) fprintf( outfile, " \"\\t.long 0\\n\"\n" );
171 else switch(odp->type)
172 {
173 case TYPE_EXTERN:
174 case TYPE_STDCALL:
175 case TYPE_VARARGS:
176 case TYPE_CDECL:
177 if (!(odp->flags & FLAG_FORWARD))
178 {
179 fprintf( outfile, " \"\\t.long " __ASM_NAME("%s") "\\n\"\n",
180 (odp->flags & FLAG_REGISTER) ? make_internal_name( odp, spec, "regs" )
181 : odp->link_name );
182 }
183 else
184 {
185 fprintf( outfile, " \"\\t.long __wine_spec_forwards+%d\\n\"\n", fwd_size );
186 fwd_size += strlen(odp->link_name) + 1;
187 }
188 break;
189 case TYPE_STUB:
190 fprintf( outfile, " \"\\t.long " __ASM_NAME("%s") "\\n\"\n",
191 make_internal_name( odp, spec, "stub" ) );
192 break;
193 default:
194 assert(0);
195 }
196 }
197 total_size += (spec->limit - spec->base + 1) * sizeof(int);
198
199 if (spec->nb_names)
200 {
201 /* output the function name pointers */
202
203 int namepos = strlen(spec->file_name) + 1;
204
205 fprintf( outfile, " \"__wine_spec_exp_name_ptrs:\\n\"\n" );
206 for (i = 0; i < spec->nb_names; i++)
207 {
208 fprintf( outfile, " \"\\t.long __wine_spec_exp_names+%d\\n\"\n", namepos );
209 namepos += strlen(spec->names[i]->name) + 1;
210 }
211 total_size += spec->nb_names * sizeof(int);
212 }
213
214 /* output the function names */
215
216 fprintf( outfile, " \"\\t.text\\n\"\n" );
217 fprintf( outfile, " \"__wine_spec_exp_names:\\n\"\n" );
218 fprintf( outfile, " \"\\t" __ASM_STRING " \\\"%s\\\"\\n\"\n", spec->file_name );
219 for (i = 0; i < spec->nb_names; i++)
220 fprintf( outfile, " \"\\t" __ASM_STRING " \\\"%s\\\"\\n\"\n", spec->names[i]->name );
221 fprintf( outfile, " \"\\t.data\\n\"\n" );
222
223 if (spec->nb_names)
224 {
225 /* output the function ordinals */
226
227 fprintf( outfile, " \"__wine_spec_exp_ordinals:\\n\"\n" );
228 for (i = 0; i < spec->nb_names; i++)
229 {
230 fprintf( outfile, " \"\\t" __ASM_SHORT " %d\\n\"\n",
231 spec->names[i]->ordinal - spec->base );
232 }
233 total_size += spec->nb_names * sizeof(short);
234 if (spec->nb_names % 2)
235 {
236 fprintf( outfile, " \"\\t" __ASM_SHORT " 0\\n\"\n" );
237 total_size += sizeof(short);
238 }
239 }
240
241 /* output forward strings */
242
243 if (fwd_size)
244 {
245 fprintf( outfile, " \"__wine_spec_forwards:\\n\"\n" );
246 for (i = spec->base; i <= spec->limit; i++)
247 {
248 ORDDEF *odp = spec->ordinals[i];
249 if (odp && (odp->flags & FLAG_FORWARD))
250 fprintf( outfile, " \"\\t" __ASM_STRING " \\\"%s\\\"\\n\"\n", odp->link_name );
251 }
252 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
253 total_size += (fwd_size + 3) & ~3;
254 }
255
256 /* output relays */
257
258 if (debugging)
259 {
260 for (i = spec->base; i <= spec->limit; i++)
261 {
262 ORDDEF *odp = spec->ordinals[i];
263 unsigned int j, args, mask = 0;
264 const char *name;
265
266 /* skip nonexistent entry points */
267 if (!odp) goto ignore;
268 /* skip non-functions */
269 if ((odp->type != TYPE_STDCALL) && (odp->type != TYPE_CDECL)) goto ignore;
270 /* skip norelay and forward entry points */
271 if (odp->flags & (FLAG_NORELAY|FLAG_FORWARD)) goto ignore;
272
273 for (j = 0; odp->u.func.arg_types[j]; j++)
274 {
275 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
276 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
277 }
278 if ((odp->flags & FLAG_RET64) && (j < 16)) mask |= 0x80000000;
279
280 name = odp->link_name;
281 args = strlen(odp->u.func.arg_types) * sizeof(int);
282 if (odp->flags & FLAG_REGISTER) name = make_internal_name( odp, spec, "regs" );
283
284 switch(odp->type)
285 {
286 case TYPE_STDCALL:
287 fprintf( outfile, " \"\\tjmp " __ASM_NAME("%s") "\\n\"\n", name );
288 fprintf( outfile, " \"\\tret $%d\\n\"\n", args );
289 fprintf( outfile, " \"\\t.long " __ASM_NAME("%s") ",0x%08x\\n\"\n", name, mask );
290 break;
291 case TYPE_CDECL:
292 fprintf( outfile, " \"\\tjmp " __ASM_NAME("%s") "\\n\"\n", name );
293 fprintf( outfile, " \"\\tret\\n\"\n" );
294 fprintf( outfile, " \"\\t" __ASM_SHORT " %d\\n\"\n", args );
295 fprintf( outfile, " \"\\t.long " __ASM_NAME("%s") ",0x%08x\\n\"\n", name, mask );
296 break;
297 default:
298 assert(0);
299 }
300 continue;
301
302 ignore:
303 fprintf( outfile, " \"\\t.long 0,0,0,0\\n\"\n" );
304 }
305 }
306
307 fprintf( outfile, " \"\\t.text\\n\"\n" );
308 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
309 fprintf( outfile, ");\n\n" );
310
311 return total_size;
312 }
313
314
315 /*******************************************************************
316 * output_stub_funcs
317 *
318 * Output the functions for stub entry points
319 */
320 static void output_stub_funcs( FILE *outfile, DLLSPEC *spec )
321 {
322 int i;
323
324 for (i = 0; i < spec->nb_entry_points; i++)
325 {
326 ORDDEF *odp = &spec->entry_points[i];
327 if (odp->type != TYPE_STUB) continue;
328 fprintf( outfile, "#ifdef __GNUC__\n" );
329 fprintf( outfile, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
330 fprintf( outfile, "#endif\n\n" );
331 fprintf( outfile, "struct exc_record {\n" );
332 fprintf( outfile, " unsigned int code, flags;\n" );
333 fprintf( outfile, " void *rec, *addr;\n" );
334 fprintf( outfile, " unsigned int params;\n" );
335 fprintf( outfile, " const void *info[15];\n" );
336 fprintf( outfile, "};\n\n" );
337 fprintf( outfile, "extern void __stdcall RtlRaiseException( struct exc_record * );\n\n" );
338 fprintf( outfile, "static void __wine_unimplemented( const char *func )\n{\n" );
339 fprintf( outfile, " struct exc_record rec;\n" );
340 fprintf( outfile, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB );
341 fprintf( outfile, " rec.flags = %d;\n", EH_NONCONTINUABLE );
342 fprintf( outfile, " rec.rec = 0;\n" );
343 fprintf( outfile, " rec.params = 2;\n" );
344 fprintf( outfile, " rec.info[0] = \"%s\";\n", spec->file_name );
345 fprintf( outfile, " rec.info[1] = func;\n" );
346 fprintf( outfile, "#ifdef __GNUC__\n" );
347 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
348 fprintf( outfile, "#else\n" );
349 fprintf( outfile, " rec.addr = 0;\n" );
350 fprintf( outfile, "#endif\n" );
351 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
352 break;
353 }
354
355 for (i = 0; i < spec->nb_entry_points; i++)
356 {
357 const ORDDEF *odp = &spec->entry_points[i];
358 if (odp->type != TYPE_STUB) continue;
359 fprintf( outfile, "void %s(void) ", make_internal_name( odp, spec, "stub" ) );
360 if (odp->name)
361 fprintf( outfile, "{ __wine_unimplemented(\"%s\"); }\n", odp->name );
362 else if (odp->export_name)
363 fprintf( outfile, "{ __wine_unimplemented(\"%s\"); }\n", odp->export_name );
364 else
365 fprintf( outfile, "{ __wine_unimplemented(\"%d\"); }\n", odp->ordinal );
366 }
367 }
368
369
370 /*******************************************************************
371 * output_register_funcs
372 *
373 * Output the functions for register entry points
374 */
375 static void output_register_funcs( FILE *outfile, DLLSPEC *spec )
376 {
377 const char *name;
378 int i;
379
380 for (i = 0; i < spec->nb_entry_points; i++)
381 {
382 const ORDDEF *odp = &spec->entry_points[i];
383 if (odp->type != TYPE_STDCALL && odp->type != TYPE_CDECL) continue;
384 if (!(odp->flags & FLAG_REGISTER)) continue;
385 if (odp->flags & FLAG_FORWARD) continue;
386 name = make_internal_name( odp, spec, "regs" );
387 fprintf( outfile,
388 "asm(\".align %d\\n\\t\"\n"
389 " \"" __ASM_FUNC("%s") "\\n\\t\"\n"
390 " \"" __ASM_NAME("%s") ":\\n\\t\"\n"
391 " \"call " __ASM_NAME("__wine_call_from_32_regs") "\\n\\t\"\n"
392 " \".long " __ASM_NAME("%s") "\\n\\t\"\n"
393 " \".byte %d,%d\");\n",
394 get_alignment(4),
395 name, name, odp->link_name,
396 strlen(odp->u.func.arg_types) * sizeof(int),
397 (odp->type == TYPE_CDECL) ? 0 : (strlen(odp->u.func.arg_types) * sizeof(int)) );
398 }
399 }
400
401
402 /*******************************************************************
403 * output_dll_init
404 *
405 * Output code for calling a dll constructor and destructor.
406 */
407 void output_dll_init( FILE *outfile, const char *constructor, const char *destructor )
408 {
409 fprintf( outfile, "#ifndef __GNUC__\n" );
410 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
411 fprintf( outfile, "#endif\n" );
412
413 #if defined(__i386__)
414 if (constructor)
415 {
416 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
417 fprintf( outfile, " \"\\tcall " __ASM_NAME("%s") "\\n\"\n", constructor );
418 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
419 }
420 if (destructor)
421 {
422 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
423 fprintf( outfile, " \"\\tcall " __ASM_NAME("%s") "\\n\"\n", destructor );
424 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
425 }
426 #elif defined(__sparc__)
427 if (constructor)
428 {
429 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
430 fprintf( outfile, " \"\\tcall " __ASM_NAME("%s") "\\n\"\n", constructor );
431 fprintf( outfile, " \"\\tnop\\n\"\n" );
432 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
433 }
434 if (destructor)
435 {
436 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
437 fprintf( outfile, " \"\\tcall " __ASM_NAME("%s") "\\n\"\n", destructor );
438 fprintf( outfile, " \"\\tnop\\n\"\n" );
439 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
440 }
441 #elif defined(__powerpc__)
442 # ifdef __APPLE__
443 /* Mach-O doesn't have an init section */
444 if (constructor)
445 {
446 fprintf( outfile, "asm(\"\\t.mod_init_func\\n\"\n" );
447 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
448 fprintf( outfile, " \"\\t.long " __ASM_NAME("%s") "\\n\"\n", constructor );
449 fprintf( outfile, " \"\\t.text\\n\");\n" );
450 }
451 if (destructor)
452 {
453 fprintf( outfile, "asm(\"\\t.mod_term_func\\n\"\n" );
454 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
455 fprintf( outfile, " \"\\t.long " __ASM_NAME("%s") "\\n\"\n", destructor );
456 fprintf( outfile, " \"\\t.text\\n\");\n" );
457 }
458 # else /* __APPLE__ */
459 if (constructor)
460 {
461 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
462 fprintf( outfile, " \"\\tbl " __ASM_NAME("%s") "\\n\"\n", constructor );
463 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
464 }
465 if (destructor)
466 {
467 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
468 fprintf( outfile, " \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor );
469 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
470 }
471 # endif /* __APPLE__ */
472 #elif defined(__ALPHA__)
473 if (constructor)
474 {
475 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
476 fprintf( outfile, " \"\\tjsr $26," __ASM_NAME("%s") "\\n\"\n", constructor );
477 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
478 }
479 if (destructor)
480 {
481 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
482 fprintf( outfile, " \"\\tjsr $26," __ASM_NAME("%s") "\\n\"\n", destructor );
483 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
484 }
485 #else
486 #error You need to define the DLL constructor for your architecture
487 #endif
488 fprintf( outfile, "#ifndef __GNUC__\n" );
489 fprintf( outfile, "}\n" );
490 fprintf( outfile, "#endif\n" );
491 }
492
493
494 /*******************************************************************
495 * BuildSpec32File
496 *
497 * Build a Win32 C file from a spec file.
498 */
499 void BuildSpec32File( FILE *outfile, DLLSPEC *spec )
500 {
501 int exports_size = 0;
502 int nr_exports, nr_imports;
503 DWORD page_size;
504 const char *init_func = spec->init_func;
505
506 #ifdef HAVE_GETPAGESIZE
507 page_size = getpagesize();
508 #elif defined(__svr4__)
509 page_size = sysconf(_SC_PAGESIZE);
510 #elif defined(_WINDOWS)
511 {
512 SYSTEM_INFO si;
513 GetSystemInfo(&si);
514 page_size = si.dwPageSize;
515 }
516 #else
517 # error Cannot get the page size on this platform
518 #endif
519
520 nr_exports = spec->base <= spec->limit ? spec->limit - spec->base + 1 : 0;
521 resolve_imports( spec );
522 output_standard_file_header( outfile );
523
524 /* Reserve some space for the PE header */
525
526 fprintf( outfile, "extern char __wine_spec_pe_header[];\n" );
527 fprintf( outfile, "#ifndef __GNUC__\n" );
528 fprintf( outfile, "static void __asm__dummy_header(void) {\n" );
529 fprintf( outfile, "#endif\n" );
530 fprintf( outfile, "asm(\".text\\n\\t\"\n" );
531 fprintf( outfile, " \".align %d\\n\"\n", get_alignment(page_size) );
532 fprintf( outfile, " \"" __ASM_NAME("__wine_spec_pe_header") ":\\t" __ASM_SKIP " 65536\\n\\t\"\n" );
533 fprintf( outfile, " \".data\\n\\t\"\n" );
534 fprintf( outfile, " \".align %d\\n\"\n", get_alignment(4) );
535 fprintf( outfile, " \"" __ASM_NAME("__wine_spec_data_start") ":\\t.long 1\");\n" );
536 fprintf( outfile, "#ifndef __GNUC__\n" );
537 fprintf( outfile, "}\n" );
538 fprintf( outfile, "#endif\n" );
539
540 #ifdef __APPLE__
541 fprintf( outfile, "static char _end[4];\n" );
542 #else
543 fprintf( outfile, "extern char _end[];\n" );
544 #endif
545
546 fprintf( outfile, "extern int __wine_spec_data_start[], __wine_spec_exports[];\n\n" );
547
548 #ifdef __i386__
549 fprintf( outfile, "#define __stdcall __attribute__((__stdcall__))\n\n" );
550 #else
551 fprintf( outfile, "#define __stdcall\n\n" );
552 #endif
553
554 if (nr_exports)
555 {
556 /* Output the stub functions */
557
558 output_stub_funcs( outfile, spec );
559
560 fprintf( outfile, "#ifndef __GNUC__\n" );
561 fprintf( outfile, "static void __asm__dummy(void) {\n" );
562 fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
563
564 /* Output code for all register functions */
565
566 output_register_funcs( outfile, spec );
567
568 /* Output the exports and relay entry points */
569
570 exports_size = output_exports( outfile, nr_exports, spec );
571
572 fprintf( outfile, "#ifndef __GNUC__\n" );
573 fprintf( outfile, "}\n" );
574 fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
575 }
576
577 /* Output the DLL imports */
578
579 nr_imports = output_imports( outfile, spec );
580
581 /* Output the resources */
582
583 output_resources( outfile, spec );
584
585 /* Output the entry point function */
586
587 fprintf( outfile, "static int __wine_spec_init_state;\n" );
588 fprintf( outfile, "extern int __wine_main_argc;\n" );
589 fprintf( outfile, "extern char **__wine_main_argv;\n" );
590 fprintf( outfile, "extern char **__wine_main_environ;\n" );
591 fprintf( outfile, "extern unsigned short **__wine_main_wargv;\n" );
592 #ifdef __APPLE__
593 fprintf( outfile, "extern _dyld_func_lookup(char *, void *);" );
594 fprintf( outfile, "static void __wine_spec_hidden_init(int argc, char** argv, char** envp)\n" );
595 fprintf( outfile, "{\n" );
596 fprintf( outfile, " void (*init)(void);\n" );
597 fprintf( outfile, " _dyld_func_lookup(\"__dyld_make_delayed_module_initializer_calls\", (unsigned long *)&init);\n" );
598 fprintf( outfile, " init();\n" );
599 fprintf( outfile, "}\n" );
600 fprintf( outfile, "static void __wine_spec_hidden_fini()\n" );
601 fprintf( outfile, "{\n" );
602 fprintf( outfile, " void (*fini)(void);\n" );
603 fprintf( outfile, " _dyld_func_lookup(\"__dyld_mod_term_funcs\", (unsigned long *)&fini);\n" );
604 fprintf( outfile, " fini();\n" );
605 fprintf( outfile, "}\n" );
606 fprintf( outfile, "#define _init __wine_spec_hidden_init\n" );
607 fprintf( outfile, "#define _fini __wine_spec_hidden_fini\n" );
608 #else
609 fprintf( outfile, "extern void _init(int, char**, char**);\n" );
610 fprintf( outfile, "extern void _fini();\n" );
611 #endif
612
613 if (spec->characteristics & IMAGE_FILE_DLL)
614 {
615 if (init_func)
616 fprintf( outfile, "extern int __stdcall %s( void*, unsigned int, void* );\n\n", init_func );
617 else
618 {
619 declare_weak_function( outfile, "int __stdcall", "DllMain", "void*, unsigned int, void*" );
620 init_func = "DllMain";
621 }
622 fprintf( outfile,
623 "static int __stdcall __wine_dll_main( void *inst, unsigned int reason, void *reserved )\n"
624 "{\n"
625 " int ret;\n"
626 " if (reason == %d && __wine_spec_init_state == 1)\n"
627 " _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
628 " ret = %s ? %s( inst, reason, reserved ) : 1;\n"
629 " if (reason == %d && __wine_spec_init_state == 1) _fini();\n"
630 " return ret;\n"
631 "}\n",
632 DLL_PROCESS_ATTACH, init_func, init_func, DLL_PROCESS_DETACH );
633 init_func = "__wine_dll_main";
634 }
635 else switch(spec->subsystem)
636 {
637 case IMAGE_SUBSYSTEM_NATIVE:
638 if (init_func)
639 fprintf( outfile, "extern int __stdcall %s( void*, void* );\n\n", init_func );
640 else
641 {
642 declare_weak_function( outfile, "int __stdcall", "DriverEntry", "void*, void*");
643 init_func = "DriverEntry";
644 }
645 fprintf( outfile,
646 "static int __stdcall __wine_driver_entry( void *obj, void *path )\n"
647 "{\n"
648 " int ret;\n"
649 " if (__wine_spec_init_state == 1)\n"
650 " _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
651 " ret = %s ? %s( obj, path ) : 0;\n"
652 " if (__wine_spec_init_state == 1) _fini();\n"
653 " return ret;\n"
654 "}\n",
655 init_func, init_func );
656 init_func = "__wine_driver_entry";
657 break;
658 case IMAGE_SUBSYSTEM_WINDOWS_GUI:
659 case IMAGE_SUBSYSTEM_WINDOWS_CUI:
660 if (init_func)
661 fprintf( outfile, "extern int %s( int argc, char *argv[] );\n", init_func );
662 else
663 {
664 declare_weak_function( outfile, "int", "main", "int argc, char *argv[]" );
665 declare_weak_function( outfile, "int", "wmain", "int argc, unsigned short *argv[]" );
666 declare_weak_function( outfile, "int __stdcall", "WinMain", "void *,void *,char *,int" );
667 }
668 fprintf( outfile,
669 "\ntypedef struct {\n"
670 " unsigned int cb;\n"
671 " char *lpReserved, *lpDesktop, *lpTitle;\n"
672 " unsigned int dwX, dwY, dwXSize, dwYSize;\n"
673 " unsigned int dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;\n"
674 " unsigned short wShowWindow, cbReserved2;\n"
675 " char *lpReserved2;\n"
676 " void *hStdInput, *hStdOutput, *hStdError;\n"
677 "} STARTUPINFOA;\n"
678 "extern char * __stdcall GetCommandLineA(void);\n"
679 "extern void * __stdcall GetModuleHandleA(char *);\n"
680 "extern void __stdcall GetStartupInfoA(STARTUPINFOA *);\n"
681 "extern void __stdcall ExitProcess(unsigned int);\n"
682 "static void __wine_exe_main(void)\n"
683 "{\n"
684 " int ret;\n"
685 " if (__wine_spec_init_state == 1)\n"
686 " _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n" );
687 if (init_func)
688 fprintf( outfile,
689 " ret = %s( __wine_main_argc, __wine_main_argv );\n", init_func );
690 else
691 fprintf( outfile,
692 " if (WinMain) {\n"
693 " STARTUPINFOA info;\n"
694 " char *cmdline = GetCommandLineA();\n"
695 " int bcount=0, in_quotes=0;\n"
696 " while (*cmdline) {\n"
697 " if ((*cmdline=='\\t' || *cmdline==' ') && !in_quotes) break;\n"
698 " else if (*cmdline=='\\\\') bcount++;\n"
699 " else if (*cmdline=='\\\"') {\n"
700 " if ((bcount & 1)==0) in_quotes=!in_quotes;\n"
701 " bcount=0;\n"
702 " }\n"
703 " else bcount=0;\n"
704 " cmdline++;\n"
705 " }\n"
706 " while (*cmdline=='\\t' || *cmdline==' ') cmdline++;\n"
707 " GetStartupInfoA( &info );\n"
708 " if (!(info.dwFlags & 1)) info.wShowWindow = 1;\n"
709 " ret = WinMain( GetModuleHandleA(0), 0, cmdline, info.wShowWindow );\n"
710 " }\n"
711 " else if (wmain) ret = wmain( __wine_main_argc, __wine_main_wargv );\n"
712 " else ret = main( __wine_main_argc, __wine_main_argv );\n" );
713 fprintf( outfile,
714 " if (__wine_spec_init_state == 1) _fini();\n"
715 " ExitProcess( ret );\n"
716 "}\n\n" );
717 init_func = "__wine_exe_main";
718 break;
719 }
720
721 /* Output the NT header */
722
723 /* this is the IMAGE_NT_HEADERS structure, but we cannot include winnt.h here */
724 fprintf( outfile, "static const struct image_nt_headers\n{\n" );
725 fprintf( outfile, " int Signature;\n" );
726 fprintf( outfile, " struct file_header {\n" );
727 fprintf( outfile, " short Machine;\n" );
728 fprintf( outfile, " short NumberOfSections;\n" );
729 fprintf( outfile, " int TimeDateStamp;\n" );
730 fprintf( outfile, " void *PointerToSymbolTable;\n" );
731 fprintf( outfile, " int NumberOfSymbols;\n" );
732 fprintf( outfile, " short SizeOfOptionalHeader;\n" );
733 fprintf( outfile, " short Characteristics;\n" );
734 fprintf( outfile, " } FileHeader;\n" );
735 fprintf( outfile, " struct opt_header {\n" );
736 fprintf( outfile, " short Magic;\n" );
737 fprintf( outfile, " char MajorLinkerVersion, MinorLinkerVersion;\n" );
738 fprintf( outfile, " int SizeOfCode;\n" );
739 fprintf( outfile, " int SizeOfInitializedData;\n" );
740 fprintf( outfile, " int SizeOfUninitializedData;\n" );
741 fprintf( outfile, " void *AddressOfEntryPoint;\n" );
742 fprintf( outfile, " void *BaseOfCode;\n" );
743 fprintf( outfile, " void *BaseOfData;\n" );
744 fprintf( outfile, " void *ImageBase;\n" );
745 fprintf( outfile, " int SectionAlignment;\n" );
746 fprintf( outfile, " int FileAlignment;\n" );
747 fprintf( outfile, " short MajorOperatingSystemVersion;\n" );
748 fprintf( outfile, " short MinorOperatingSystemVersion;\n" );
749 fprintf( outfile, " short MajorImageVersion;\n" );
750 fprintf( outfile, " short MinorImageVersion;\n" );
751 fprintf( outfile, " short MajorSubsystemVersion;\n" );
752 fprintf( outfile, " short MinorSubsystemVersion;\n" );
753 fprintf( outfile, " int Win32VersionValue;\n" );
754 fprintf( outfile, " void *SizeOfImage;\n" );
755 fprintf( outfile, " int SizeOfHeaders;\n" );
756 fprintf( outfile, " int CheckSum;\n" );
757 fprintf( outfile, " short Subsystem;\n" );
758 fprintf( outfile, " short DllCharacteristics;\n" );
759 fprintf( outfile, " int SizeOfStackReserve;\n" );
760 fprintf( outfile, " int SizeOfStackCommit;\n" );
761 fprintf( outfile, " int SizeOfHeapReserve;\n" );
762 fprintf( outfile, " int SizeOfHeapCommit;\n" );
763 fprintf( outfile, " int LoaderFlags;\n" );
764 fprintf( outfile, " int NumberOfRvaAndSizes;\n" );
765 fprintf( outfile, " struct { const void *VirtualAddress; int Size; } DataDirectory[%d];\n",
766 IMAGE_NUMBEROF_DIRECTORY_ENTRIES );
767 fprintf( outfile, " } OptionalHeader;\n" );
768 fprintf( outfile, "} nt_header = {\n" );
769 fprintf( outfile, " 0x%04x,\n", IMAGE_NT_SIGNATURE ); /* Signature */
770 #ifdef __i386__
771 fprintf( outfile, " { 0x%04x,\n", IMAGE_FILE_MACHINE_I386 ); /* Machine */
772 #elif defined(__powerpc__)
773 fprintf( outfile, " { 0x%04x,\n", IMAGE_FILE_MACHINE_POWERPC ); /* Machine */
774 #elif defined(__ALPHA__)
775 fprintf( outfile, " { 0x%04x,\n", IMAGE_FILE_MACHINE_ALPHA ); /* Machine */
776 #else
777 fprintf( outfile, " { 0x%04x,\n", IMAGE_FILE_MACHINE_UNKNOWN ); /* Machine */
778 #endif
779 fprintf( outfile, " 0, 0, 0, 0,\n" );
780 fprintf( outfile, " sizeof(nt_header.OptionalHeader),\n" ); /* SizeOfOptionalHeader */
781 fprintf( outfile, " 0x%04x },\n", spec->characteristics ); /* Characteristics */
782
783 fprintf( outfile, " { 0x%04x,\n", IMAGE_NT_OPTIONAL_HDR_MAGIC ); /* Magic */
784 fprintf( outfile, " 0, 0,\n" ); /* Major/MinorLinkerVersion */
785 fprintf( outfile, " 0, 0, 0,\n" ); /* SizeOfCode/Data */
786 fprintf( outfile, " %s,\n", init_func ); /* AddressOfEntryPoint */
787 fprintf( outfile, " 0, __wine_spec_data_start,\n" ); /* BaseOfCode/Data */
788 fprintf( outfile, " __wine_spec_pe_header,\n" ); /* ImageBase */
789 fprintf( outfile, " %ld,\n", page_size ); /* SectionAlignment */
790 fprintf( outfile, " %ld,\n", page_size ); /* FileAlignment */
791 fprintf( outfile, " 1, 0,\n" ); /* Major/MinorOperatingSystemVersion */
792 fprintf( outfile, " 0, 0,\n" ); /* Major/MinorImageVersion */
793 fprintf( outfile, " %d,\n", spec->subsystem_major ); /* MajorSubsystemVersion */
794 fprintf( outfile, " %d,\n", spec->subsystem_minor ); /* MinorSubsystemVersion */
795 fprintf( outfile, " 0,\n" ); /* Win32VersionValue */
796 fprintf( outfile, " _end,\n" ); /* SizeOfImage */
797 fprintf( outfile, " %ld,\n", page_size ); /* SizeOfHeaders */
798 fprintf( outfile, " 0,\n" ); /* CheckSum */
799 fprintf( outfile, " 0x%04x,\n", spec->subsystem );/* Subsystem */
800 fprintf( outfile, " 0,\n" ); /* DllCharacteristics */
801 fprintf( outfile, " %d, %ld,\n", /* SizeOfStackReserve/Commit */
802 (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
803 fprintf( outfile, " %d, %ld,\n", /* SizeOfHeapReserve/Commit */
804 (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
805 fprintf( outfile, " 0,\n" ); /* LoaderFlags */
806 fprintf( outfile, " %d,\n", IMAGE_NUMBEROF_DIRECTORY_ENTRIES ); /* NumberOfRvaAndSizes */
807 fprintf( outfile, " {\n" );
808 fprintf( outfile, " { %s, %d },\n", /* IMAGE_DIRECTORY_ENTRY_EXPORT */
809 exports_size ? "__wine_spec_exports" : "0", exports_size );
810 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_IMPORT */
811 nr_imports ? "&imports" : "0", nr_imports ? "sizeof(imports)" : "0" );
812 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_RESOURCE */
813 spec->nb_resources ? "&resources" : "0",
814 spec->nb_resources ? "sizeof(resources)" : "0" );
815 fprintf( outfile, " }\n }\n};\n\n" );
816
817 /* Output the DLL constructor */
818
819 fprintf( outfile,
820 "void __wine_spec_init(void)\n"
821 "{\n"
822 " extern void __wine_dll_register( const struct image_nt_headers *, const char * );\n"
823 " __wine_spec_init_state = 1;\n"
824 " __wine_dll_register( &nt_header, \"%s\" );\n"
825 "}\n\n",
826 spec->file_name );
827
828 output_dll_init( outfile, "__wine_spec_init_ctor", NULL );
829 fprintf( outfile,
830 "void __wine_spec_init_ctor(void)\n"
831 "{\n"
832 " if (__wine_spec_init_state) return;\n"
833 " __wine_spec_init();\n"
834 " __wine_spec_init_state = 2;\n"
835 "}\n" );
836 }
837
838
839 /*******************************************************************
840 * BuildDef32File
841 *
842 * Build a Win32 def file from a spec file.
843 */
844 void BuildDef32File( FILE *outfile, DLLSPEC *spec )
845 {
846 const char *name;
847 int i;
848
849 if (spec_file_name)
850 fprintf( outfile, "; File generated automatically from %s; do not edit!\n\n",
851 spec_file_name );
852 else
853 fprintf( outfile, "; File generated automatically; do not edit!\n\n" );
854
855 fprintf(outfile, "LIBRARY %s\n\n", spec->file_name);
856
857 fprintf(outfile, "EXPORTS\n");
858
859 /* Output the exports and relay entry points */
860
861 for(i = 0; i < spec->nb_entry_points; i++)
862 {
863 const ORDDEF *odp = &spec->entry_points[i];
864 int is_data = 0;
865
866 if (!odp) continue;
867 if (odp->name) name = odp->name;
868 else if (odp->type == TYPE_STUB) name = make_internal_name( odp, spec, "stub" );
869 else if (odp->export_name) name = odp->export_name;
870 else name = make_internal_name( odp, spec, "noname_export" );
871
872 fprintf(outfile, " %s", name);
873
874 switch(odp->type)
875 {
876 case TYPE_EXTERN:
877 is_data = 1;
878 /* fall through */
879 case TYPE_VARARGS:
880 case TYPE_CDECL:
881 /* try to reduce output */
882 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
883 fprintf(outfile, "=%s", odp->link_name);
884 break;
885 case TYPE_STDCALL:
886 {
887 int at_param = strlen(odp->u.func.arg_types) * sizeof(int);
888 if (!kill_at) fprintf(outfile, "@%d", at_param);
889 if (odp->flags & FLAG_FORWARD)
890 {
891 fprintf(outfile, "=%s", odp->link_name);
892 }
893 else if (strcmp(name, odp->link_name)) /* try to reduce output */
894 {
895 fprintf(outfile, "=%s", odp->link_name);
896 if (!kill_at) fprintf(outfile, "@%d", at_param);
897 }
898 break;
899 }
900 case TYPE_STUB:
901 {
902 if (!kill_at)
903 {
904 const char *check = name + strlen(name);
905 while (name != check &&
906 '0' <= check[-1] && check[-1] <= '9')
907 {
908 check--;
909 }
910 if (name != check && check != name + strlen(name) &&
911 '@' == check[-1])
912 {
913 fprintf(outfile, "%s", check - 1);
914 }
915 }
916 if (NULL != odp->name)
917 {
918 fprintf(outfile, "=%s", make_internal_name( odp, spec, "stub" ));
919 }
920 break;
921 }
922 default:
923 assert(0);
924 }
925 fprintf( outfile, " @%d", odp->ordinal );
926 #if 0 /* MinGW binutils cannot handle this correctly */
927 if (!odp->name) fprintf( outfile, " NONAME" );
928 #else
929 if (!odp->name && (odp->type == TYPE_STUB || odp->export_name)) fprintf( outfile, " NONAME" );
930 #endif
931 if (is_data) fprintf( outfile, " DATA" );
932 #if 0
933 /* MinGW binutils cannot handle this correctly */
934 if (odp->flags & FLAG_PRIVATE) fprintf( outfile, " PRIVATE" );
935 #endif
936 fprintf( outfile, "\n" );
937 }
938 }
939
940
941 /*******************************************************************
942 * BuildDebugFile
943 *
944 * Build the debugging channels source file.
945 */
946 void BuildDebugFile( FILE *outfile, const char *srcdir, char **argv )
947 {
948 int nr_debug;
949 char *prefix, *p;
950
951 while (*argv)
952 {
953 if (!parse_debug_channels( srcdir, *argv++ )) exit(1);
954 }
955
956 output_standard_file_header( outfile );
957 nr_debug = output_debug( outfile );
958 if (!nr_debug)
959 {
960 fprintf( outfile, "/* no debug channels found for this module */\n" );
961 return;
962 }
963
964 if (output_file_name)
965 {
966 if ((p = strrchr( output_file_name, '/' ))) p++;
967 prefix = xstrdup( p ? p : output_file_name );
968 if ((p = strchr( prefix, '.' ))) *p = 0;
969 strcpy( p, make_c_identifier(p) );
970 }
971 else prefix = xstrdup( "_" );
972
973 /* Output the DLL constructor */
974
975 fprintf( outfile,
976 "#ifdef __GNUC__\n"
977 "void __wine_dbg_%s_init(void) __attribute__((constructor));\n"
978 "void __wine_dbg_%s_fini(void) __attribute__((destructor));\n"
979 "#else\n"
980 "static void __asm__dummy_dll_init(void) {\n",
981 prefix, prefix );
982
983 #if defined(__i386__)
984 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
985 fprintf( outfile, " \"\\tcall " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
986 fprintf( outfile, " \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
987 fprintf( outfile, " \"\\tcall " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
988 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
989 #elif defined(__sparc__)
990 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
991 fprintf( outfile, " \"\\tcall " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
992 fprintf( outfile, " \"\\tnop\\n\"\n" );
993 fprintf( outfile, " \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
994 fprintf( outfile, " \"\\tcall " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
995 fprintf( outfile, " \"\\tnop\\n\"\n" );
996 fprintf( outfile, " \"\\t.section\t\\\".text\\\"\\n\");\n" );
997 #elif defined(__powerpc__)
998 # ifdef __APPLE__
999 fprintf( outfile, "asm(\"\\t.mod_init_func\\n\"\n" );
1000 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
1001 fprintf( outfile, " \"\\t.long " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
1002 fprintf( outfile, " \"\\t.text\\n\");\n" );
1003 fprintf( outfile, "asm(\"\\t.mod_term_func\\n\"\n" );
1004 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
1005 fprintf( outfile, " \"\\t.long " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
1006 fprintf( outfile, " \"\\t.text\\n\");\n" );
1007 # else
1008 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
1009 fprintf( outfile, " \"\\tbl " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
1010 fprintf( outfile, " \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
1011 fprintf( outfile, " \"\\tbl " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
1012 fprintf( outfile, " \"\\t.text\\n\");\n" );
1013 # endif
1014 #elif defined(__ALPHA__)
1015 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
1016 fprintf( outfile, " \"\\tjsr $26," __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
1017 fprintf( outfile, " \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
1018 fprintf( outfile, " \"\\tjsr $26," __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
1019 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
1020 #else
1021 #error You need to define the DLL constructor for your architecture
1022 #endif
1023 fprintf( outfile, "}\n#endif /* defined(__GNUC__) */\n\n" );
1024
1025 fprintf( outfile,
1026 "void __wine_dbg_%s_init(void)\n"
1027 "{\n"
1028 " extern void *__wine_dbg_register( char * const *, int );\n"
1029 " if (!debug_registration) debug_registration = __wine_dbg_register( debug_channels, %d );\n"
1030 "}\n\n", prefix, nr_debug );
1031 fprintf( outfile,
1032 "void __wine_dbg_%s_fini(void)\n"
1033 "{\n"
1034 " extern void __wine_dbg_unregister( void* );\n"
1035 " __wine_dbg_unregister( debug_registration );\n"
1036 "}\n", prefix );
1037
1038 free( prefix );
1039 }
1040
1041
1042 /*******************************************************************
1043 * BuildPedllFile
1044 *
1045 * Build a PE DLL C file from a spec file.
1046 */
1047 void BuildPedllFile( FILE *outfile, DLLSPEC *spec )
1048 {
1049 int nr_exports;
1050
1051 nr_exports = spec->base <= spec->limit ? spec->limit - spec->base + 1 : 0;
1052 output_standard_file_header( outfile );
1053
1054 if (nr_exports)
1055 {
1056 /* Output the stub functions */
1057
1058 output_stub_funcs( outfile, spec );
1059 }
1060 }