Modified winebuild to use the __ASM_FUNC macro for greater portability.
[wine/multimedia.git] / tools / winebuild / spec32.c
blob552b90736381c7a356302db99519118d6122e5dd
1 /*
2 * 32-bit spec files
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 */
11 #include <assert.h>
12 #include <ctype.h>
13 #include <unistd.h>
15 #include "config.h"
16 #include "winbase.h"
17 #include "wine/exception.h"
18 #include "build.h"
21 static int string_compare( const void *ptr1, const void *ptr2 )
23 const char * const *str1 = ptr1;
24 const char * const *str2 = ptr2;
25 return strcmp( *str1, *str2 );
29 /*******************************************************************
30 * make_internal_name
32 * Generate an internal name for an entry point. Used for stubs etc.
34 static const char *make_internal_name( const ORDDEF *odp, const char *prefix )
36 static char buffer[256];
37 if (odp->name[0]) sprintf( buffer, "__wine_%s_%s", prefix, odp->name );
38 else sprintf( buffer, "__wine_%s_%d", prefix, odp->ordinal );
39 return buffer;
42 /*******************************************************************
43 * AssignOrdinals
45 * Assign ordinals to all entry points.
47 static void AssignOrdinals(void)
49 int i, ordinal;
51 if ( !nb_names ) return;
53 /* start assigning from Base, or from 1 if no ordinal defined yet */
54 if (Base == MAX_ORDINALS) Base = 1;
55 for (i = 0, ordinal = Base; i < nb_names; i++)
57 if (Names[i]->ordinal != -1) continue; /* already has an ordinal */
58 while (Ordinals[ordinal]) ordinal++;
59 if (ordinal >= MAX_ORDINALS)
61 current_line = Names[i]->lineno;
62 fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
64 Names[i]->ordinal = ordinal;
65 Ordinals[ordinal] = Names[i];
67 if (ordinal > Limit) Limit = ordinal;
71 /*******************************************************************
72 * output_debug
74 * Output the debug channels.
76 static int output_debug( FILE *outfile )
78 int i;
80 if (!nb_debug_channels) return 0;
81 qsort( debug_channels, nb_debug_channels, sizeof(debug_channels[0]), string_compare );
83 for (i = 0; i < nb_debug_channels; i++)
84 fprintf( outfile, "char __wine_dbch_%s[] = \"\\003%s\";\n",
85 debug_channels[i], debug_channels[i] );
87 fprintf( outfile, "\nstatic char * const debug_channels[%d] =\n{\n", nb_debug_channels );
88 for (i = 0; i < nb_debug_channels; i++)
90 fprintf( outfile, " __wine_dbch_%s", debug_channels[i] );
91 if (i < nb_debug_channels - 1) fprintf( outfile, ",\n" );
93 fprintf( outfile, "\n};\n\n" );
94 fprintf( outfile, "static void *debug_registration;\n\n" );
96 return nb_debug_channels;
100 /*******************************************************************
101 * output_exports
103 * Output the export table for a Win32 module.
105 static void output_exports( FILE *outfile, int nr_exports, int fwd_size )
107 int i, fwd_pos = 0;
109 if (!nr_exports) return;
111 fprintf( outfile, "\n\n/* exports */\n\n" );
112 fprintf( outfile, "typedef void (*func_ptr)();\n" );
113 fprintf( outfile, "static struct {\n" );
114 fprintf( outfile, " struct {\n" );
115 fprintf( outfile, " unsigned int Characteristics;\n" );
116 fprintf( outfile, " unsigned int TimeDateStamp;\n" );
117 fprintf( outfile, " unsigned short MajorVersion;\n" );
118 fprintf( outfile, " unsigned short MinorVersion;\n" );
119 fprintf( outfile, " const char *Name;\n" );
120 fprintf( outfile, " unsigned int Base;\n" );
121 fprintf( outfile, " unsigned int NumberOfFunctions;\n" );
122 fprintf( outfile, " unsigned int NumberOfNames;\n" );
123 fprintf( outfile, " func_ptr *AddressOfFunctions;\n" );
124 fprintf( outfile, " const char **AddressOfNames;\n" );
125 fprintf( outfile, " unsigned short *AddressOfNameOrdinals;\n" );
126 fprintf( outfile, " func_ptr functions[%d];\n", nr_exports );
127 if (nb_names)
129 fprintf( outfile, " const char *names[%d];\n", nb_names );
130 fprintf( outfile, " unsigned short ordinals[%d];\n", nb_names );
131 if (nb_names % 2) fprintf( outfile, " unsigned short pad1;\n" );
133 if (fwd_size)
135 fprintf( outfile, " char forwards[%d];\n", (fwd_size + 3) & ~3 );
137 fprintf( outfile, " } exp;\n" );
139 if (debugging)
141 fprintf( outfile, " struct {\n" );
142 fprintf( outfile, " unsigned char jmp;\n" );
143 fprintf( outfile, " unsigned char addr[4];\n" );
144 fprintf( outfile, " unsigned char ret;\n" );
145 fprintf( outfile, " unsigned short args;\n" );
146 fprintf( outfile, " func_ptr orig;\n" );
147 fprintf( outfile, " unsigned int argtypes;\n" );
148 fprintf( outfile, " } relay[%d];\n", nr_exports );
151 fprintf( outfile, "} exports = {\n {\n" );
152 fprintf( outfile, " 0,\n" ); /* Characteristics */
153 fprintf( outfile, " 0,\n" ); /* TimeDateStamp */
154 fprintf( outfile, " 0,\n" ); /* MajorVersion */
155 fprintf( outfile, " 0,\n" ); /* MinorVersion */
156 fprintf( outfile, " dllname,\n" ); /* Name */
157 fprintf( outfile, " %d,\n", Base ); /* Base */
158 fprintf( outfile, " %d,\n", nr_exports ); /* NumberOfFunctions */
159 fprintf( outfile, " %d,\n", nb_names ); /* NumberOfNames */
160 fprintf( outfile, " exports.exp.functions,\n" ); /* AddressOfFunctions */
161 if (nb_names)
163 fprintf( outfile, " exports.exp.names,\n" ); /* AddressOfNames */
164 fprintf( outfile, " exports.exp.ordinals,\n" ); /* AddressOfNameOrdinals */
166 else
168 fprintf( outfile, " 0,\n" ); /* AddressOfNames */
169 fprintf( outfile, " 0,\n" ); /* AddressOfNameOrdinals */
172 /* output the function addresses */
174 fprintf( outfile, " {\n " );
175 for (i = Base; i <= Limit; i++)
177 ORDDEF *odp = Ordinals[i];
178 if (!odp) fprintf( outfile, "0" );
179 else switch(odp->type)
181 case TYPE_EXTERN:
182 fprintf( outfile, "%s", odp->u.ext.link_name );
183 break;
184 case TYPE_STDCALL:
185 case TYPE_VARARGS:
186 case TYPE_CDECL:
187 fprintf( outfile, "%s", odp->u.func.link_name);
188 break;
189 case TYPE_STUB:
190 fprintf( outfile, "%s", make_internal_name( odp, "stub" ) );
191 break;
192 case TYPE_REGISTER:
193 fprintf( outfile, "%s", make_internal_name( odp, "regs" ) );
194 break;
195 case TYPE_VARIABLE:
196 fprintf( outfile, "(func_ptr)%s", make_internal_name( odp, "var" ) );
197 break;
198 case TYPE_FORWARD:
199 fprintf( outfile, "(func_ptr)&exports.exp.forwards[%d] /* %s */",
200 fwd_pos, odp->u.fwd.link_name );
201 fwd_pos += strlen(odp->u.fwd.link_name) + 1;
202 break;
203 default:
204 assert(0);
206 if (i < Limit) fprintf( outfile, ",\n " );
207 else fprintf( outfile, "\n },\n" );
210 if (nb_names)
212 /* output the function names */
214 fprintf( outfile, " {\n" );
215 for (i = 0; i < nb_names; i++)
217 if (i) fprintf( outfile, ",\n" );
218 fprintf( outfile, " \"%s\"", Names[i]->name );
220 fprintf( outfile, "\n },\n" );
222 /* output the function ordinals */
224 fprintf( outfile, " {\n " );
225 for (i = 0; i < nb_names; i++)
227 fprintf( outfile, "%4d", Names[i]->ordinal - Base );
228 if (i < nb_names-1)
230 fputc( ',', outfile );
231 if ((i % 8) == 7) fprintf( outfile, "\n " );
234 fprintf( outfile, "\n },\n" );
235 if (nb_names % 2) fprintf( outfile, " 0,\n" );
238 /* output forwards */
240 if (fwd_size)
242 for (i = Base; i <= Limit; i++)
244 ORDDEF *odp = Ordinals[i];
245 if (odp && odp->type == TYPE_FORWARD)
246 fprintf( outfile, " \"%s\\0\"\n", odp->u.fwd.link_name );
250 /* output relays */
252 if (debugging)
254 fprintf( outfile, " },\n {\n" );
255 for (i = Base; i <= Limit; i++)
257 ORDDEF *odp = Ordinals[i];
258 unsigned int j, mask = 0;
260 /* skip non-existent entry points */
261 if (!odp) goto ignore;
262 /* skip non-functions */
263 if ((odp->type != TYPE_STDCALL) &&
264 (odp->type != TYPE_CDECL) &&
265 (odp->type != TYPE_REGISTER)) goto ignore;
266 /* skip norelay entry points */
267 if (odp->flags & FLAG_NORELAY) goto ignore;
269 for (j = 0; odp->u.func.arg_types[j]; j++)
271 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
272 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
274 if ((odp->flags & FLAG_RET64) && (j < 16)) mask |= 0x80000000;
276 switch(odp->type)
278 case TYPE_STDCALL:
279 fprintf( outfile, " { 0xe9, { 0,0,0,0 }, 0xc2, 0x%04x, %s, 0x%08x }",
280 strlen(odp->u.func.arg_types) * sizeof(int),
281 odp->u.func.link_name, mask );
282 break;
283 case TYPE_CDECL:
284 fprintf( outfile, " { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
285 strlen(odp->u.func.arg_types) * sizeof(int),
286 odp->u.func.link_name, mask );
287 break;
288 case TYPE_REGISTER:
289 fprintf( outfile, " { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
290 0x8000 | (strlen(odp->u.func.arg_types) * sizeof(int)),
291 make_internal_name( odp, "regs" ), mask );
292 break;
293 default:
294 assert(0);
296 goto done;
298 ignore:
299 fprintf( outfile, " { 0, { 0,0,0,0 }, 0, 0, 0, 0 }" );
300 done:
301 if (i < Limit) fprintf( outfile, ",\n" );
305 fprintf( outfile, " }\n};\n\n" );
307 /* output __wine_dllexport symbols */
309 for (i = 0; i < nb_names; i++)
311 char *p;
312 if (Names[i]->flags & FLAG_NOIMPORT) continue;
313 /* check for invalid characters in the name */
314 for (p = Names[i]->name; *p; p++) if (!isalnum(*p) && *p != '_') break;
315 if (!*p) fprintf( outfile, "const char __wine_dllexport_%s_%s = 0;\n",
316 DLLName, Names[i]->name );
321 /*******************************************************************
322 * output_stub_funcs
324 * Output the functions for stub entry points
326 static void output_stub_funcs( FILE *outfile )
328 int i;
329 ORDDEF *odp;
331 for (i = 0, odp = EntryPoints; i < nb_entry_points; i++, odp++)
333 if (odp->type != TYPE_STUB) continue;
334 fprintf( outfile, "#ifdef __GNUC__\n" );
335 fprintf( outfile, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
336 fprintf( outfile, "#endif\n" );
337 fprintf( outfile, "static void __wine_unimplemented( const char *func )\n{\n" );
338 fprintf( outfile, " struct exc_record {\n" );
339 fprintf( outfile, " unsigned int code, flags;\n" );
340 fprintf( outfile, " void *rec, *addr;\n" );
341 fprintf( outfile, " unsigned int params;\n" );
342 fprintf( outfile, " const void *info[15];\n" );
343 fprintf( outfile, " } rec;\n" );
344 fprintf( outfile, " extern void RtlRaiseException( struct exc_record * );\n\n" );
345 fprintf( outfile, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB );
346 fprintf( outfile, " rec.flags = %d;\n", EH_NONCONTINUABLE );
347 fprintf( outfile, " rec.rec = 0;\n" );
348 fprintf( outfile, " rec.params = 2;\n" );
349 fprintf( outfile, " rec.info[0] = dllname;\n" );
350 fprintf( outfile, " rec.info[1] = func;\n" );
351 fprintf( outfile, "#ifdef __GNUC__\n" );
352 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
353 fprintf( outfile, "#else\n" );
354 fprintf( outfile, " rec.addr = 0;\n" );
355 fprintf( outfile, "#endif\n" );
356 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
357 break;
360 for (i = 0, odp = EntryPoints; i < nb_entry_points; i++, odp++)
362 if (odp->type != TYPE_STUB) continue;
363 fprintf( outfile, "static void %s(void) ", make_internal_name( odp, "stub" ) );
364 if (odp->name[0])
365 fprintf( outfile, "{ __wine_unimplemented(\"%s\"); }\n", odp->name );
366 else
367 fprintf( outfile, "{ __wine_unimplemented(\"%d\"); }\n", odp->ordinal );
372 /*******************************************************************
373 * output_register_funcs
375 * Output the functions for register entry points
377 static void output_register_funcs( FILE *outfile )
379 ORDDEF *odp;
380 const char *name;
381 int i;
383 fprintf( outfile, "#ifndef __GNUC__\n" );
384 fprintf( outfile, "static void __asm__dummy(void) {\n" );
385 fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
386 for (i = 0, odp = EntryPoints; i < nb_entry_points; i++, odp++)
388 if (odp->type != TYPE_REGISTER) continue;
389 name = make_internal_name( odp, "regs" );
390 fprintf( outfile,
391 "asm(\".align 4\\n\\t\"\n"
392 " \"" __ASM_FUNC("%s") "\\n\\t\"\n"
393 " \"" PREFIX "%s:\\n\\t\"\n"
394 " \"call " PREFIX "CALL32_Regs\\n\\t\"\n"
395 " \".long " PREFIX "%s\\n\\t\"\n"
396 " \".byte %d,%d\");\n",
397 name, name, odp->u.func.link_name,
398 4 * strlen(odp->u.func.arg_types), 4 * strlen(odp->u.func.arg_types) );
400 fprintf( outfile, "#ifndef __GNUC__\n" );
401 fprintf( outfile, "}\n" );
402 fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
406 /*******************************************************************
407 * BuildSpec32File
409 * Build a Win32 C file from a spec file.
411 void BuildSpec32File( FILE *outfile )
413 ORDDEF *odp;
414 int i, j, fwd_size = 0, have_regs = FALSE;
415 int nr_exports, nr_imports, nr_resources, nr_debug;
416 int characteristics, subsystem, has_imports;
417 const char *init_func;
418 DWORD page_size;
420 #ifdef HAVE_GETPAGESIZE
421 page_size = getpagesize();
422 #else
423 # ifdef __svr4__
424 page_size = sysconf(_SC_PAGESIZE);
425 # else
426 # error Cannot get the page size on this platform
427 # endif
428 #endif
430 AssignOrdinals();
431 nr_exports = Base <= Limit ? Limit - Base + 1 : 0;
433 has_imports = resolve_imports( outfile );
435 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
436 input_file_name );
438 /* Reserve some space for the PE header */
440 fprintf( outfile, "extern char pe_header[];\n" );
441 fprintf( outfile, "asm(\".section .text\\n\\t\"\n" );
442 fprintf( outfile, " \".align %ld\\n\"\n", page_size );
443 fprintf( outfile, " \"pe_header:\\t.fill %ld,1,0\\n\\t\");\n", page_size );
445 fprintf( outfile, "static const char dllname[] = \"%s\";\n\n", DLLName );
447 /* Output the stub functions */
449 output_stub_funcs( outfile );
451 /* Output the DLL functions prototypes */
453 for (i = 0, odp = EntryPoints; i < nb_entry_points; i++, odp++)
455 switch(odp->type)
457 case TYPE_EXTERN:
458 fprintf( outfile, "extern void %s();\n", odp->u.ext.link_name );
459 break;
460 case TYPE_STDCALL:
461 case TYPE_VARARGS:
462 case TYPE_CDECL:
463 fprintf( outfile, "extern void %s();\n", odp->u.func.link_name );
464 break;
465 case TYPE_FORWARD:
466 fwd_size += strlen(odp->u.fwd.link_name) + 1;
467 break;
468 case TYPE_REGISTER:
469 fprintf( outfile, "extern void %s();\n", make_internal_name( odp, "regs" ) );
470 have_regs = TRUE;
471 break;
472 case TYPE_STUB:
473 break;
474 case TYPE_VARIABLE:
475 fprintf( outfile, "unsigned int %s[%d] = {",
476 make_internal_name( odp, "var" ), odp->u.var.n_values );
477 for (j = 0; j < odp->u.var.n_values; j++)
479 fprintf( outfile, " 0x%08x", odp->u.var.values[j] );
480 if (j < odp->u.var.n_values-1) fputc( ',', outfile );
482 fprintf( outfile, " };\n" );
483 break;
484 default:
485 fatal_error("function type %d not available for Win32\n", odp->type);
489 /* Output code for all register functions */
491 if (have_regs) output_register_funcs( outfile );
493 /* Output the exports and relay entry points */
495 output_exports( outfile, nr_exports, fwd_size );
497 /* Output the DLL imports */
499 nr_imports = output_imports( outfile );
501 /* Output the resources */
503 nr_resources = output_resources( outfile );
505 /* Output the debug channels */
507 nr_debug = output_debug( outfile );
509 /* Output LibMain function */
511 init_func = DLLInitFunc[0] ? DLLInitFunc : NULL;
512 characteristics = subsystem = 0;
513 switch(SpecMode)
515 case SPEC_MODE_DLL:
516 if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
517 characteristics = IMAGE_FILE_DLL;
518 break;
519 case SPEC_MODE_GUIEXE:
520 if (!init_func) init_func = "WinMain";
521 fprintf( outfile,
522 "\n#include <winbase.h>\n"
523 "int _ARGC;\n"
524 "char **_ARGV;\n"
525 "static void __wine_exe_main(void)\n"
526 "{\n"
527 " extern int PASCAL %s(HINSTANCE,HINSTANCE,LPSTR,INT);\n"
528 " extern int __wine_get_main_args( char ***argv );\n"
529 " STARTUPINFOA info;\n"
530 " LPSTR cmdline = GetCommandLineA();\n"
531 " while (*cmdline && *cmdline != ' ') cmdline++;\n"
532 " if (*cmdline) cmdline++;\n"
533 " GetStartupInfoA( &info );\n"
534 " if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = 1;\n"
535 " _ARGC = __wine_get_main_args( &_ARGV );\n"
536 " ExitProcess( %s( GetModuleHandleA(0), 0, cmdline, info.wShowWindow ) );\n"
537 "}\n\n", init_func, init_func );
538 if (!has_imports)
539 fprintf( outfile,
540 "int main( int argc, char *argv[] )\n"
541 "{\n"
542 " extern void PROCESS_InitWinelib( int, char ** );\n"
543 " PROCESS_InitWinelib( argc, argv );\n"
544 " return 1;\n"
545 "}\n\n" );
546 init_func = "__wine_exe_main";
547 subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
548 break;
549 case SPEC_MODE_CUIEXE:
550 if (!init_func) init_func = has_imports ? "main" : "wine_main";
551 fprintf( outfile,
552 "\n#include <winbase.h>\n"
553 "int _ARGC;\n"
554 "char **_ARGV;\n"
555 "static void __wine_exe_main(void)\n"
556 "{\n"
557 " extern int %s( int argc, char *argv[] );\n"
558 " extern int __wine_get_main_args( char ***argv );\n"
559 " _ARGC = __wine_get_main_args( &_ARGV );\n"
560 " ExitProcess( %s( _ARGC, _ARGV ) );\n"
561 "}\n\n", init_func, init_func );
562 if (!has_imports)
563 fprintf( outfile,
564 "int main( int argc, char *argv[] )\n"
565 "{\n"
566 " extern void PROCESS_InitWinelib( int, char ** );\n"
567 " PROCESS_InitWinelib( argc, argv );\n"
568 " return 1;\n"
569 "}\n\n" );
570 init_func = "__wine_exe_main";
571 subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
572 break;
573 case SPEC_MODE_GUIEXE_NO_MAIN:
574 if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
575 subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
576 break;
577 case SPEC_MODE_CUIEXE_NO_MAIN:
578 if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
579 subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
580 break;
583 /* Output the NT header */
585 /* this is the IMAGE_NT_HEADERS structure, but we cannot include winnt.h here */
586 fprintf( outfile, "static const struct image_nt_headers\n{\n" );
587 fprintf( outfile, " int Signature;\n" );
588 fprintf( outfile, " struct file_header {\n" );
589 fprintf( outfile, " short Machine;\n" );
590 fprintf( outfile, " short NumberOfSections;\n" );
591 fprintf( outfile, " int TimeDateStamp;\n" );
592 fprintf( outfile, " void *PointerToSymbolTable;\n" );
593 fprintf( outfile, " int NumberOfSymbols;\n" );
594 fprintf( outfile, " short SizeOfOptionalHeader;\n" );
595 fprintf( outfile, " short Characteristics;\n" );
596 fprintf( outfile, " } FileHeader;\n" );
597 fprintf( outfile, " struct opt_header {\n" );
598 fprintf( outfile, " short Magic;\n" );
599 fprintf( outfile, " char MajorLinkerVersion, MinorLinkerVersion;\n" );
600 fprintf( outfile, " int SizeOfCode;\n" );
601 fprintf( outfile, " int SizeOfInitializedData;\n" );
602 fprintf( outfile, " int SizeOfUninitializedData;\n" );
603 fprintf( outfile, " void *AddressOfEntryPoint;\n" );
604 fprintf( outfile, " void *BaseOfCode;\n" );
605 fprintf( outfile, " void *BaseOfData;\n" );
606 fprintf( outfile, " void *ImageBase;\n" );
607 fprintf( outfile, " int SectionAlignment;\n" );
608 fprintf( outfile, " int FileAlignment;\n" );
609 fprintf( outfile, " short MajorOperatingSystemVersion;\n" );
610 fprintf( outfile, " short MinorOperatingSystemVersion;\n" );
611 fprintf( outfile, " short MajorImageVersion;\n" );
612 fprintf( outfile, " short MinorImageVersion;\n" );
613 fprintf( outfile, " short MajorSubsystemVersion;\n" );
614 fprintf( outfile, " short MinorSubsystemVersion;\n" );
615 fprintf( outfile, " int Win32VersionValue;\n" );
616 fprintf( outfile, " int SizeOfImage;\n" );
617 fprintf( outfile, " int SizeOfHeaders;\n" );
618 fprintf( outfile, " int CheckSum;\n" );
619 fprintf( outfile, " short Subsystem;\n" );
620 fprintf( outfile, " short DllCharacteristics;\n" );
621 fprintf( outfile, " int SizeOfStackReserve;\n" );
622 fprintf( outfile, " int SizeOfStackCommit;\n" );
623 fprintf( outfile, " int SizeOfHeapReserve;\n" );
624 fprintf( outfile, " int SizeOfHeapCommit;\n" );
625 fprintf( outfile, " int LoaderFlags;\n" );
626 fprintf( outfile, " int NumberOfRvaAndSizes;\n" );
627 fprintf( outfile, " struct { const void *VirtualAddress; int Size; } DataDirectory[%d];\n",
628 IMAGE_NUMBEROF_DIRECTORY_ENTRIES );
629 fprintf( outfile, " } OptionalHeader;\n" );
630 fprintf( outfile, "} nt_header = {\n" );
631 fprintf( outfile, " 0x%04x,\n", IMAGE_NT_SIGNATURE ); /* Signature */
633 fprintf( outfile, " { 0x%04x,\n", IMAGE_FILE_MACHINE_I386 ); /* Machine */
634 fprintf( outfile, " 0, 0, 0, 0,\n" );
635 fprintf( outfile, " sizeof(nt_header.OptionalHeader),\n" ); /* SizeOfOptionalHeader */
636 fprintf( outfile, " 0x%04x },\n", characteristics ); /* Characteristics */
638 fprintf( outfile, " { 0x%04x,\n", IMAGE_NT_OPTIONAL_HDR_MAGIC ); /* Magic */
639 fprintf( outfile, " 0, 0,\n" ); /* Major/MinorLinkerVersion */
640 fprintf( outfile, " 0, 0, 0,\n" ); /* SizeOfCode/Data */
641 fprintf( outfile, " %s,\n", init_func ? init_func : "0" ); /* AddressOfEntryPoint */
642 fprintf( outfile, " 0, 0,\n" ); /* BaseOfCode/Data */
643 fprintf( outfile, " pe_header,\n" ); /* ImageBase */
644 fprintf( outfile, " %ld,\n", page_size ); /* SectionAlignment */
645 fprintf( outfile, " %ld,\n", page_size ); /* FileAlignment */
646 fprintf( outfile, " 1, 0,\n" ); /* Major/MinorOperatingSystemVersion */
647 fprintf( outfile, " 0, 0,\n" ); /* Major/MinorImageVersion */
648 fprintf( outfile, " 4, 0,\n" ); /* Major/MinorSubsystemVersion */
649 fprintf( outfile, " 0,\n" ); /* Win32VersionValue */
650 fprintf( outfile, " %ld,\n", page_size ); /* SizeOfImage */
651 fprintf( outfile, " %ld,\n", page_size ); /* SizeOfHeaders */
652 fprintf( outfile, " 0,\n" ); /* CheckSum */
653 fprintf( outfile, " 0x%04x,\n", subsystem ); /* Subsystem */
654 fprintf( outfile, " 0, 0, 0, 0, 0, 0,\n" );
655 fprintf( outfile, " %d,\n", IMAGE_NUMBEROF_DIRECTORY_ENTRIES ); /* NumberOfRvaAndSizes */
656 fprintf( outfile, " {\n" );
657 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_EXPORT */
658 nr_exports ? "&exports" : "0", nr_exports ? "sizeof(exports.exp)" : "0" );
659 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_IMPORT */
660 nr_imports ? "&imports" : "0", nr_imports ? "sizeof(imports)" : "0" );
661 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_RESOURCE */
662 nr_resources ? "&resources" : "0", nr_resources ? "sizeof(resources)" : "0" );
663 fprintf( outfile, " }\n }\n};\n\n" );
665 /* Output the DLL constructor */
667 fprintf( outfile, "#ifdef __GNUC__\n" );
668 fprintf( outfile, "static void init(void) __attribute__((constructor));\n" );
669 if (nr_debug)
670 fprintf( outfile, "static void fini(void) __attribute__((destructor));\n" );
671 fprintf( outfile, "#else /* defined(__GNUC__) */\n" );
672 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
673 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
674 fprintf( outfile, " \"\\tcall init\\n\"\n" );
675 fprintf( outfile, " \"\\t.previous\\n\");\n" );
676 if (nr_debug)
678 fprintf( outfile, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
679 fprintf( outfile, " \"\\tcall fini\\n\"\n" );
680 fprintf( outfile, " \"\\t.previous\\n\");\n" );
682 fprintf( outfile, "}\n" );
683 fprintf( outfile, "#endif /* defined(__GNUC__) */\n\n" );
684 fprintf( outfile, "static void init(void)\n{\n" );
685 fprintf( outfile, " extern void __wine_dll_register( const struct image_nt_headers *, const char * );\n" );
686 fprintf( outfile, " extern void *__wine_dbg_register( char * const *, int );\n");
687 fprintf( outfile, " __wine_dll_register( &nt_header, \"%s\" );\n", DLLFileName );
688 if (nr_debug)
689 fprintf( outfile, " debug_registration = __wine_dbg_register( debug_channels, %d );\n",
690 nr_debug );
691 fprintf( outfile, "}\n" );
692 if (nr_debug)
694 fprintf( outfile, "\nstatic void fini(void)\n{\n" );
695 fprintf( outfile, " extern void __wine_dbg_unregister( void * );\n");
696 fprintf( outfile, " __wine_dbg_unregister( debug_registration );\n" );
697 fprintf( outfile, "}\n" );