4 * Copyright 1996 Alexandre Julliard
11 #include "builtin32.h"
18 #include "stackframe.h"
24 /* Built-in modules descriptors */
25 /* Don't change these structures! (see tools/build.c) */
29 const char *name
; /* DLL name */
30 void *module_start
; /* 32-bit address of the module data */
31 int module_size
; /* Size of the module data */
32 const BYTE
*code_start
; /* 32-bit address of DLL code */
33 const BYTE
*data_start
; /* 32-bit address of DLL data */
38 const WIN16_DESCRIPTOR
*descr
; /* DLL descriptor */
39 int flags
; /* flags (see below) */
43 #define DLL_FLAG_NOT_USED 0x01 /* Use original Windows DLL if possible */
44 #define DLL_FLAG_ALWAYS_USED 0x02 /* Always use built-in DLL */
48 extern const WIN16_DESCRIPTOR COMMDLG_Descriptor
;
49 extern const WIN16_DESCRIPTOR COMPOBJ_Descriptor
;
50 extern const WIN16_DESCRIPTOR DDEML_Descriptor
;
51 extern const WIN16_DESCRIPTOR GDI_Descriptor
;
52 extern const WIN16_DESCRIPTOR KERNEL_Descriptor
;
53 extern const WIN16_DESCRIPTOR KEYBOARD_Descriptor
;
54 extern const WIN16_DESCRIPTOR LZEXPAND_Descriptor
;
55 extern const WIN16_DESCRIPTOR MMSYSTEM_Descriptor
;
56 extern const WIN16_DESCRIPTOR MOUSE_Descriptor
;
57 extern const WIN16_DESCRIPTOR OLE2CONV_Descriptor
;
58 extern const WIN16_DESCRIPTOR OLE2DISP_Descriptor
;
59 extern const WIN16_DESCRIPTOR OLE2NLS_Descriptor
;
60 extern const WIN16_DESCRIPTOR OLE2PROX_Descriptor
;
61 extern const WIN16_DESCRIPTOR OLE2THK_Descriptor
;
62 extern const WIN16_DESCRIPTOR OLE2_Descriptor
;
63 extern const WIN16_DESCRIPTOR OLECLI_Descriptor
;
64 extern const WIN16_DESCRIPTOR OLESVR_Descriptor
;
65 extern const WIN16_DESCRIPTOR SHELL_Descriptor
;
66 extern const WIN16_DESCRIPTOR SOUND_Descriptor
;
67 extern const WIN16_DESCRIPTOR STORAGE_Descriptor
;
68 extern const WIN16_DESCRIPTOR STRESS_Descriptor
;
69 extern const WIN16_DESCRIPTOR SYSTEM_Descriptor
;
70 extern const WIN16_DESCRIPTOR TOOLHELP_Descriptor
;
71 extern const WIN16_DESCRIPTOR USER_Descriptor
;
72 extern const WIN16_DESCRIPTOR VER_Descriptor
;
73 extern const WIN16_DESCRIPTOR W32SYS_Descriptor
;
74 extern const WIN16_DESCRIPTOR WIN32S16_Descriptor
;
75 extern const WIN16_DESCRIPTOR WIN87EM_Descriptor
;
76 extern const WIN16_DESCRIPTOR WINASPI_Descriptor
;
77 extern const WIN16_DESCRIPTOR WINDEBUG_Descriptor
;
78 extern const WIN16_DESCRIPTOR WING_Descriptor
;
79 extern const WIN16_DESCRIPTOR WINSOCK_Descriptor
;
80 extern const WIN16_DESCRIPTOR WPROCS_Descriptor
;
82 /* Table of all built-in DLLs */
84 static BUILTIN16_DLL BuiltinDLLs
[] =
86 { &KERNEL_Descriptor
, DLL_FLAG_ALWAYS_USED
},
87 { &USER_Descriptor
, DLL_FLAG_ALWAYS_USED
},
88 { &GDI_Descriptor
, DLL_FLAG_ALWAYS_USED
},
89 { &SYSTEM_Descriptor
, DLL_FLAG_ALWAYS_USED
},
90 { &WPROCS_Descriptor
, DLL_FLAG_ALWAYS_USED
},
91 { &WINDEBUG_Descriptor
, DLL_FLAG_ALWAYS_USED
},
92 { &COMMDLG_Descriptor
, DLL_FLAG_NOT_USED
},
93 { &COMPOBJ_Descriptor
, DLL_FLAG_NOT_USED
},
94 { &DDEML_Descriptor
, DLL_FLAG_NOT_USED
},
95 { &KEYBOARD_Descriptor
, 0 },
96 { &LZEXPAND_Descriptor
, 0 },
97 { &MMSYSTEM_Descriptor
, 0 },
98 { &MOUSE_Descriptor
, 0 },
99 { &OLE2CONV_Descriptor
, DLL_FLAG_NOT_USED
},
100 { &OLE2DISP_Descriptor
, DLL_FLAG_NOT_USED
},
101 { &OLE2NLS_Descriptor
, DLL_FLAG_NOT_USED
},
102 { &OLE2PROX_Descriptor
, DLL_FLAG_NOT_USED
},
103 { &OLE2THK_Descriptor
, DLL_FLAG_NOT_USED
},
104 { &OLE2_Descriptor
, DLL_FLAG_NOT_USED
},
105 { &OLECLI_Descriptor
, DLL_FLAG_NOT_USED
},
106 { &OLESVR_Descriptor
, DLL_FLAG_NOT_USED
},
107 { &SHELL_Descriptor
, 0 },
108 { &SOUND_Descriptor
, 0 },
109 { &STORAGE_Descriptor
, DLL_FLAG_NOT_USED
},
110 { &STRESS_Descriptor
, 0 },
111 { &TOOLHELP_Descriptor
, 0 },
112 { &VER_Descriptor
, 0 },
113 { &W32SYS_Descriptor
, 0 },
114 { &WIN32S16_Descriptor
, 0 },
115 { &WIN87EM_Descriptor
, DLL_FLAG_NOT_USED
},
116 { &WINASPI_Descriptor
, 0 },
117 { &WING_Descriptor
, 0 },
118 { &WINSOCK_Descriptor
, 0 },
123 /* Ordinal number for interrupt 0 handler in WPROCS.DLL */
124 #define FIRST_INTERRUPT_ORDINAL 100
127 /***********************************************************************
128 * BUILTIN_DoLoadModule16
130 * Load a built-in Win16 module. Helper function for BUILTIN_LoadModule
133 static HMODULE16
BUILTIN_DoLoadModule16( const WIN16_DESCRIPTOR
*descr
)
137 SEGTABLEENTRY
*pSegTable
;
139 HMODULE16 hModule
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, descr
->module_start
,
140 descr
->module_size
, 0,
141 FALSE
, FALSE
, FALSE
, NULL
);
142 if (!hModule
) return 0;
143 FarSetOwner( hModule
, hModule
);
145 dprintf_module( stddeb
, "Built-in %s: hmodule=%04x\n",
146 descr
->name
, hModule
);
147 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
148 pModule
->self
= hModule
;
150 /* Allocate the code segment */
152 pSegTable
= NE_SEG_TABLE( pModule
);
153 pSegTable
->selector
= GLOBAL_CreateBlock( GMEM_FIXED
, descr
->code_start
,
154 pSegTable
->minsize
, hModule
,
155 TRUE
, TRUE
, FALSE
, NULL
);
156 if (!pSegTable
->selector
) return 0;
159 /* Allocate the data segment */
161 minsize
= pSegTable
->minsize
? pSegTable
->minsize
: 0x10000;
162 minsize
+= pModule
->heap_size
;
163 if (minsize
> 0x10000) minsize
= 0x10000;
164 pSegTable
->selector
= GLOBAL_Alloc( GMEM_FIXED
, minsize
,
165 hModule
, FALSE
, FALSE
, FALSE
);
166 if (!pSegTable
->selector
) return 0;
167 if (pSegTable
->minsize
) memcpy( GlobalLock16( pSegTable
->selector
),
168 descr
->data_start
, pSegTable
->minsize
);
169 if (pModule
->heap_size
)
170 LocalInit( pSegTable
->selector
, pSegTable
->minsize
, minsize
);
172 MODULE_RegisterModule( pModule
);
177 /***********************************************************************
180 * Load all built-in modules marked as 'always used'.
182 BOOL32
BUILTIN_Init(void)
189 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
191 if (dll
->flags
& DLL_FLAG_ALWAYS_USED
)
192 if (!BUILTIN_DoLoadModule16( dll
->descr
)) return FALSE
;
195 /* Set the USER and GDI heap selectors */
197 pModule
= MODULE_GetPtr( GetModuleHandle16( "USER" ));
198 USER_HeapSel
= (NE_SEG_TABLE( pModule
) + pModule
->dgroup
- 1)->selector
;
199 pModule
= MODULE_GetPtr( GetModuleHandle16( "GDI" ));
200 GDI_HeapSel
= (NE_SEG_TABLE( pModule
) + pModule
->dgroup
- 1)->selector
;
202 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
204 hModule
= GetModuleHandle16( "KERNEL" );
205 MODULE_SetEntryPoint( hModule
, 178, GetWinFlags() );
207 /* Initialize the real-mode selector entry points */
209 DOSMEM_InitExports( hModule
);
211 /* Set interrupt vectors from entry points in WPROCS.DLL */
213 hModule
= GetModuleHandle16( "WPROCS" );
214 for (vector
= 0; vector
< 256; vector
++)
216 FARPROC16 proc
= MODULE_GetEntryPoint( hModule
,
217 FIRST_INTERRUPT_ORDINAL
+vector
);
219 INT_SetHandler( vector
, proc
);
226 /***********************************************************************
229 * Load a built-in module. If the 'force' parameter is FALSE, we only
230 * load the module if it has not been disabled via the -dll option.
232 HMODULE32
BUILTIN_LoadModule( LPCSTR name
, BOOL32 force
)
234 BUILTIN16_DLL
*table
;
235 char dllname
[16], *p
;
237 /* Fix the name in case we have a full path and extension */
239 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
240 lstrcpyn32A( dllname
, name
, sizeof(dllname
) );
241 if ((p
= strrchr( dllname
, '.' ))) *p
= '\0';
243 for (table
= BuiltinDLLs
; table
->descr
; table
++)
244 if (!lstrcmpi32A( table
->descr
->name
, dllname
)) break;
245 if (!table
->descr
) return BUILTIN32_LoadModule( name
, force
);
246 if ((table
->flags
& DLL_FLAG_NOT_USED
) && !force
) return 0;
248 return BUILTIN_DoLoadModule16( table
->descr
);
252 /***********************************************************************
253 * BUILTIN_GetEntryPoint16
255 * Return the ordinal and name corresponding to a CS:IP address.
256 * This is used only by relay debugging.
258 LPCSTR
BUILTIN_GetEntryPoint16( WORD cs
, WORD ip
, WORD
*pOrd
)
260 static char buffer
[80];
261 WORD ordinal
, i
, max_offset
;
265 if (!(pModule
= MODULE_GetPtr( FarGetOwner( GlobalHandle16(cs
) ))))
268 /* Search for the ordinal */
270 p
= (BYTE
*)pModule
+ pModule
->entry_table
;
282 case 1: /* code segment */
288 if ((*(WORD
*)p
<= ip
) && (*(WORD
*)p
>= max_offset
))
290 max_offset
= *(WORD
*)p
;
297 case 0xff: /* moveable (should not happen in built-in modules) */
298 fprintf( stderr
, "Built-in module has moveable entry\n" );
302 default: /* other segment */
309 /* Search for the name in the resident names table */
310 /* (built-in modules have no non-resident table) */
312 p
= (BYTE
*)pModule
+ pModule
->name_table
;
315 p
+= *p
+ 1 + sizeof(WORD
);
316 if (*(WORD
*)(p
+ *p
+ 1) == *pOrd
) break;
319 sprintf( buffer
, "%.*s.%d: %.*s",
320 *((BYTE
*)pModule
+ pModule
->name_table
),
321 (char *)pModule
+ pModule
->name_table
+ 1,
322 *pOrd
, *p
, (char *)(p
+ 1) );
327 /**********************************************************************
328 * BUILTIN_DefaultIntHandler
330 * Default interrupt handler.
332 void BUILTIN_DefaultIntHandler( CONTEXT
*context
)
335 STACK16FRAME
*frame
= CURRENT_STACK16
;
336 BUILTIN_GetEntryPoint16( frame
->entry_cs
, frame
->entry_ip
, &ordinal
);
337 INT_BARF( context
, ordinal
- FIRST_INTERRUPT_ORDINAL
);
341 /***********************************************************************
342 * BUILTIN_ParseDLLOptions
344 * Set runtime DLL usage flags
346 BOOL32
BUILTIN_ParseDLLOptions( const char *str
)
353 while (*str
&& isspace(*str
)) str
++;
354 if (!*str
) return TRUE
;
355 if ((*str
!= '+') && (*str
!= '-')) return FALSE
;
357 if (!(p
= strchr( str
, ',' ))) p
= str
+ strlen(str
);
358 while ((p
> str
) && isspace(p
[-1])) p
--;
359 if (p
== str
) return FALSE
;
360 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
362 if (!lstrncmpi32A( str
, dll
->descr
->name
, (int)(p
- str
) ))
366 if (dll
->flags
& DLL_FLAG_ALWAYS_USED
) return FALSE
;
367 dll
->flags
|= DLL_FLAG_NOT_USED
;
369 else dll
->flags
&= ~DLL_FLAG_NOT_USED
;
374 if (!BUILTIN32_EnableDLL( str
, (int)(p
- str
), (str
[-1] == '+') ))
377 while (*str
&& (isspace(*str
) || (*str
== ','))) str
++;
383 /***********************************************************************
386 * Print the list of built-in DLLs that can be disabled.
388 void BUILTIN_PrintDLLs(void)
393 fprintf(stderr
,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
394 fprintf(stderr
,"Available Win16 DLLs:\n");
395 for (i
= 0, dll
= BuiltinDLLs
; dll
->descr
; dll
++)
397 if (!(dll
->flags
& DLL_FLAG_ALWAYS_USED
))
398 fprintf( stderr
, "%-9s%c", dll
->descr
->name
,
399 ((++i
) % 8) ? ' ' : '\n' );
401 fprintf(stderr
,"\n");
402 BUILTIN32_PrintDLLs();