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
18 #include "wine/exception.h"
22 static int string_compare( const void *ptr1
, const void *ptr2
)
24 const char * const *str1
= ptr1
;
25 const char * const *str2
= ptr2
;
26 return strcmp( *str1
, *str2
);
30 /*******************************************************************
33 * Generate an internal name for an entry point. Used for stubs etc.
35 static const char *make_internal_name( const ORDDEF
*odp
, const char *prefix
)
37 static char buffer
[256];
41 sprintf( buffer
, "__wine_%s_%s_%s", prefix
, DLLName
, odp
->name
);
42 /* make sure name is a legal C identifier */
43 for (p
= buffer
; *p
; p
++) if (!isalnum(*p
) && *p
!= '_') break;
44 if (!*p
) return buffer
;
46 sprintf( buffer
, "__wine_%s_%s_%d", prefix
, DLLName
, odp
->ordinal
);
50 /*******************************************************************
53 * Assign ordinals to all entry points.
55 static void AssignOrdinals(void)
59 if ( !nb_names
) return;
61 /* start assigning from Base, or from 1 if no ordinal defined yet */
62 if (Base
== MAX_ORDINALS
) Base
= 1;
63 for (i
= 0, ordinal
= Base
; i
< nb_names
; i
++)
65 if (Names
[i
]->ordinal
!= -1) continue; /* already has an ordinal */
66 while (Ordinals
[ordinal
]) ordinal
++;
67 if (ordinal
>= MAX_ORDINALS
)
69 current_line
= Names
[i
]->lineno
;
70 fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS
);
72 Names
[i
]->ordinal
= ordinal
;
73 Ordinals
[ordinal
] = Names
[i
];
75 if (ordinal
> Limit
) Limit
= ordinal
;
79 /*******************************************************************
82 * Output the debug channels.
84 static int output_debug( FILE *outfile
)
88 if (!nb_debug_channels
) return 0;
89 qsort( debug_channels
, nb_debug_channels
, sizeof(debug_channels
[0]), string_compare
);
91 for (i
= 0; i
< nb_debug_channels
; i
++)
92 fprintf( outfile
, "char __wine_dbch_%s[] = \"\\003%s\";\n",
93 debug_channels
[i
], debug_channels
[i
] );
95 fprintf( outfile
, "\nstatic char * const debug_channels[%d] =\n{\n", nb_debug_channels
);
96 for (i
= 0; i
< nb_debug_channels
; i
++)
98 fprintf( outfile
, " __wine_dbch_%s", debug_channels
[i
] );
99 if (i
< nb_debug_channels
- 1) fprintf( outfile
, ",\n" );
101 fprintf( outfile
, "\n};\n\n" );
102 fprintf( outfile
, "static void *debug_registration;\n\n" );
104 return nb_debug_channels
;
108 /*******************************************************************
111 * Output the export table for a Win32 module.
113 static int output_exports( FILE *outfile
, int nr_exports
)
115 int i
, fwd_size
= 0, total_size
= 0;
118 if (!nr_exports
) return 0;
120 fprintf( outfile
, "asm(\".data\\n\"\n" );
121 fprintf( outfile
, " \"\\t.align %d\\n\"\n", get_alignment(4) );
122 fprintf( outfile
, " \"" PREFIX
"__wine_spec_exports:\\n\"\n" );
124 /* export directory header */
126 fprintf( outfile
, " \"\\t.long 0\\n\"\n" ); /* Characteristics */
127 fprintf( outfile
, " \"\\t.long 0\\n\"\n" ); /* TimeDateStamp */
128 fprintf( outfile
, " \"\\t.long 0\\n\"\n" ); /* MajorVersion/MinorVersion */
129 fprintf( outfile
, " \"\\t.long " PREFIX
"dllname\\n\"\n" ); /* Name */
130 fprintf( outfile
, " \"\\t.long %d\\n\"\n", Base
); /* Base */
131 fprintf( outfile
, " \"\\t.long %d\\n\"\n", nr_exports
); /* NumberOfFunctions */
132 fprintf( outfile
, " \"\\t.long %d\\n\"\n", nb_names
); /* NumberOfNames */
133 fprintf( outfile
, " \"\\t.long __wine_spec_exports_funcs\\n\"\n" ); /* AddressOfFunctions */
136 fprintf( outfile
, " \"\\t.long __wine_spec_exp_name_ptrs\\n\"\n" ); /* AddressOfNames */
137 fprintf( outfile
, " \"\\t.long __wine_spec_exp_ordinals\\n\"\n" ); /* AddressOfNameOrdinals */
141 fprintf( outfile
, " \"\\t.long 0\\n\"\n" ); /* AddressOfNames */
142 fprintf( outfile
, " \"\\t.long 0\\n\"\n" ); /* AddressOfNameOrdinals */
144 total_size
+= 10 * sizeof(int);
146 /* output the function pointers */
148 fprintf( outfile
, " \"__wine_spec_exports_funcs:\\n\"\n" );
149 for (i
= Base
; i
<= Limit
; i
++)
151 ORDDEF
*odp
= Ordinals
[i
];
152 if (!odp
) fprintf( outfile
, " \"\\t.long 0\\n\"\n" );
153 else switch(odp
->type
)
156 fprintf( outfile
, " \"\\t.long " PREFIX
"%s\\n\"\n", odp
->link_name
);
161 fprintf( outfile
, " \"\\t.long " PREFIX
"%s\\n\"\n", odp
->link_name
);
164 fprintf( outfile
, " \"\\t.long " PREFIX
"%s\\n\"\n", make_internal_name( odp
, "stub" ) );
167 fprintf( outfile
, " \"\\t.long " PREFIX
"%s\\n\"\n", make_internal_name( odp
, "regs" ) );
170 fprintf( outfile
, " \"\\t.long " PREFIX
"%s\\n\"\n", make_internal_name( odp
, "var" ) );
173 fprintf( outfile
, " \"\\t.long __wine_spec_forwards+%d\\n\"\n", fwd_size
);
174 fwd_size
+= strlen(odp
->link_name
) + 1;
180 total_size
+= (Limit
- Base
+ 1) * sizeof(int);
184 /* output the function name pointers */
188 fprintf( outfile
, " \"__wine_spec_exp_name_ptrs:\\n\"\n" );
189 for (i
= 0; i
< nb_names
; i
++)
191 fprintf( outfile
, " \"\\t.long __wine_spec_exp_names+%d\\n\"\n", namepos
);
192 namepos
+= strlen(Names
[i
]->name
) + 1;
194 total_size
+= nb_names
* sizeof(int);
196 /* output the function names */
198 fprintf( outfile
, " \"\\t.text 1\\n\"\n" );
199 fprintf( outfile
, " \"__wine_spec_exp_names:\\n\"\n" );
200 for (i
= 0; i
< nb_names
; i
++)
201 fprintf( outfile
, " \"\\t" STRING
" \\\"%s\\\"\\n\"\n", Names
[i
]->name
);
202 fprintf( outfile
, " \"\\t.data\\n\"\n" );
204 /* output the function ordinals */
206 fprintf( outfile
, " \"__wine_spec_exp_ordinals:\\n\"\n" );
207 for (i
= 0; i
< nb_names
; i
++)
209 fprintf( outfile
, " \"\\t.short %d\\n\"\n", Names
[i
]->ordinal
- Base
);
211 total_size
+= nb_names
* sizeof(short);
214 fprintf( outfile
, " \"\\t.short 0\\n\"\n" );
215 total_size
+= sizeof(short);
219 /* output forward strings */
223 fprintf( outfile
, " \"__wine_spec_forwards:\\n\"\n" );
224 for (i
= Base
; i
<= Limit
; i
++)
226 ORDDEF
*odp
= Ordinals
[i
];
227 if (odp
&& odp
->type
== TYPE_FORWARD
)
228 fprintf( outfile
, " \"\\t" STRING
" \\\"%s\\\"\\n\"\n", odp
->link_name
);
230 fprintf( outfile
, " \"\\t.align %d\\n\"\n", get_alignment(4) );
231 total_size
+= (fwd_size
+ 3) & ~3;
238 for (i
= Base
; i
<= Limit
; i
++)
240 ORDDEF
*odp
= Ordinals
[i
];
241 unsigned int j
, mask
= 0;
243 /* skip non-existent entry points */
244 if (!odp
) goto ignore
;
245 /* skip non-functions */
246 if ((odp
->type
!= TYPE_STDCALL
) &&
247 (odp
->type
!= TYPE_CDECL
) &&
248 (odp
->type
!= TYPE_REGISTER
)) goto ignore
;
249 /* skip norelay entry points */
250 if (odp
->flags
& FLAG_NORELAY
) goto ignore
;
252 for (j
= 0; odp
->u
.func
.arg_types
[j
]; j
++)
254 if (odp
->u
.func
.arg_types
[j
] == 't') mask
|= 1<< (j
*2);
255 if (odp
->u
.func
.arg_types
[j
] == 'W') mask
|= 2<< (j
*2);
257 if ((odp
->flags
& FLAG_RET64
) && (j
< 16)) mask
|= 0x80000000;
262 fprintf( outfile
, " \"\\tjmp " PREFIX
"%s\\n\"\n", odp
->link_name
);
263 fprintf( outfile
, " \"\\tret $%d\\n\"\n",
264 strlen(odp
->u
.func
.arg_types
) * sizeof(int) );
265 fprintf( outfile
, " \"\\t.long " PREFIX
"%s,0x%08x\\n\"\n",
266 odp
->link_name
, mask
);
269 fprintf( outfile
, " \"\\tjmp " PREFIX
"%s\\n\"\n", odp
->link_name
);
270 fprintf( outfile
, " \"\\tret\\n\"\n" );
271 fprintf( outfile
, " \"\\t.short %d\\n\"\n",
272 strlen(odp
->u
.func
.arg_types
) * sizeof(int) );
273 fprintf( outfile
, " \"\\t.long " PREFIX
"%s,0x%08x\\n\"\n",
274 odp
->link_name
, mask
);
277 fprintf( outfile
, " \"\\tjmp " PREFIX
"%s\\n\"\n",
278 make_internal_name( odp
, "regs" ) );
279 fprintf( outfile
, " \"\\tret\\n\"\n" );
280 fprintf( outfile
, " \"\\t.short 0x%04x\\n\"\n",
281 0x8000 | strlen(odp
->u
.func
.arg_types
) * sizeof(int) );
282 fprintf( outfile
, " \"\\t.long " PREFIX
"%s,0x%08x\\n\"\n",
283 make_internal_name( odp
, "regs" ), mask
);
291 fprintf( outfile
, " \"\\t.long 0,0,0,0\\n\"\n" );
296 /* output __wine_dllexport symbols */
298 for (i
= 0; i
< nb_names
; i
++)
300 if (Names
[i
]->flags
& FLAG_NOIMPORT
) continue;
301 /* check for invalid characters in the name */
302 for (p
= Names
[i
]->name
; *p
; p
++)
303 if (!isalnum(*p
) && *p
!= '_' && *p
!= '.') goto next
;
304 fprintf( outfile
, " \"\\t.globl " PREFIX
"__wine_dllexport_%s_%s\\n\"\n",
305 DLLName
, Names
[i
]->name
);
306 fprintf( outfile
, " \"" PREFIX
"__wine_dllexport_%s_%s:\\n\"\n",
307 DLLName
, Names
[i
]->name
);
310 fprintf( outfile
, " \"\\t.long 0xffffffff\\n\"\n" );
312 /* output variables */
314 for (i
= 0; i
< nb_entry_points
; i
++)
316 ORDDEF
*odp
= EntryPoints
[i
];
317 if (odp
->type
== TYPE_VARIABLE
)
320 fprintf( outfile
, " \"%s:\\n\"\n", make_internal_name( odp
, "var" ) );
321 fprintf( outfile
, " \"\\t.long " );
322 for (j
= 0; j
< odp
->u
.var
.n_values
; j
++)
324 fprintf( outfile
, "0x%08x", odp
->u
.var
.values
[j
] );
325 if (j
< odp
->u
.var
.n_values
-1) fputc( ',', outfile
);
327 fprintf( outfile
, "\\n\"\n" );
331 fprintf( outfile
, ");\n\n" );
337 /*******************************************************************
340 * Output the functions for stub entry points
342 static void output_stub_funcs( FILE *outfile
)
346 for (i
= 0; i
< nb_entry_points
; i
++)
348 ORDDEF
*odp
= EntryPoints
[i
];
349 if (odp
->type
!= TYPE_STUB
) continue;
350 fprintf( outfile
, "#ifdef __GNUC__\n" );
351 fprintf( outfile
, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
352 fprintf( outfile
, "#endif\n\n" );
353 fprintf( outfile
, "struct exc_record {\n" );
354 fprintf( outfile
, " unsigned int code, flags;\n" );
355 fprintf( outfile
, " void *rec, *addr;\n" );
356 fprintf( outfile
, " unsigned int params;\n" );
357 fprintf( outfile
, " const void *info[15];\n" );
358 fprintf( outfile
, "};\n\n" );
359 fprintf( outfile
, "extern void __stdcall RtlRaiseException( struct exc_record * );\n\n" );
360 fprintf( outfile
, "static void __wine_unimplemented( const char *func )\n{\n" );
361 fprintf( outfile
, " struct exc_record rec;\n" );
362 fprintf( outfile
, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB
);
363 fprintf( outfile
, " rec.flags = %d;\n", EH_NONCONTINUABLE
);
364 fprintf( outfile
, " rec.rec = 0;\n" );
365 fprintf( outfile
, " rec.params = 2;\n" );
366 fprintf( outfile
, " rec.info[0] = dllname;\n" );
367 fprintf( outfile
, " rec.info[1] = func;\n" );
368 fprintf( outfile
, "#ifdef __GNUC__\n" );
369 fprintf( outfile
, " rec.addr = __builtin_return_address(1);\n" );
370 fprintf( outfile
, "#else\n" );
371 fprintf( outfile
, " rec.addr = 0;\n" );
372 fprintf( outfile
, "#endif\n" );
373 fprintf( outfile
, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
377 for (i
= 0; i
< nb_entry_points
; i
++)
379 ORDDEF
*odp
= EntryPoints
[i
];
380 if (odp
->type
!= TYPE_STUB
) continue;
381 fprintf( outfile
, "void %s(void) ", make_internal_name( odp
, "stub" ) );
383 fprintf( outfile
, "{ __wine_unimplemented(\"%s\"); }\n", odp
->name
);
385 fprintf( outfile
, "{ __wine_unimplemented(\"%d\"); }\n", odp
->ordinal
);
390 /*******************************************************************
391 * output_register_funcs
393 * Output the functions for register entry points
395 static void output_register_funcs( FILE *outfile
)
400 for (i
= 0; i
< nb_entry_points
; i
++)
402 ORDDEF
*odp
= EntryPoints
[i
];
403 if (odp
->type
!= TYPE_REGISTER
) continue;
404 name
= make_internal_name( odp
, "regs" );
406 "asm(\".align %d\\n\\t\"\n"
407 " \"" __ASM_FUNC("%s") "\\n\\t\"\n"
408 " \"" PREFIX
"%s:\\n\\t\"\n"
409 " \"call " PREFIX
"CALL32_Regs\\n\\t\"\n"
410 " \".long " PREFIX
"%s\\n\\t\"\n"
411 " \".byte %d,%d\");\n",
413 name
, name
, odp
->link_name
,
414 4 * strlen(odp
->u
.func
.arg_types
), 4 * strlen(odp
->u
.func
.arg_types
) );
419 /*******************************************************************
422 * Build a Win32 C file from a spec file.
424 void BuildSpec32File( FILE *outfile
)
426 int exports_size
= 0;
427 int nr_exports
, nr_imports
, nr_resources
, nr_debug
;
428 int characteristics
, subsystem
;
431 #ifdef HAVE_GETPAGESIZE
432 page_size
= getpagesize();
435 page_size
= sysconf(_SC_PAGESIZE
);
437 # error Cannot get the page size on this platform
442 nr_exports
= Base
<= Limit
? Limit
- Base
+ 1 : 0;
446 fprintf( outfile
, "/* File generated automatically from %s; do not edit! */\n\n",
449 /* Reserve some space for the PE header */
451 fprintf( outfile
, "extern char pe_header[];\n" );
452 fprintf( outfile
, "asm(\".section .text\\n\\t\"\n" );
453 fprintf( outfile
, " \".align %d\\n\"\n", get_alignment(page_size
) );
454 fprintf( outfile
, " \"" PREFIX
"pe_header:\\t.fill %ld,1,0\\n\\t\");\n", page_size
);
456 fprintf( outfile
, "static const char dllname[] = \"%s\";\n\n", DLLName
);
457 fprintf( outfile
, "extern int __wine_spec_exports[];\n\n" );
460 fprintf( outfile
, "#define __stdcall __attribute__((__stdcall__))\n\n" );
462 fprintf( outfile
, "#define __stdcall\n\n" );
467 /* Output the stub functions */
469 output_stub_funcs( outfile
);
471 fprintf( outfile
, "#ifndef __GNUC__\n" );
472 fprintf( outfile
, "static void __asm__dummy(void) {\n" );
473 fprintf( outfile
, "#endif /* !defined(__GNUC__) */\n" );
475 /* Output code for all register functions */
477 output_register_funcs( outfile
);
479 /* Output the exports and relay entry points */
481 exports_size
= output_exports( outfile
, nr_exports
);
483 fprintf( outfile
, "#ifndef __GNUC__\n" );
484 fprintf( outfile
, "}\n" );
485 fprintf( outfile
, "#endif /* !defined(__GNUC__) */\n" );
488 /* Output the DLL imports */
490 nr_imports
= output_imports( outfile
);
492 /* Output the resources */
494 nr_resources
= output_resources( outfile
);
496 /* Output the debug channels */
498 nr_debug
= output_debug( outfile
);
500 /* Output LibMain function */
502 characteristics
= subsystem
= 0;
506 if (init_func
) fprintf( outfile
, "extern void %s();\n", init_func
);
507 characteristics
= IMAGE_FILE_DLL
;
509 case SPEC_MODE_GUIEXE
:
510 if (!init_func
) init_func
= "WinMain";
512 "\n#include <winbase.h>\n"
515 "extern int __stdcall %s(HINSTANCE,HINSTANCE,LPSTR,INT);\n"
516 "static void __wine_exe_main(void)\n"
518 " extern int __wine_get_main_args( char ***argv );\n"
519 " STARTUPINFOA info;\n"
520 " LPSTR cmdline = GetCommandLineA();\n"
521 " while (*cmdline && *cmdline != ' ') cmdline++;\n"
522 " if (*cmdline) cmdline++;\n"
523 " GetStartupInfoA( &info );\n"
524 " if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = 1;\n"
525 " _ARGC = __wine_get_main_args( &_ARGV );\n"
526 " ExitProcess( %s( GetModuleHandleA(0), 0, cmdline, info.wShowWindow ) );\n"
527 "}\n\n", init_func
, init_func
);
528 init_func
= "__wine_exe_main";
529 subsystem
= IMAGE_SUBSYSTEM_WINDOWS_GUI
;
531 case SPEC_MODE_GUIEXE_UNICODE
:
532 if (!init_func
) init_func
= "WinMain";
534 "\n#include <winbase.h>\n"
537 "extern int __stdcall %s(HINSTANCE,HINSTANCE,LPSTR,INT);\n"
538 "static void __wine_exe_main(void)\n"
540 " extern int __wine_get_wmain_args( WCHAR ***argv );\n"
541 " STARTUPINFOA info;\n"
542 " LPSTR cmdline = GetCommandLineA();\n"
543 " while (*cmdline && *cmdline != ' ') cmdline++;\n"
544 " if (*cmdline) cmdline++;\n"
545 " GetStartupInfoA( &info );\n"
546 " if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = 1;\n"
547 " _ARGC = __wine_get_wmain_args( &_ARGV );\n"
548 " ExitProcess( %s( GetModuleHandleA(0), 0, cmdline, info.wShowWindow ) );\n"
549 "}\n\n", init_func
, init_func
);
550 init_func
= "__wine_exe_main";
551 subsystem
= IMAGE_SUBSYSTEM_WINDOWS_GUI
;
553 case SPEC_MODE_CUIEXE
:
554 if (!init_func
) init_func
= "main";
558 "extern void __stdcall ExitProcess(int);\n"
559 "static void __wine_exe_main(void)\n"
561 " extern int %s( int argc, char *argv[] );\n"
562 " extern int __wine_get_main_args( char ***argv );\n"
563 " _ARGC = __wine_get_main_args( &_ARGV );\n"
564 " ExitProcess( %s( _ARGC, _ARGV ) );\n"
565 "}\n\n", init_func
, init_func
);
566 init_func
= "__wine_exe_main";
567 subsystem
= IMAGE_SUBSYSTEM_WINDOWS_CUI
;
569 case SPEC_MODE_CUIEXE_UNICODE
:
570 if (!init_func
) init_func
= "wmain";
572 "\ntypedef unsigned short WCHAR;\n"
575 "extern void __stdcall ExitProcess(int);\n"
576 "static void __wine_exe_main(void)\n"
578 " extern int %s( int argc, WCHAR *argv[] );\n"
579 " extern int __wine_get_wmain_args( WCHAR ***argv );\n"
580 " _ARGC = __wine_get_wmain_args( &_ARGV );\n"
581 " ExitProcess( %s( _ARGC, _ARGV ) );\n"
582 "}\n\n", init_func
, init_func
);
583 init_func
= "__wine_exe_main";
584 subsystem
= IMAGE_SUBSYSTEM_WINDOWS_CUI
;
588 /* Output the NT header */
590 /* this is the IMAGE_NT_HEADERS structure, but we cannot include winnt.h here */
591 fprintf( outfile
, "static const struct image_nt_headers\n{\n" );
592 fprintf( outfile
, " int Signature;\n" );
593 fprintf( outfile
, " struct file_header {\n" );
594 fprintf( outfile
, " short Machine;\n" );
595 fprintf( outfile
, " short NumberOfSections;\n" );
596 fprintf( outfile
, " int TimeDateStamp;\n" );
597 fprintf( outfile
, " void *PointerToSymbolTable;\n" );
598 fprintf( outfile
, " int NumberOfSymbols;\n" );
599 fprintf( outfile
, " short SizeOfOptionalHeader;\n" );
600 fprintf( outfile
, " short Characteristics;\n" );
601 fprintf( outfile
, " } FileHeader;\n" );
602 fprintf( outfile
, " struct opt_header {\n" );
603 fprintf( outfile
, " short Magic;\n" );
604 fprintf( outfile
, " char MajorLinkerVersion, MinorLinkerVersion;\n" );
605 fprintf( outfile
, " int SizeOfCode;\n" );
606 fprintf( outfile
, " int SizeOfInitializedData;\n" );
607 fprintf( outfile
, " int SizeOfUninitializedData;\n" );
608 fprintf( outfile
, " void *AddressOfEntryPoint;\n" );
609 fprintf( outfile
, " void *BaseOfCode;\n" );
610 fprintf( outfile
, " void *BaseOfData;\n" );
611 fprintf( outfile
, " void *ImageBase;\n" );
612 fprintf( outfile
, " int SectionAlignment;\n" );
613 fprintf( outfile
, " int FileAlignment;\n" );
614 fprintf( outfile
, " short MajorOperatingSystemVersion;\n" );
615 fprintf( outfile
, " short MinorOperatingSystemVersion;\n" );
616 fprintf( outfile
, " short MajorImageVersion;\n" );
617 fprintf( outfile
, " short MinorImageVersion;\n" );
618 fprintf( outfile
, " short MajorSubsystemVersion;\n" );
619 fprintf( outfile
, " short MinorSubsystemVersion;\n" );
620 fprintf( outfile
, " int Win32VersionValue;\n" );
621 fprintf( outfile
, " int SizeOfImage;\n" );
622 fprintf( outfile
, " int SizeOfHeaders;\n" );
623 fprintf( outfile
, " int CheckSum;\n" );
624 fprintf( outfile
, " short Subsystem;\n" );
625 fprintf( outfile
, " short DllCharacteristics;\n" );
626 fprintf( outfile
, " int SizeOfStackReserve;\n" );
627 fprintf( outfile
, " int SizeOfStackCommit;\n" );
628 fprintf( outfile
, " int SizeOfHeapReserve;\n" );
629 fprintf( outfile
, " int SizeOfHeapCommit;\n" );
630 fprintf( outfile
, " int LoaderFlags;\n" );
631 fprintf( outfile
, " int NumberOfRvaAndSizes;\n" );
632 fprintf( outfile
, " struct { const void *VirtualAddress; int Size; } DataDirectory[%d];\n",
633 IMAGE_NUMBEROF_DIRECTORY_ENTRIES
);
634 fprintf( outfile
, " } OptionalHeader;\n" );
635 fprintf( outfile
, "} nt_header = {\n" );
636 fprintf( outfile
, " 0x%04x,\n", IMAGE_NT_SIGNATURE
); /* Signature */
638 fprintf( outfile
, " { 0x%04x,\n", IMAGE_FILE_MACHINE_I386
); /* Machine */
639 fprintf( outfile
, " 0, 0, 0, 0,\n" );
640 fprintf( outfile
, " sizeof(nt_header.OptionalHeader),\n" ); /* SizeOfOptionalHeader */
641 fprintf( outfile
, " 0x%04x },\n", characteristics
); /* Characteristics */
643 fprintf( outfile
, " { 0x%04x,\n", IMAGE_NT_OPTIONAL_HDR_MAGIC
); /* Magic */
644 fprintf( outfile
, " 0, 0,\n" ); /* Major/MinorLinkerVersion */
645 fprintf( outfile
, " 0, 0, 0,\n" ); /* SizeOfCode/Data */
646 fprintf( outfile
, " %s,\n", init_func
? init_func
: "0" ); /* AddressOfEntryPoint */
647 fprintf( outfile
, " 0, 0,\n" ); /* BaseOfCode/Data */
648 fprintf( outfile
, " pe_header,\n" ); /* ImageBase */
649 fprintf( outfile
, " %ld,\n", page_size
); /* SectionAlignment */
650 fprintf( outfile
, " %ld,\n", page_size
); /* FileAlignment */
651 fprintf( outfile
, " 1, 0,\n" ); /* Major/MinorOperatingSystemVersion */
652 fprintf( outfile
, " 0, 0,\n" ); /* Major/MinorImageVersion */
653 fprintf( outfile
, " 4, 0,\n" ); /* Major/MinorSubsystemVersion */
654 fprintf( outfile
, " 0,\n" ); /* Win32VersionValue */
655 fprintf( outfile
, " %ld,\n", page_size
); /* SizeOfImage */
656 fprintf( outfile
, " %ld,\n", page_size
); /* SizeOfHeaders */
657 fprintf( outfile
, " 0,\n" ); /* CheckSum */
658 fprintf( outfile
, " 0x%04x,\n", subsystem
); /* Subsystem */
659 fprintf( outfile
, " 0,\n" ); /* DllCharacteristics */
660 fprintf( outfile
, " %d, 0,\n", stack_size
*1024 ); /* SizeOfStackReserve/Commit */
661 fprintf( outfile
, " %d, 0,\n", DLLHeapSize
*1024 );/* SizeOfHeapReserve/Commit */
662 fprintf( outfile
, " 0,\n" ); /* LoaderFlags */
663 fprintf( outfile
, " %d,\n", IMAGE_NUMBEROF_DIRECTORY_ENTRIES
); /* NumberOfRvaAndSizes */
664 fprintf( outfile
, " {\n" );
665 fprintf( outfile
, " { %s, %d },\n", /* IMAGE_DIRECTORY_ENTRY_EXPORT */
666 exports_size
? "__wine_spec_exports" : "0", exports_size
);
667 fprintf( outfile
, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_IMPORT */
668 nr_imports
? "&imports" : "0", nr_imports
? "sizeof(imports)" : "0" );
669 fprintf( outfile
, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_RESOURCE */
670 nr_resources
? "&resources" : "0", nr_resources
? "sizeof(resources)" : "0" );
671 fprintf( outfile
, " }\n }\n};\n\n" );
673 /* Output the DLL constructor */
675 fprintf( outfile
, "#ifndef __GNUC__\n" );
676 fprintf( outfile
, "static void __asm__dummy_dll_init(void) {\n" );
677 fprintf( outfile
, "#endif /* defined(__GNUC__) */\n" );
679 #if defined(__i386__)
680 fprintf( outfile
, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
681 fprintf( outfile
, " \"\\tcall " PREFIX
"__wine_spec_%s_init\\n\"\n", DLLName
);
682 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
685 fprintf( outfile
, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
686 fprintf( outfile
, " \"\\tcall " PREFIX
"__wine_spec_%s_fini\\n\"\n", DLLName
);
687 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
689 #elif defined(__sparc__)
690 fprintf( outfile
, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
691 fprintf( outfile
, " \"\\tcall " PREFIX
"__wine_spec_%s_init\\n\"\n", DLLName
);
692 fprintf( outfile
, " \"\\tnop\\n\"\n" );
693 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
696 fprintf( outfile
, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
697 fprintf( outfile
, " \"\\tcall " PREFIX
"__wine_spec_%s_fini\\n\"\n", DLLName
);
698 fprintf( outfile
, " \"\\tnop\\n\"\n" );
699 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
701 #elif defined(__PPC__)
702 fprintf( outfile
, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
703 fprintf( outfile
, " \"\\tbl " PREFIX
"__wine_spec_%s_init\\n\"\n",
705 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
708 fprintf( outfile
, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
709 fprintf( outfile
, " \"\\tbl " PREFIX
"__wine_spec_%s_fini\\n\"\n",
711 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
714 #error You need to define the DLL constructor for your architecture
717 fprintf( outfile
, "#ifndef __GNUC__\n" );
718 fprintf( outfile
, "}\n" );
719 fprintf( outfile
, "#endif /* defined(__GNUC__) */\n\n" );
722 "void __wine_spec_%s_init(void)\n"
724 " extern void __wine_dll_register( const struct image_nt_headers *, const char * );\n"
725 " extern void *__wine_dbg_register( char * const *, int );\n"
726 " __wine_dll_register( &nt_header, \"%s\" );\n",
727 DLLName
, DLLFileName
);
729 fprintf( outfile
, " debug_registration = __wine_dbg_register( debug_channels, %d );\n",
731 fprintf( outfile
, "}\n" );
735 "\nvoid __wine_spec_%s_fini(void)\n"
737 " extern void __wine_dbg_unregister( void* );\n"
738 " __wine_dbg_unregister( debug_registration );\n"