4 * Copyright 1995 Alexandre Julliard
7 #ifndef __WINE_MODULE_H
8 #define __WINE_MODULE_H
12 #include "wine/windef16.h"
13 #include "wine/winbase16.h"
15 /* In-memory module structure. See 'Windows Internals' p. 219 */
16 typedef struct _NE_MODULE
18 WORD magic; /* 00 'NE' signature */
19 WORD count; /* 02 Usage count */
20 WORD entry_table; /* 04 Near ptr to entry table */
21 HMODULE16 next; /* 06 Selector to next module */
22 WORD dgroup_entry; /* 08 Near ptr to segment entry for DGROUP */
23 WORD fileinfo; /* 0a Near ptr to file info (OFSTRUCT) */
24 WORD flags; /* 0c Module flags */
25 WORD dgroup; /* 0e Logical segment for DGROUP */
26 WORD heap_size; /* 10 Initial heap size */
27 WORD stack_size; /* 12 Initial stack size */
28 WORD ip; /* 14 Initial ip */
29 WORD cs; /* 16 Initial cs (logical segment) */
30 WORD sp; /* 18 Initial stack pointer */
31 WORD ss; /* 1a Initial ss (logical segment) */
32 WORD seg_count; /* 1c Number of segments in segment table */
33 WORD modref_count; /* 1e Number of module references */
34 WORD nrname_size; /* 20 Size of non-resident names table */
35 WORD seg_table; /* 22 Near ptr to segment table */
36 WORD res_table; /* 24 Near ptr to resource table */
37 WORD name_table; /* 26 Near ptr to resident names table */
38 WORD modref_table; /* 28 Near ptr to module reference table */
39 WORD import_table; /* 2a Near ptr to imported names table */
40 DWORD nrname_fpos; /* 2c File offset of non-resident names table */
41 WORD moveable_entries; /* 30 Number of moveable entries in entry table*/
42 WORD alignment; /* 32 Alignment shift count */
43 WORD truetype; /* 34 Set to 2 if TrueType font */
44 BYTE os_flags; /* 36 Operating system flags */
45 BYTE misc_flags; /* 37 Misc. flags */
46 HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize */
47 HANDLE16 nrname_handle; /* 3a Handle to non-resident name table */
48 WORD min_swap_area; /* 3c Min. swap area size */
49 WORD expected_version; /* 3e Expected Windows version */
50 /* From here, these are extra fields not present in normal Windows */
51 HMODULE module32; /* 40 PE module handle for Win32 modules */
52 HMODULE16 self; /* 44 Handle for this module */
53 WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
54 LPVOID hRsrcMap; /* HRSRC 16->32 map (for 32-bit modules) */
62 WORD offs WINE_PACKED;
66 WORD first; /* ordinal */
67 WORD last; /* ordinal */
68 WORD next; /* bundle */
72 /* In-memory segment table */
75 WORD filepos; /* Position in file, in sectors */
76 WORD size; /* Segment size on disk */
77 WORD flags; /* Segment flags */
78 WORD minsize; /* Min. size of segment in memory */
79 HANDLE16 hSeg; /* Selector or handle (selector - 1) */
80 /* of segment in memory */
84 /* Self-loading modules contain this structure in their first segment */
90 WORD version; /* Must be "A0" (0x3041) */
92 FARPROC16 BootApp; /* startup procedure */
93 FARPROC16 LoadAppSeg; /* procedure to load a segment */
95 FARPROC16 MyAlloc; /* memory allocation procedure,
96 * wine must write this field */
97 FARPROC16 EntryAddrProc;
98 FARPROC16 ExitProc; /* exit procedure */
100 FARPROC16 SetOwner; /* Set Owner procedure, exported by wine */
113 /* internal representation of 32bit modules. per process. */
114 typedef struct _wine_modref
116 struct _wine_modref *next;
117 struct _wine_modref *prev;
119 HMODULE16 hDummyMod; /* Win16 dummy module */
120 void *dlhandle; /* handle returned by dlopen() */
121 int tlsindex; /* TLS index or -1 if none */
123 FARPROC (*find_export)( struct _wine_modref *wm, LPCSTR func, BOOL snoop );
126 struct _wine_modref **deps;
133 char *short_filename;
137 #define WINE_MODREF_INTERNAL 0x00000001
138 #define WINE_MODREF_NO_DLL_CALLS 0x00000002
139 #define WINE_MODREF_PROCESS_ATTACHED 0x00000004
140 #define WINE_MODREF_DONT_RESOLVE_REFS 0x00000020
141 #define WINE_MODREF_MARKER 0x80000000
143 extern WINE_MODREF *MODULE_modref_list;
147 #define NE_SEG_TABLE(pModule) \
148 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
150 #define NE_MODULE_TABLE(pModule) \
151 ((WORD *)((char *)(pModule) + (pModule)->modref_table))
153 #define NE_MODULE_NAME(pModule) \
154 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
156 #define PE_HEADER(module) \
157 ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
158 (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
160 #define PE_SECTIONS(module) \
161 ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
162 PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
165 extern WINE_MODREF *MODULE_AllocModRef( HMODULE hModule, LPCSTR filename );
166 extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, BOOL snoop );
167 extern BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
168 extern void MODULE_DllProcessDetach( BOOL bForceDetach, LPVOID lpReserved );
169 extern void MODULE_DllThreadAttach( LPVOID lpReserved );
170 extern void MODULE_DllThreadDetach( LPVOID lpReserved );
171 extern WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
172 extern BOOL MODULE_FreeLibrary( WINE_MODREF *wm );
173 extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
174 extern HMODULE MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
175 extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
176 extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
177 extern void MODULE_WalkModref( DWORD id );
179 /* loader/ne/module.c */
180 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
181 extern void NE_DumpModule( HMODULE16 hModule );
182 extern void NE_WalkModules(void);
183 extern void NE_RegisterModule( NE_MODULE *pModule );
184 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
185 extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
186 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
187 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
188 extern HANDLE NE_OpenFile( NE_MODULE *pModule );
190 /* loader/ne/resource.c */
191 extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
192 extern BOOL NE_InitResourceHandler( HMODULE16 hModule );
193 extern HRSRC16 NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
194 extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC16 hRsrc );
195 extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
196 extern BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
197 extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
198 extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
200 /* loader/ne/segment.c */
201 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
202 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
203 extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
204 extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
205 extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
206 extern void NE_InitializeDLLs( HMODULE16 hModule );
207 extern void NE_DllProcessAttach( HMODULE16 hModule );
209 /* loader/ne/convert.c */
210 HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
212 /* loader/pe_resource.c */
213 extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
214 extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
215 extern DWORD PE_SizeofResource(HRSRC);
216 extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
218 /* loader/pe_image.c */
219 extern WINE_MODREF *PE_LoadLibraryExA(LPCSTR, DWORD);
220 extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
221 extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
222 DWORD flags, HANDLE hFile, BOOL builtin );
223 extern void PE_InitTls(void);
224 extern BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved );
227 extern WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags);
229 /* relay32/builtin.c */
230 extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags);
231 extern HMODULE BUILTIN32_LoadExeModule( HMODULE main );
232 extern void *BUILTIN32_dlopen( const char *name );
233 extern int BUILTIN32_dlclose( void *handle );
235 /* USER signal proc flags and codes */
236 /* See PROCESS_CallUserSignalProc for comments */
237 #define USIG_FLAGS_WIN32 0x0001
238 #define USIG_FLAGS_GUI 0x0002
239 #define USIG_FLAGS_FEEDBACK 0x0004
240 #define USIG_FLAGS_FAULT 0x0008
242 #define USIG_DLL_UNLOAD_WIN16 0x0001
243 #define USIG_DLL_UNLOAD_WIN32 0x0002
244 #define USIG_FAULT_DIALOG_PUSH 0x0003
245 #define USIG_FAULT_DIALOG_POP 0x0004
246 #define USIG_DLL_UNLOAD_ORPHANS 0x0005
247 #define USIG_THREAD_INIT 0x0010
248 #define USIG_THREAD_EXIT 0x0020
249 #define USIG_PROCESS_CREATE 0x0100
250 #define USIG_PROCESS_INIT 0x0200
251 #define USIG_PROCESS_EXIT 0x0300
252 #define USIG_PROCESS_DESTROY 0x0400
253 #define USIG_PROCESS_RUNNING 0x0500
254 #define USIG_PROCESS_LOADED 0x0600
256 /* scheduler/process.c */
257 extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule );
258 extern BOOL PROCESS_Create( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
259 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
260 BOOL inherit, DWORD flags,
261 STARTUPINFOA *startup, PROCESS_INFORMATION *info,
262 LPCSTR lpCurrentDirectory );
264 #endif /* __WINE_MODULE_H */