4 * Copyright 1996 Alexandre Julliard
21 /* Built-in modules descriptors */
22 /* Don't change these structures! (see tools/build.c) */
26 const BYTE
*code_start
; /* 32-bit address of DLL code */
27 const BYTE
*data_start
; /* 32-bit address of DLL data */
32 int base
; /* Ordinal base */
33 int size
; /* Number of functions */
34 const void **functions
; /* Pointer to functions table */
35 const char * const *names
; /* Pointer to names table */
40 const char *name
; /* DLL name */
41 void *module_start
; /* 32-bit address of the module data */
42 int module_size
; /* Size of the module data */
45 WIN16_DESCRIPTOR win16
; /* Descriptor for Win16 DLL */
46 WIN32_DESCRIPTOR win32
; /* Descriptor for Win32 DLL */
52 const DLL_DESCRIPTOR
*descr
; /* DLL descriptor */
53 int flags
; /* flags (see below) */
58 #define DLL_FLAG_NOT_USED 0x01 /* Use original Windows DLL if possible */
59 #define DLL_FLAG_ALWAYS_USED 0x02 /* Always use built-in DLL */
60 #define DLL_FLAG_WIN32 0x04 /* DLL is a Win32 DLL */
64 extern const DLL_DESCRIPTOR KERNEL_Descriptor
;
65 extern const DLL_DESCRIPTOR USER_Descriptor
;
66 extern const DLL_DESCRIPTOR GDI_Descriptor
;
67 extern const DLL_DESCRIPTOR WIN87EM_Descriptor
;
68 extern const DLL_DESCRIPTOR MMSYSTEM_Descriptor
;
69 extern const DLL_DESCRIPTOR SHELL_Descriptor
;
70 extern const DLL_DESCRIPTOR SOUND_Descriptor
;
71 extern const DLL_DESCRIPTOR KEYBOARD_Descriptor
;
72 extern const DLL_DESCRIPTOR WINSOCK_Descriptor
;
73 extern const DLL_DESCRIPTOR STRESS_Descriptor
;
74 extern const DLL_DESCRIPTOR SYSTEM_Descriptor
;
75 extern const DLL_DESCRIPTOR TOOLHELP_Descriptor
;
76 extern const DLL_DESCRIPTOR MOUSE_Descriptor
;
77 extern const DLL_DESCRIPTOR COMMDLG_Descriptor
;
78 extern const DLL_DESCRIPTOR OLE2_Descriptor
;
79 extern const DLL_DESCRIPTOR OLE2CONV_Descriptor
;
80 extern const DLL_DESCRIPTOR OLE2DISP_Descriptor
;
81 extern const DLL_DESCRIPTOR OLE2NLS_Descriptor
;
82 extern const DLL_DESCRIPTOR OLE2PROX_Descriptor
;
83 extern const DLL_DESCRIPTOR OLECLI_Descriptor
;
84 extern const DLL_DESCRIPTOR OLESVR_Descriptor
;
85 extern const DLL_DESCRIPTOR COMPOBJ_Descriptor
;
86 extern const DLL_DESCRIPTOR STORAGE_Descriptor
;
87 extern const DLL_DESCRIPTOR WPROCS_Descriptor
;
88 extern const DLL_DESCRIPTOR DDEML_Descriptor
;
89 extern const DLL_DESCRIPTOR LZEXPAND_Descriptor
;
90 extern const DLL_DESCRIPTOR VER_Descriptor
;
91 extern const DLL_DESCRIPTOR W32SYS_Descriptor
;
95 extern const DLL_DESCRIPTOR ADVAPI32_Descriptor
;
96 extern const DLL_DESCRIPTOR COMCTL32_Descriptor
;
97 extern const DLL_DESCRIPTOR COMDLG32_Descriptor
;
98 extern const DLL_DESCRIPTOR CRTDLL_Descriptor
;
99 extern const DLL_DESCRIPTOR OLE32_Descriptor
;
100 extern const DLL_DESCRIPTOR GDI32_Descriptor
;
101 extern const DLL_DESCRIPTOR KERNEL32_Descriptor
;
102 extern const DLL_DESCRIPTOR LZ32_Descriptor
;
103 extern const DLL_DESCRIPTOR NTDLL_Descriptor
;
104 extern const DLL_DESCRIPTOR SHELL32_Descriptor
;
105 extern const DLL_DESCRIPTOR USER32_Descriptor
;
106 extern const DLL_DESCRIPTOR VERSION_Descriptor
;
107 extern const DLL_DESCRIPTOR WINMM_Descriptor
;
108 extern const DLL_DESCRIPTOR WINSPOOL_Descriptor
;
109 extern const DLL_DESCRIPTOR WSOCK32_Descriptor
;
111 /* Table of all built-in DLLs */
113 static BUILTIN_DLL BuiltinDLLs
[] =
116 { &KERNEL_Descriptor
, DLL_FLAG_ALWAYS_USED
},
117 { &USER_Descriptor
, DLL_FLAG_ALWAYS_USED
},
118 { &GDI_Descriptor
, DLL_FLAG_ALWAYS_USED
},
119 { &WIN87EM_Descriptor
, DLL_FLAG_NOT_USED
},
120 { &SHELL_Descriptor
, 0 },
121 { &SOUND_Descriptor
, 0 },
122 { &KEYBOARD_Descriptor
, 0 },
123 { &WINSOCK_Descriptor
, 0 },
124 { &STRESS_Descriptor
, 0 },
125 { &MMSYSTEM_Descriptor
, 0 },
126 { &SYSTEM_Descriptor
, 0 },
127 { &TOOLHELP_Descriptor
, 0 },
128 { &MOUSE_Descriptor
, 0 },
129 { &COMMDLG_Descriptor
, DLL_FLAG_NOT_USED
},
130 { &OLE2_Descriptor
, DLL_FLAG_NOT_USED
},
131 { &OLE2CONV_Descriptor
, DLL_FLAG_NOT_USED
},
132 { &OLE2DISP_Descriptor
, DLL_FLAG_NOT_USED
},
133 { &OLE2NLS_Descriptor
, DLL_FLAG_NOT_USED
},
134 { &OLE2PROX_Descriptor
, DLL_FLAG_NOT_USED
},
135 { &OLECLI_Descriptor
, DLL_FLAG_NOT_USED
},
136 { &OLESVR_Descriptor
, DLL_FLAG_NOT_USED
},
137 { &COMPOBJ_Descriptor
, DLL_FLAG_NOT_USED
},
138 { &STORAGE_Descriptor
, DLL_FLAG_NOT_USED
},
139 { &WPROCS_Descriptor
, DLL_FLAG_ALWAYS_USED
},
140 { &DDEML_Descriptor
, DLL_FLAG_NOT_USED
},
141 { &LZEXPAND_Descriptor
, 0 },
142 { &VER_Descriptor
, 0 },
143 { &W32SYS_Descriptor
, 0 },
145 { &ADVAPI32_Descriptor
, 0 },
146 { &COMCTL32_Descriptor
, 0 },
147 { &COMDLG32_Descriptor
, 0 },
148 { &CRTDLL_Descriptor
, 0 },
149 { &OLE32_Descriptor
, 0 },
150 { &GDI32_Descriptor
, 0 },
151 { &KERNEL32_Descriptor
, DLL_FLAG_ALWAYS_USED
},
152 { &LZ32_Descriptor
, 0 },
153 { &NTDLL_Descriptor
, 0 },
154 { &SHELL32_Descriptor
, 0 },
155 { &USER32_Descriptor
, 0 },
156 { &VERSION_Descriptor
, 0 },
157 { &WINMM_Descriptor
, 0 },
158 { &WINSPOOL_Descriptor
, 0 },
159 { &WSOCK32_Descriptor
, 0 },
165 /***********************************************************************
168 * Load all built-in modules marked as 'always used'.
170 BOOL16
BUILTIN_Init(void)
175 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
176 if (dll
->flags
& DLL_FLAG_ALWAYS_USED
)
177 if (!BUILTIN_LoadModule(dll
->descr
->name
, TRUE
)) return FALSE
;
179 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
181 MODULE_SetEntryPoint( GetModuleHandle( "KERNEL" ), 178, GetWinFlags() );
183 /* Set the USER and GDI heap selectors */
185 pModule
= MODULE_GetPtr( GetModuleHandle( "USER" ));
186 USER_HeapSel
= (NE_SEG_TABLE( pModule
) + pModule
->dgroup
- 1)->selector
;
187 pModule
= MODULE_GetPtr( GetModuleHandle( "GDI" ));
188 GDI_HeapSel
= (NE_SEG_TABLE( pModule
) + pModule
->dgroup
- 1)->selector
;
194 /***********************************************************************
197 * Load a built-in module. If the 'force' parameter is FALSE, we only
198 * load the module if it has not been disabled via the -dll option.
200 HMODULE16
BUILTIN_LoadModule( LPCSTR name
, BOOL16 force
)
205 char dllname
[16], *p
;
207 /* Fix the name in case we have a full path and extension */
209 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
210 lstrcpyn32A( dllname
, name
, sizeof(dllname
) );
211 if ((p
= strrchr( dllname
, '.' ))) *p
= '\0';
213 for (table
= BuiltinDLLs
; table
->descr
; table
++)
214 if (!lstrcmpi32A( table
->descr
->name
, dllname
)) break;
215 if (!table
->descr
) return 0;
216 if ((table
->flags
& DLL_FLAG_NOT_USED
) && !force
) return 0;
218 hModule
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, table
->descr
->module_start
,
219 table
->descr
->module_size
, 0,
220 FALSE
, FALSE
, FALSE
, NULL
);
221 if (!hModule
) return 0;
222 FarSetOwner( hModule
, hModule
);
224 dprintf_module( stddeb
, "Built-in %s: hmodule=%04x\n",
225 table
->descr
->name
, hModule
);
226 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
227 pModule
->self
= hModule
;
229 if (pModule
->flags
& NE_FFLAGS_WIN32
)
231 pModule
->pe_module
= (PE_MODULE
*)table
;
232 table
->flags
|= DLL_FLAG_WIN32
;
234 else /* Win16 module */
236 const WIN16_DESCRIPTOR
*descr
= &table
->descr
->u
.win16
;
239 /* Allocate the code segment */
241 SEGTABLEENTRY
*pSegTable
= NE_SEG_TABLE( pModule
);
242 pSegTable
->selector
= GLOBAL_CreateBlock(GMEM_FIXED
, descr
->code_start
,
243 pSegTable
->minsize
, hModule
,
244 TRUE
, TRUE
, FALSE
, NULL
);
245 if (!pSegTable
->selector
) return 0;
248 /* Allocate the data segment */
250 minsize
= pSegTable
->minsize
? pSegTable
->minsize
: 0x10000;
251 minsize
+= pModule
->heap_size
;
252 if (minsize
> 0x10000) minsize
= 0x10000;
253 pSegTable
->selector
= GLOBAL_Alloc( GMEM_FIXED
, minsize
,
254 hModule
, FALSE
, FALSE
, FALSE
);
255 if (!pSegTable
->selector
) return 0;
256 if (pSegTable
->minsize
) memcpy( GlobalLock16( pSegTable
->selector
),
257 descr
->data_start
, pSegTable
->minsize
);
258 if (pModule
->heap_size
)
259 LocalInit( pSegTable
->selector
, pSegTable
->minsize
, minsize
);
262 MODULE_RegisterModule( pModule
);
267 /***********************************************************************
268 * BUILTIN_GetEntryPoint16
270 * Return the ordinal and name corresponding to a CS:IP address.
271 * This is used only by relay debugging.
273 LPCSTR
BUILTIN_GetEntryPoint16( WORD cs
, WORD ip
, WORD
*pOrd
)
275 static char buffer
[80];
276 WORD ordinal
, i
, max_offset
;
280 if (!(pModule
= MODULE_GetPtr( FarGetOwner( GlobalHandle16(cs
) ))))
283 /* Search for the ordinal */
285 p
= (BYTE
*)pModule
+ pModule
->entry_table
;
297 case 1: /* code segment */
303 if ((*(WORD
*)p
<= ip
) && (*(WORD
*)p
>= max_offset
))
305 max_offset
= *(WORD
*)p
;
312 case 0xff: /* moveable (should not happen in built-in modules) */
313 fprintf( stderr
, "Built-in module has moveable entry\n" );
317 default: /* other segment */
324 /* Search for the name in the resident names table */
325 /* (built-in modules have no non-resident table) */
327 p
= (BYTE
*)pModule
+ pModule
->name_table
;
330 p
+= *p
+ 1 + sizeof(WORD
);
331 if (*(WORD
*)(p
+ *p
+ 1) == *pOrd
) break;
334 sprintf( buffer
, "%.*s.%d: %.*s",
335 *((BYTE
*)pModule
+ pModule
->name_table
),
336 (char *)pModule
+ pModule
->name_table
+ 1,
337 *pOrd
, *p
, (char *)(p
+ 1) );
342 /***********************************************************************
343 * BUILTIN_GetEntryPoint32
345 * Return the name of the DLL entry point corresponding
346 * to a relay entry point address. This is used only by relay debugging.
348 LPCSTR
BUILTIN_GetEntryPoint32( void *relay
)
350 static char buffer
[80];
355 /* First find the module */
357 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
358 if ((dll
->flags
& DLL_FLAG_WIN32
) &&
359 (dll
->descr
->u
.win32
.functions
[0] <= relay
) &&
360 (dll
->descr
->u
.win32
.functions
[dll
->descr
->u
.win32
.size
-1] >relay
))
364 sprintf( buffer
, "???.???: %08x", (UINT32
)relay
);
368 /* Do a binary search for the function */
370 relay
= (BYTE
*)relay
- 11; /* The relay entry point is 11 bytes long */
371 funcs
= dll
->descr
->u
.win32
.functions
;
373 size
= dll
->descr
->u
.win32
.size
;
376 i
= (first
+ size
) / 2;
377 if (funcs
[i
] == relay
) break;
378 if (funcs
[i
] > relay
) size
= i
;
381 sprintf( buffer
, "%s.%d: %s",
382 dll
->descr
->name
, i
, dll
->descr
->u
.win32
.names
[i
] );
387 /***********************************************************************
388 * BUILTIN_GetProcAddress32
390 * Implementation of GetProcAddress() for built-in Win32 modules.
391 * FIXME: this should be unified with the real GetProcAddress32().
393 FARPROC32
BUILTIN_GetProcAddress32( NE_MODULE
*pModule
, LPCSTR function
)
395 BUILTIN_DLL
*dll
= (BUILTIN_DLL
*)pModule
->pe_module
;
396 const WIN32_DESCRIPTOR
*info
= &dll
->descr
->u
.win32
;
398 if (!dll
) return NULL
;
400 if (HIWORD(function
)) /* Find function by name */
404 dprintf_module( stddeb
, "Looking for function %s in %s\n",
405 function
, dll
->descr
->name
);
406 for (i
= 0; i
< info
->size
; i
++)
407 if (info
->names
[i
] && !strcmp( function
, info
->names
[i
] ))
408 return (FARPROC32
)info
->functions
[i
];
410 else /* Find function by ordinal */
412 WORD ordinal
= LOWORD(function
);
413 dprintf_module( stddeb
, "Looking for ordinal %d in %s\n",
414 ordinal
, dll
->descr
->name
);
415 if (ordinal
&& ordinal
< info
->size
)
416 return (FARPROC32
)info
->functions
[ordinal
- info
->base
];
422 /***********************************************************************
423 * BUILTIN_ParseDLLOptions
425 * Set runtime DLL usage flags
427 BOOL16
BUILTIN_ParseDLLOptions( const char *str
)
434 while (*str
&& isspace(*str
)) str
++;
435 if (!*str
) return TRUE
;
436 if ((*str
!= '+') && (*str
!= '-')) return FALSE
;
438 if (!(p
= strchr( str
, ',' ))) p
= str
+ strlen(str
);
439 while ((p
> str
) && isspace(p
[-1])) p
--;
440 if (p
== str
) return FALSE
;
441 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
443 if (!lstrncmpi32A( str
, dll
->descr
->name
, (int)(p
- str
) ))
447 if (dll
->flags
& DLL_FLAG_ALWAYS_USED
) return FALSE
;
448 dll
->flags
|= DLL_FLAG_NOT_USED
;
450 else dll
->flags
&= ~DLL_FLAG_NOT_USED
;
454 if (!dll
->descr
) return FALSE
;
456 while (*str
&& (isspace(*str
) || (*str
== ','))) str
++;
462 /***********************************************************************
465 * Print the list of built-in DLLs that can be disabled.
467 void BUILTIN_PrintDLLs(void)
472 for (i
= 0, dll
= BuiltinDLLs
; dll
->descr
; dll
++)
474 if (!(dll
->flags
& DLL_FLAG_ALWAYS_USED
))
475 fprintf( stderr
, "%-9s%c", dll
->descr
->name
,
476 ((++i
) % 8) ? ' ' : '\n' );
478 fprintf(stderr
,"\n");