Changeset 673 for trunk/src/kernel32/os2native.cpp
- Timestamp:
- Aug 25, 1999, 10:57:14 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/os2native.cpp
r657 r673 1 /* $Id: os2native.cpp,v 1. 6 1999-08-24 12:23:24 sandervlExp $ */1 /* $Id: os2native.cpp,v 1.7 1999-08-25 08:57:14 phaller Exp $ */ 2 2 3 3 /* … … 20 20 #define INCL_DOSMEMMGR 21 21 #define INCL_DOSPROCESS 22 #include <os2wrap.h> 22 #include <os2wrap.h> //Odin32 OS/2 api wrappers 23 23 #include <stdlib.h> 24 24 #include <stdio.h> … … 80 80 if (cbSize > 0x7fc00000) /* 2Gb - 4Mb */ 81 81 { 82 82 dprintf(("VirtualAlloc: size too large")); 83 83 // SetLastError( ERROR_OUTOFMEMORY ); 84 84 return NULL; … … 88 88 (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE))) 89 89 { 90 90 dprintf(("VirtualAlloc: Invalid parameter")); 91 91 // SetLastError( ERROR_INVALID_PARAMETER ); 92 92 return NULL; … … 103 103 if(fdwProtect & PAGE_EXECUTE_READWRITE) flag |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 104 104 if(fdwProtect & PAGE_EXECUTE_READ) flag |= (PAG_EXECUTE | PAG_READ); 105 if(fdwProtect & PAGE_EXECUTE) 105 if(fdwProtect & PAGE_EXECUTE) flag |= PAG_EXECUTE; 106 106 107 107 if(fdwProtect & PAGE_GUARD) flag |= PAG_GUARD; 108 108 109 109 //just do this if other options are used 110 if(!(flag & (PAG_READ | PAG_WRITE | PAG_EXECUTE)) || flag == 0) { 111 dprintf(("VirtualAlloc: Unknown protection flags, default to read/write")); 112 flag |= PAG_READ | PAG_WRITE; 113 } 114 115 if(fdwAllocationType & MEM_COMMIT && lpvAddress != NULL) { 116 Address = lpvAddress; 117 118 rc = DosSetMem(lpvAddress, cbSize, flag); 110 if(!(flag & (PAG_READ | PAG_WRITE | PAG_EXECUTE)) || flag == 0) 111 { 112 dprintf(("VirtualAlloc: Unknown protection flags, default to read/write")); 113 flag |= PAG_READ | PAG_WRITE; 114 } 115 116 if(fdwAllocationType & MEM_COMMIT && lpvAddress != NULL) 117 { 118 Address = lpvAddress; 119 120 rc = DosSetMem(lpvAddress, cbSize, flag); 119 121 //might try to commit larger part with same base address 120 if(rc == ERROR_ACCESS_DENIED && cbSize > 4096 ) {//knut: AND more than one page 121 char *newbase = (char *)lpvAddress + ((cbSize-1) & 0xFFFFF000); //knut: lets not start after the last page! 122 ULONG size, os2flags; 123 124 while(newbase >= (char *)lpvAddress) { //knut: should check first page to!! 125 size = 4096; 126 os2flags = 0; 127 rc = DosQueryMem(newbase, &size, &os2flags); 128 if(rc) break; 129 if(os2flags & PAG_COMMIT) { 130 newbase += 4096; 131 break; 132 } 133 newbase -= 4096; 134 } 135 if(rc == 0) { 136 //In case it wants to commit bytes that fall into the last 137 //page of the previous commit command 138 if(cbSize > ((int)newbase - (int)lpvAddress)) { 139 rc = DosSetMem(newbase, cbSize - ((int)newbase - (int)lpvAddress), flag); 140 } 141 } 142 else return(NULL); 122 if(rc == ERROR_ACCESS_DENIED && cbSize > 4096 ) 123 { //knut: AND more than one page 124 char *newbase = (char *)lpvAddress + ((cbSize-1) & 0xFFFFF000); //knut: lets not start after the last page! 125 ULONG size, os2flags; 126 127 while(newbase >= (char *)lpvAddress) 128 { //knut: should check first page to!! 129 size = 4096; 130 os2flags = 0; 131 rc = DosQueryMem(newbase, &size, &os2flags); 132 if(rc) 133 break; 134 135 if(os2flags & PAG_COMMIT) 136 { 137 newbase += 4096; 138 break; 143 139 } 144 else 145 { 146 if(rc == ERROR_INVALID_ADDRESS) 147 { 148 rc = DosAllocMem(&Address, cbSize, flag | flAllocMem ); 149 } 150 else 151 if(rc) dprintf(("Unexpected DosSetMem error %x", rc)); 152 } 153 } 154 else { 140 newbase -= 4096; 141 } 142 143 if(rc == 0) 144 { 145 //In case it wants to commit bytes that fall into the last 146 //page of the previous commit command 147 if(cbSize > ((int)newbase - (int)lpvAddress)) 148 rc = DosSetMem(newbase, cbSize - ((int)newbase - (int)lpvAddress), flag); 149 } 150 else 151 return(NULL); 152 153 } 154 else 155 { 156 if(rc == ERROR_INVALID_ADDRESS) 157 rc = DosAllocMem(&Address, cbSize, flag | flAllocMem ); 158 else 159 if(rc) 160 dprintf(("Unexpected DosSetMem error %x", rc)); 161 } 162 } 163 else 164 { 155 165 /*knut: flAllocMem */ 156 166 rc = DosAllocMem(&Address, cbSize, flag | flAllocMem ); … … 158 168 159 169 //TODO: Set last error in case rc != 0 160 if(rc) { 161 dprintf(("DosSetMem returned %d\n", rc)); 170 if(rc) 171 { 172 dprintf(("DosSetMem returned %d\n", rc)); 162 173 // SetLastError( ERROR_OUTOFMEMORY ); 163 174 return(NULL); 164 175 } 165 176 … … 265 276 266 277 if(lpvAddress == NULL || pmbiBuffer == NULL || cbLength == 0) { 267 278 return 0; 268 279 } 269 280 cbRangeSize = cbLength; 270 281 rc = DosQueryMem(lpvAddress, &cbRangeSize, &dAttr); 271 282 if(rc) { 272 273 283 dprintf(("VirtualQuery - DosQueryMem %x %x returned %d\n", lpvAddress, cbLength, rc)); 284 return 0; 274 285 } 275 286 memset(pmbiBuffer, 0, sizeof(MEMORY_BASIC_INFORMATION)); … … 291 302 292 303 if(dAttr & PAG_FREE) 293 304 pmbiBuffer->State = MEM_FREE; 294 305 else 295 306 if(dAttr & PAG_COMMIT) 296 297 else 298 307 pmbiBuffer->State = MEM_COMMIT; 308 else pmbiBuffer->State = MEM_RESERVE; 309 299 310 if(!(dAttr & PAG_SHARED)) 300 311 pmbiBuffer->Type = MEM_PRIVATE; 301 312 302 313 //TODO: This is not correct: AllocationProtect should contain the protection … … 304 315 pmbiBuffer->AllocationProtect = pmbiBuffer->Protect; 305 316 if(dAttr & PAG_BASE) { 306 317 pmbiBuffer->AllocationBase = lpvAddress; 307 318 } 308 319 else { 309 310 311 312 313 314 315 316 317 318 319 320 320 while(lpvAddress > 0) { 321 rc = DosQueryMem(lpvAddress, &cbRangeSize, &dAttr); 322 if(rc) { 323 dprintf(("VirtualQuery - DosQueryMem %x %x returned %d\n", lpvAddress, cbLength, rc)); 324 break; 325 } 326 if(dAttr & PAG_BASE) { 327 pmbiBuffer->AllocationBase = lpvAddress; 328 break; 329 } 330 lpvAddress = (LPVOID)((ULONG)lpvAddress - PAGE_SIZE); 331 } 321 332 } 322 333 return sizeof(MEMORY_BASIC_INFORMATION);
Note:
See TracChangeset
for help on using the changeset viewer.