index == 3 corresponds to Alt-Gr + Shift.
[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 "dosexe.h"
12 #include "pe_image.h"
13
14   /* In-memory module structure. See 'Windows Internals' p. 219 */
15 typedef struct _NE_MODULE
16 {
17     WORD    magic;            /* 00 'NE' signature */
18     WORD    count;            /* 02 Usage count */
19     WORD    entry_table;      /* 04 Near ptr to entry table */
20     HMODULE16  next;          /* 06 Selector to next module */
21     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 */
45     HANDLE16   dlls_to_init;  /* 38 List of DLLs to initialize */
46     HANDLE16   nrname_handle; /* 3a Handle to non-resident name table */
47     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 */
50     HMODULE  module32;      /* 40 PE module handle for Win32 modules */
51     HMODULE16  self;          /* 44 Handle for this module */
52     WORD    self_loading_sel; /* 46 Selector used for self-loading apps. */
53     LPDOSTASK lpDosTask;
54     LPVOID  dos_image;        /* pointer to DOS memory (for DOS apps) */
55     LPVOID  hRsrcMap;         /* HRSRC 16->32 map (for 32-bit modules) */
56 } NE_MODULE;
57
58
59   /* In-memory segment table */
60 typedef struct
61 {
62     WORD      filepos;   /* Position in file, in sectors */
63     WORD      size;      /* Segment size on disk */
64     WORD      flags;     /* Segment flags */
65     WORD      minsize;   /* Min. size of segment in memory */
66     HANDLE16  hSeg;      /* Selector or handle (selector - 1) */
67                          /* of segment in memory */
68 } SEGTABLEENTRY;
69
70
71   /* Self-loading modules contain this structure in their first segment */
72
73 #pragma pack(1)
74
75 typedef struct
76 {
77     WORD      version;       /* Must be "A0" (0x3041) */
78     WORD      reserved;
79     FARPROC16 BootApp;       /* startup procedure */
80     FARPROC16 LoadAppSeg;    /* procedure to load a segment */
81     FARPROC16 reserved2;
82     FARPROC16 MyAlloc;       /* memory allocation procedure, 
83                               * wine must write this field */
84     FARPROC16 EntryAddrProc;
85     FARPROC16 ExitProc;      /* exit procedure */
86     WORD      reserved3[4];
87     FARPROC16 SetOwner;      /* Set Owner procedure, exported by wine */
88 } SELFLOADHEADER;
89
90   /* Parameters for LoadModule() */
91 typedef struct
92 {
93     HGLOBAL16 hEnvironment;         /* Environment segment */
94     SEGPTR    cmdLine WINE_PACKED;  /* Command-line */
95     SEGPTR    showCmd WINE_PACKED;  /* Code for ShowWindow() */
96     SEGPTR    reserved WINE_PACKED;
97 } LOADPARAMS16;
98
99 typedef struct 
100 {
101     LPSTR lpEnvAddress;
102     LPSTR lpCmdLine;
103     UINT16 *lpCmdShow;
104     DWORD dwReserved;
105 } LOADPARAMS;
106
107 #pragma pack(4)
108
109 /* internal representation of 32bit modules. per process. */
110 typedef enum { MODULE32_PE=1, MODULE32_ELF /* ,... */ } MODULE32_TYPE;
111 typedef struct _wine_modref
112 {
113         struct _wine_modref     *next;
114         struct _wine_modref     *prev;
115         MODULE32_TYPE           type;
116         union {
117                 PE_MODREF       pe;
118                 ELF_MODREF      elf;
119         } binfmt;
120
121         HMODULE         module;
122
123         int                     nDeps;
124         struct _wine_modref     **deps;
125
126         int                     flags;
127         int                     refCount;
128
129         char                    *modname;
130         char                    *shortname;
131         char                    *longname;
132 } WINE_MODREF;
133
134 #define WINE_MODREF_INTERNAL              0x00000001
135 #define WINE_MODREF_NO_DLL_CALLS          0x00000002
136 #define WINE_MODREF_PROCESS_ATTACHED      0x00000004
137 #define WINE_MODREF_PROCESS_DETACHED      0x00000008
138 #define WINE_MODREF_LOAD_AS_DATAFILE      0x00000010
139 #define WINE_MODREF_DONT_RESOLVE_REFS     0x00000020
140 #define WINE_MODREF_MARKER                0x80000000
141
142
143
144 /* Resource types */
145 typedef struct resource_typeinfo_s NE_TYPEINFO;
146 typedef struct resource_nameinfo_s NE_NAMEINFO;
147
148 #define NE_SEG_TABLE(pModule) \
149     ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
150
151 #define NE_MODULE_TABLE(pModule) \
152     ((WORD *)((char *)(pModule) + (pModule)->modref_table))
153
154 #define NE_MODULE_NAME(pModule) \
155     (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
156
157 /* module.c */
158 extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, BOOL snoop );
159 extern WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hModule );
160 extern void MODULE_InitializeDLLs( HMODULE root, DWORD type, LPVOID lpReserved );
161 extern HMODULE MODULE_FindModule( LPCSTR path );
162 extern HMODULE MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName );
163 extern FARPROC16 MODULE_GetWndProcEntry16( const char *name );
164 extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
165 extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
166 HMODULE MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
167
168 /* resource.c */
169 extern INT       WINAPI AccessResource(HMODULE,HRSRC); 
170
171 /* loader/ne/module.c */
172 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
173 extern void NE_DumpModule( HMODULE16 hModule );
174 extern void NE_WalkModules(void);
175 extern void NE_RegisterModule( NE_MODULE *pModule );
176 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
177 extern FARPROC16 NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
178 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
179 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
180 extern HANDLE NE_OpenFile( NE_MODULE *pModule );
181 extern HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL implicit );
182 extern BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env, 
183                               LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
184                               BOOL inherit, LPSTARTUPINFOA startup,
185                               LPPROCESS_INFORMATION info );
186
187 /* loader/ne/resource.c */
188 extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
189 extern BOOL NE_InitResourceHandler( HMODULE16 hModule );
190 extern HRSRC16 NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
191 extern INT16 NE_AccessResource( NE_MODULE *pModule, HRSRC16 hRsrc );
192 extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC16 hRsrc );
193 extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
194 extern BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
195 extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
196 extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
197
198 /* loader/ne/segment.c */
199 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
200 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
201 extern void NE_FixupPrologs( NE_MODULE *pModule );
202 extern void NE_InitializeDLLs( HMODULE16 hModule );
203 extern BOOL NE_CreateSegments( NE_MODULE *pModule );
204 extern HINSTANCE16 NE_CreateInstance( NE_MODULE *pModule, HINSTANCE16 *prev,
205                                       BOOL lib_only );
206
207 /* loader/ne/convert.c */
208 HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
209
210 /* if1632/builtin.c */
211 extern BOOL BUILTIN_Init(void);
212 extern HMODULE16 BUILTIN_LoadModule( LPCSTR name, BOOL force );
213 extern LPCSTR BUILTIN_GetEntryPoint16( WORD cs, WORD ip, WORD *pOrd );
214 extern BOOL BUILTIN_ParseDLLOptions( char *str );
215 extern void BUILTIN_PrintDLLs(void);
216
217 /* relay32/builtin.c */
218 extern HMODULE BUILTIN32_LoadImage( LPCSTR name, OFSTRUCT *ofs, BOOL force );
219 extern BOOL BUILTIN32_ParseDLLOptions( char *str );
220
221 /* if1632/builtin.c */
222 extern HMODULE16 (*fnBUILTIN_LoadModule)(LPCSTR name, BOOL force);
223
224 #endif  /* __WINE_MODULE_H */