| 1 | /* $Id: OS2KVM.h,v 1.11 2001-02-19 05:53:53 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 | */ | 
|---|
| 166 | typedef USHORT  VMHOB; | 
|---|
| 167 |  | 
|---|
| 168 | /* | 
|---|
| 169 | * Handle to Arena Record. | 
|---|
| 170 | */ | 
|---|
| 171 | typedef VMHOB  VMHAR; | 
|---|
| 172 |  | 
|---|
| 173 |  | 
|---|
| 174 | /* | 
|---|
| 175 | * VMAllocMem struct - found in SDFs. | 
|---|
| 176 | */ | 
|---|
| 177 | typedef struct _vmac | 
|---|
| 178 | { | 
|---|
| 179 | ULONG       ac_va;                  /* off=0 cb=4 Virtual Address. */ | 
|---|
| 180 | USHORT      ac_sel;                 /* off=4 cb=2 Selector. */ | 
|---|
| 181 | USHORT      ac_hob;                 /* off=6 cb=2 Object handle. */ | 
|---|
| 182 | } VMAC, *PVMAC; | 
|---|
| 183 |  | 
|---|
| 184 |  | 
|---|
| 185 | /* | 
|---|
| 186 | * Dummy structs we need pointers for. | 
|---|
| 187 | */ | 
|---|
| 188 | typedef PVOID   PVMAR; | 
|---|
| 189 | typedef PVOID   PVMBM; | 
|---|
| 190 | typedef PVOID   PVMHAR; | 
|---|
| 191 | typedef PVOID   PVMAT; | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | /* | 
|---|
| 195 | * Arena Header structure as defined in SG24-4640-00 and all SDF files. | 
|---|
| 196 | */ | 
|---|
| 197 | typedef struct vmah_s | 
|---|
| 198 | { | 
|---|
| 199 | struct vmah_s *         ah_pahNext; /* Link to next arena. */ | 
|---|
| 200 | struct vmah_s *         ah_pahPrev; /* Link to previous arena. */ | 
|---|
| 201 | PVMAR                   ah_parSen;  /* Pointer to the arena sentinel. */ | 
|---|
| 202 | PVMAR                   ah_parFree; /* Hint of 1st free block in arena. */ | 
|---|
| 203 | PVMBM                   ah_papbm;   /* Pointer to bitmap directory. */ | 
|---|
| 204 | PVMHAR                  ah_paharHash;/*Hash table pointer. */ | 
|---|
| 205 | PVMAT                   ah_pat;     /* Pointer to per-type info. */ | 
|---|
| 206 | ULONG                   ah_fl;      /* Flags. */ | 
|---|
| 207 | ULONG                   ah_laddrMin;/* Minimum address currently mapped. */ | 
|---|
| 208 | ULONG                   ah_laddrMax;/* Maximum address currently mapped. */ | 
|---|
| 209 | ULONG                   ah_car;     /* Count of arena entries. */ | 
|---|
| 210 | ULONG                   ah_carBitmap;/*Max entry count to need bitmap. */ | 
|---|
| 211 | ULONG                   ah_lbmNumbMax;  /* Max bitmap number */ | 
|---|
| 212 | ULONG                   ah_lbmeNumbMax; /* Max bitmap entry number */ | 
|---|
| 213 | ULONG                   ah_lHashNumbMax;/* Max hash table index. */ | 
|---|
| 214 | VMHOB                   ah_hob;     /* Arena header pseudo-handle. */ | 
|---|
| 215 | USHORT                  ah_filler;  /* Filler to 4-byte align struct. */ | 
|---|
| 216 | } VMAH, *PVMAH; | 
|---|
| 217 |  | 
|---|
| 218 |  | 
|---|
| 219 | /******************************************************************************* | 
|---|
| 220 | *   Global Variables                                                           * | 
|---|
| 221 | *******************************************************************************/ | 
|---|
| 222 | /** | 
|---|
| 223 | * Virtual Address Limit - this pointer might be NULL! | 
|---|
| 224 | */ | 
|---|
| 225 | extern ULONG *pVirtualAddressLimit; | 
|---|
| 226 | #define VirtualAddressLimit (pVirtualAddressLimit ? *pVirtualAddressLimit : 0x20000000) | 
|---|
| 227 |  | 
|---|
| 228 | /** | 
|---|
| 229 | * System arena header. | 
|---|
| 230 | */ | 
|---|
| 231 | extern PVMAH pahvmSys; | 
|---|
| 232 | #define ahvmSys (*pahvmSys) | 
|---|
| 233 |  | 
|---|
| 234 | /** | 
|---|
| 235 | * Shared arena header. | 
|---|
| 236 | */ | 
|---|
| 237 | extern PVMAH pahvmShr; | 
|---|
| 238 | #define ahvmShr (*pahvmShr) | 
|---|
| 239 |  | 
|---|
| 240 | /** | 
|---|
| 241 | * High Shread arena header - only aurora and Warp Server Advanced SMP. | 
|---|
| 242 | */ | 
|---|
| 243 | extern PVMAH pahvmhShr; | 
|---|
| 244 | #define ahvmhShr (*pahvmhShr) | 
|---|
| 245 |  | 
|---|
| 246 |  | 
|---|
| 247 | /******************************************************************************* | 
|---|
| 248 | *   Exported Functions                                                         * | 
|---|
| 249 | *******************************************************************************/ | 
|---|
| 250 | HMTE KRNLCALL VMGetOwner( | 
|---|
| 251 | ULONG ulCS, | 
|---|
| 252 | ULONG ulEIP); | 
|---|
| 253 |  | 
|---|
| 254 | APIRET KRNLCALL VMAllocMem( | 
|---|
| 255 | ULONG   cbSize, | 
|---|
| 256 | ULONG   cbCommit, | 
|---|
| 257 | ULONG   flFlags1, | 
|---|
| 258 | HPTDA   hPTDA, | 
|---|
| 259 | USHORT  usVMOwnerId, | 
|---|
| 260 | HMTE    hMTE, | 
|---|
| 261 | ULONG   flFlags2, | 
|---|
| 262 | ULONG   SomeArg2, | 
|---|
| 263 | PVMAC   pvmac); | 
|---|
| 264 |  | 
|---|
| 265 | APIRET KRNLCALL VMFreeMem( | 
|---|
| 266 | ULONG   ulAddress, | 
|---|
| 267 | HPTDA   hPTDA, | 
|---|
| 268 | ULONG   flFlags); | 
|---|
| 269 |  | 
|---|
| 270 | APIRET KRNLCALL VMMapDebugAlias( | 
|---|
| 271 | ULONG   flVMFlags, | 
|---|
| 272 | ULONG   ulAddress, | 
|---|
| 273 | ULONG   cbSize, | 
|---|
| 274 | HPTDA   hPTDA, | 
|---|
| 275 | PVMAC   pvmac); | 
|---|
| 276 |  | 
|---|
| 277 | APIRET KRNLCALL VMObjHandleInfo( | 
|---|
| 278 | USHORT  usHob, | 
|---|
| 279 | PULONG  pulAddr, | 
|---|
| 280 | PUSHORT pushPTDA); | 
|---|
| 281 |  | 
|---|
| 282 | #ifdef _OS2KLDR_H_ | 
|---|
| 283 | PMTE KRNLCALL VMPseudoHandleMap( | 
|---|
| 284 | HMTE    hMTE); | 
|---|
| 285 | #endif | 
|---|
| 286 |  | 
|---|
| 287 | /** | 
|---|
| 288 | * This function seems to find the top of the private arena. | 
|---|
| 289 | * And for high arena kernels (AURORA and W3SMP?) it is modified | 
|---|
| 290 | * to calc the top of the high private arena, given flFlag = 4. | 
|---|
| 291 | * -- | 
|---|
| 292 | * This function is really intented for resizing / recaling the size of | 
|---|
| 293 | * the shared arena(s). But, it's useful for finding the highest used | 
|---|
| 294 | * private arena(s). | 
|---|
| 295 | * @param   flFlags             VMRSBF_* flags. | 
|---|
| 296 | * @param   pulSentinelAddress  Pointer to return variable (optional). | 
|---|
| 297 | */ | 
|---|
| 298 | VOID    KRNLCALL vmRecalcShrBound( | 
|---|
| 299 | ULONG   flFlags, | 
|---|
| 300 | PULONG  pulSentinelAddress); | 
|---|
| 301 |  | 
|---|
| 302 |  | 
|---|
| 303 | #endif | 
|---|