source: trunk/src/win32k/kKrnlLib/include/OS2KVM.h

Last change on this file was 6837, checked in by bird, 24 years ago

Varible mappings. And some minor fixing.

File size: 13.9 KB
Line 
1/* $Id: OS2KVM.h,v 1.3 2001-09-27 03:04:12 bird Exp $
2 *
3 * OS/2 kernel VM functions.
4 *
5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11
12#ifndef _OS2KVM_h_
13#define _OS2KVM_h_
14
15
16/*******************************************************************************
17* Defined Constants And Macros *
18*******************************************************************************/
19
20/*
21 * From SG24-4640-00
22 * Object flags. (ob_fs)
23 */
24#define OB_PSEUDO 0x8000 /* Pseudo-object */
25#define OB_API 0x4000 /* API allocated object */
26#define OB_LOCKWAIT 0x2000 /* Some thread to wake in VMUnlock */
27#define OB_LALIAS 0x1000 /* Object has aliases */
28#define OB_SHARED 0x0800 /* Object's contents are shared */
29#define OB_UVIRT 0x0400 /* UVirt object */
30#define OB_ZEROINIT 0x0200 /* Object is zero-initialized */
31#define OB_RESIDENT 0x0100 /* Initial allocation was resident */
32#define OB_LOWMEM 0x0040 /* Object is in low memory */
33#define OB_GUARD 0x0080 /* Page attribute/permission flags */
34#define OB_EXEC 0x0020 /* Executable */
35#define OB_READ 0x0010 /* Read permission */
36#define OB_USER 0x0008 /* User Storage */
37#define OB_WRITE 0x0004 /* Write permission */
38#define OB_HUGE 0x0002 /* Object is huge */
39#define OB_SHRINKABLE 0x0001 /* Object is Shrinkable */
40#define OB_DHSETMEM 0x0001 /* DevHlp_VMSetMems are allowed */
41
42
43/*
44 * From SG24-4640-00
45 * ob_xflags
46 */
47#define VMOB_SLOCK_WAIT 0x01 /* Waiting on short term locks to clear */
48#define VMOB_LLOCK_WAIT 0x02 /* Waiting on long term locks to clear */
49#define VMOB_DISC_SEG 0x04 /* Object is part of a discardable seg */
50#define VMOB_HIGHMEM 0x08 /* Object was allocated via dh_vmalloc */
51
52
53
54/* v8086.h */
55#define VM_PG_W 0x00000002 /* VPMPG_W - Page Writeable. */
56#define VM_PG_U 0x00000004 /* VPMPG_U - Page User Mode Accessible.*/
57#define VM_PG_X 0x00000008 /* VPMPG_X - Page Executable. */
58#define VM_PG_R 0x00000010 /* VPMPG_R - Page Readable. */
59#define VM_PG_RESERVED 0x00001000 /* VPMPG_RESERVED- Reservered */
60
61/* vpmx2.h */
62#define VM_PG_SWAPPABLE 0x00000000 /* Swappable */
63
64
65
66/*
67 * VMAlloc flFlag1 guessings
68 */
69#define VMA_CONTIG 0x00000001UL /* VMDHA_CONTIG */
70#define VMA_WRITE VM_PG_W /* PAG_WRITE and OB_WRITE */
71#define VMA_USER VM_PG_U /* OB_USER */
72#define VMA_EXECUTE VM_PG_X /* PAG_EXECUTE and OB_READ !! */
73#define VMA_READ VM_PG_R /* PAG_READ and OB_EXEC !! */
74#define VMA_LOWMEM 0x00000020UL /* OB_LOWMEM < 1MB physical */
75#define VMA_GUARD 0x00000040UL /* PAG_GUARD and VMDHA_16M and OB_GUARD */
76#if 0
77#define VMA_RESIDENT 0x00000080UL /* OB_RESIDENT */
78#define VMA_ZEROINIT 0x00000100UL /* OB_ZEROINIT */
79#define VMA_PHYS 0x00000200UL /* VMDHA_PHYS */
80#define VMA_FIXED 0x00000400UL /* VMDHA_FIXED and OB_SHARED */
81#else
82#define VMA_ZEROFILL 0x00000080UL
83#define VMA_SWAPONWRITE 0x00000100UL
84#define VMA_UVIRT 0x00000200UL /* VMDHA_PHYS */
85#define VMA_RESIDENT 0x00000400UL /* VMDHA_FIXED and OB_SHARED */
86#endif
87#define VMA_DISCARDABLE 0x00000800UL /* discarable object */
88#define VMA_SHARE 0x00001000UL /* OBJSHARE and OBJEXEC (which implies shared) */
89#define VMA_PROTECTED 0x00004000UL /* PAG_PROTECTED */
90#define VMA_LOWMEM2 0x00010000UL /* OB_LOWMEM */
91#define VMA_VDM 0x00040000UL /* (VPMVMAC_VDM) VDM allocation */
92#define VMA_DECOMMIT 0x00080000UL /* PAG_DECOMMIT */
93#define VMA_TILE 0x00400000UL /* OBJ_TILE */
94#define VMA_SELALLOC 0x00400000UL /* Allocates selector */
95#define VMA_SHRINKABLE 0x00800000UL /* OB_SHRINKABLE */
96#define VMA_HUGH 0x01000000UL /* OB_HUGH */
97
98#define VMA_ARENASHARED 0x04000000UL /* Shared Arena */
99#define VMA_ARENASYSTEM 0x00000000UL /* System Arena */
100#define VMA_ARENAPRIVATE 0x02000000UL /* (VPMVMAC_ARENAPRV) Private Arena */
101#define VMA_ARENAHEAP 0x06000000UL /* Heap Arena */
102#define VMA_ARENAHIGHA 0x00008000UL /* High shared arena (Warp >= fp13) - flag! Use together with VMA_ARENASHARED or VMA_ARENAPRIVATE */
103#define VMA_ARENAHIGH (options.ulBuild >= AURORAGA ? VMA_ARENAHIGHA : 0UL)
104#define VMA_ARENAMASKW 0x06000000UL /* Warp < fp13 Arena Mask */
105#define VMA_ARENAMASKA 0x06008000UL /* Aurora Arena Mask */
106#define VMA_ARENAMASK (options.ulBuild >= AURORAGA ? VMA_ARENAMASKA : VMA_ARENAMASKW)
107
108#define VMA_ALIGNSEL 0x10000000UL /* Selector aligment */
109#define VMA_ALIGNPAGE 0x18000000UL /* (VPMVMAC_ALIGNPAGE) Page alignment */
110
111#define VMA_LOCMASK 0xC0000000UL /* Location mask */
112#define VMA_LOCSPECIFIC 0x80000000UL /* (VPMVMAC_LOCSPECIFIC) Specific location */
113#define VMA_LOCABOVE 0x40000000UL /* (VPMVMAC_LOCABOVE) Above or equal to specified location */
114#define VMA_LOCANY 0x00000000UL /* Anywhere */
115
116
117
118/*
119 * VMAlloc flFlags2 guessings - These are flags to the Selector Manager.
120 * Now prefixed SELAF - SELectorAllocFlags.
121 */
122#if 0 /*???*/
123#define VDHAM_FIXED 0x0000UL
124#define VDHAM_SWAPPABLE 0x0001UL
125#define VPMVMFM_VDM 0x00000004UL/* Request on behalf of VDM */
126#endif
127#define SELAF_SELMAP 0x0400
128#define SELAF_WRITE 0x0002 /* Writable selector. (PAG_WRITE) */
129#define SELAF_DPL0 0x0000 /* Descriptor privilege level - Ring 0 */
130#define SELAF_DPL1 0x0020 /* Descriptor privilege level - Ring 1 */
131#define SELAF_DPL2 0x0040 /* Descriptor privilege level - Ring 2 */
132#define SELAF_DPL3 0x0060 /* Descriptor privilege level - Ring 3 */
133
134
135/*
136 * VMMapDebugAlias flags.
137 */
138#define VMMDA_ARENAPRIVATE 0 /* Create alias in private arena */
139#define VMMDA_ARENASYSTEM 4 /* Create alias in system arena */
140#define VMMDA_READONLY 1 /* Create readonly alias */
141
142
143/*
144 * vmRecalcShrBound flags.
145 */
146#define VMRSBF_ARENASHR 0 /* Queries for the Shared Arena. */
147#define VMRSBF_ARENAHIGH 4 /* Queries for the High Shared Arena. */
148#define VMRSBF_UPDATE 1 /* Seems to update the Sentinel Arena Record. */
149
150
151/*
152 * Arena Header flags as defined in SG24-4640-00.
153 */
154#define VMAH_BITMAP_BYPASS 0x00000001 /* Worth bypassing bitmap */
155#define VMAH_NO_HASH_WRAP 0x00000002 /* No hash table wraparound yet */
156#define VMAH_GROW_DOWN 0x00000004 /* Arena grows down */
157
158
159/*******************************************************************************
160* Structures and Typedefs *
161*******************************************************************************/
162
163/*
164 * Handle to Memory Object.
165 */
166typedef USHORT VMHOB;
167typedef VMHOB * PVMHOB;
168
169
170/*
171 * Handle to Arena Record.
172 */
173typedef VMHOB VMHAR;
174typedef VMHOB * PVMHAR;
175
176
177/*
178 * VMAllocMem struct - found in SDFs.
179 */
180typedef struct _vmac
181{
182 ULONG ac_va; /* off=0 cb=4 Virtual Address. */
183 USHORT ac_sel; /* off=4 cb=2 Selector. */
184 USHORT ac_hob; /* off=6 cb=2 Object handle. */
185} VMAC, *PVMAC;
186
187
188/*
189 * Dummy structs we need pointers for.
190 */
191typedef PVOID PVMAR;
192typedef PVOID PVMBM;
193typedef PVOID PVMAT;
194
195
196/*
197 * Arena Header structure as defined in SG24-4640-00 and all SDF files.
198 */
199typedef struct vmah_s
200{
201 struct vmah_s * ah_pahNext; /* Link to next arena. */
202 struct vmah_s * ah_pahPrev; /* Link to previous arena. */
203 PVMAR ah_parSen; /* Pointer to the arena sentinel. */
204 PVMAR ah_parFree; /* Hint of 1st free block in arena. */
205 PVMBM ah_papbm; /* Pointer to bitmap directory. */
206 PVMHAR ah_paharHash;/*Hash table pointer. */
207 PVMAT ah_pat; /* Pointer to per-type info. */
208 ULONG ah_fl; /* Flags. */
209 ULONG ah_laddrMin;/* Minimum address currently mapped. */
210 ULONG ah_laddrMax;/* Maximum address currently mapped. */
211 ULONG ah_car; /* Count of arena entries. */
212 ULONG ah_carBitmap;/*Max entry count to need bitmap. */
213 ULONG ah_lbmNumbMax; /* Max bitmap number */
214 ULONG ah_lbmeNumbMax; /* Max bitmap entry number */
215 ULONG ah_lHashNumbMax;/* Max hash table index. */
216 VMHOB ah_hob; /* Arena header pseudo-handle. */
217 USHORT ah_filler; /* Filler to 4-byte align struct. */
218} VMAH, *PVMAH;
219
220
221/*******************************************************************************
222* Global Variables *
223*******************************************************************************/
224/*
225 * Mapping from _stdcall variable names nonmangled names.
226 */
227#ifndef KKRNLLIB
228 #if defined(__IBMC__) || defined(__IBMCPP__)
229 #pragma map(VirtualAddressLimit, "_VirtualAddressLimit")
230 #pragma map(ahvmSys, "_ahvmSys")
231 #pragma map(ahvmShr, "_ahvmShr")
232 #pragma map(ahvmhShr, "_ahvmhShr")
233 #else
234 #pragma VirtualAddressLimit _VirtualAddressLimit
235 #pragma ahvmSys _ahvmSys
236 #pragma ahvmShr _ahvmShr
237 #pragma ahvmhShr _ahvmhShr
238 #endif
239#endif
240
241
242/**
243 * Virtual Address Limit - this pointer might be NULL!
244 */
245#ifdef KKRNLLIB
246extern ULONG *pVirtualAddressLimit;
247#define VirtualAddressLimit (pVirtualAddressLimit ? *pVirtualAddressLimit : 0x20000000UL)
248#else
249extern ULONG VirtualAddressLimit;
250#define VirtualAddressLimit (&VirtualAddressLimit ? VirtualAddressLimit : 0x20000000UL)
251#endif
252
253/**
254 * System arena header.
255 */
256#ifdef KKRNLLIB
257extern PVMAH pahvmSys;
258#define ahvmSys (*pahvmSys)
259#else
260extern VMAH ahvmSys;
261#endif
262
263/**
264 * Shared arena header.
265 */
266#ifdef KKRNLLIB
267extern PVMAH pahvmShr;
268#define ahvmShr (*pahvmShr)
269#else
270extern VMAH ahvmShr;
271#endif
272
273/**
274 * High Shread arena header - only aurora and Warp Server Advanced SMP.
275 * Check if &ahvmhShr is NULL!
276 */
277#ifdef KKRNLLIB
278extern PVMAH pahvmhShr;
279#define ahvmhShr (*pahvmhShr)
280#else
281extern VMAH ahvmhShr;
282#endif
283
284
285/*******************************************************************************
286* Exported Functions *
287*******************************************************************************/
288HMTE KRNLCALL VMGetOwner(
289 ULONG ulCS,
290 ULONG ulEIP);
291HMTE KRNLCALL OrgVMGetOwner(
292 ULONG ulCS,
293 ULONG ulEIP);
294
295APIRET KRNLCALL VMAllocMem(
296 ULONG cbSize,
297 ULONG cbCommit,
298 ULONG flFlags1,
299 HPTDA hPTDA,
300 USHORT usVMOwnerId,
301 HMTE hMTE,
302 ULONG flFlags2,
303 ULONG SomeArg2,
304 PVMAC pvmac);
305APIRET KRNLCALL OrgVMAllocMem(
306 ULONG cbSize,
307 ULONG cbCommit,
308 ULONG flFlags1,
309 HPTDA hPTDA,
310 USHORT usVMOwnerId,
311 HMTE hMTE,
312 ULONG flFlags2,
313 ULONG SomeArg2,
314 PVMAC pvmac);
315
316APIRET KRNLCALL VMFreeMem(
317 ULONG ulAddress,
318 HPTDA hPTDA,
319 ULONG flFlags);
320APIRET KRNLCALL OrgVMFreeMem(
321 ULONG ulAddress,
322 HPTDA hPTDA,
323 ULONG flFlags);
324
325APIRET KRNLCALL VMMapDebugAlias(
326 ULONG flVMFlags,
327 ULONG ulAddress,
328 ULONG cbSize,
329 HPTDA hPTDA,
330 PVMAC pvmac);
331APIRET KRNLCALL OrgVMMapDebugAlias(
332 ULONG flVMFlags,
333 ULONG ulAddress,
334 ULONG cbSize,
335 HPTDA hPTDA,
336 PVMAC pvmac);
337
338APIRET KRNLCALL VMObjHandleInfo(
339 USHORT usHob,
340 PULONG pulAddr,
341 PUSHORT pushPTDA);
342APIRET KRNLCALL OrgVMObjHandleInfo(
343 USHORT usHob,
344 PULONG pulAddr,
345 PUSHORT pushPTDA);
346
347#ifdef _OS2KLDR_H_
348PMTE KRNLCALL VMPseudoHandleMap(
349 HMTE hMTE);
350PMTE KRNLCALL OrgVMPseudoHandleMap(
351 HMTE hMTE);
352#endif
353
354/**
355 * This function seems to find the top of the private arena.
356 * And for high arena kernels (AURORA and W3SMP?) it is modified
357 * to calc the top of the high private arena, given flFlag = 4.
358 * --
359 * This function is really intented for resizing / recaling the size of
360 * the shared arena(s). But, it's useful for finding the highest used
361 * private arena(s).
362 * @param flFlags VMRSBF_* flags.
363 * @param pulSentinelAddress Pointer to return variable (optional).
364 */
365VOID KRNLCALL vmRecalcShrBound(
366 ULONG flFlags,
367 PULONG pulSentinelAddress);
368VOID KRNLCALL OrgvmRecalcShrBound(
369 ULONG flFlags,
370 PULONG pulSentinelAddress);
371
372
373/**
374 * Creates a pseudo handle for a given memory address.
375 * @returns OS/2 return code. NO_ERROR on success.
376 * @param pvData Pointer to the data which the handle should represent.
377 * @param hobOwner Owner of the pseudo handle.
378 * @param phob Pointer to object handle variable. Upon successful return
379 * this will hold the handle value of the crated pseudo handle.
380 * @remark Used for many types of handles within the kernel.
381 * Among them are the loader HMTEs. The loader uses usOwner = 0xffa6 (ldrmte).
382 */
383APIRET KRNLCALL VMCreatePseudoHandle(
384 PVOID pvData,
385 VMHOB usOwner,
386 PVMHOB phob);
387APIRET KRNLCALL OrgVMCreatePseudoHandle(
388 PVOID pvData,
389 VMHOB usOwner,
390 PVMHOB phob);
391
392
393/**
394 * This call frees a pseudo handle pointer previously allocated by
395 * VMCreatePseudoHandle.
396 * @returns OS/2 return code.
397 * @param hob Handle to be freed.
398 */
399APIRET KRNLCALL VMFreePseudoHandle(
400 VMHOB hob);
401APIRET KRNLCALL OrgVMFreePseudoHandle(
402 VMHOB hob);
403
404
405#endif
Note: See TracBrowser for help on using the repository browser.