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
17 #include "wine/exception.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 /*******************************************************************
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
);
42 /*******************************************************************
45 * Assign ordinals to all entry points.
47 static void AssignOrdinals(void)
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 /*******************************************************************
74 * Output the debug channels.
76 static int output_debug( FILE *outfile
)
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 /*******************************************************************
103 * Output the export table for a Win32 module.
105 static void output_exports( FILE *outfile
, int nr_exports
, int fwd_size
)
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
);
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" );
135 fprintf( outfile
, " char forwards[%d];\n", (fwd_size
+ 3) & ~3 );
137 fprintf( outfile
, " } exp;\n" );
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 */
163 fprintf( outfile
, " exports.exp.names,\n" ); /* AddressOfNames */
164 fprintf( outfile
, " exports.exp.ordinals,\n" ); /* AddressOfNameOrdinals */
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
)
182 fprintf( outfile
, "%s", odp
->u
.ext
.link_name
);
187 fprintf( outfile
, "%s", odp
->u
.func
.link_name
);
190 fprintf( outfile
, "%s", make_internal_name( odp
, "stub" ) );
193 fprintf( outfile
, "%s", make_internal_name( odp
, "regs" ) );
196 fprintf( outfile
, "(func_ptr)%s", make_internal_name( odp
, "var" ) );
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;
206 if (i
< Limit
) fprintf( outfile
, ",\n " );
207 else fprintf( outfile
, "\n },\n" );
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
);
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 */
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
);
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;
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
);
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
);
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
);
299 fprintf( outfile
, " { 0, { 0,0,0,0 }, 0, 0, 0, 0 }" );
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
++)
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 /*******************************************************************
324 * Output the functions for stub entry points
326 static void output_stub_funcs( FILE *outfile
)
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" );
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" ) );
365 fprintf( outfile
, "{ __wine_unimplemented(\"%s\"); }\n", odp
->name
);
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
)
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" );
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 /*******************************************************************
409 * Build a Win32 C file from a spec file.
411 void BuildSpec32File( FILE *outfile
)
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
;
420 #ifdef HAVE_GETPAGESIZE
421 page_size
= getpagesize();
424 page_size
= sysconf(_SC_PAGESIZE
);
426 # error Cannot get the page size on this platform
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",
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
++)
458 fprintf( outfile
, "extern void %s();\n", odp
->u
.ext
.link_name
);
463 fprintf( outfile
, "extern void %s();\n", odp
->u
.func
.link_name
);
466 fwd_size
+= strlen(odp
->u
.fwd
.link_name
) + 1;
469 fprintf( outfile
, "extern void %s();\n", make_internal_name( odp
, "regs" ) );
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" );
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;
516 if (init_func
) fprintf( outfile
, "extern void %s();\n", init_func
);
517 characteristics
= IMAGE_FILE_DLL
;
519 case SPEC_MODE_GUIEXE
:
520 if (!init_func
) init_func
= "WinMain";
522 "\n#include <winbase.h>\n"
525 "static void __wine_exe_main(void)\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
);
540 "int main( int argc, char *argv[] )\n"
542 " extern void PROCESS_InitWinelib( int, char ** );\n"
543 " PROCESS_InitWinelib( argc, argv );\n"
546 init_func
= "__wine_exe_main";
547 subsystem
= IMAGE_SUBSYSTEM_WINDOWS_GUI
;
549 case SPEC_MODE_CUIEXE
:
550 if (!init_func
) init_func
= has_imports
? "main" : "wine_main";
552 "\n#include <winbase.h>\n"
555 "static void __wine_exe_main(void)\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
);
564 "int main( int argc, char *argv[] )\n"
566 " extern void PROCESS_InitWinelib( int, char ** );\n"
567 " PROCESS_InitWinelib( argc, argv );\n"
570 init_func
= "__wine_exe_main";
571 subsystem
= IMAGE_SUBSYSTEM_WINDOWS_CUI
;
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
;
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
;
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" );
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" );
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
);
689 fprintf( outfile
, " debug_registration = __wine_dbg_register( debug_channels, %d );\n",
691 fprintf( outfile
, "}\n" );
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" );