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
19 #include "wine/exception.h"
23 static int string_compare( const void *ptr1, const void *ptr2 )
25 const char * const *str1 = ptr1;
26 const char * const *str2 = ptr2;
27 return strcmp( *str1, *str2 );
31 /*******************************************************************
34 * Generate an internal name for an entry point. Used for stubs etc.
36 static const char *make_internal_name( const ORDDEF *odp, const char *prefix )
38 static char buffer[256];
42 sprintf( buffer, "__wine_%s_%s_%s", prefix, DLLName, odp->name );
43 /* make sure name is a legal C identifier */
44 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
45 if (!*p) return buffer;
47 sprintf( buffer, "__wine_%s_%s_%d", prefix, DLLName, odp->ordinal );
51 /*******************************************************************
54 * Assign ordinals to all entry points.
56 static void AssignOrdinals(void)
60 if ( !nb_names ) return;
62 /* start assigning from Base, or from 1 if no ordinal defined yet */
63 if (Base == MAX_ORDINALS) Base = 1;
64 for (i = 0, ordinal = Base; i < nb_names; i++)
66 if (Names[i]->ordinal != -1) continue; /* already has an ordinal */
67 while (Ordinals[ordinal]) ordinal++;
68 if (ordinal >= MAX_ORDINALS)
70 current_line = Names[i]->lineno;
71 fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
73 Names[i]->ordinal = ordinal;
74 Ordinals[ordinal] = Names[i];
76 if (ordinal > Limit) Limit = ordinal;
80 /*******************************************************************
83 * Output the debug channels.
85 static int output_debug( FILE *outfile )
89 if (!nb_debug_channels) return 0;
90 qsort( debug_channels, nb_debug_channels, sizeof(debug_channels[0]), string_compare );
92 for (i = 0; i < nb_debug_channels; i++)
93 fprintf( outfile, "char __wine_dbch_%s[] = \"\\003%s\";\n",
94 debug_channels[i], debug_channels[i] );
96 fprintf( outfile, "\nstatic char * const debug_channels[%d] =\n{\n", nb_debug_channels );
97 for (i = 0; i < nb_debug_channels; i++)
99 fprintf( outfile, " __wine_dbch_%s", debug_channels[i] );
100 if (i < nb_debug_channels - 1) fprintf( outfile, ",\n" );
102 fprintf( outfile, "\n};\n\n" );
103 fprintf( outfile, "static void *debug_registration;\n\n" );
105 return nb_debug_channels;
109 /*******************************************************************
112 * Output the export table for a Win32 module.
114 static int output_exports( FILE *outfile, int nr_exports )
116 int i, fwd_size = 0, total_size = 0;
119 if (!nr_exports) return 0;
121 fprintf( outfile, "asm(\".data\\n\"\n" );
122 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
123 fprintf( outfile, " \"" PREFIX "__wine_spec_exports:\\n\"\n" );
125 /* export directory header */
127 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* Characteristics */
128 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* TimeDateStamp */
129 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* MajorVersion/MinorVersion */
130 fprintf( outfile, " \"\\t.long " PREFIX "dllname\\n\"\n" ); /* Name */
131 fprintf( outfile, " \"\\t.long %d\\n\"\n", Base ); /* Base */
132 fprintf( outfile, " \"\\t.long %d\\n\"\n", nr_exports ); /* NumberOfFunctions */
133 fprintf( outfile, " \"\\t.long %d\\n\"\n", nb_names ); /* NumberOfNames */
134 fprintf( outfile, " \"\\t.long __wine_spec_exports_funcs\\n\"\n" ); /* AddressOfFunctions */
137 fprintf( outfile, " \"\\t.long __wine_spec_exp_name_ptrs\\n\"\n" ); /* AddressOfNames */
138 fprintf( outfile, " \"\\t.long __wine_spec_exp_ordinals\\n\"\n" ); /* AddressOfNameOrdinals */
142 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* AddressOfNames */
143 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* AddressOfNameOrdinals */
145 total_size += 10 * sizeof(int);
147 /* output the function pointers */
149 fprintf( outfile, " \"__wine_spec_exports_funcs:\\n\"\n" );
150 for (i = Base; i <= Limit; i++)
152 ORDDEF *odp = Ordinals[i];
153 if (!odp) fprintf( outfile, " \"\\t.long 0\\n\"\n" );
154 else switch(odp->type)
157 fprintf( outfile, " \"\\t.long " PREFIX "%s\\n\"\n", odp->link_name );
162 fprintf( outfile, " \"\\t.long " PREFIX "%s\\n\"\n", odp->link_name);
165 fprintf( outfile, " \"\\t.long " PREFIX "%s\\n\"\n", make_internal_name( odp, "stub" ) );
168 fprintf( outfile, " \"\\t.long " PREFIX "%s\\n\"\n", make_internal_name( odp, "regs" ) );
171 fprintf( outfile, " \"\\t.long " PREFIX "%s\\n\"\n", make_internal_name( odp, "var" ) );
174 fprintf( outfile, " \"\\t.long __wine_spec_forwards+%d\\n\"\n", fwd_size );
175 fwd_size += strlen(odp->link_name) + 1;
181 total_size += (Limit - Base + 1) * sizeof(int);
185 /* output the function name pointers */
189 fprintf( outfile, " \"__wine_spec_exp_name_ptrs:\\n\"\n" );
190 for (i = 0; i < nb_names; i++)
192 fprintf( outfile, " \"\\t.long __wine_spec_exp_names+%d\\n\"\n", namepos );
193 namepos += strlen(Names[i]->name) + 1;
195 total_size += nb_names * sizeof(int);
197 /* output the function names */
199 fprintf( outfile, " \"\\t.text 1\\n\"\n" );
200 fprintf( outfile, " \"__wine_spec_exp_names:\\n\"\n" );
201 for (i = 0; i < nb_names; i++)
202 fprintf( outfile, " \"\\t" STRING " \\\"%s\\\"\\n\"\n", Names[i]->name );
203 fprintf( outfile, " \"\\t.data\\n\"\n" );
205 /* output the function ordinals */
207 fprintf( outfile, " \"__wine_spec_exp_ordinals:\\n\"\n" );
208 for (i = 0; i < nb_names; i++)
210 fprintf( outfile, " \"\\t.short %d\\n\"\n", Names[i]->ordinal - Base );
212 total_size += nb_names * sizeof(short);
215 fprintf( outfile, " \"\\t.short 0\\n\"\n" );
216 total_size += sizeof(short);
220 /* output forward strings */
224 fprintf( outfile, " \"__wine_spec_forwards:\\n\"\n" );
225 for (i = Base; i <= Limit; i++)
227 ORDDEF *odp = Ordinals[i];
228 if (odp && odp->type == TYPE_FORWARD)
229 fprintf( outfile, " \"\\t" STRING " \\\"%s\\\"\\n\"\n", odp->link_name );
231 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
232 total_size += (fwd_size + 3) & ~3;
239 for (i = Base; i <= Limit; i++)
241 ORDDEF *odp = Ordinals[i];
242 unsigned int j, mask = 0;
244 /* skip non-existent entry points */
245 if (!odp) goto ignore;
246 /* skip non-functions */
247 if ((odp->type != TYPE_STDCALL) &&
248 (odp->type != TYPE_CDECL) &&
249 (odp->type != TYPE_REGISTER)) goto ignore;
250 /* skip norelay entry points */
251 if (odp->flags & FLAG_NORELAY) goto ignore;
253 for (j = 0; odp->u.func.arg_types[j]; j++)
255 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
256 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
258 if ((odp->flags & FLAG_RET64) && (j < 16)) mask |= 0x80000000;
263 fprintf( outfile, " \"\\tjmp " PREFIX "%s\\n\"\n", odp->link_name );
264 fprintf( outfile, " \"\\tret $%d\\n\"\n",
265 strlen(odp->u.func.arg_types) * sizeof(int) );
266 fprintf( outfile, " \"\\t.long " PREFIX "%s,0x%08x\\n\"\n",
267 odp->link_name, mask );
270 fprintf( outfile, " \"\\tjmp " PREFIX "%s\\n\"\n", odp->link_name );
271 fprintf( outfile, " \"\\tret\\n\"\n" );
272 fprintf( outfile, " \"\\t.short %d\\n\"\n",
273 strlen(odp->u.func.arg_types) * sizeof(int) );
274 fprintf( outfile, " \"\\t.long " PREFIX "%s,0x%08x\\n\"\n",
275 odp->link_name, mask );
278 fprintf( outfile, " \"\\tjmp " PREFIX "%s\\n\"\n",
279 make_internal_name( odp, "regs" ) );
280 fprintf( outfile, " \"\\tret\\n\"\n" );
281 fprintf( outfile, " \"\\t.short 0x%04x\\n\"\n",
282 0x8000 | strlen(odp->u.func.arg_types) * sizeof(int) );
283 fprintf( outfile, " \"\\t.long " PREFIX "%s,0x%08x\\n\"\n",
284 make_internal_name( odp, "regs" ), mask );
292 fprintf( outfile, " \"\\t.long 0,0,0,0\\n\"\n" );
297 /* output __wine_dllexport symbols */
299 for (i = 0; i < nb_names; i++)
301 if (Names[i]->flags & FLAG_NOIMPORT) continue;
302 /* check for invalid characters in the name */
303 for (p = Names[i]->name; *p; p++)
304 if (!isalnum(*p) && *p != '_' && *p != '.') break;
306 fprintf( outfile, " \"\\t.globl " PREFIX "__wine_dllexport_%s_%s\\n\"\n",
307 DLLName, Names[i]->name );
308 fprintf( outfile, " \"" PREFIX "__wine_dllexport_%s_%s:\\n\"\n",
309 DLLName, Names[i]->name );
311 fprintf( outfile, " \"\\t.long 0xffffffff\\n\"\n" );
313 /* output variables */
315 for (i = 0; i < nb_entry_points; i++)
317 ORDDEF *odp = EntryPoints[i];
318 if (odp->type == TYPE_VARIABLE)
321 fprintf( outfile, " \"%s:\\n\"\n", make_internal_name( odp, "var" ) );
322 fprintf( outfile, " \"\\t.long " );
323 for (j = 0; j < odp->u.var.n_values; j++)
325 fprintf( outfile, "0x%08x", odp->u.var.values[j] );
326 if (j < odp->u.var.n_values-1) fputc( ',', outfile );
328 fprintf( outfile, "\\n\"\n" );
332 fprintf( outfile, ");\n\n" );
338 /*******************************************************************
341 * Output the functions for stub entry points
343 static void output_stub_funcs( FILE *outfile )
347 for (i = 0; i < nb_entry_points; i++)
349 ORDDEF *odp = EntryPoints[i];
350 if (odp->type != TYPE_STUB) continue;
351 fprintf( outfile, "#ifdef __GNUC__\n" );
352 fprintf( outfile, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
353 fprintf( outfile, "#endif\n\n" );
354 fprintf( outfile, "struct exc_record {\n" );
355 fprintf( outfile, " unsigned int code, flags;\n" );
356 fprintf( outfile, " void *rec, *addr;\n" );
357 fprintf( outfile, " unsigned int params;\n" );
358 fprintf( outfile, " const void *info[15];\n" );
359 fprintf( outfile, "};\n\n" );
360 fprintf( outfile, "extern void __stdcall RtlRaiseException( struct exc_record * );\n\n" );
361 fprintf( outfile, "static void __wine_unimplemented( const char *func )\n{\n" );
362 fprintf( outfile, " struct exc_record rec;\n" );
363 fprintf( outfile, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB );
364 fprintf( outfile, " rec.flags = %d;\n", EH_NONCONTINUABLE );
365 fprintf( outfile, " rec.rec = 0;\n" );
366 fprintf( outfile, " rec.params = 2;\n" );
367 fprintf( outfile, " rec.info[0] = dllname;\n" );
368 fprintf( outfile, " rec.info[1] = func;\n" );
369 fprintf( outfile, "#ifdef __GNUC__\n" );
370 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
371 fprintf( outfile, "#else\n" );
372 fprintf( outfile, " rec.addr = 0;\n" );
373 fprintf( outfile, "#endif\n" );
374 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
378 for (i = 0; i < nb_entry_points; i++)
380 ORDDEF *odp = EntryPoints[i];
381 if (odp->type != TYPE_STUB) continue;
382 fprintf( outfile, "void %s(void) ", make_internal_name( odp, "stub" ) );
384 fprintf( outfile, "{ __wine_unimplemented(\"%s\"); }\n", odp->name );
386 fprintf( outfile, "{ __wine_unimplemented(\"%d\"); }\n", odp->ordinal );
391 /*******************************************************************
392 * output_register_funcs
394 * Output the functions for register entry points
396 static void output_register_funcs( FILE *outfile )
401 for (i = 0; i < nb_entry_points; i++)
403 ORDDEF *odp = EntryPoints[i];
404 if (odp->type != TYPE_REGISTER) continue;
405 name = make_internal_name( odp, "regs" );
407 "asm(\".align %d\\n\\t\"\n"
408 " \"" __ASM_FUNC("%s") "\\n\\t\"\n"
409 " \"" PREFIX "%s:\\n\\t\"\n"
410 " \"call " PREFIX "CALL32_Regs\\n\\t\"\n"
411 " \".long " PREFIX "%s\\n\\t\"\n"
412 " \".byte %d,%d\");\n",
414 name, name, odp->link_name,
415 4 * strlen(odp->u.func.arg_types), 4 * strlen(odp->u.func.arg_types) );
420 /*******************************************************************
423 * Build a Win32 C file from a spec file.
425 void BuildSpec32File( FILE *outfile )
427 int exports_size = 0;
428 int nr_exports, nr_imports, nr_resources, nr_debug;
429 int characteristics, subsystem;
432 #ifdef HAVE_GETPAGESIZE
433 page_size = getpagesize();
436 page_size = sysconf(_SC_PAGESIZE);
438 # error Cannot get the page size on this platform
443 nr_exports = Base <= Limit ? Limit - Base + 1 : 0;
447 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
450 /* Reserve some space for the PE header */
452 fprintf( outfile, "extern char pe_header[];\n" );
453 fprintf( outfile, "asm(\".section .text\\n\\t\"\n" );
454 fprintf( outfile, " \".align %d\\n\"\n", get_alignment(page_size) );
455 fprintf( outfile, " \"" PREFIX "pe_header:\\t.fill %ld,1,0\\n\\t\");\n", page_size );
457 fprintf( outfile, "static const char dllname[] = \"%s\";\n\n", DLLName );
458 fprintf( outfile, "extern int __wine_spec_exports[];\n\n" );
461 fprintf( outfile, "#define __stdcall __attribute__((__stdcall__))\n\n" );
463 fprintf( outfile, "#define __stdcall\n\n" );
468 /* Output the stub functions */
470 output_stub_funcs( outfile );
472 fprintf( outfile, "#ifndef __GNUC__\n" );
473 fprintf( outfile, "static void __asm__dummy(void) {\n" );
474 fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
476 /* Output code for all register functions */
478 output_register_funcs( outfile );
480 /* Output the exports and relay entry points */
482 exports_size = output_exports( outfile, nr_exports );
484 fprintf( outfile, "#ifndef __GNUC__\n" );
485 fprintf( outfile, "}\n" );
486 fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
489 /* Output the DLL imports */
491 nr_imports = output_imports( outfile );
493 /* Output the resources */
495 nr_resources = output_resources( outfile );
497 /* Output the debug channels */
499 nr_debug = output_debug( outfile );
501 /* Output LibMain function */
503 characteristics = subsystem = 0;
507 if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
508 characteristics = IMAGE_FILE_DLL;
510 case SPEC_MODE_GUIEXE:
511 if (!init_func) init_func = "WinMain";
513 "\ntypedef struct {\n"
514 " unsigned int cb;\n"
515 " char *lpReserved, *lpDesktop, *lpTitle;\n"
516 " unsigned int dwX, dwY, dwXSize, dwYSize;\n"
517 " unsigned int dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;\n"
518 " unsigned short wShowWindow, cbReserved2;\n"
519 " char *lpReserved2;\n"
520 " void *hStdInput, *hStdOutput, *hStdError;\n"
524 "extern int __stdcall %s(void *,void *,char *,int);\n"
525 "extern char * __stdcall GetCommandLineA(void);\n"
526 "extern void * __stdcall GetModuleHandleA(char *);\n"
527 "extern void __stdcall GetStartupInfoA(STARTUPINFOA *);\n"
528 "extern void __stdcall ExitProcess(unsigned int);\n"
529 "static void __wine_exe_main(void)\n"
531 " extern int __wine_get_main_args( char ***argv );\n"
532 " STARTUPINFOA info;\n"
533 " char *cmdline = GetCommandLineA();\n"
534 " while (*cmdline && *cmdline != ' ') cmdline++;\n"
535 " if (*cmdline) cmdline++;\n"
536 " GetStartupInfoA( &info );\n"
537 " if (!(info.dwFlags & 1)) info.wShowWindow = 1;\n"
538 " _ARGC = __wine_get_main_args( &_ARGV );\n"
539 " ExitProcess( %s( GetModuleHandleA(0), 0, cmdline, info.wShowWindow ) );\n"
540 "}\n\n", init_func, init_func );
541 init_func = "__wine_exe_main";
542 subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
544 case SPEC_MODE_GUIEXE_UNICODE:
545 if (!init_func) init_func = "WinMain";
547 "\ntypedef unsigned short WCHAR;\n"
549 " unsigned int cb;\n"
550 " char *lpReserved, *lpDesktop, *lpTitle;\n"
551 " unsigned int dwX, dwY, dwXSize, dwYSize;\n"
552 " unsigned int dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;\n"
553 " unsigned short wShowWindow, cbReserved2;\n"
554 " char *lpReserved2;\n"
555 " void *hStdInput, *hStdOutput, *hStdError;\n"
559 "extern int __stdcall %s(void *,void *,char *,int);\n"
560 "extern char * __stdcall GetCommandLineA(void);\n"
561 "extern void * __stdcall GetModuleHandleA(char *);\n"
562 "extern void __stdcall GetStartupInfoA(STARTUPINFOA *);\n"
563 "extern void __stdcall ExitProcess(unsigned int);\n"
564 "static void __wine_exe_main(void)\n"
566 " extern int __wine_get_wmain_args( WCHAR ***argv );\n"
567 " STARTUPINFOA info;\n"
568 " char *cmdline = GetCommandLineA();\n"
569 " while (*cmdline && *cmdline != ' ') cmdline++;\n"
570 " if (*cmdline) cmdline++;\n"
571 " GetStartupInfoA( &info );\n"
572 " if (!(info.dwFlags & 1)) info.wShowWindow = 1;\n"
573 " _ARGC = __wine_get_wmain_args( &_ARGV );\n"
574 " ExitProcess( %s( GetModuleHandleA(0), 0, cmdline, info.wShowWindow ) );\n"
575 "}\n\n", init_func, init_func );
576 init_func = "__wine_exe_main";
577 subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
579 case SPEC_MODE_CUIEXE:
580 if (!init_func) init_func = "main";
584 "extern void __stdcall ExitProcess(int);\n"
585 "static void __wine_exe_main(void)\n"
587 " extern int %s( int argc, char *argv[] );\n"
588 " extern int __wine_get_main_args( char ***argv );\n"
589 " _ARGC = __wine_get_main_args( &_ARGV );\n"
590 " ExitProcess( %s( _ARGC, _ARGV ) );\n"
591 "}\n\n", init_func, init_func );
592 init_func = "__wine_exe_main";
593 subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
595 case SPEC_MODE_CUIEXE_UNICODE:
596 if (!init_func) init_func = "wmain";
598 "\ntypedef unsigned short WCHAR;\n"
601 "extern void __stdcall ExitProcess(int);\n"
602 "static void __wine_exe_main(void)\n"
604 " extern int %s( int argc, WCHAR *argv[] );\n"
605 " extern int __wine_get_wmain_args( WCHAR ***argv );\n"
606 " _ARGC = __wine_get_wmain_args( &_ARGV );\n"
607 " ExitProcess( %s( _ARGC, _ARGV ) );\n"
608 "}\n\n", init_func, init_func );
609 init_func = "__wine_exe_main";
610 subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
614 /* Output the NT header */
616 /* this is the IMAGE_NT_HEADERS structure, but we cannot include winnt.h here */
617 fprintf( outfile, "static const struct image_nt_headers\n{\n" );
618 fprintf( outfile, " int Signature;\n" );
619 fprintf( outfile, " struct file_header {\n" );
620 fprintf( outfile, " short Machine;\n" );
621 fprintf( outfile, " short NumberOfSections;\n" );
622 fprintf( outfile, " int TimeDateStamp;\n" );
623 fprintf( outfile, " void *PointerToSymbolTable;\n" );
624 fprintf( outfile, " int NumberOfSymbols;\n" );
625 fprintf( outfile, " short SizeOfOptionalHeader;\n" );
626 fprintf( outfile, " short Characteristics;\n" );
627 fprintf( outfile, " } FileHeader;\n" );
628 fprintf( outfile, " struct opt_header {\n" );
629 fprintf( outfile, " short Magic;\n" );
630 fprintf( outfile, " char MajorLinkerVersion, MinorLinkerVersion;\n" );
631 fprintf( outfile, " int SizeOfCode;\n" );
632 fprintf( outfile, " int SizeOfInitializedData;\n" );
633 fprintf( outfile, " int SizeOfUninitializedData;\n" );
634 fprintf( outfile, " void *AddressOfEntryPoint;\n" );
635 fprintf( outfile, " void *BaseOfCode;\n" );
636 fprintf( outfile, " void *BaseOfData;\n" );
637 fprintf( outfile, " void *ImageBase;\n" );
638 fprintf( outfile, " int SectionAlignment;\n" );
639 fprintf( outfile, " int FileAlignment;\n" );
640 fprintf( outfile, " short MajorOperatingSystemVersion;\n" );
641 fprintf( outfile, " short MinorOperatingSystemVersion;\n" );
642 fprintf( outfile, " short MajorImageVersion;\n" );
643 fprintf( outfile, " short MinorImageVersion;\n" );
644 fprintf( outfile, " short MajorSubsystemVersion;\n" );
645 fprintf( outfile, " short MinorSubsystemVersion;\n" );
646 fprintf( outfile, " int Win32VersionValue;\n" );
647 fprintf( outfile, " int SizeOfImage;\n" );
648 fprintf( outfile, " int SizeOfHeaders;\n" );
649 fprintf( outfile, " int CheckSum;\n" );
650 fprintf( outfile, " short Subsystem;\n" );
651 fprintf( outfile, " short DllCharacteristics;\n" );
652 fprintf( outfile, " int SizeOfStackReserve;\n" );
653 fprintf( outfile, " int SizeOfStackCommit;\n" );
654 fprintf( outfile, " int SizeOfHeapReserve;\n" );
655 fprintf( outfile, " int SizeOfHeapCommit;\n" );
656 fprintf( outfile, " int LoaderFlags;\n" );
657 fprintf( outfile, " int NumberOfRvaAndSizes;\n" );
658 fprintf( outfile, " struct { const void *VirtualAddress; int Size; } DataDirectory[%d];\n",
659 IMAGE_NUMBEROF_DIRECTORY_ENTRIES );
660 fprintf( outfile, " } OptionalHeader;\n" );
661 fprintf( outfile, "} nt_header = {\n" );
662 fprintf( outfile, " 0x%04x,\n", IMAGE_NT_SIGNATURE ); /* Signature */
664 fprintf( outfile, " { 0x%04x,\n", IMAGE_FILE_MACHINE_I386 ); /* Machine */
665 fprintf( outfile, " 0, 0, 0, 0,\n" );
666 fprintf( outfile, " sizeof(nt_header.OptionalHeader),\n" ); /* SizeOfOptionalHeader */
667 fprintf( outfile, " 0x%04x },\n", characteristics ); /* Characteristics */
669 fprintf( outfile, " { 0x%04x,\n", IMAGE_NT_OPTIONAL_HDR_MAGIC ); /* Magic */
670 fprintf( outfile, " 0, 0,\n" ); /* Major/MinorLinkerVersion */
671 fprintf( outfile, " 0, 0, 0,\n" ); /* SizeOfCode/Data */
672 fprintf( outfile, " %s,\n", init_func ? init_func : "0" ); /* AddressOfEntryPoint */
673 fprintf( outfile, " 0, 0,\n" ); /* BaseOfCode/Data */
674 fprintf( outfile, " pe_header,\n" ); /* ImageBase */
675 fprintf( outfile, " %ld,\n", page_size ); /* SectionAlignment */
676 fprintf( outfile, " %ld,\n", page_size ); /* FileAlignment */
677 fprintf( outfile, " 1, 0,\n" ); /* Major/MinorOperatingSystemVersion */
678 fprintf( outfile, " 0, 0,\n" ); /* Major/MinorImageVersion */
679 fprintf( outfile, " 4, 0,\n" ); /* Major/MinorSubsystemVersion */
680 fprintf( outfile, " 0,\n" ); /* Win32VersionValue */
681 fprintf( outfile, " %ld,\n", page_size ); /* SizeOfImage */
682 fprintf( outfile, " %ld,\n", page_size ); /* SizeOfHeaders */
683 fprintf( outfile, " 0,\n" ); /* CheckSum */
684 fprintf( outfile, " 0x%04x,\n", subsystem ); /* Subsystem */
685 fprintf( outfile, " 0,\n" ); /* DllCharacteristics */
686 fprintf( outfile, " %d, 0,\n", stack_size*1024 ); /* SizeOfStackReserve/Commit */
687 fprintf( outfile, " %d, 0,\n", DLLHeapSize*1024 );/* SizeOfHeapReserve/Commit */
688 fprintf( outfile, " 0,\n" ); /* LoaderFlags */
689 fprintf( outfile, " %d,\n", IMAGE_NUMBEROF_DIRECTORY_ENTRIES ); /* NumberOfRvaAndSizes */
690 fprintf( outfile, " {\n" );
691 fprintf( outfile, " { %s, %d },\n", /* IMAGE_DIRECTORY_ENTRY_EXPORT */
692 exports_size ? "__wine_spec_exports" : "0", exports_size );
693 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_IMPORT */
694 nr_imports ? "&imports" : "0", nr_imports ? "sizeof(imports)" : "0" );
695 fprintf( outfile, " { %s, %s },\n", /* IMAGE_DIRECTORY_ENTRY_RESOURCE */
696 nr_resources ? "&resources" : "0", nr_resources ? "sizeof(resources)" : "0" );
697 fprintf( outfile, " }\n }\n};\n\n" );
699 /* Output the DLL constructor */
701 fprintf( outfile, "#ifndef __GNUC__\n" );
702 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
703 fprintf( outfile, "#endif /* defined(__GNUC__) */\n" );
705 #if defined(__i386__)
706 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
707 fprintf( outfile, " \"\\tcall " PREFIX "__wine_spec_%s_init\\n\"\n", DLLName );
708 fprintf( outfile, " \"\\t.previous\\n\");\n" );
711 fprintf( outfile, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
712 fprintf( outfile, " \"\\tcall " PREFIX "__wine_spec_%s_fini\\n\"\n", DLLName );
713 fprintf( outfile, " \"\\t.previous\\n\");\n" );
715 #elif defined(__sparc__)
716 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
717 fprintf( outfile, " \"\\tcall " PREFIX "__wine_spec_%s_init\\n\"\n", DLLName );
718 fprintf( outfile, " \"\\tnop\\n\"\n" );
719 fprintf( outfile, " \"\\t.previous\\n\");\n" );
722 fprintf( outfile, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
723 fprintf( outfile, " \"\\tcall " PREFIX "__wine_spec_%s_fini\\n\"\n", DLLName );
724 fprintf( outfile, " \"\\tnop\\n\"\n" );
725 fprintf( outfile, " \"\\t.previous\\n\");\n" );
727 #elif defined(__PPC__)
728 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
729 fprintf( outfile, " \"\\tbl " PREFIX "__wine_spec_%s_init\\n\"\n",
731 fprintf( outfile, " \"\\t.previous\\n\");\n" );
734 fprintf( outfile, "asm(\"\\t.section\t.fini ,\\\"ax\\\"\\n\"\n" );
735 fprintf( outfile, " \"\\tbl " PREFIX "__wine_spec_%s_fini\\n\"\n",
737 fprintf( outfile, " \"\\t.previous\\n\");\n" );
740 #error You need to define the DLL constructor for your architecture
743 fprintf( outfile, "#ifndef __GNUC__\n" );
744 fprintf( outfile, "}\n" );
745 fprintf( outfile, "#endif /* defined(__GNUC__) */\n\n" );
748 "void __wine_spec_%s_init(void)\n"
750 " extern void __wine_dll_register( const struct image_nt_headers *, const char * );\n"
751 " extern void *__wine_dbg_register( char * const *, int );\n"
752 " __wine_dll_register( &nt_header, \"%s\" );\n",
753 DLLName, DLLFileName );
755 fprintf( outfile, " debug_registration = __wine_dbg_register( debug_channels, %d );\n",
757 fprintf( outfile, "}\n" );
761 "\nvoid __wine_spec_%s_fini(void)\n"
763 " extern void __wine_dbg_unregister( void* );\n"
764 " __wine_dbg_unregister( debug_registration );\n"