2 * Kernel 16-bit private definitions
4 * Copyright 1995 Alexandre Julliard
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.
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.
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
21 #ifndef __WINE_KERNEL16_PRIVATE_H
22 #define __WINE_KERNEL16_PRIVATE_H
24 #include "wine/winbase16.h"
31 /* In-memory module structure. See 'Windows Internals' p. 219 */
32 typedef struct _NE_MODULE
34 WORD ne_magic; /* 00 'NE' signature */
35 WORD count; /* 02 Usage count (ne_ver/ne_rev on disk) */
36 WORD ne_enttab; /* 04 Near ptr to entry table */
37 HMODULE16 next; /* 06 Selector to next module (ne_cbenttab on disk) */
38 WORD dgroup_entry; /* 08 Near ptr to segment entry for DGROUP (ne_crc on disk) */
39 WORD fileinfo; /* 0a Near ptr to file info (OFSTRUCT) (ne_crc on disk) */
40 WORD ne_flags; /* 0c Module flags */
41 WORD ne_autodata; /* 0e Logical segment for DGROUP */
42 WORD ne_heap; /* 10 Initial heap size */
43 WORD ne_stack; /* 12 Initial stack size */
44 DWORD ne_csip; /* 14 Initial cs:ip */
45 DWORD ne_sssp; /* 18 Initial ss:sp */
46 WORD ne_cseg; /* 1c Number of segments in segment table */
47 WORD ne_cmod; /* 1e Number of module references */
48 WORD ne_cbnrestab; /* 20 Size of non-resident names table */
49 WORD ne_segtab; /* 22 Near ptr to segment table */
50 WORD ne_rsrctab; /* 24 Near ptr to resource table */
51 WORD ne_restab; /* 26 Near ptr to resident names table */
52 WORD ne_modtab; /* 28 Near ptr to module reference table */
53 WORD ne_imptab; /* 2a Near ptr to imported names table */
54 DWORD ne_nrestab; /* 2c File offset of non-resident names table */
55 WORD ne_cmovent; /* 30 Number of moveable entries in entry table*/
56 WORD ne_align; /* 32 Alignment shift count */
57 WORD ne_cres; /* 34 # of resource segments */
58 BYTE ne_exetyp; /* 36 Operating system flags */
59 BYTE ne_flagsothers; /* 37 Misc. flags */
60 HANDLE16 dlls_to_init; /* 38 List of DLLs to initialize (ne_pretthunks on disk) */
61 HANDLE16 nrname_handle; /* 3a Handle to non-resident name table (ne_psegrefbytes on disk) */
62 WORD ne_swaparea; /* 3c Min. swap area size */
63 WORD ne_expver; /* 3e Expected Windows version */
64 /* From here, these are extra fields not present in normal Windows */
65 HMODULE module32; /* 40 PE module handle for Win32 modules */
66 HMODULE16 self; /* 44 Handle for this module */
67 WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
68 LPVOID rsrc32_map; /* 48 HRSRC 16->32 map (for 32-bit modules) */
69 HANDLE fd; /* 4c handle to the binary file */
72 /* this structure is always located at offset 0 of the DGROUP segment */
75 WORD null; /* Always 0 */
76 DWORD old_ss_sp; /* Stack pointer; used by SwitchTaskTo() */
77 WORD heap; /* Pointer to the local heap information (if any) */
78 WORD atomtable; /* Pointer to the local atom table (if any) */
79 WORD stacktop; /* Top of the stack */
80 WORD stackmin; /* Lowest stack address used so far */
81 WORD stackbottom; /* Bottom of the stack */
84 /* THHOOK Kernel Data Structure */
85 typedef struct _THHOOK
87 HANDLE16 hGlobalHeap; /* 00 (handle BURGERMASTER) */
88 WORD pGlobalHeap; /* 02 (selector BURGERMASTER) */
89 HMODULE16 hExeHead; /* 04 hFirstModule */
90 HMODULE16 hExeSweep; /* 06 (unused) */
91 HANDLE16 TopPDB; /* 08 (handle of KERNEL PDB) */
92 HANDLE16 HeadPDB; /* 0A (first PDB in list) */
93 HANDLE16 TopSizePDB; /* 0C (unused) */
94 HTASK16 HeadTDB; /* 0E hFirstTask */
95 HTASK16 CurTDB; /* 10 hCurrentTask */
96 HTASK16 LoadTDB; /* 12 (unused) */
97 HTASK16 LockTDB; /* 14 hLockedTask */
100 extern THHOOK *pThhook;
104 #define NE_SEG_TABLE(pModule) \
105 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->ne_segtab))
107 #define NE_MODULE_NAME(pModule) \
108 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
110 #define CURRENT_STACK16 ((STACK16FRAME*)MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved))
111 #define CURRENT_DS (CURRENT_STACK16->ds)
113 /* push bytes on the 16-bit stack of a thread; return a segptr to the first pushed byte */
114 static inline SEGPTR stack16_push( int size )
116 STACK16FRAME *frame = CURRENT_STACK16;
117 memmove( (char*)frame - size, frame, sizeof(*frame) );
118 NtCurrentTeb()->WOW32Reserved = (char *)NtCurrentTeb()->WOW32Reserved - size;
119 return (SEGPTR)((char *)NtCurrentTeb()->WOW32Reserved + sizeof(*frame));
122 /* pop bytes from the 16-bit stack of a thread */
123 static inline void stack16_pop( int size )
125 STACK16FRAME *frame = CURRENT_STACK16;
126 memmove( (char*)frame + size, frame, sizeof(*frame) );
127 NtCurrentTeb()->WOW32Reserved = (char *)NtCurrentTeb()->WOW32Reserved + size;
131 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
132 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
133 extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
134 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
135 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
136 extern HANDLE NE_OpenFile( NE_MODULE *pModule );
137 extern DWORD NE_StartTask(void);
140 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
141 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
142 extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
143 extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
144 extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
145 extern void NE_InitializeDLLs( HMODULE16 hModule );
146 extern void NE_DllProcessAttach( HMODULE16 hModule );
147 extern void NE_CallUserSignalProc( HMODULE16 hModule, UINT16 code );
150 extern WORD SELECTOR_AllocBlock( const void *base, DWORD size, unsigned char flags );
151 extern WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size );
152 extern void SELECTOR_FreeBlock( WORD sel );
153 #define IS_SELECTOR_32BIT(sel) \
154 (wine_ldt_is_system(sel) || (wine_ldt_copy.flags[LOWORD(sel) >> 3] & WINE_LDT_FLAGS_32BIT))
157 extern void SNOOP16_RegisterDLL(HMODULE16,LPCSTR);
158 extern FARPROC16 SNOOP16_GetProcAddress16(HMODULE16,DWORD,FARPROC16);
159 extern int SNOOP16_ShowDebugmsgSnoop(const char *dll,int ord,const char *fname);
162 extern void TASK_CreateMainTask(void);
163 extern HTASK16 TASK_SpawnTask( NE_MODULE *pModule, WORD cmdShow,
164 LPCSTR cmdline, BYTE len, HANDLE *hThread );
165 extern void TASK_ExitTask(void);
166 extern HTASK16 TASK_GetTaskFromThread( DWORD thread );
167 extern TDB *TASK_GetCurrent(void);
168 extern void TASK_InstallTHHook( THHOOK *pNewThook );
170 #endif /* __WINE_KERNEL16_PRIVATE_H */