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
;
136 char data
[1]; /* space for storing filename and short_filename */
139 #define WINE_MODREF_INTERNAL 0x00000001
140 #define WINE_MODREF_NO_DLL_CALLS 0x00000002
141 #define WINE_MODREF_PROCESS_ATTACHED 0x00000004
142 #define WINE_MODREF_DONT_RESOLVE_REFS 0x00000020
143 #define WINE_MODREF_MARKER 0x80000000
145 extern WINE_MODREF
*MODULE_modref_list
;
149 #define NE_SEG_TABLE(pModule) \
150 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
152 #define NE_MODULE_TABLE(pModule) \
153 ((WORD *)((char *)(pModule) + (pModule)->modref_table))
155 #define NE_MODULE_NAME(pModule) \
156 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
158 #define PE_HEADER(module) \
159 ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
160 (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
162 #define PE_SECTIONS(module) \
163 ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
164 PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
168 LOADORDER_INVALID
= 0, /* Must be 0 */
169 LOADORDER_DLL
, /* Native DLLs */
170 LOADORDER_SO
, /* Native .so libraries */
171 LOADORDER_BI
, /* Built-in modules */
176 extern WINE_MODREF
*MODULE_AllocModRef( HMODULE hModule
, LPCSTR filename
);
177 extern FARPROC
MODULE_GetProcAddress( HMODULE hModule
, LPCSTR function
, BOOL snoop
);
178 extern BOOL
MODULE_DllProcessAttach( WINE_MODREF
*wm
, LPVOID lpReserved
);
179 extern void MODULE_DllProcessDetach( BOOL bForceDetach
, LPVOID lpReserved
);
180 extern void MODULE_DllThreadAttach( LPVOID lpReserved
);
181 extern void MODULE_DllThreadDetach( LPVOID lpReserved
);
182 extern WINE_MODREF
*MODULE_LoadLibraryExA( LPCSTR libname
, HFILE hfile
, DWORD flags
);
183 extern BOOL
MODULE_FreeLibrary( WINE_MODREF
*wm
);
184 extern WINE_MODREF
*MODULE_FindModule( LPCSTR path
);
185 extern HMODULE16
MODULE_CreateDummyModule( LPCSTR filename
, HMODULE module32
);
186 extern FARPROC16 WINAPI
WIN32_GetProcAddress16( HMODULE hmodule
, LPCSTR name
);
187 extern SEGPTR WINAPI
HasGPHandler16( SEGPTR address
);
188 extern void MODULE_WalkModref( DWORD id
);
190 /* loader/ne/module.c */
191 extern NE_MODULE
*NE_GetPtr( HMODULE16 hModule
);
192 extern void NE_DumpModule( HMODULE16 hModule
);
193 extern void NE_WalkModules(void);
194 extern void NE_RegisterModule( NE_MODULE
*pModule
);
195 extern WORD
NE_GetOrdinal( HMODULE16 hModule
, const char *name
);
196 extern FARPROC16 WINAPI
NE_GetEntryPoint( HMODULE16 hModule
, WORD ordinal
);
197 extern FARPROC16
NE_GetEntryPointEx( HMODULE16 hModule
, WORD ordinal
, BOOL16 snoop
);
198 extern BOOL16
NE_SetEntryPoint( HMODULE16 hModule
, WORD ordinal
, WORD offset
);
199 extern HANDLE
NE_OpenFile( NE_MODULE
*pModule
);
200 extern DWORD
NE_StartTask(void);
202 /* loader/ne/resource.c */
203 extern HGLOBAL16 WINAPI
NE_DefResourceHandler(HGLOBAL16
,HMODULE16
,HRSRC16
);
204 extern BOOL
NE_InitResourceHandler( HMODULE16 hModule
);
205 extern HRSRC16
NE_FindResource( NE_MODULE
*pModule
, LPCSTR name
, LPCSTR type
);
206 extern DWORD
NE_SizeofResource( NE_MODULE
*pModule
, HRSRC16 hRsrc
);
207 extern HGLOBAL16
NE_LoadResource( NE_MODULE
*pModule
, HRSRC16 hRsrc
);
208 extern BOOL16
NE_FreeResource( NE_MODULE
*pModule
, HGLOBAL16 handle
);
209 extern NE_TYPEINFO
*NE_FindTypeSection( LPBYTE pResTab
, NE_TYPEINFO
*pTypeInfo
, LPCSTR typeId
);
210 extern NE_NAMEINFO
*NE_FindResourceFromType( LPBYTE pResTab
, NE_TYPEINFO
*pTypeInfo
, LPCSTR resId
);
212 /* loader/ne/segment.c */
213 extern BOOL
NE_LoadSegment( NE_MODULE
*pModule
, WORD segnum
);
214 extern BOOL
NE_LoadAllSegments( NE_MODULE
*pModule
);
215 extern BOOL
NE_CreateSegment( NE_MODULE
*pModule
, int segnum
);
216 extern BOOL
NE_CreateAllSegments( NE_MODULE
*pModule
);
217 extern HINSTANCE16
NE_GetInstance( NE_MODULE
*pModule
);
218 extern void NE_InitializeDLLs( HMODULE16 hModule
);
219 extern void NE_DllProcessAttach( HMODULE16 hModule
);
221 /* loader/ne/convert.c */
222 HGLOBAL16
NE_LoadPEResource( NE_MODULE
*pModule
, WORD type
, LPVOID bits
, DWORD size
);
224 /* loader/pe_resource.c */
225 extern HRSRC
PE_FindResourceW(HMODULE
,LPCWSTR
,LPCWSTR
);
226 extern HRSRC
PE_FindResourceExW(HMODULE
,LPCWSTR
,LPCWSTR
,WORD
);
227 extern DWORD
PE_SizeofResource(HRSRC
);
228 extern HGLOBAL
PE_LoadResource(HMODULE
,HRSRC
);
230 /* loader/pe_image.c */
231 extern WINE_MODREF
*PE_LoadLibraryExA(LPCSTR
, DWORD
);
232 extern HMODULE
PE_LoadImage( HANDLE hFile
, LPCSTR filename
, DWORD flags
);
233 extern WINE_MODREF
*PE_CreateModule( HMODULE hModule
, LPCSTR filename
,
234 DWORD flags
, HANDLE hFile
, BOOL builtin
);
235 extern void PE_InitTls(void);
236 extern BOOL
PE_InitDLL( HMODULE module
, DWORD type
, LPVOID lpReserved
);
238 /* loader/loadorder.c */
239 extern void MODULE_InitLoadOrder(void);
240 extern void MODULE_GetLoadOrder( enum loadorder_type plo
[], const char *path
, BOOL win32
);
241 extern void MODULE_AddLoadOrderOption( const char *option
);
244 extern WINE_MODREF
*ELF_LoadLibraryExA( LPCSTR libname
, DWORD flags
);
246 /* relay32/builtin.c */
247 extern WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR name
, DWORD flags
);
248 extern HMODULE
BUILTIN32_LoadExeModule( HMODULE main
);
249 extern void *BUILTIN32_dlopen( const char *name
);
250 extern int BUILTIN32_dlclose( void *handle
);
252 /* USER signal proc flags and codes */
253 /* See PROCESS_CallUserSignalProc for comments */
254 #define USIG_FLAGS_WIN32 0x0001
255 #define USIG_FLAGS_GUI 0x0002
256 #define USIG_FLAGS_FEEDBACK 0x0004
257 #define USIG_FLAGS_FAULT 0x0008
259 #define USIG_DLL_UNLOAD_WIN16 0x0001
260 #define USIG_DLL_UNLOAD_WIN32 0x0002
261 #define USIG_FAULT_DIALOG_PUSH 0x0003
262 #define USIG_FAULT_DIALOG_POP 0x0004
263 #define USIG_DLL_UNLOAD_ORPHANS 0x0005
264 #define USIG_THREAD_INIT 0x0010
265 #define USIG_THREAD_EXIT 0x0020
266 #define USIG_PROCESS_CREATE 0x0100
267 #define USIG_PROCESS_INIT 0x0200
268 #define USIG_PROCESS_EXIT 0x0300
269 #define USIG_PROCESS_DESTROY 0x0400
270 #define USIG_PROCESS_RUNNING 0x0500
271 #define USIG_PROCESS_LOADED 0x0600
273 /* scheduler/process.c */
274 extern void PROCESS_CallUserSignalProc( UINT uCode
, HMODULE16 hModule
);
275 extern BOOL
PROCESS_Create( HANDLE hFile
, LPCSTR filename
, LPSTR cmd_line
, LPCSTR env
,
276 LPSECURITY_ATTRIBUTES psa
, LPSECURITY_ATTRIBUTES tsa
,
277 BOOL inherit
, DWORD flags
,
278 STARTUPINFOA
*startup
, PROCESS_INFORMATION
*info
,
279 LPCSTR lpCurrentDirectory
);
281 #endif /* __WINE_MODULE_H */