Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Module definitions |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 21 | #ifndef __WINE_MODULE_H |
| 22 | #define __WINE_MODULE_H |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 24 | #include <stdarg.h> |
Dimitrie O. Paun | 53f9c21 | 2003-08-28 21:43:34 +0000 | [diff] [blame] | 25 | #include <windef.h> |
| 26 | #include <winbase.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 27 | #include <winreg.h> |
Dimitrie O. Paun | 53f9c21 | 2003-08-28 21:43:34 +0000 | [diff] [blame] | 28 | #include <wine/windef16.h> |
| 29 | #include <wine/winbase16.h> |
| 30 | #include <winternl.h> |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | e828308 | 2004-01-09 22:18:49 +0000 | [diff] [blame] | 32 | #include <pshpack1.h> |
| 33 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 34 | /* In-memory module structure. See 'Windows Internals' p. 219 */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 35 | typedef struct _NE_MODULE |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 36 | { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 37 | WORD magic; /* 00 'NE' signature */ |
| 38 | WORD count; /* 02 Usage count */ |
| 39 | WORD entry_table; /* 04 Near ptr to entry table */ |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 40 | HMODULE16 next; /* 06 Selector to next module */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 41 | WORD dgroup_entry; /* 08 Near ptr to segment entry for DGROUP */ |
| 42 | WORD fileinfo; /* 0a Near ptr to file info (OFSTRUCT) */ |
| 43 | WORD flags; /* 0c Module flags */ |
| 44 | WORD dgroup; /* 0e Logical segment for DGROUP */ |
| 45 | WORD heap_size; /* 10 Initial heap size */ |
| 46 | WORD stack_size; /* 12 Initial stack size */ |
| 47 | WORD ip; /* 14 Initial ip */ |
| 48 | WORD cs; /* 16 Initial cs (logical segment) */ |
| 49 | WORD sp; /* 18 Initial stack pointer */ |
| 50 | WORD ss; /* 1a Initial ss (logical segment) */ |
| 51 | WORD seg_count; /* 1c Number of segments in segment table */ |
| 52 | WORD modref_count; /* 1e Number of module references */ |
| 53 | WORD nrname_size; /* 20 Size of non-resident names table */ |
| 54 | WORD seg_table; /* 22 Near ptr to segment table */ |
| 55 | WORD res_table; /* 24 Near ptr to resource table */ |
| 56 | WORD name_table; /* 26 Near ptr to resident names table */ |
| 57 | WORD modref_table; /* 28 Near ptr to module reference table */ |
| 58 | WORD import_table; /* 2a Near ptr to imported names table */ |
| 59 | DWORD nrname_fpos; /* 2c File offset of non-resident names table */ |
| 60 | WORD moveable_entries; /* 30 Number of moveable entries in entry table*/ |
| 61 | WORD alignment; /* 32 Alignment shift count */ |
| 62 | WORD truetype; /* 34 Set to 2 if TrueType font */ |
| 63 | BYTE os_flags; /* 36 Operating system flags */ |
| 64 | BYTE misc_flags; /* 37 Misc. flags */ |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 65 | HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize */ |
| 66 | HANDLE16 nrname_handle; /* 3a Handle to non-resident name table */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 67 | WORD min_swap_area; /* 3c Min. swap area size */ |
| 68 | WORD expected_version; /* 3e Expected Windows version */ |
| 69 | /* From here, these are extra fields not present in normal Windows */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 70 | HMODULE module32; /* 40 PE module handle for Win32 modules */ |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 71 | HMODULE16 self; /* 44 Handle for this module */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 72 | WORD self_loading_sel; /* 46 Selector used for self-loading apps. */ |
Ulrich Weigand | 80a69b6 | 1998-11-25 17:58:51 +0000 | [diff] [blame] | 73 | LPVOID hRsrcMap; /* HRSRC 16->32 map (for 32-bit modules) */ |
Alexandre Julliard | 8db8368 | 2003-09-18 04:35:34 +0000 | [diff] [blame] | 74 | HANDLE fd; /* handle to the binary file */ |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 75 | } NE_MODULE; |
| 76 | |
Alexandre Julliard | 8664b89 | 1996-04-05 14:58:24 +0000 | [diff] [blame] | 77 | |
Andreas Mohr | dca5e56 | 1999-04-16 08:17:17 +0000 | [diff] [blame] | 78 | typedef struct { |
| 79 | BYTE type; |
| 80 | BYTE flags; |
| 81 | BYTE segnum; |
Alexandre Julliard | e828308 | 2004-01-09 22:18:49 +0000 | [diff] [blame] | 82 | WORD offs; |
Andreas Mohr | dca5e56 | 1999-04-16 08:17:17 +0000 | [diff] [blame] | 83 | } ET_ENTRY; |
| 84 | |
| 85 | typedef struct { |
| 86 | WORD first; /* ordinal */ |
| 87 | WORD last; /* ordinal */ |
| 88 | WORD next; /* bundle */ |
| 89 | } ET_BUNDLE; |
| 90 | |
| 91 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 92 | /* In-memory segment table */ |
| 93 | typedef struct |
| 94 | { |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 95 | WORD filepos; /* Position in file, in sectors */ |
| 96 | WORD size; /* Segment size on disk */ |
| 97 | WORD flags; /* Segment flags */ |
| 98 | WORD minsize; /* Min. size of segment in memory */ |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 99 | HANDLE16 hSeg; /* Selector or handle (selector - 1) */ |
| 100 | /* of segment in memory */ |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 101 | } SEGTABLEENTRY; |
| 102 | |
Alexandre Julliard | 436eda3 | 2003-11-25 00:42:26 +0000 | [diff] [blame] | 103 | |
| 104 | /* THHOOK Kernel Data Structure */ |
| 105 | typedef struct _THHOOK |
| 106 | { |
| 107 | HANDLE16 hGlobalHeap; /* 00 (handle BURGERMASTER) */ |
| 108 | WORD pGlobalHeap; /* 02 (selector BURGERMASTER) */ |
| 109 | HMODULE16 hExeHead; /* 04 hFirstModule */ |
| 110 | HMODULE16 hExeSweep; /* 06 (unused) */ |
| 111 | HANDLE16 TopPDB; /* 08 (handle of KERNEL PDB) */ |
| 112 | HANDLE16 HeadPDB; /* 0A (first PDB in list) */ |
| 113 | HANDLE16 TopSizePDB; /* 0C (unused) */ |
| 114 | HTASK16 HeadTDB; /* 0E hFirstTask */ |
| 115 | HTASK16 CurTDB; /* 10 hCurrentTask */ |
| 116 | HTASK16 LoadTDB; /* 12 (unused) */ |
| 117 | HTASK16 LockTDB; /* 14 hLockedTask */ |
| 118 | } THHOOK; |
| 119 | |
| 120 | extern THHOOK *pThhook; |
| 121 | |
Alexandre Julliard | e828308 | 2004-01-09 22:18:49 +0000 | [diff] [blame] | 122 | #include <poppack.h> |
| 123 | |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 124 | /* Resource types */ |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 125 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 126 | #define NE_SEG_TABLE(pModule) \ |
| 127 | ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table)) |
| 128 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 129 | #define NE_MODULE_NAME(pModule) \ |
| 130 | (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName) |
| 131 | |
Alexandre Julliard | 081ee94 | 2000-08-07 04:12:41 +0000 | [diff] [blame] | 132 | |
Alexandre Julliard | f899ef0 | 2001-07-23 00:04:00 +0000 | [diff] [blame] | 133 | enum loadorder_type |
| 134 | { |
| 135 | LOADORDER_INVALID = 0, /* Must be 0 */ |
| 136 | LOADORDER_DLL, /* Native DLLs */ |
Alexandre Julliard | f899ef0 | 2001-07-23 00:04:00 +0000 | [diff] [blame] | 137 | LOADORDER_BI, /* Built-in modules */ |
| 138 | LOADORDER_NTYPES |
| 139 | }; |
| 140 | |
Alexandre Julliard | 3536316 | 2002-05-22 21:32:49 +0000 | [diff] [blame] | 141 | /* return values for MODULE_GetBinaryType */ |
| 142 | enum binary_type |
| 143 | { |
| 144 | BINARY_UNKNOWN, |
| 145 | BINARY_PE_EXE, |
| 146 | BINARY_PE_DLL, |
| 147 | BINARY_WIN16, |
| 148 | BINARY_OS216, |
| 149 | BINARY_DOS, |
| 150 | BINARY_UNIX_EXE, |
| 151 | BINARY_UNIX_LIB |
| 152 | }; |
| 153 | |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 154 | /* module.c */ |
Alexandre Julliard | adb5329 | 2003-05-14 19:51:14 +0000 | [diff] [blame] | 155 | extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved ); |
Alexandre Julliard | 3536316 | 2002-05-22 21:32:49 +0000 | [diff] [blame] | 156 | extern enum binary_type MODULE_GetBinaryType( HANDLE hfile ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 157 | |
Alexandre Julliard | 436eda3 | 2003-11-25 00:42:26 +0000 | [diff] [blame] | 158 | /* ne_module.c */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 159 | extern NE_MODULE *NE_GetPtr( HMODULE16 hModule ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 160 | extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name ); |
Uwe Bonnes | e5266e8 | 1999-07-15 16:09:05 +0000 | [diff] [blame] | 161 | extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal ); |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 162 | extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 163 | extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 164 | extern HANDLE NE_OpenFile( NE_MODULE *pModule ); |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 165 | extern DWORD NE_StartTask(void); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 166 | |
Alexandre Julliard | 436eda3 | 2003-11-25 00:42:26 +0000 | [diff] [blame] | 167 | /* resource16.c */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 168 | extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16); |
Ulrich Weigand | 6d76a20 | 1999-01-31 10:13:44 +0000 | [diff] [blame] | 169 | |
Alexandre Julliard | 436eda3 | 2003-11-25 00:42:26 +0000 | [diff] [blame] | 170 | /* ne_segment.c */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 171 | extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ); |
| 172 | extern BOOL NE_LoadAllSegments( NE_MODULE *pModule ); |
Ulrich Weigand | 61206bd | 1999-11-21 00:50:30 +0000 | [diff] [blame] | 173 | extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum ); |
| 174 | extern BOOL NE_CreateAllSegments( NE_MODULE *pModule ); |
| 175 | extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 176 | extern void NE_InitializeDLLs( HMODULE16 hModule ); |
Ulrich Weigand | 2149934 | 1999-12-05 02:50:38 +0000 | [diff] [blame] | 177 | extern void NE_DllProcessAttach( HMODULE16 hModule ); |
Alexandre Julliard | c963e25 | 2003-05-15 23:11:00 +0000 | [diff] [blame] | 178 | extern void NE_CallUserSignalProc( HMODULE16 hModule, UINT16 code ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 179 | |
Alexandre Julliard | 436eda3 | 2003-11-25 00:42:26 +0000 | [diff] [blame] | 180 | /* task.c */ |
| 181 | extern void TASK_CreateMainTask(void); |
| 182 | extern HTASK16 TASK_SpawnTask( NE_MODULE *pModule, WORD cmdShow, |
| 183 | LPCSTR cmdline, BYTE len, HANDLE *hThread ); |
| 184 | extern void TASK_ExitTask(void); |
| 185 | extern HTASK16 TASK_GetTaskFromThread( DWORD thread ); |
| 186 | extern TDB *TASK_GetCurrent(void); |
| 187 | extern void TASK_InstallTHHook( THHOOK *pNewThook ); |
| 188 | |
| 189 | /* loadorder.c */ |
Alexandre Julliard | 1cb92bb | 2003-09-27 03:50:40 +0000 | [diff] [blame] | 190 | extern void MODULE_GetLoadOrderW( enum loadorder_type plo[], const WCHAR *app_name, |
Alexandre Julliard | 16b4411 | 2003-11-25 01:03:04 +0000 | [diff] [blame] | 191 | const WCHAR *path ); |
Alexandre Julliard | f899ef0 | 2001-07-23 00:04:00 +0000 | [diff] [blame] | 192 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 193 | #endif /* __WINE_MODULE_H */ |