Rewrote module TLS support and moved it to ntdll.
[wine/multimedia.git] / include / module.h
blob0bea5928f31298023b71b70a9f0eed44ea06bfd2
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"
28 #include "winternl.h"
30 /* In-memory module structure. See 'Windows Internals' p. 219 */
31 typedef struct _NE_MODULE
33 WORD magic; /* 00 'NE' signature */
34 WORD count; /* 02 Usage count */
35 WORD entry_table; /* 04 Near ptr to entry table */
36 HMODULE16 next; /* 06 Selector to next module */
37 WORD dgroup_entry; /* 08 Near ptr to segment entry for DGROUP */
38 WORD fileinfo; /* 0a Near ptr to file info (OFSTRUCT) */
39 WORD flags; /* 0c Module flags */
40 WORD dgroup; /* 0e Logical segment for DGROUP */
41 WORD heap_size; /* 10 Initial heap size */
42 WORD stack_size; /* 12 Initial stack size */
43 WORD ip; /* 14 Initial ip */
44 WORD cs; /* 16 Initial cs (logical segment) */
45 WORD sp; /* 18 Initial stack pointer */
46 WORD ss; /* 1a Initial ss (logical segment) */
47 WORD seg_count; /* 1c Number of segments in segment table */
48 WORD modref_count; /* 1e Number of module references */
49 WORD nrname_size; /* 20 Size of non-resident names table */
50 WORD seg_table; /* 22 Near ptr to segment table */
51 WORD res_table; /* 24 Near ptr to resource table */
52 WORD name_table; /* 26 Near ptr to resident names table */
53 WORD modref_table; /* 28 Near ptr to module reference table */
54 WORD import_table; /* 2a Near ptr to imported names table */
55 DWORD nrname_fpos; /* 2c File offset of non-resident names table */
56 WORD moveable_entries; /* 30 Number of moveable entries in entry table*/
57 WORD alignment; /* 32 Alignment shift count */
58 WORD truetype; /* 34 Set to 2 if TrueType font */
59 BYTE os_flags; /* 36 Operating system flags */
60 BYTE misc_flags; /* 37 Misc. flags */
61 HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize */
62 HANDLE16 nrname_handle; /* 3a Handle to non-resident name table */
63 WORD min_swap_area; /* 3c Min. swap area size */
64 WORD expected_version; /* 3e Expected Windows version */
65 /* From here, these are extra fields not present in normal Windows */
66 HMODULE module32; /* 40 PE module handle for Win32 modules */
67 HMODULE16 self; /* 44 Handle for this module */
68 WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
69 LPVOID hRsrcMap; /* HRSRC 16->32 map (for 32-bit modules) */
70 } NE_MODULE;
73 typedef struct {
74 BYTE type;
75 BYTE flags;
76 BYTE segnum;
77 WORD offs WINE_PACKED;
78 } ET_ENTRY;
80 typedef struct {
81 WORD first; /* ordinal */
82 WORD last; /* ordinal */
83 WORD next; /* bundle */
84 } ET_BUNDLE;
87 /* In-memory segment table */
88 typedef struct
90 WORD filepos; /* Position in file, in sectors */
91 WORD size; /* Segment size on disk */
92 WORD flags; /* Segment flags */
93 WORD minsize; /* Min. size of segment in memory */
94 HANDLE16 hSeg; /* Selector or handle (selector - 1) */
95 /* of segment in memory */
96 } SEGTABLEENTRY;
99 /* Self-loading modules contain this structure in their first segment */
101 #include "pshpack1.h"
103 typedef struct
105 WORD version; /* Must be "A0" (0x3041) */
106 WORD reserved;
107 FARPROC16 BootApp; /* startup procedure */
108 FARPROC16 LoadAppSeg; /* procedure to load a segment */
109 FARPROC16 reserved2;
110 FARPROC16 MyAlloc; /* memory allocation procedure,
111 * wine must write this field */
112 FARPROC16 EntryAddrProc;
113 FARPROC16 ExitProc; /* exit procedure */
114 WORD reserved3[4];
115 FARPROC16 SetOwner; /* Set Owner procedure, exported by wine */
116 } SELFLOADHEADER;
118 typedef struct
120 LPSTR lpEnvAddress;
121 LPSTR lpCmdLine;
122 UINT16 *lpCmdShow;
123 DWORD dwReserved;
124 } LOADPARAMS;
126 #include "poppack.h"
128 /* internal representation of 32bit modules. per process. */
129 typedef struct _wine_modref
131 struct _wine_modref *next;
132 struct _wine_modref *prev;
133 HMODULE16 hDummyMod; /* Win16 dummy module */
134 void *dlhandle; /* handle returned by dlopen() */
135 LDR_MODULE ldr;
137 int nDeps;
138 struct _wine_modref **deps;
140 char *filename;
141 char *modname;
142 char *short_filename;
143 char *short_modname;
145 char data[1]; /* space for storing filename and short_filename */
146 } WINE_MODREF;
148 extern WINE_MODREF *MODULE_modref_list;
150 /* Resource types */
152 #define NE_SEG_TABLE(pModule) \
153 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
155 #define NE_MODULE_TABLE(pModule) \
156 ((WORD *)((char *)(pModule) + (pModule)->modref_table))
158 #define NE_MODULE_NAME(pModule) \
159 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
162 enum loadorder_type
164 LOADORDER_INVALID = 0, /* Must be 0 */
165 LOADORDER_DLL, /* Native DLLs */
166 LOADORDER_BI, /* Built-in modules */
167 LOADORDER_NTYPES
170 /* return values for MODULE_GetBinaryType */
171 enum binary_type
173 BINARY_UNKNOWN,
174 BINARY_PE_EXE,
175 BINARY_PE_DLL,
176 BINARY_WIN16,
177 BINARY_OS216,
178 BINARY_DOS,
179 BINARY_UNIX_EXE,
180 BINARY_UNIX_LIB
183 /* module.c */
184 extern NTSTATUS MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
185 extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved );
186 extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
187 extern HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
188 extern enum binary_type MODULE_GetBinaryType( HANDLE hfile );
189 extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
190 extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
191 extern void MODULE_WalkModref( DWORD id );
193 /* loader/ne/module.c */
194 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
195 extern void NE_DumpModule( HMODULE16 hModule );
196 extern void NE_WalkModules(void);
197 extern void NE_InitResourceHandler( NE_MODULE *pModule );
198 extern void NE_RegisterModule( NE_MODULE *pModule );
199 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
200 extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
201 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
202 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
203 extern HANDLE NE_OpenFile( NE_MODULE *pModule );
204 extern DWORD NE_StartTask(void);
206 /* loader/ne/resource.c */
207 extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
209 /* loader/ne/segment.c */
210 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
211 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
212 extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
213 extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
214 extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
215 extern void NE_InitializeDLLs( HMODULE16 hModule );
216 extern void NE_DllProcessAttach( HMODULE16 hModule );
218 /* loader/pe_resource.c */
219 extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
220 extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
222 /* loader/pe_image.c */
223 extern NTSTATUS PE_LoadLibraryExA(LPCSTR, DWORD, WINE_MODREF**);
224 extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
225 extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
226 DWORD flags, HANDLE hFile, BOOL builtin );
227 extern DWORD PE_fixup_imports(WINE_MODREF *wm);
229 /* loader/loadorder.c */
230 extern BOOL MODULE_GetBuiltinPath( const char *libname, const char *ext, char *filename, UINT size );
231 extern void MODULE_GetLoadOrder( enum loadorder_type plo[], const char *path, BOOL win32 );
232 extern void MODULE_AddLoadOrderOption( const char *option );
234 /* relay32/builtin.c */
235 extern NTSTATUS BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags, WINE_MODREF**);
236 extern HMODULE BUILTIN32_LoadExeModule( HMODULE main );
237 extern NTSTATUS BUILTIN32_dlopen( const char *name, void** handle );
239 /* if1632/builtin.c */
240 extern HMODULE16 BUILTIN_LoadModule( LPCSTR name );
241 extern BOOL BUILTIN_IsPresent( LPCSTR name );
243 /* USER signal proc flags and codes */
244 /* See PROCESS_CallUserSignalProc for comments */
245 #define USIG_FLAGS_WIN32 0x0001
246 #define USIG_FLAGS_GUI 0x0002
247 #define USIG_FLAGS_FEEDBACK 0x0004
248 #define USIG_FLAGS_FAULT 0x0008
250 #define USIG_DLL_UNLOAD_WIN16 0x0001
251 #define USIG_DLL_UNLOAD_WIN32 0x0002
252 #define USIG_FAULT_DIALOG_PUSH 0x0003
253 #define USIG_FAULT_DIALOG_POP 0x0004
254 #define USIG_DLL_UNLOAD_ORPHANS 0x0005
255 #define USIG_THREAD_INIT 0x0010
256 #define USIG_THREAD_EXIT 0x0020
257 #define USIG_PROCESS_CREATE 0x0100
258 #define USIG_PROCESS_INIT 0x0200
259 #define USIG_PROCESS_EXIT 0x0300
260 #define USIG_PROCESS_DESTROY 0x0400
261 #define USIG_PROCESS_RUNNING 0x0500
262 #define USIG_PROCESS_LOADED 0x0600
264 /* scheduler/process.c */
265 extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE16 hModule );
267 #endif /* __WINE_MODULE_H */