nsiproxy.sys: Implement change notifications for NSI_IP_UNICAST_TABLE.
[wine.git] / dlls / krnl386.exe16 / kernel16_private.h
bloba70dfeeec9f463fc8bc246b439cbd1e52f2b0f30
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_KERNEL16_PRIVATE_H
22 #define __WINE_KERNEL16_PRIVATE_H
24 #include "wine/winbase16.h"
25 #include "winreg.h"
26 #include "winternl.h"
27 #include "wine/asm.h"
29 #include "pshpack1.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; /* PE module handle for Win32 modules */
66 HMODULE owner32; /* PE module containing this one for 16-bit builtins */
67 HMODULE16 self; /* Handle for this module */
68 WORD self_loading_sel; /* Selector used for self-loading apps. */
69 LPVOID rsrc32_map; /* HRSRC 16->32 map (for 32-bit modules) */
70 LPCVOID mapping; /* mapping of the binary file */
71 SIZE_T mapping_size; /* size of the file mapping */
72 } NE_MODULE;
74 typedef struct
76 BYTE type;
77 BYTE flags;
78 BYTE segnum;
79 WORD offs;
80 } ET_ENTRY;
82 typedef struct
84 WORD first; /* ordinal */
85 WORD last; /* ordinal */
86 WORD next; /* bundle */
87 } ET_BUNDLE;
90 /* In-memory segment table */
91 typedef struct
93 WORD filepos; /* Position in file, in sectors */
94 WORD size; /* Segment size on disk */
95 WORD flags; /* Segment flags */
96 WORD minsize; /* Min. size of segment in memory */
97 HANDLE16 hSeg; /* Selector or handle (selector - 1) of segment in memory */
98 } SEGTABLEENTRY;
100 /* this structure is always located at offset 0 of the DGROUP segment */
101 typedef struct
103 WORD null; /* Always 0 */
104 WORD old_sp; /* Stack pointer; used by SwitchTaskTo() */
105 WORD old_ss;
106 WORD heap; /* Pointer to the local heap information (if any) */
107 WORD atomtable; /* Pointer to the local atom table (if any) */
108 WORD stacktop; /* Top of the stack */
109 WORD stackmin; /* Lowest stack address used so far */
110 WORD stackbottom; /* Bottom of the stack */
111 } INSTANCEDATA;
113 /* relay entry points */
115 typedef struct
117 WORD pushw_bp; /* pushw %bp */
118 BYTE pushl; /* pushl $target */
119 void *target;
120 WORD call; /* call CALLFROM16 */
121 short callfrom16;
122 } ENTRYPOINT16;
124 typedef struct
126 BYTE pushl; /* pushl $relay */
127 void *relay;
128 BYTE lcall; /* lcall __FLATCS__:glue */
129 void *glue;
130 WORD flatcs;
131 WORD ret[5]; /* return sequence */
132 WORD movl; /* movl arg_types[1],arg_types[0](%esi) */
133 DWORD arg_types[2]; /* type of each argument */
134 } CALLFROM16;
136 /* THHOOK Kernel Data Structure */
137 typedef struct _THHOOK
139 HANDLE16 hGlobalHeap; /* 00 (handle BURGERMASTER) */
140 WORD pGlobalHeap; /* 02 (selector BURGERMASTER) */
141 HMODULE16 hExeHead; /* 04 hFirstModule */
142 HMODULE16 hExeSweep; /* 06 (unused) */
143 HANDLE16 TopPDB; /* 08 (handle of KERNEL PDB) */
144 HANDLE16 HeadPDB; /* 0A (first PDB in list) */
145 HANDLE16 TopSizePDB; /* 0C (unused) */
146 HTASK16 HeadTDB; /* 0E hFirstTask */
147 HTASK16 CurTDB; /* 10 hCurrentTask */
148 HTASK16 LoadTDB; /* 12 (unused) */
149 HTASK16 LockTDB; /* 14 hLockedTask */
150 } THHOOK;
152 extern LONG __wine_call_from_16(void);
153 extern void __wine_call_from_16_regs(void);
155 extern THHOOK *pThhook;
157 #include "poppack.h"
159 #define NE_SEG_TABLE(pModule) \
160 ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->ne_segtab))
162 #define NE_MODULE_NAME(pModule) \
163 (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
165 #define NE_GET_DATA(pModule,offset,size) \
166 ((const void *)(((offset)+(size) <= pModule->mapping_size) ? \
167 (const char *)pModule->mapping + (offset) : NULL))
169 #define NE_READ_DATA(pModule,buffer,offset,size) \
170 (((offset)+(size) <= pModule->mapping_size) ? \
171 (memcpy( buffer, (const char *)pModule->mapping + (offset), (size) ), TRUE) : FALSE)
173 /* push bytes on the 16-bit stack of a thread; return a segptr to the first pushed byte */
174 static inline SEGPTR stack16_push( int size )
176 STACK16FRAME *frame = CURRENT_STACK16;
177 memmove( (char*)frame - size, frame, sizeof(*frame) );
178 CURRENT_SP -= size;
179 return MAKESEGPTR( CURRENT_SS, CURRENT_SP + sizeof(*frame) );
182 /* pop bytes from the 16-bit stack of a thread */
183 static inline void stack16_pop( int size )
185 STACK16FRAME *frame = CURRENT_STACK16;
186 memmove( (char*)frame + size, frame, sizeof(*frame) );
187 CURRENT_SP += size;
190 /* dosmem.c */
191 extern BOOL DOSMEM_Init(void);
192 extern BOOL DOSMEM_InitDosMemory(void);
193 extern LPVOID DOSMEM_MapRealToLinear(DWORD); /* real-mode to linear */
194 extern LPVOID DOSMEM_MapDosToLinear(UINT); /* linear DOS to Wine */
195 extern UINT DOSMEM_MapLinearToDos(LPVOID); /* linear Wine to DOS */
196 extern BOOL DOSMEM_MapDosLayout(void);
197 extern LPVOID DOSMEM_AllocBlock(UINT size, WORD* p);
198 extern BOOL DOSMEM_FreeBlock(void* ptr);
199 extern UINT DOSMEM_ResizeBlock(void* ptr, UINT size, BOOL exact);
200 extern UINT DOSMEM_Available(void);
202 /* global16.c */
203 extern HGLOBAL16 GLOBAL_CreateBlock( UINT16 flags, void *ptr, DWORD size,
204 HGLOBAL16 hOwner, unsigned char selflags );
205 extern BOOL16 GLOBAL_FreeBlock( HGLOBAL16 handle );
206 extern BOOL16 GLOBAL_MoveBlock( HGLOBAL16 handle, void *ptr, DWORD size );
207 extern HGLOBAL16 GLOBAL_Alloc( WORD flags, DWORD size, HGLOBAL16 hOwner, unsigned char selflags );
209 /* instr.c */
210 extern DWORD __wine_emulate_instruction( EXCEPTION_RECORD *rec, CONTEXT *context );
211 extern LONG CALLBACK INSTR_vectored_handler( EXCEPTION_POINTERS *ptrs );
213 /* ne_module.c */
214 extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
215 extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
216 extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
217 extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
218 extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
219 extern DWORD NE_StartTask(void);
221 /* ne_segment.c */
222 extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
223 extern BOOL NE_LoadAllSegments( NE_MODULE *pModule );
224 extern BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
225 extern BOOL NE_CreateAllSegments( NE_MODULE *pModule );
226 extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
227 extern void NE_InitializeDLLs( HMODULE16 hModule );
228 extern void NE_DllProcessAttach( HMODULE16 hModule );
229 extern void NE_CallUserSignalProc( HMODULE16 hModule, UINT16 code );
231 /* selector.c */
232 #define LDT_SIZE 8192
233 struct ldt_copy
235 void *base[LDT_SIZE];
236 unsigned int limit[LDT_SIZE];
237 unsigned char flags[LDT_SIZE];
239 extern const struct ldt_copy *ldt_copy;
241 #define LDT_FLAGS_DATA 0x13 /* Data segment */
242 #define LDT_FLAGS_CODE 0x1b /* Code segment */
243 #define LDT_FLAGS_32BIT 0x40 /* Segment is 32-bit (code or stack) */
245 static inline void *ldt_get_base( WORD sel ) { return ldt_copy->base[sel >> 3]; }
246 static inline unsigned int ldt_get_limit( WORD sel ) { return ldt_copy->limit[sel >> 3]; }
247 static inline unsigned char ldt_get_flags( WORD sel ) { return ldt_copy->flags[sel >> 3]; }
249 extern void init_selectors(void);
250 extern BOOL ldt_is_system( WORD sel );
251 extern BOOL ldt_is_valid( WORD sel );
252 extern void *ldt_get_ptr( WORD sel, DWORD offset );
253 extern BOOL ldt_get_entry( WORD sel, LDT_ENTRY *entry );
254 extern void ldt_set_entry( WORD sel, LDT_ENTRY entry );
255 extern WORD SELECTOR_AllocBlock( const void *base, DWORD size, unsigned char flags );
256 extern WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size );
257 extern void SELECTOR_FreeBlock( WORD sel );
258 #define IS_SELECTOR_32BIT(sel) \
259 (ldt_is_system(sel) || (ldt_copy->flags[LOWORD(sel) >> 3] & LDT_FLAGS_32BIT))
261 static inline WORD get_cs(void) { WORD res; __asm__( "movw %%cs,%0" : "=r" (res) ); return res; }
262 static inline WORD get_ds(void) { WORD res; __asm__( "movw %%ds,%0" : "=r" (res) ); return res; }
263 static inline WORD get_fs(void) { WORD res; __asm__( "movw %%fs,%0" : "=r" (res) ); return res; }
264 static inline WORD get_gs(void) { WORD res; __asm__( "movw %%gs,%0" : "=r" (res) ); return res; }
266 /* relay16.c */
267 extern int relay_call_from_16( void *entry_point, unsigned char *args16, CONTEXT *context );
268 extern void RELAY16_InitDebugLists(void);
270 /* snoop16.c */
271 extern void SNOOP16_RegisterDLL(HMODULE16,LPCSTR);
272 extern FARPROC16 SNOOP16_GetProcAddress16(HMODULE16,DWORD,FARPROC16);
273 extern BOOL SNOOP16_ShowDebugmsgSnoop(const char *dll,int ord,const char *fname);
275 /* syslevel.c */
276 extern VOID SYSLEVEL_CheckNotLevel( INT level );
278 /* task.c */
279 extern void TASK_CreateMainTask(void);
280 extern HTASK16 TASK_SpawnTask( NE_MODULE *pModule, WORD cmdShow,
281 LPCSTR cmdline, BYTE len, HANDLE *hThread );
282 extern void TASK_ExitTask(void);
283 extern HTASK16 TASK_GetTaskFromThread( DWORD thread );
284 extern TDB *TASK_GetCurrent(void);
285 extern void TASK_InstallTHHook( THHOOK *pNewThook );
287 extern BOOL WOWTHUNK_Init(void);
289 extern WORD DOSMEM_0000H;
290 extern WORD DOSMEM_BiosDataSeg;
291 extern WORD DOSMEM_BiosSysSeg;
292 extern DWORD CallTo16_DataSelector;
293 extern DWORD CallTo16_TebSelector;
295 extern WORD cbclient_selector;
296 extern WORD cbclientex_selector;
298 struct tagSYSLEVEL;
300 struct kernel_thread_data
302 SEGPTR stack; /* 16-bit stack pointer */
303 WORD stack_sel; /* 16-bit stack selector */
304 WORD htask16; /* Win16 task handle */
305 DWORD sys_count[4]; /* syslevel mutex entry counters */
306 struct tagSYSLEVEL *sys_mutex[4]; /* syslevel mutex pointers */
309 C_ASSERT( sizeof(struct kernel_thread_data) <= sizeof(((TEB *)0)->SystemReserved1) );
311 static inline struct kernel_thread_data *kernel_get_thread_data(void)
313 return (struct kernel_thread_data *)NtCurrentTeb()->SystemReserved1;
316 /* Push a DWORD on the 32-bit stack */
317 static inline void stack32_push( CONTEXT *context, DWORD val )
319 context->Esp -= sizeof(DWORD);
320 *(DWORD *)context->Esp = val;
323 /* Pop a DWORD from the 32-bit stack */
324 static inline DWORD stack32_pop( CONTEXT *context )
326 DWORD ret = *(DWORD *)context->Esp;
327 context->Esp += sizeof(DWORD);
328 return ret;
331 #define DEFINE_REGS_ENTRYPOINT(name) \
332 __ASM_STDCALL_FUNC( name, 0, \
333 "pushl %ebp\n\t" \
334 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
335 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
336 "movl %esp,%ebp\n\t" \
337 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
338 "leal -(0x2cc+4)(%esp),%esp\n\t" /* sizeof(CONTEXT) + space for %eax */ \
339 "movl %eax,-4(%ebp)\n\t" \
340 "pushl %esp\n\t" /* context */ \
341 "call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t" \
342 "movl -4(%ebp),%eax\n\t" \
343 "movl %eax,0xb0(%esp)\n\t" /* context->Eax */ \
344 "pushl %esp\n\t" /* context */ \
345 "call " __ASM_STDCALL("__regs_" #name,4) "\n\t" \
346 "pushl %esp\n\t" /* context */ \
347 "pushl $-2\n\t" /* GetCurrentThread() */ \
348 "call " __ASM_STDCALL("NtSetContextThread",8) "\n\t" \
349 "ret" ) /* fake ret to make copy protections happy */
351 #endif /* __WINE_KERNEL16_PRIVATE_H */