Added support for ordinal hint in PE_FindExportedFunction.
[wine/multimedia.git] / include / module.h
blobd1d5ccd3fbc5f0d4fd2a2caa5e33def368d5d12e
1 /*
2 * Module definitions
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_MODULE_H
22 #define __WINE_MODULE_H
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wine/windef16.h"
27 #include "wine/winbase16.h"
29 /* In-memory module structure. See 'Windows Internals' p. 219 */
30 typedef struct _NE_MODULE
32 WORD magic; /* 00 'NE' signature */
33 WORD count; /* 02 Usage count */
34 WORD entry_table; /* 04 Near ptr to entry table */
35 HMODULE16 next; /* 06 Selector to next module */
36 WORD dgroup_entry; /* 08 Near ptr to segment entry for DGROUP */
37 WORD fileinfo; /* 0a Near ptr to file info (OFSTRUCT) */
38 WORD flags; /* 0c Module flags */
39 WORD dgroup; /* 0e Logical segment for DGROUP */
40 WORD heap_size; /* 10 Initial heap size */
41 WORD stack_size; /* 12 Initial stack size */
42 WORD ip; /* 14 Initial ip */
43 WORD cs; /* 16 Initial cs (logical segment) */
44 WORD sp; /* 18 Initial stack pointer */
45 WORD ss; /* 1a Initial ss (logical segment) */
46 WORD seg_count; /* 1c Number of segments in segment table */
47 WORD modref_count; /* 1e Number of module references */
48 WORD nrname_size; /* 20 Size of non-resident names table */
49 WORD seg_table; /* 22 Near ptr to segment table */
50 WORD res_table; /* 24 Near ptr to resource table */
51 WORD name_table; /* 26 Near ptr to resident names table */
52 WORD modref_table; /* 28 Near ptr to module reference table */
53 WORD import_table; /* 2a Near ptr to imported names table */
54 DWORD nrname_fpos; /* 2c File offset of non-resident names table */
55 WORD moveable_entries; /* 30 Number of moveable entries in entry table*/
56 WORD alignment; /* 32 Alignment shift count */
57 WORD truetype; /* 34 Set to 2 if TrueType font */
58 BYTE os_flags; /* 36 Operating system flags */
59 BYTE misc_flags; /* 37 Misc. flags */
60 HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize */
61 HANDLE16 nrname_handle; /* 3a Handle to non-resident name table */
62 WORD min_swap_area; /* 3c Min. swap area size */
63 WORD expected_version; /* 3e Expected Windows version */
64 /* From here, these are extra fields not present in normal Windows */
65 HMODULE module32; /* 40 PE module handle for Win32 modules */
66 HMODULE16 self; /* 44 Handle for this module */
67 WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
68 LPVOID hRsrcMap; /* HRSRC 16->32 map (for 32-bit modules) */
69 } NE_MODULE;
72 typedef struct {
73 BYTE type;
74 BYTE flags;
75 BYTE segnum;
76 WORD offs WINE_PACKED;
77 } ET_ENTRY;
79 typedef struct {
80 WORD first; /* ordinal */
81 WORD last; /* ordinal */
82 WORD next; /* bundle */
83 } ET_BUNDLE;
86 /* In-memory segment table */
87 typedef struct
89 WORD filepos; /* Position in file, in sectors */
90 WORD size; /* Segment size on disk */
91 WORD flags; /* Segment flags */
92 WORD minsize; /* Min. size of segment in memory */
93 HANDLE16 hSeg; /* Selector or handle (selector - 1) */
94 /* of segment in memory */
95 } SEGTABLEENTRY;
98 /* Self-loading modules contain this structure in their first segment */
100 #include "pshpack1.h"
102 typedef struct
104 WORD version; /* Must be "A0" (0x3041) */
105 WORD reserved;
106 FARPROC16 BootApp; /* startup procedure */
107 FARPROC16 LoadAppSeg; /* procedure to load a segment */
108 FARPROC16 reserved2;
109 FARPROC16 MyAlloc; /* memory allocation procedure,
110 * wine must write this field */
111 FARPROC16 EntryAddrProc;
112 FARPROC16 ExitProc; /* exit procedure */
113 WORD reserved3[4];
114 FARPROC16 SetOwner; /* Set Owner procedure, exported by wine */
115 } SELFLOADHEADER;
117 typedef struct
119 LPSTR lpEnvAddress;
120 LPSTR lpCmdLine;
121 UINT16 *lpCmdShow;
122 DWORD dwReserved;
123 } LOADPARAMS;
125 #include "poppack.h"
127 /* internal representation of 32bit modules. per process. */
128 typedef struct _wine_modref
130 struct _wine_modref *next;
131 struct _wine_modref *prev;
132 HMODULE module;
133 HMODULE16 hDummyMod; /* Win16 dummy module */
134 void *dlhandle; /* handle returned by dlopen() */
135 int tlsindex; /* TLS index or -1 if none */
137 FARPROC (*find_export)( struct _wine_modref *wm, LPCSTR func,
138 int hint, BOOL snoop );
140 int nDeps;
141 struct _wine_modref **deps;
143 int flags;
144 int refCount;
146 char *filename;
147 char *modname;
148 char *short_filename;
149 char *short_modname;
151 char data[1]; /* space for storing filename and short_filename */
152 } WINE_MODREF;
154 #define WINE_MODREF_INTERNAL 0x00000001
155 #define WINE_MODREF_NO_DLL_CALLS 0x00000002
156 #define WINE_MODREF_PROCESS_ATTACHED 0x00000004
157 #define WINE_MODREF_DONT_RESOLVE_REFS 0x00000020
158 #define WINE_MODREF_MARKER 0x80000000
160 extern WINE_MODREF *MODULE_modref_list;
162 /* Resource types */
164 #define NE_SEG_TABLE(pModule) \
165 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
167 #define NE_MODULE_TABLE(pModule) \
168 ((WORD *)((char *)(pModule) + (pModule)->modref_table))
170 #define NE_MODULE_NAME(pModule) \
171 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
173 #define PE_HEADER(module) \
174 ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
175 (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
177 #define PE_SECTIONS(module) \
178 ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
179 PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
181 enum loadorder_type
183 LOADORDER_INVALID = 0, /* Must be 0 */
184 LOADORDER_DLL, /* Native DLLs */
185 LOADORDER_SO, /* Native .so libraries */
186 LOADORDER_BI, /* Built-in modules */
187 LOADORDER_NTYPES
190 /* return values for MODULE_GetBinaryType */
191 enum binary_type
193 BINARY_UNKNOWN,
194 BINARY_PE_EXE,
195 BINARY_PE_DLL,
196 BINARY_WIN16,
197 BINARY_OS216,
198 BINARY_DOS,
199 BINARY_UNIX_EXE,
200 BINARY_UNIX_LIB
203 /* module.c */
204 extern WINE_MODREF *MODULE_AllocModRef( HMODULE hModule, LPCSTR filename );
205 extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, int hint, BOOL snoop );
206 extern BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
207 extern void MODULE_DllProcessDetach( BOOL bForceDetach, LPVOID lpReserved );
208 extern void MODULE_DllThreadAttach( LPVOID lpReserved );
209 extern void MODULE_DllThreadDetach( LPVOID lpReserved );
210 extern WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
211 extern BOOL MODULE_FreeLibrary( WINE_MODREF *wm );
212 extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
213 extern HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
214 extern enum binary_type MODULE_GetBinaryType( HANDLE hfile );
215 extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
216 extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
217 extern void MODULE_WalkModref( DWORD id );
219 /* loader/ne/module.c */
220 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
221 extern void NE_DumpModule( HMODULE16 hModule );
222 extern void NE_WalkModules(void);
223 extern void NE_RegisterModule( NE_MODULE *pModule );
224 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
225 extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
226 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
227 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
228 extern HANDLE NE_OpenFile( NE_MODULE *pModule );
229 extern DWORD NE_StartTask(void);
231 /* loader/ne/resource.c */
232 extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
233 extern BOOL NE_InitResourceHandler( HMODULE16 hModule );
234 extern HRSRC16 NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
235 extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC16 hRsrc );
236 extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
237 extern BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
238 extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
239 extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
241 /* loader/ne/segment.c */
242 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
243 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
244 extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
245 extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
246 extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
247 extern void NE_InitializeDLLs( HMODULE16 hModule );
248 extern void NE_DllProcessAttach( HMODULE16 hModule );
250 /* loader/ne/convert.c */
251 HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
253 /* loader/pe_resource.c */
254 extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
255 extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
256 extern DWORD PE_SizeofResource(HRSRC);
257 extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
259 /* loader/pe_image.c */
260 extern WINE_MODREF *PE_LoadLibraryExA(LPCSTR, DWORD);
261 extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
262 extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
263 DWORD flags, HANDLE hFile, BOOL builtin );
264 extern void PE_InitTls(void);
265 extern BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved );
266 extern DWORD PE_fixup_imports(WINE_MODREF *wm);
268 /* loader/loadorder.c */
269 extern void MODULE_GetLoadOrder( enum loadorder_type plo[], const char *path, BOOL win32 );
270 extern void MODULE_AddLoadOrderOption( const char *option );
272 /* loader/elf.c */
273 extern WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags);
275 /* relay32/builtin.c */
276 extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags);
277 extern HMODULE BUILTIN32_LoadExeModule( HMODULE main );
278 extern void *BUILTIN32_dlopen( const char *name );
279 extern int BUILTIN32_dlclose( void *handle );
281 /* USER signal proc flags and codes */
282 /* See PROCESS_CallUserSignalProc for comments */
283 #define USIG_FLAGS_WIN32 0x0001
284 #define USIG_FLAGS_GUI 0x0002
285 #define USIG_FLAGS_FEEDBACK 0x0004
286 #define USIG_FLAGS_FAULT 0x0008
288 #define USIG_DLL_UNLOAD_WIN16 0x0001
289 #define USIG_DLL_UNLOAD_WIN32 0x0002
290 #define USIG_FAULT_DIALOG_PUSH 0x0003
291 #define USIG_FAULT_DIALOG_POP 0x0004
292 #define USIG_DLL_UNLOAD_ORPHANS 0x0005
293 #define USIG_THREAD_INIT 0x0010
294 #define USIG_THREAD_EXIT 0x0020
295 #define USIG_PROCESS_CREATE 0x0100
296 #define USIG_PROCESS_INIT 0x0200
297 #define USIG_PROCESS_EXIT 0x0300
298 #define USIG_PROCESS_DESTROY 0x0400
299 #define USIG_PROCESS_RUNNING 0x0500
300 #define USIG_PROCESS_LOADED 0x0600
302 /* scheduler/process.c */
303 extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE16 hModule );
305 #endif /* __WINE_MODULE_H */