4 * Copyright 1996 Alexandre Julliard
11 #include "builtin32.h"
18 #include "stackframe.h"
25 /* Built-in modules descriptors */
26 /* Don't change these structures! (see tools/build.c) */
30 const char *name; /* DLL name */
31 void *module_start; /* 32-bit address of the module data */
32 int module_size; /* Size of the module data */
33 const BYTE *code_start; /* 32-bit address of DLL code */
34 const BYTE *data_start; /* 32-bit address of DLL data */
39 const WIN16_DESCRIPTOR *descr; /* DLL descriptor */
40 int flags; /* flags (see below) */
44 #define DLL_FLAG_NOT_USED 0x01 /* Use original Windows DLL if possible */
45 #define DLL_FLAG_ALWAYS_USED 0x02 /* Always use built-in DLL */
49 extern const WIN16_DESCRIPTOR AVIFILE_Descriptor;
50 extern const WIN16_DESCRIPTOR COMM_Descriptor;
51 extern const WIN16_DESCRIPTOR COMMDLG_Descriptor;
52 extern const WIN16_DESCRIPTOR COMPOBJ_Descriptor;
53 extern const WIN16_DESCRIPTOR DDEML_Descriptor;
54 extern const WIN16_DESCRIPTOR DISPDIB_Descriptor;
55 extern const WIN16_DESCRIPTOR DISPLAY_Descriptor;
56 extern const WIN16_DESCRIPTOR GDI_Descriptor;
57 extern const WIN16_DESCRIPTOR KERNEL_Descriptor;
58 extern const WIN16_DESCRIPTOR KEYBOARD_Descriptor;
59 extern const WIN16_DESCRIPTOR LZEXPAND_Descriptor;
60 extern const WIN16_DESCRIPTOR MMSYSTEM_Descriptor;
61 extern const WIN16_DESCRIPTOR MOUSE_Descriptor;
62 extern const WIN16_DESCRIPTOR MSACM_Descriptor;
63 extern const WIN16_DESCRIPTOR MSVIDEO_Descriptor;
64 extern const WIN16_DESCRIPTOR OLE2CONV_Descriptor;
65 extern const WIN16_DESCRIPTOR OLE2DISP_Descriptor;
66 extern const WIN16_DESCRIPTOR OLE2NLS_Descriptor;
67 extern const WIN16_DESCRIPTOR OLE2PROX_Descriptor;
68 extern const WIN16_DESCRIPTOR OLE2THK_Descriptor;
69 extern const WIN16_DESCRIPTOR OLE2_Descriptor;
70 extern const WIN16_DESCRIPTOR OLECLI_Descriptor;
71 extern const WIN16_DESCRIPTOR OLESVR_Descriptor;
72 extern const WIN16_DESCRIPTOR RASAPI16_Descriptor;
73 extern const WIN16_DESCRIPTOR SHELL_Descriptor;
74 extern const WIN16_DESCRIPTOR SOUND_Descriptor;
75 extern const WIN16_DESCRIPTOR STORAGE_Descriptor;
76 extern const WIN16_DESCRIPTOR STRESS_Descriptor;
77 extern const WIN16_DESCRIPTOR SYSTEM_Descriptor;
78 extern const WIN16_DESCRIPTOR TOOLHELP_Descriptor;
79 extern const WIN16_DESCRIPTOR TYPELIB_Descriptor;
80 extern const WIN16_DESCRIPTOR USER_Descriptor;
81 extern const WIN16_DESCRIPTOR VER_Descriptor;
82 extern const WIN16_DESCRIPTOR W32SYS_Descriptor;
83 extern const WIN16_DESCRIPTOR WIN32S16_Descriptor;
84 extern const WIN16_DESCRIPTOR WIN87EM_Descriptor;
85 extern const WIN16_DESCRIPTOR WINASPI_Descriptor;
86 extern const WIN16_DESCRIPTOR WINDEBUG_Descriptor;
87 extern const WIN16_DESCRIPTOR WINEPS_Descriptor;
88 extern const WIN16_DESCRIPTOR WING_Descriptor;
89 extern const WIN16_DESCRIPTOR WINSOCK_Descriptor;
90 extern const WIN16_DESCRIPTOR WPROCS_Descriptor;
92 /* Table of all built-in DLLs */
94 static BUILTIN16_DLL BuiltinDLLs[] =
96 { &KERNEL_Descriptor, 0 },
97 { &USER_Descriptor, 0 },
98 { &GDI_Descriptor, 0 },
99 { &SYSTEM_Descriptor, DLL_FLAG_ALWAYS_USED },
100 { &DISPLAY_Descriptor, DLL_FLAG_ALWAYS_USED },
101 { &WPROCS_Descriptor, DLL_FLAG_ALWAYS_USED },
102 { &WINDEBUG_Descriptor, DLL_FLAG_NOT_USED },
103 { &AVIFILE_Descriptor, DLL_FLAG_NOT_USED },
104 { &COMMDLG_Descriptor, DLL_FLAG_NOT_USED },
105 { &COMPOBJ_Descriptor, DLL_FLAG_NOT_USED },
106 { &DDEML_Descriptor, DLL_FLAG_NOT_USED },
107 { &DISPDIB_Descriptor, 0 },
108 { &KEYBOARD_Descriptor, 0 },
109 { &COMM_Descriptor, 0 },
110 { &LZEXPAND_Descriptor, 0 },
111 { &MMSYSTEM_Descriptor, 0 },
112 { &MOUSE_Descriptor, 0 },
113 { &MSACM_Descriptor, 0 },
114 { &MSVIDEO_Descriptor, 0 },
115 { &OLE2CONV_Descriptor, DLL_FLAG_NOT_USED },
116 { &OLE2DISP_Descriptor, DLL_FLAG_NOT_USED },
117 { &OLE2NLS_Descriptor, DLL_FLAG_NOT_USED },
118 { &OLE2PROX_Descriptor, DLL_FLAG_NOT_USED },
119 { &OLE2THK_Descriptor, DLL_FLAG_NOT_USED },
120 { &OLE2_Descriptor, DLL_FLAG_NOT_USED },
121 { &OLECLI_Descriptor, DLL_FLAG_NOT_USED },
122 { &OLESVR_Descriptor, DLL_FLAG_NOT_USED },
123 { &RASAPI16_Descriptor, 0 },
124 { &SHELL_Descriptor, 0 },
125 { &SOUND_Descriptor, 0 },
126 { &STORAGE_Descriptor, DLL_FLAG_NOT_USED },
127 { &STRESS_Descriptor, 0 },
128 { &TOOLHELP_Descriptor, 0 },
129 { &TYPELIB_Descriptor, DLL_FLAG_NOT_USED },
130 { &VER_Descriptor, 0 },
131 { &W32SYS_Descriptor, DLL_FLAG_NOT_USED },
132 { &WIN32S16_Descriptor, DLL_FLAG_NOT_USED },
133 { &WIN87EM_Descriptor, DLL_FLAG_NOT_USED },
134 { &WINASPI_Descriptor, 0 },
135 { &WINEPS_Descriptor, DLL_FLAG_ALWAYS_USED },
136 { &WING_Descriptor, 0 },
137 { &WINSOCK_Descriptor, 0 },
142 /* Ordinal number for interrupt 0 handler in WPROCS.DLL */
143 #define FIRST_INTERRUPT_ORDINAL 100
146 /***********************************************************************
147 * BUILTIN_DoLoadModule16
149 * Load a built-in Win16 module. Helper function for BUILTIN_LoadModule
152 static HMODULE16 BUILTIN_DoLoadModule16( const WIN16_DESCRIPTOR *descr )
156 SEGTABLEENTRY *pSegTable;
158 HMODULE16 hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, descr->module_start,
159 descr->module_size, 0,
160 FALSE, FALSE, FALSE, NULL );
161 if (!hModule) return 0;
162 FarSetOwner( hModule, hModule );
164 TRACE(module, "Built-in %s: hmodule=%04x\n",
165 descr->name, hModule );
166 pModule = (NE_MODULE *)GlobalLock16( hModule );
167 pModule->self = hModule;
169 /* Allocate the code segment */
171 pSegTable = NE_SEG_TABLE( pModule );
172 pSegTable->hSeg = GLOBAL_CreateBlock( GMEM_FIXED, descr->code_start,
173 pSegTable->minsize, hModule,
174 TRUE, TRUE, FALSE, NULL );
175 if (!pSegTable->hSeg) return 0;
178 /* Allocate the data segment */
180 minsize = pSegTable->minsize ? pSegTable->minsize : 0x10000;
181 minsize += pModule->heap_size;
182 if (minsize > 0x10000) minsize = 0x10000;
183 pSegTable->hSeg = GLOBAL_Alloc( GMEM_FIXED, minsize,
184 hModule, FALSE, FALSE, FALSE );
185 if (!pSegTable->hSeg) return 0;
186 if (pSegTable->minsize) memcpy( GlobalLock16( pSegTable->hSeg ),
187 descr->data_start, pSegTable->minsize);
188 if (pModule->heap_size)
189 LocalInit( GlobalHandleToSel(pSegTable->hSeg),
190 pSegTable->minsize, minsize );
192 NE_RegisterModule( pModule );
197 /***********************************************************************
200 * Load all built-in modules marked as 'always used'.
202 BOOL32 BUILTIN_Init(void)
208 fnBUILTIN_LoadModule = BUILTIN_LoadModule;
210 for (dll = BuiltinDLLs; dll->descr; dll++)
212 if (dll->flags & DLL_FLAG_ALWAYS_USED)
213 if (!BUILTIN_DoLoadModule16( dll->descr )) return FALSE;
216 /* Set interrupt vectors from entry points in WPROCS.DLL */
218 hModule = GetModuleHandle16( "WPROCS" );
219 for (vector = 0; vector < 256; vector++)
221 FARPROC16 proc = NE_GetEntryPoint( hModule,
222 FIRST_INTERRUPT_ORDINAL + vector );
224 INT_SetPMHandler( vector, proc );
233 /***********************************************************************
236 * Load a built-in module. If the 'force' parameter is FALSE, we only
237 * load the module if it has not been disabled via the -dll option.
239 HMODULE16 BUILTIN_LoadModule( LPCSTR name, BOOL32 force )
241 BUILTIN16_DLL *table;
242 char dllname[16], *p;
244 /* Fix the name in case we have a full path and extension */
246 if ((p = strrchr( name, '\\' ))) name = p + 1;
247 lstrcpyn32A( dllname, name, sizeof(dllname) );
248 if ((p = strrchr( dllname, '.' ))) *p = '\0';
250 for (table = BuiltinDLLs; table->descr; table++)
251 if (!lstrcmpi32A( table->descr->name, dllname )) break;
252 if (!table->descr) return 0;
253 if ((table->flags & DLL_FLAG_NOT_USED) && !force) return 0;
255 return BUILTIN_DoLoadModule16( table->descr );
259 /***********************************************************************
260 * BUILTIN_GetEntryPoint16
262 * Return the ordinal and name corresponding to a CS:IP address.
263 * This is used only by relay debugging.
265 LPCSTR BUILTIN_GetEntryPoint16( WORD cs, WORD ip, WORD *pOrd )
267 static char buffer[80];
268 WORD ordinal, i, max_offset;
272 if (!(pModule = NE_GetPtr( FarGetOwner( GlobalHandle16(cs) ))))
275 /* Search for the ordinal */
277 p = (BYTE *)pModule + pModule->entry_table;
289 case 1: /* code segment */
295 if ((*(WORD *)p <= ip) && (*(WORD *)p >= max_offset))
297 max_offset = *(WORD *)p;
304 case 0xff: /* moveable (should not happen in built-in modules) */
305 TRACE( relay, "Built-in module has moveable entry\n" );
309 default: /* other segment */
316 /* Search for the name in the resident names table */
317 /* (built-in modules have no non-resident table) */
319 p = (BYTE *)pModule + pModule->name_table;
322 p += *p + 1 + sizeof(WORD);
323 if (*(WORD *)(p + *p + 1) == *pOrd) break;
326 sprintf( buffer, "%.*s.%d: %.*s",
327 *((BYTE *)pModule + pModule->name_table),
328 (char *)pModule + pModule->name_table + 1,
329 *pOrd, *p, (char *)(p + 1) );
334 /**********************************************************************
335 * BUILTIN_DefaultIntHandler
337 * Default interrupt handler.
339 void BUILTIN_DefaultIntHandler( CONTEXT *context )
342 STACK16FRAME *frame = CURRENT_STACK16;
343 BUILTIN_GetEntryPoint16( frame->entry_cs, frame->entry_ip, &ordinal );
344 INT_BARF( context, ordinal - FIRST_INTERRUPT_ORDINAL );
348 /***********************************************************************
349 * BUILTIN_ParseDLLOptions
351 * Set runtime DLL usage flags
353 BOOL32 BUILTIN_ParseDLLOptions( const char *str )
360 while (*str && isspace(*str)) str++;
361 if (!*str) return TRUE;
362 if ((*str != '+') && (*str != '-')) return FALSE;
364 if (!(p = strchr( str, ',' ))) p = str + strlen(str);
365 while ((p > str) && isspace(p[-1])) p--;
366 if (p == str) return FALSE;
367 for (dll = BuiltinDLLs; dll->descr; dll++)
369 if (!lstrncmpi32A( str, dll->descr->name, (int)(p - str) ))
371 if (dll->descr->name[(int)(p-str)]) /* only partial match */
375 if (dll->flags & DLL_FLAG_ALWAYS_USED) return FALSE;
376 dll->flags |= DLL_FLAG_NOT_USED;
378 else dll->flags &= ~DLL_FLAG_NOT_USED;
383 if (!BUILTIN32_EnableDLL( str, (int)(p - str), (str[-1] == '+') ))
386 while (*str && (isspace(*str) || (*str == ','))) str++;
392 /***********************************************************************
395 * Print the list of built-in DLLs that can be disabled.
397 void BUILTIN_PrintDLLs(void)
402 MSG("Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
403 MSG("Available Win16 DLLs:\n");
404 for (i = 0, dll = BuiltinDLLs; dll->descr; dll++)
406 if (!(dll->flags & DLL_FLAG_ALWAYS_USED))
407 MSG("%-9s%c", dll->descr->name,
408 ((++i) % 8) ? ' ' : '\n' );
411 BUILTIN32_PrintDLLs();