blob: 1b139a798468ac7426c33a00943e2b5724600301 [file] [log] [blame]
Alexandre Julliard594997c1995-04-30 10:05:20 +00001/*
2 * Module definitions
3 *
4 * Copyright 1995 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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 Julliard594997c1995-04-30 10:05:20 +000019 */
20
Alexandre Julliardc6c09441997-01-12 18:32:19 +000021#ifndef __WINE_MODULE_H
22#define __WINE_MODULE_H
Alexandre Julliard594997c1995-04-30 10:05:20 +000023
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000024#include <stdarg.h>
Dimitrie O. Paun53f9c212003-08-28 21:43:34 +000025#include <windef.h>
26#include <winbase.h>
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000027#include <winreg.h>
Dimitrie O. Paun53f9c212003-08-28 21:43:34 +000028#include <wine/windef16.h>
29#include <wine/winbase16.h>
30#include <winternl.h>
Alexandre Julliard767e6f61998-08-09 12:47:43 +000031
Alexandre Julliarde8283082004-01-09 22:18:49 +000032#include <pshpack1.h>
33
Alexandre Julliard594997c1995-04-30 10:05:20 +000034 /* In-memory module structure. See 'Windows Internals' p. 219 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000035typedef struct _NE_MODULE
Alexandre Julliard594997c1995-04-30 10:05:20 +000036{
Alexandre Julliard329f0681996-04-14 13:21:20 +000037 WORD magic; /* 00 'NE' signature */
38 WORD count; /* 02 Usage count */
39 WORD entry_table; /* 04 Near ptr to entry table */
Alexandre Julliard3051b641996-07-05 17:14:13 +000040 HMODULE16 next; /* 06 Selector to next module */
Alexandre Julliard329f0681996-04-14 13:21:20 +000041 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 Julliard3051b641996-07-05 17:14:13 +000065 HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize */
66 HANDLE16 nrname_handle; /* 3a Handle to non-resident name table */
Alexandre Julliard329f0681996-04-14 13:21:20 +000067 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 Julliarda3960291999-02-26 11:11:13 +000070 HMODULE module32; /* 40 PE module handle for Win32 modules */
Alexandre Julliard3051b641996-07-05 17:14:13 +000071 HMODULE16 self; /* 44 Handle for this module */
Alexandre Julliard329f0681996-04-14 13:21:20 +000072 WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
Ulrich Weigand80a69b61998-11-25 17:58:51 +000073 LPVOID hRsrcMap; /* HRSRC 16->32 map (for 32-bit modules) */
Alexandre Julliard8db83682003-09-18 04:35:34 +000074 HANDLE fd; /* handle to the binary file */
Alexandre Julliard594997c1995-04-30 10:05:20 +000075} NE_MODULE;
76
Alexandre Julliard8664b891996-04-05 14:58:24 +000077
Andreas Mohrdca5e561999-04-16 08:17:17 +000078typedef struct {
79 BYTE type;
80 BYTE flags;
81 BYTE segnum;
Alexandre Julliarde8283082004-01-09 22:18:49 +000082 WORD offs;
Andreas Mohrdca5e561999-04-16 08:17:17 +000083} ET_ENTRY;
84
85typedef struct {
86 WORD first; /* ordinal */
87 WORD last; /* ordinal */
88 WORD next; /* bundle */
89} ET_BUNDLE;
90
91
Alexandre Julliard594997c1995-04-30 10:05:20 +000092 /* In-memory segment table */
93typedef struct
94{
Alexandre Julliard3051b641996-07-05 17:14:13 +000095 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 Julliardd30dfd21998-09-27 18:28:36 +000099 HANDLE16 hSeg; /* Selector or handle (selector - 1) */
100 /* of segment in memory */
Alexandre Julliard594997c1995-04-30 10:05:20 +0000101} SEGTABLEENTRY;
102
Alexandre Julliard436eda32003-11-25 00:42:26 +0000103
104 /* THHOOK Kernel Data Structure */
105typedef 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
120extern THHOOK *pThhook;
121
Alexandre Julliarde8283082004-01-09 22:18:49 +0000122#include <poppack.h>
123
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000124/* Resource types */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000125
Alexandre Julliard594997c1995-04-30 10:05:20 +0000126#define NE_SEG_TABLE(pModule) \
127 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
128
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000129#define NE_MODULE_NAME(pModule) \
130 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
131
Alexandre Julliard081ee942000-08-07 04:12:41 +0000132
Alexandre Julliardf899ef02001-07-23 00:04:00 +0000133enum loadorder_type
134{
135 LOADORDER_INVALID = 0, /* Must be 0 */
136 LOADORDER_DLL, /* Native DLLs */
Alexandre Julliardf899ef02001-07-23 00:04:00 +0000137 LOADORDER_BI, /* Built-in modules */
138 LOADORDER_NTYPES
139};
140
Alexandre Julliard35363162002-05-22 21:32:49 +0000141/* return values for MODULE_GetBinaryType */
142enum 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 Julliard2ace16a1996-04-28 15:09:19 +0000154/* module.c */
Alexandre Julliardadb53292003-05-14 19:51:14 +0000155extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved );
Alexandre Julliard35363162002-05-22 21:32:49 +0000156extern enum binary_type MODULE_GetBinaryType( HANDLE hfile );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000157
Alexandre Julliard436eda32003-11-25 00:42:26 +0000158/* ne_module.c */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000159extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000160extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
Uwe Bonnese5266e81999-07-15 16:09:05 +0000161extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
Ulrich Weiganda3527cf1998-10-11 19:31:10 +0000162extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000163extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000164extern HANDLE NE_OpenFile( NE_MODULE *pModule );
Alexandre Julliard9ee9eff2001-02-28 05:29:50 +0000165extern DWORD NE_StartTask(void);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000166
Alexandre Julliard436eda32003-11-25 00:42:26 +0000167/* resource16.c */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000168extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
Ulrich Weigand6d76a201999-01-31 10:13:44 +0000169
Alexandre Julliard436eda32003-11-25 00:42:26 +0000170/* ne_segment.c */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000171extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
172extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
Ulrich Weigand61206bd1999-11-21 00:50:30 +0000173extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
174extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
175extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000176extern void NE_InitializeDLLs( HMODULE16 hModule );
Ulrich Weigand21499341999-12-05 02:50:38 +0000177extern void NE_DllProcessAttach( HMODULE16 hModule );
Alexandre Julliardc963e252003-05-15 23:11:00 +0000178extern void NE_CallUserSignalProc( HMODULE16 hModule, UINT16 code );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000179
Alexandre Julliard436eda32003-11-25 00:42:26 +0000180/* task.c */
181extern void TASK_CreateMainTask(void);
182extern HTASK16 TASK_SpawnTask( NE_MODULE *pModule, WORD cmdShow,
183 LPCSTR cmdline, BYTE len, HANDLE *hThread );
184extern void TASK_ExitTask(void);
185extern HTASK16 TASK_GetTaskFromThread( DWORD thread );
186extern TDB *TASK_GetCurrent(void);
187extern void TASK_InstallTHHook( THHOOK *pNewThook );
188
189/* loadorder.c */
Alexandre Julliard1cb92bb2003-09-27 03:50:40 +0000190extern void MODULE_GetLoadOrderW( enum loadorder_type plo[], const WCHAR *app_name,
Alexandre Julliard16b44112003-11-25 01:03:04 +0000191 const WCHAR *path );
Alexandre Julliardf899ef02001-07-23 00:04:00 +0000192
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000193#endif /* __WINE_MODULE_H */