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
146 #define NE_SEG_TABLE(pModule) \
147 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
149 #define NE_MODULE_TABLE(pModule) \
150 ((WORD *)((char *)(pModule) + (pModule)->modref_table))
152 #define NE_MODULE_NAME(pModule) \
153 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
155 #define PE_HEADER(module) \
156 ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
157 (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
159 #define PE_SECTIONS(module) \
160 ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
161 PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
164 extern WINE_MODREF
*MODULE_AllocModRef( HMODULE hModule
, LPCSTR filename
);
165 extern FARPROC
MODULE_GetProcAddress( HMODULE hModule
, LPCSTR function
, BOOL snoop
);
166 extern BOOL
MODULE_DllProcessAttach( WINE_MODREF
*wm
, LPVOID lpReserved
);
167 extern void MODULE_DllProcessDetach( BOOL bForceDetach
, LPVOID lpReserved
);
168 extern void MODULE_DllThreadAttach( LPVOID lpReserved
);
169 extern void MODULE_DllThreadDetach( LPVOID lpReserved
);
170 extern WINE_MODREF
*MODULE_LoadLibraryExA( LPCSTR libname
, HFILE hfile
, DWORD flags
);
171 extern BOOL
MODULE_FreeLibrary( WINE_MODREF
*wm
);
172 extern WINE_MODREF
*MODULE_FindModule( LPCSTR path
);
173 extern HMODULE
MODULE_CreateDummyModule( LPCSTR filename
, HMODULE module32
);
174 extern FARPROC16 WINAPI
WIN32_GetProcAddress16( HMODULE hmodule
, LPCSTR name
);
175 extern SEGPTR WINAPI
HasGPHandler16( SEGPTR address
);
176 extern void MODULE_WalkModref( DWORD id
);
178 /* loader/ne/module.c */
179 extern NE_MODULE
*NE_GetPtr( HMODULE16 hModule
);
180 extern void NE_DumpModule( HMODULE16 hModule
);
181 extern void NE_WalkModules(void);
182 extern void NE_RegisterModule( NE_MODULE
*pModule
);
183 extern WORD
NE_GetOrdinal( HMODULE16 hModule
, const char *name
);
184 extern FARPROC16 WINAPI
NE_GetEntryPoint( HMODULE16 hModule
, WORD ordinal
);
185 extern FARPROC16
NE_GetEntryPointEx( HMODULE16 hModule
, WORD ordinal
, BOOL16 snoop
);
186 extern BOOL16
NE_SetEntryPoint( HMODULE16 hModule
, WORD ordinal
, WORD offset
);
187 extern HANDLE
NE_OpenFile( NE_MODULE
*pModule
);
189 /* loader/ne/resource.c */
190 extern HGLOBAL16 WINAPI
NE_DefResourceHandler(HGLOBAL16
,HMODULE16
,HRSRC16
);
191 extern BOOL
NE_InitResourceHandler( HMODULE16 hModule
);
192 extern HRSRC16
NE_FindResource( NE_MODULE
*pModule
, LPCSTR name
, LPCSTR type
);
193 extern DWORD
NE_SizeofResource( NE_MODULE
*pModule
, HRSRC16 hRsrc
);
194 extern HGLOBAL16
NE_LoadResource( NE_MODULE
*pModule
, HRSRC16 hRsrc
);
195 extern BOOL16
NE_FreeResource( NE_MODULE
*pModule
, HGLOBAL16 handle
);
196 extern NE_TYPEINFO
*NE_FindTypeSection( LPBYTE pResTab
, NE_TYPEINFO
*pTypeInfo
, LPCSTR typeId
);
197 extern NE_NAMEINFO
*NE_FindResourceFromType( LPBYTE pResTab
, NE_TYPEINFO
*pTypeInfo
, LPCSTR resId
);
199 /* loader/ne/segment.c */
200 extern BOOL
NE_LoadSegment( NE_MODULE
*pModule
, WORD segnum
);
201 extern BOOL
NE_LoadAllSegments( NE_MODULE
*pModule
);
202 extern BOOL
NE_CreateSegment( NE_MODULE
*pModule
, int segnum
);
203 extern BOOL
NE_CreateAllSegments( NE_MODULE
*pModule
);
204 extern HINSTANCE16
NE_GetInstance( NE_MODULE
*pModule
);
205 extern void NE_InitializeDLLs( HMODULE16 hModule
);
206 extern void NE_DllProcessAttach( HMODULE16 hModule
);
208 /* loader/ne/convert.c */
209 HGLOBAL16
NE_LoadPEResource( NE_MODULE
*pModule
, WORD type
, LPVOID bits
, DWORD size
);
211 /* loader/pe_resource.c */
212 extern HRSRC
PE_FindResourceW(HMODULE
,LPCWSTR
,LPCWSTR
);
213 extern HRSRC
PE_FindResourceExW(HMODULE
,LPCWSTR
,LPCWSTR
,WORD
);
214 extern DWORD
PE_SizeofResource(HRSRC
);
215 extern HGLOBAL
PE_LoadResource(HMODULE
,HRSRC
);
217 /* loader/pe_image.c */
218 extern WINE_MODREF
*PE_LoadLibraryExA(LPCSTR
, DWORD
);
219 extern HMODULE
PE_LoadImage( HANDLE hFile
, LPCSTR filename
, DWORD flags
);
220 extern WINE_MODREF
*PE_CreateModule( HMODULE hModule
, LPCSTR filename
,
221 DWORD flags
, HFILE hFile
, BOOL builtin
);
222 extern void PE_InitTls(void);
223 extern BOOL
PE_InitDLL( HMODULE module
, DWORD type
, LPVOID lpReserved
);
226 extern WINE_MODREF
*ELF_LoadLibraryExA( LPCSTR libname
, DWORD flags
);
228 /* relay32/builtin.c */
229 extern WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR name
, DWORD flags
);
230 extern HMODULE
BUILTIN32_LoadExeModule( HMODULE main
);
231 extern void *BUILTIN32_dlopen( const char *name
);
232 extern int BUILTIN32_dlclose( void *handle
);
234 #endif /* __WINE_MODULE_H */