blob: c99c6c6a304467dcc7c8e5f080bac24ce9f4f4fd [file] [log] [blame]
Alexandre Julliard594997c1995-04-30 10:05:20 +00001/*
2 * Module definitions
3 *
4 * Copyright 1995 Alexandre Julliard
5 */
6
Alexandre Julliardc6c09441997-01-12 18:32:19 +00007#ifndef __WINE_MODULE_H
8#define __WINE_MODULE_H
Alexandre Julliard594997c1995-04-30 10:05:20 +00009
Jim Aston2e1cafa1999-03-14 16:35:05 +000010#include "windef.h"
Alexandre Julliard081ee942000-08-07 04:12:41 +000011#include "winbase.h"
Alexandre Julliard83f52d12000-09-26 22:20:14 +000012#include "wine/windef16.h"
Alexandre Julliard767e6f61998-08-09 12:47:43 +000013
Alexandre Julliard594997c1995-04-30 10:05:20 +000014 /* In-memory module structure. See 'Windows Internals' p. 219 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000015typedef struct _NE_MODULE
Alexandre Julliard594997c1995-04-30 10:05:20 +000016{
Alexandre Julliard329f0681996-04-14 13:21:20 +000017 WORD magic; /* 00 'NE' signature */
18 WORD count; /* 02 Usage count */
19 WORD entry_table; /* 04 Near ptr to entry table */
Alexandre Julliard3051b641996-07-05 17:14:13 +000020 HMODULE16 next; /* 06 Selector to next module */
Alexandre Julliard329f0681996-04-14 13:21:20 +000021 WORD dgroup_entry; /* 08 Near ptr to segment entry for DGROUP */
22 WORD fileinfo; /* 0a Near ptr to file info (OFSTRUCT) */
23 WORD flags; /* 0c Module flags */
24 WORD dgroup; /* 0e Logical segment for DGROUP */
25 WORD heap_size; /* 10 Initial heap size */
26 WORD stack_size; /* 12 Initial stack size */
27 WORD ip; /* 14 Initial ip */
28 WORD cs; /* 16 Initial cs (logical segment) */
29 WORD sp; /* 18 Initial stack pointer */
30 WORD ss; /* 1a Initial ss (logical segment) */
31 WORD seg_count; /* 1c Number of segments in segment table */
32 WORD modref_count; /* 1e Number of module references */
33 WORD nrname_size; /* 20 Size of non-resident names table */
34 WORD seg_table; /* 22 Near ptr to segment table */
35 WORD res_table; /* 24 Near ptr to resource table */
36 WORD name_table; /* 26 Near ptr to resident names table */
37 WORD modref_table; /* 28 Near ptr to module reference table */
38 WORD import_table; /* 2a Near ptr to imported names table */
39 DWORD nrname_fpos; /* 2c File offset of non-resident names table */
40 WORD moveable_entries; /* 30 Number of moveable entries in entry table*/
41 WORD alignment; /* 32 Alignment shift count */
42 WORD truetype; /* 34 Set to 2 if TrueType font */
43 BYTE os_flags; /* 36 Operating system flags */
44 BYTE misc_flags; /* 37 Misc. flags */
Alexandre Julliard3051b641996-07-05 17:14:13 +000045 HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize */
46 HANDLE16 nrname_handle; /* 3a Handle to non-resident name table */
Alexandre Julliard329f0681996-04-14 13:21:20 +000047 WORD min_swap_area; /* 3c Min. swap area size */
48 WORD expected_version; /* 3e Expected Windows version */
49 /* From here, these are extra fields not present in normal Windows */
Alexandre Julliarda3960291999-02-26 11:11:13 +000050 HMODULE module32; /* 40 PE module handle for Win32 modules */
Alexandre Julliard3051b641996-07-05 17:14:13 +000051 HMODULE16 self; /* 44 Handle for this module */
Alexandre Julliard329f0681996-04-14 13:21:20 +000052 WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
Ulrich Weigand80a69b61998-11-25 17:58:51 +000053 LPVOID hRsrcMap; /* HRSRC 16->32 map (for 32-bit modules) */
Alexandre Julliard594997c1995-04-30 10:05:20 +000054} NE_MODULE;
55
Alexandre Julliard8664b891996-04-05 14:58:24 +000056
Andreas Mohrdca5e561999-04-16 08:17:17 +000057typedef struct {
58 BYTE type;
59 BYTE flags;
60 BYTE segnum;
61 WORD offs WINE_PACKED;
62} ET_ENTRY;
63
64typedef struct {
65 WORD first; /* ordinal */
66 WORD last; /* ordinal */
67 WORD next; /* bundle */
68} ET_BUNDLE;
69
70
Alexandre Julliard594997c1995-04-30 10:05:20 +000071 /* In-memory segment table */
72typedef struct
73{
Alexandre Julliard3051b641996-07-05 17:14:13 +000074 WORD filepos; /* Position in file, in sectors */
75 WORD size; /* Segment size on disk */
76 WORD flags; /* Segment flags */
77 WORD minsize; /* Min. size of segment in memory */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000078 HANDLE16 hSeg; /* Selector or handle (selector - 1) */
79 /* of segment in memory */
Alexandre Julliard594997c1995-04-30 10:05:20 +000080} SEGTABLEENTRY;
81
Alexandre Julliard8664b891996-04-05 14:58:24 +000082
Alexandre Julliardff8331e1995-09-18 11:19:54 +000083 /* Self-loading modules contain this structure in their first segment */
84
Patrik Stridvallc7a8dde1999-04-25 12:36:53 +000085#include "pshpack1.h"
Alexandre Julliarda845b881998-06-01 10:44:35 +000086
Alexandre Julliardff8331e1995-09-18 11:19:54 +000087typedef struct
88{
Andreas Mohre6c12ee1998-10-11 17:36:46 +000089 WORD version; /* Must be "A0" (0x3041) */
Alexandre Julliard3051b641996-07-05 17:14:13 +000090 WORD reserved;
91 FARPROC16 BootApp; /* startup procedure */
92 FARPROC16 LoadAppSeg; /* procedure to load a segment */
93 FARPROC16 reserved2;
94 FARPROC16 MyAlloc; /* memory allocation procedure,
95 * wine must write this field */
96 FARPROC16 EntryAddrProc;
97 FARPROC16 ExitProc; /* exit procedure */
98 WORD reserved3[4];
99 FARPROC16 SetOwner; /* Set Owner procedure, exported by wine */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000100} SELFLOADHEADER;
101
Alexandre Julliardca22b331996-07-12 19:02:39 +0000102 /* Parameters for LoadModule() */
Alexandre Julliard2787be81995-05-22 18:23:01 +0000103typedef struct
104{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +0000105 HGLOBAL16 hEnvironment; /* Environment segment */
106 SEGPTR cmdLine WINE_PACKED; /* Command-line */
107 SEGPTR showCmd WINE_PACKED; /* Code for ShowWindow() */
108 SEGPTR reserved WINE_PACKED;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000109} LOADPARAMS16;
Alexandre Julliard594997c1995-04-30 10:05:20 +0000110
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000111typedef struct
112{
113 LPSTR lpEnvAddress;
114 LPSTR lpCmdLine;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000115 UINT16 *lpCmdShow;
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000116 DWORD dwReserved;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000117} LOADPARAMS;
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000118
Patrik Stridvallc7a8dde1999-04-25 12:36:53 +0000119#include "poppack.h"
Alexandre Julliardca22b331996-07-12 19:02:39 +0000120
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000121/* internal representation of 32bit modules. per process. */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000122typedef struct _wine_modref
123{
Alexandre Julliard081ee942000-08-07 04:12:41 +0000124 struct _wine_modref *next;
125 struct _wine_modref *prev;
126 HMODULE module;
Andreas Mohrcabee392000-10-25 21:22:27 +0000127 HMODULE16 hDummyMod; /* Win16 dummy module */
Alexandre Julliard081ee942000-08-07 04:12:41 +0000128 void *dlhandle; /* handle returned by dlopen() */
129 int tlsindex; /* TLS index or -1 if none */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000130
Alexandre Julliard081ee942000-08-07 04:12:41 +0000131 FARPROC (*find_export)( struct _wine_modref *wm, LPCSTR func, BOOL snoop );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000132
Ulrich Weiganda3527cf1998-10-11 19:31:10 +0000133 int nDeps;
134 struct _wine_modref **deps;
Ulrich Weigande469a581999-03-27 16:45:57 +0000135
136 int flags;
137 int refCount;
Ulrich Weiganda3527cf1998-10-11 19:31:10 +0000138
Ulrich Weigand237e8e91999-12-04 04:04:58 +0000139 char *filename;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000140 char *modname;
Ulrich Weigand237e8e91999-12-04 04:04:58 +0000141 char *short_filename;
142 char *short_modname;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000143} WINE_MODREF;
144
Ulrich Weigande469a581999-03-27 16:45:57 +0000145#define WINE_MODREF_INTERNAL 0x00000001
146#define WINE_MODREF_NO_DLL_CALLS 0x00000002
147#define WINE_MODREF_PROCESS_ATTACHED 0x00000004
Ulrich Weigande469a581999-03-27 16:45:57 +0000148#define WINE_MODREF_DONT_RESOLVE_REFS 0x00000020
149#define WINE_MODREF_MARKER 0x80000000
150
151
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000152/* Resource types */
153typedef struct resource_typeinfo_s NE_TYPEINFO;
154typedef struct resource_nameinfo_s NE_NAMEINFO;
155
Alexandre Julliard594997c1995-04-30 10:05:20 +0000156#define NE_SEG_TABLE(pModule) \
157 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
158
159#define NE_MODULE_TABLE(pModule) \
160 ((WORD *)((char *)(pModule) + (pModule)->modref_table))
161
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000162#define NE_MODULE_NAME(pModule) \
163 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
164
Alexandre Julliard081ee942000-08-07 04:12:41 +0000165#define PE_HEADER(module) \
166 ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
167 (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
168
169#define PE_SECTIONS(module) \
170 ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
171 PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
172
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000173/* module.c */
Alexandre Julliard081ee942000-08-07 04:12:41 +0000174extern WINE_MODREF *MODULE_AllocModRef( HMODULE hModule, LPCSTR filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000175extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, BOOL snoop );
Bertho Stultiensc1d1cfe1999-04-18 12:14:06 +0000176extern BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
177extern void MODULE_DllProcessDetach( BOOL bForceDetach, LPVOID lpReserved );
178extern void MODULE_DllThreadAttach( LPVOID lpReserved );
179extern void MODULE_DllThreadDetach( LPVOID lpReserved );
180extern WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
181extern BOOL MODULE_FreeLibrary( WINE_MODREF *wm );
182extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
Alexandre Julliardc192ba22000-05-29 21:25:10 +0000183extern BOOL MODULE_GetBinaryType( HANDLE hfile, LPCSTR filename, LPDWORD lpBinaryType );
Alexandre Julliardb4459522000-04-15 21:00:55 +0000184extern HMODULE MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000185extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
186extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
Guy Albertelli0e65b381999-06-12 10:49:36 +0000187extern void MODULE_WalkModref( DWORD id );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000188
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000189/* loader/ne/module.c */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000190extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000191extern void NE_DumpModule( HMODULE16 hModule );
192extern void NE_WalkModules(void);
193extern void NE_RegisterModule( NE_MODULE *pModule );
194extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
Uwe Bonnese5266e81999-07-15 16:09:05 +0000195extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
Ulrich Weiganda3527cf1998-10-11 19:31:10 +0000196extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000197extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000198extern HANDLE NE_OpenFile( NE_MODULE *pModule );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000199
200/* loader/ne/resource.c */
201extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000202extern BOOL NE_InitResourceHandler( HMODULE16 hModule );
Ulrich Weigand80a69b61998-11-25 17:58:51 +0000203extern HRSRC16 NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
Ulrich Weigand80a69b61998-11-25 17:58:51 +0000204extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC16 hRsrc );
205extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
206extern BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
Ulrich Weigand6d76a201999-01-31 10:13:44 +0000207extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
208extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
209
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000210/* loader/ne/segment.c */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000211extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
212extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
Ulrich Weigand61206bd1999-11-21 00:50:30 +0000213extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
214extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
215extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000216extern void NE_InitializeDLLs( HMODULE16 hModule );
Ulrich Weigand21499341999-12-05 02:50:38 +0000217extern void NE_DllProcessAttach( HMODULE16 hModule );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000218
Ulrich Weigand80a69b61998-11-25 17:58:51 +0000219/* loader/ne/convert.c */
220HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
Ulrich Weigand80a69b61998-11-25 17:58:51 +0000221
Alexandre Julliard081ee942000-08-07 04:12:41 +0000222/* loader/pe_resource.c */
Dmitry Timoshkov05c88fa2000-08-11 12:50:56 +0000223extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
Alexandre Julliard081ee942000-08-07 04:12:41 +0000224extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
Alexandre Julliard32936f02000-08-07 23:50:00 +0000225extern DWORD PE_SizeofResource(HRSRC);
Alexandre Julliard081ee942000-08-07 04:12:41 +0000226extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
Alexandre Julliard081ee942000-08-07 04:12:41 +0000227
228/* loader/pe_image.c */
229extern WINE_MODREF *PE_LoadLibraryExA(LPCSTR, DWORD);
230extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
231extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
232 DWORD flags, HFILE hFile, BOOL builtin );
233extern void PE_InitTls(void);
234extern BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved );
235
236/* loader/elf.c */
237extern WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags);
238
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000239/* relay32/builtin.c */
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000240extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags);
Alexandre Julliarda37dec02000-06-08 00:57:24 +0000241extern HMODULE BUILTIN32_LoadExeModule(void);
Alexandre Julliarde1e75372000-04-24 17:17:49 +0000242extern void *BUILTIN32_dlopen( const char *name );
243extern int BUILTIN32_dlclose( void *handle );
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000244
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000245#endif /* __WINE_MODULE_H */