Implementation of custom dialog messages and notifications.
[wine.git] / if1632 / builtin.c
blobe6766fc68a3be956192254c309b6f0eac5972601
1 /*
2 * Built-in modules
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <ctype.h>
9 #include <string.h>
10 #include "winbase.h"
11 #include "wine/winbase16.h"
12 #include "wine/winestring.h"
13 #include "builtin16.h"
14 #include "builtin32.h"
15 #include "global.h"
16 #include "heap.h"
17 #include "module.h"
18 #include "miscemu.h"
19 #include "neexe.h"
20 #include "stackframe.h"
21 #include "user.h"
22 #include "process.h"
23 #include "task.h"
24 #include "debugtools.h"
25 #include "toolhelp.h"
27 DEFAULT_DEBUG_CHANNEL(module)
29 typedef struct
31 const WIN16_DESCRIPTOR *descr; /* DLL descriptor */
32 int flags; /* flags (see below) */
33 } BUILTIN16_DLL;
35 /* DLL flags */
36 #define DLL_FLAG_NOT_USED 0x01 /* Use original Windows DLL if possible */
37 #define DLL_FLAG_ALWAYS_USED 0x02 /* Always use built-in DLL */
39 /* 16-bit DLLs */
41 extern const WIN16_DESCRIPTOR AVIFILE_Descriptor;
42 extern const WIN16_DESCRIPTOR COMM_Descriptor;
43 extern const WIN16_DESCRIPTOR COMMDLG_Descriptor;
44 extern const WIN16_DESCRIPTOR COMPOBJ_Descriptor;
45 extern const WIN16_DESCRIPTOR DDEML_Descriptor;
46 extern const WIN16_DESCRIPTOR DISPDIB_Descriptor;
47 extern const WIN16_DESCRIPTOR DISPLAY_Descriptor;
48 extern const WIN16_DESCRIPTOR GDI_Descriptor;
49 extern const WIN16_DESCRIPTOR KERNEL_Descriptor;
50 extern const WIN16_DESCRIPTOR KEYBOARD_Descriptor;
51 extern const WIN16_DESCRIPTOR LZEXPAND_Descriptor;
52 extern const WIN16_DESCRIPTOR MMSYSTEM_Descriptor;
53 extern const WIN16_DESCRIPTOR MOUSE_Descriptor;
54 extern const WIN16_DESCRIPTOR MSACM_Descriptor;
55 extern const WIN16_DESCRIPTOR MSVIDEO_Descriptor;
56 extern const WIN16_DESCRIPTOR OLE2CONV_Descriptor;
57 extern const WIN16_DESCRIPTOR OLE2DISP_Descriptor;
58 extern const WIN16_DESCRIPTOR OLE2NLS_Descriptor;
59 extern const WIN16_DESCRIPTOR OLE2PROX_Descriptor;
60 extern const WIN16_DESCRIPTOR OLE2THK_Descriptor;
61 extern const WIN16_DESCRIPTOR OLE2_Descriptor;
62 extern const WIN16_DESCRIPTOR OLECLI_Descriptor;
63 extern const WIN16_DESCRIPTOR OLESVR_Descriptor;
64 extern const WIN16_DESCRIPTOR RASAPI16_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 TYPELIB_Descriptor;
72 extern const WIN16_DESCRIPTOR USER_Descriptor;
73 extern const WIN16_DESCRIPTOR VER_Descriptor;
74 extern const WIN16_DESCRIPTOR W32SYS_Descriptor;
75 extern const WIN16_DESCRIPTOR WIN32S16_Descriptor;
76 extern const WIN16_DESCRIPTOR WIN87EM_Descriptor;
77 extern const WIN16_DESCRIPTOR WINASPI_Descriptor;
78 extern const WIN16_DESCRIPTOR WINDEBUG_Descriptor;
79 extern const WIN16_DESCRIPTOR WINEPS_Descriptor;
80 extern const WIN16_DESCRIPTOR WING_Descriptor;
81 extern const WIN16_DESCRIPTOR WINSOCK_Descriptor;
82 extern const WIN16_DESCRIPTOR WPROCS_Descriptor;
84 /* Table of all built-in DLLs */
86 static BUILTIN16_DLL BuiltinDLLs[] =
88 { &KERNEL_Descriptor, 0 },
89 { &USER_Descriptor, 0 },
90 { &GDI_Descriptor, 0 },
91 { &SYSTEM_Descriptor, DLL_FLAG_ALWAYS_USED },
92 { &DISPLAY_Descriptor, DLL_FLAG_ALWAYS_USED },
93 { &WPROCS_Descriptor, DLL_FLAG_ALWAYS_USED },
94 { &WINDEBUG_Descriptor, DLL_FLAG_NOT_USED },
95 { &AVIFILE_Descriptor, DLL_FLAG_NOT_USED },
96 { &COMMDLG_Descriptor, DLL_FLAG_NOT_USED },
97 { &COMPOBJ_Descriptor, DLL_FLAG_NOT_USED },
98 { &DDEML_Descriptor, DLL_FLAG_NOT_USED },
99 { &DISPDIB_Descriptor, 0 },
100 { &KEYBOARD_Descriptor, 0 },
101 { &COMM_Descriptor, 0 },
102 { &LZEXPAND_Descriptor, 0 },
103 { &MMSYSTEM_Descriptor, 0 },
104 { &MOUSE_Descriptor, 0 },
105 { &MSACM_Descriptor, 0 },
106 { &MSVIDEO_Descriptor, 0 },
107 { &OLE2CONV_Descriptor, DLL_FLAG_NOT_USED },
108 { &OLE2DISP_Descriptor, DLL_FLAG_NOT_USED },
109 { &OLE2NLS_Descriptor, DLL_FLAG_NOT_USED },
110 { &OLE2PROX_Descriptor, DLL_FLAG_NOT_USED },
111 { &OLE2THK_Descriptor, DLL_FLAG_NOT_USED },
112 { &OLE2_Descriptor, DLL_FLAG_NOT_USED },
113 { &OLECLI_Descriptor, DLL_FLAG_NOT_USED },
114 { &OLESVR_Descriptor, DLL_FLAG_NOT_USED },
115 { &RASAPI16_Descriptor, 0 },
116 { &SHELL_Descriptor, 0 },
117 { &SOUND_Descriptor, 0 },
118 { &STORAGE_Descriptor, DLL_FLAG_NOT_USED },
119 { &STRESS_Descriptor, 0 },
120 { &TOOLHELP_Descriptor, 0 },
121 { &TYPELIB_Descriptor, DLL_FLAG_NOT_USED },
122 { &VER_Descriptor, 0 },
123 { &W32SYS_Descriptor, DLL_FLAG_NOT_USED },
124 { &WIN32S16_Descriptor, DLL_FLAG_NOT_USED },
125 { &WIN87EM_Descriptor, DLL_FLAG_NOT_USED },
126 { &WINASPI_Descriptor, 0 },
127 { &WINEPS_Descriptor, DLL_FLAG_ALWAYS_USED },
128 { &WING_Descriptor, 0 },
129 { &WINSOCK_Descriptor, 0 },
130 /* Last entry */
131 { NULL, 0 }
134 /* Ordinal number for interrupt 0 handler in WPROCS.DLL */
135 #define FIRST_INTERRUPT_ORDINAL 100
138 /***********************************************************************
139 * BUILTIN_DoLoadModule16
141 * Load a built-in Win16 module. Helper function for BUILTIN_LoadModule
142 * and BUILTIN_Init.
144 static HMODULE16 BUILTIN_DoLoadModule16( const WIN16_DESCRIPTOR *descr )
146 NE_MODULE *pModule;
147 int minsize;
148 SEGTABLEENTRY *pSegTable;
150 HMODULE16 hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, descr->module_start,
151 descr->module_size, 0,
152 FALSE, FALSE, FALSE, NULL );
153 if (!hModule) return 0;
154 FarSetOwner16( hModule, hModule );
156 TRACE("Built-in %s: hmodule=%04x\n",
157 descr->name, hModule );
158 pModule = (NE_MODULE *)GlobalLock16( hModule );
159 pModule->self = hModule;
161 /* Allocate the code segment */
163 pSegTable = NE_SEG_TABLE( pModule );
164 pSegTable->hSeg = GLOBAL_CreateBlock( GMEM_FIXED, descr->code_start,
165 pSegTable->minsize, hModule,
166 TRUE, TRUE, FALSE, NULL );
167 if (!pSegTable->hSeg) return 0;
168 pSegTable++;
170 /* Allocate the data segment */
172 minsize = pSegTable->minsize ? pSegTable->minsize : 0x10000;
173 minsize += pModule->heap_size;
174 if (minsize > 0x10000) minsize = 0x10000;
175 pSegTable->hSeg = GLOBAL_Alloc( GMEM_FIXED, minsize,
176 hModule, FALSE, FALSE, FALSE );
177 if (!pSegTable->hSeg) return 0;
178 if (pSegTable->minsize) memcpy( GlobalLock16( pSegTable->hSeg ),
179 descr->data_start, pSegTable->minsize);
180 if (pModule->heap_size)
181 LocalInit16( GlobalHandleToSel16(pSegTable->hSeg),
182 pSegTable->minsize, minsize );
184 NE_RegisterModule( pModule );
185 return hModule;
189 /***********************************************************************
190 * BUILTIN_Init
192 * Load all built-in modules marked as 'always used'.
194 BOOL BUILTIN_Init(void)
196 BUILTIN16_DLL *dll;
197 WORD vector;
198 HMODULE16 hModule;
200 for (dll = BuiltinDLLs; dll->descr; dll++)
202 if (dll->flags & DLL_FLAG_ALWAYS_USED)
203 if (!BUILTIN_DoLoadModule16( dll->descr )) return FALSE;
206 /* Set interrupt vectors from entry points in WPROCS.DLL */
208 hModule = GetModuleHandle16( "WPROCS" );
209 for (vector = 0; vector < 256; vector++)
211 FARPROC16 proc = NE_GetEntryPoint( hModule,
212 FIRST_INTERRUPT_ORDINAL + vector );
213 assert(proc);
214 INT_SetPMHandler( vector, proc );
217 return TRUE;
221 /***********************************************************************
222 * BUILTIN_LoadModule
224 * Load a built-in module. If the 'force' parameter is FALSE, we only
225 * load the module if it has not been disabled via the -dll option.
227 HMODULE16 BUILTIN_LoadModule( LPCSTR name, BOOL force )
229 BUILTIN16_DLL *table;
230 char dllname[16], *p;
232 /* Fix the name in case we have a full path and extension */
234 if ((p = strrchr( name, '\\' ))) name = p + 1;
235 lstrcpynA( dllname, name, sizeof(dllname) );
236 p = strrchr( dllname, '.' );
238 if (!p) strcat( dllname, ".dll" );
240 for (table = BuiltinDLLs; table->descr; table++)
242 NE_MODULE *pModule = (NE_MODULE *)table->descr->module_start;
243 OFSTRUCT *pOfs = (OFSTRUCT *)((LPBYTE)pModule + pModule->fileinfo);
244 if (!lstrcmpiA( pOfs->szPathName, dllname )) break;
247 if (!table->descr) return (HMODULE16)2;
249 if ((table->flags & DLL_FLAG_NOT_USED) && !force) return (HMODULE16)2;
251 return BUILTIN_DoLoadModule16( table->descr );
255 /***********************************************************************
256 * BUILTIN_GetEntryPoint16
258 * Return the ordinal, name, and type info corresponding to a CS:IP address.
259 * This is used only by relay debugging.
261 LPCSTR BUILTIN_GetEntryPoint16( STACK16FRAME *frame, LPSTR name, WORD *pOrd )
263 WORD i, max_offset;
264 register BYTE *p;
265 NE_MODULE *pModule;
266 ET_BUNDLE *bundle;
267 ET_ENTRY *entry;
269 if (!(pModule = NE_GetPtr( FarGetOwner16( GlobalHandle16( frame->module_cs ) ))))
270 return NULL;
272 max_offset = 0;
273 *pOrd = 0;
274 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
277 entry = (ET_ENTRY *)((BYTE *)bundle+6);
278 for (i = bundle->first + 1; i <= bundle->last; i++)
280 if ((entry->offs < frame->entry_ip)
281 && (entry->segnum == 1) /* code segment ? */
282 && (entry->offs >= max_offset))
284 max_offset = entry->offs;
285 *pOrd = i;
287 entry++;
289 } while ( (bundle->next)
290 && (bundle = (ET_BUNDLE *)((BYTE *)pModule+bundle->next)));
292 /* Search for the name in the resident names table */
293 /* (built-in modules have no non-resident table) */
295 p = (BYTE *)pModule + pModule->name_table;
296 while (*p)
298 p += *p + 1 + sizeof(WORD);
299 if (*(WORD *)(p + *p + 1) == *pOrd) break;
302 sprintf( name, "%.*s.%d: %.*s",
303 *((BYTE *)pModule + pModule->name_table),
304 (char *)pModule + pModule->name_table + 1,
305 *pOrd, *p, (char *)(p + 1) );
307 /* Retrieve type info string */
308 return *(LPCSTR *)((LPBYTE)PTR_SEG_OFF_TO_LIN( frame->module_cs, frame->callfrom_ip ) + 4);
312 /**********************************************************************
313 * BUILTIN_DefaultIntHandler
315 * Default interrupt handler.
317 void WINAPI BUILTIN_DefaultIntHandler( CONTEXT86 *context )
319 WORD ordinal;
320 char name[80];
321 BUILTIN_GetEntryPoint16( CURRENT_STACK16, name, &ordinal );
322 INT_BARF( context, ordinal - FIRST_INTERRUPT_ORDINAL );