Changed the win31 style file dialog to 32 bits structures and
[wine] / include / module.h
1 /*
2  * Module definitions
3  *
4  * Copyright 1995 Alexandre Julliard
5  */
6
7 #ifndef __WINE_MODULE_H
8 #define __WINE_MODULE_H
9
10 #include "windef.h"
11 #include "pe_image.h"
12
13   /* In-memory module structure. See 'Windows Internals' p. 219 */
14 typedef struct _NE_MODULE
15 {
16     WORD    magic;            /* 00 'NE' signature */
17     WORD    count;            /* 02 Usage count */
18     WORD    entry_table;      /* 04 Near ptr to entry table */
19     HMODULE16  next;          /* 06 Selector to next module */
20     WORD    dgroup_entry;     /* 08 Near ptr to segment entry for DGROUP */
21     WORD    fileinfo;         /* 0a Near ptr to file info (OFSTRUCT) */
22     WORD    flags;            /* 0c Module flags */
23     WORD    dgroup;           /* 0e Logical segment for DGROUP */
24     WORD    heap_size;        /* 10 Initial heap size */
25     WORD    stack_size;       /* 12 Initial stack size */
26     WORD    ip;               /* 14 Initial ip */
27     WORD    cs;               /* 16 Initial cs (logical segment) */
28     WORD    sp;               /* 18 Initial stack pointer */
29     WORD    ss;               /* 1a Initial ss (logical segment) */
30     WORD    seg_count;        /* 1c Number of segments in segment table */
31     WORD    modref_count;     /* 1e Number of module references */
32     WORD    nrname_size;      /* 20 Size of non-resident names table */
33     WORD    seg_table;        /* 22 Near ptr to segment table */
34     WORD    res_table;        /* 24 Near ptr to resource table */
35     WORD    name_table;       /* 26 Near ptr to resident names table */
36     WORD    modref_table;     /* 28 Near ptr to module reference table */
37     WORD    import_table;     /* 2a Near ptr to imported names table */
38     DWORD   nrname_fpos;      /* 2c File offset of non-resident names table */
39     WORD    moveable_entries; /* 30 Number of moveable entries in entry table*/
40     WORD    alignment;        /* 32 Alignment shift count */
41     WORD    truetype;         /* 34 Set to 2 if TrueType font */
42     BYTE    os_flags;         /* 36 Operating system flags */
43     BYTE    misc_flags;       /* 37 Misc. flags */
44     HANDLE16   dlls_to_init;  /* 38 List of DLLs to initialize */
45     HANDLE16   nrname_handle; /* 3a Handle to non-resident name table */
46     WORD    min_swap_area;    /* 3c Min. swap area size */
47     WORD    expected_version; /* 3e Expected Windows version */
48     /* From here, these are extra fields not present in normal Windows */
49     HMODULE  module32;      /* 40 PE module handle for Win32 modules */
50     HMODULE16  self;          /* 44 Handle for this module */
51     WORD    self_loading_sel; /* 46 Selector used for self-loading apps. */
52     LPVOID  hRsrcMap;         /* HRSRC 16->32 map (for 32-bit modules) */
53 } NE_MODULE;
54
55
56 typedef struct {
57     BYTE type;
58     BYTE flags;
59     BYTE segnum;
60     WORD offs WINE_PACKED;
61 } ET_ENTRY;
62
63 typedef struct {
64     WORD first; /* ordinal */
65     WORD last; /* ordinal */
66     WORD next; /* bundle */
67 } ET_BUNDLE;
68
69
70   /* In-memory segment table */
71 typedef struct
72 {
73     WORD      filepos;   /* Position in file, in sectors */
74     WORD      size;      /* Segment size on disk */
75     WORD      flags;     /* Segment flags */
76     WORD      minsize;   /* Min. size of segment in memory */
77     HANDLE16  hSeg;      /* Selector or handle (selector - 1) */
78                          /* of segment in memory */
79 } SEGTABLEENTRY;
80
81
82   /* Self-loading modules contain this structure in their first segment */
83
84 #include "pshpack1.h"
85
86 typedef struct
87 {
88     WORD      version;       /* Must be "A0" (0x3041) */
89     WORD      reserved;
90     FARPROC16 BootApp;       /* startup procedure */
91     FARPROC16 LoadAppSeg;    /* procedure to load a segment */
92     FARPROC16 reserved2;
93     FARPROC16 MyAlloc;       /* memory allocation procedure, 
94                               * wine must write this field */
95     FARPROC16 EntryAddrProc;
96     FARPROC16 ExitProc;      /* exit procedure */
97     WORD      reserved3[4];
98     FARPROC16 SetOwner;      /* Set Owner procedure, exported by wine */
99 } SELFLOADHEADER;
100
101   /* Parameters for LoadModule() */
102 typedef struct
103 {
104     HGLOBAL16 hEnvironment;         /* Environment segment */
105     SEGPTR    cmdLine WINE_PACKED;  /* Command-line */
106     SEGPTR    showCmd WINE_PACKED;  /* Code for ShowWindow() */
107     SEGPTR    reserved WINE_PACKED;
108 } LOADPARAMS16;
109
110 typedef struct 
111 {
112     LPSTR lpEnvAddress;
113     LPSTR lpCmdLine;
114     UINT16 *lpCmdShow;
115     DWORD dwReserved;
116 } LOADPARAMS;
117
118 #include "poppack.h"
119
120 /* internal representation of 32bit modules. per process. */
121 typedef enum {
122         MODULE32_PE = 1,
123         MODULE32_ELF,
124         MODULE32_ELFDLL
125 } MODULE32_TYPE;
126
127 typedef struct _wine_modref
128 {
129         struct _wine_modref     *next;
130         struct _wine_modref     *prev;
131         MODULE32_TYPE           type;
132         union {
133                 PE_MODREF       pe;
134                 ELF_MODREF      elf;
135         } binfmt;
136
137         HMODULE                 module;
138
139         int                     nDeps;
140         struct _wine_modref     **deps;
141
142         int                     flags;
143         int                     refCount;
144
145         char                    *filename;
146         char                    *modname;
147         char                    *short_filename;
148         char                    *short_modname;
149 } WINE_MODREF;
150
151 #define WINE_MODREF_INTERNAL              0x00000001
152 #define WINE_MODREF_NO_DLL_CALLS          0x00000002
153 #define WINE_MODREF_PROCESS_ATTACHED      0x00000004
154 #define WINE_MODREF_LOAD_AS_DATAFILE      0x00000010
155 #define WINE_MODREF_DONT_RESOLVE_REFS     0x00000020
156 #define WINE_MODREF_MARKER                0x80000000
157
158
159
160 /* Resource types */
161 typedef struct resource_typeinfo_s NE_TYPEINFO;
162 typedef struct resource_nameinfo_s NE_NAMEINFO;
163
164 #define NE_SEG_TABLE(pModule) \
165     ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
166
167 #define NE_MODULE_TABLE(pModule) \
168     ((WORD *)((char *)(pModule) + (pModule)->modref_table))
169
170 #define NE_MODULE_NAME(pModule) \
171     (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
172
173 /* module.c */
174 extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, BOOL snoop );
175 extern WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hModule );
176 extern BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
177 extern void MODULE_DllProcessDetach( BOOL bForceDetach, LPVOID lpReserved );
178 extern void MODULE_DllThreadAttach( LPVOID lpReserved );
179 extern void MODULE_DllThreadDetach( LPVOID lpReserved );
180 extern WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
181 extern BOOL MODULE_FreeLibrary( WINE_MODREF *wm );
182 extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
183 extern BOOL MODULE_GetBinaryType( HANDLE hfile, LPCSTR filename, LPDWORD lpBinaryType );
184 extern HMODULE MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
185 extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
186 extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
187 extern void MODULE_WalkModref( DWORD id );
188
189 /* resource.c */
190 extern INT       WINAPI AccessResource(HMODULE,HRSRC); 
191
192 /* loader/ne/module.c */
193 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
194 extern void NE_DumpModule( HMODULE16 hModule );
195 extern void NE_WalkModules(void);
196 extern void NE_RegisterModule( NE_MODULE *pModule );
197 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
198 extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
199 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
200 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
201 extern HANDLE NE_OpenFile( NE_MODULE *pModule );
202
203 /* loader/ne/resource.c */
204 extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
205 extern BOOL NE_InitResourceHandler( HMODULE16 hModule );
206 extern HRSRC16 NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
207 extern INT16 NE_AccessResource( NE_MODULE *pModule, HRSRC16 hRsrc );
208 extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC16 hRsrc );
209 extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
210 extern BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
211 extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
212 extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
213
214 /* loader/ne/segment.c */
215 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
216 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
217 extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
218 extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
219 extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
220 extern void NE_InitializeDLLs( HMODULE16 hModule );
221 extern void NE_DllProcessAttach( HMODULE16 hModule );
222
223 /* loader/ne/convert.c */
224 HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
225
226 /* relay32/builtin.c */
227 extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags);
228 extern HMODULE BUILTIN32_LoadExeModule(void);
229 extern void BUILTIN32_UnloadLibrary(WINE_MODREF *wm);
230 extern void *BUILTIN32_dlopen( const char *name );
231 extern int BUILTIN32_dlclose( void *handle );
232
233 #endif  /* __WINE_MODULE_H */