- Timestamp:
- Oct 18, 2000, 7:09:34 PM (25 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/exceptions.cpp
r4433 r4496 1 /* $Id: exceptions.cpp,v 1.4 6 2000-10-05 18:36:49sandervl Exp $ */1 /* $Id: exceptions.cpp,v 1.47 2000-10-18 17:09:31 sandervl Exp $ */ 2 2 3 3 /* WARNING: Compiling this module with ICC with optimizations turned on */ … … 1048 1048 #endif 1049 1049 1050 //in misc.cpp1051 void CheckLogException();1052 1053 1050 ULONG APIENTRY OS2ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec, 1054 1051 PEXCEPTIONREGISTRATIONRECORD pERegRec, … … 1058 1055 //SvL: Check if exception inside debug fprintf -> if so, clear lock so 1059 1056 // next dprintf won't wait forever 1060 CheckLogException(); 1061 1057 LogException(ENTER_EXCEPTION); 1062 1058 1063 1059 /* Access violation at a known location */ … … 1083 1079 } 1084 1080 dprintf(("KERNEL32: OS2ExceptionHandler: fix and continue\n")); 1085 return (XCPT_CONTINUE_EXECUTION);1081 goto continueexecution; 1086 1082 } 1087 1083 else 1088 1084 { 1089 1085 dprintf(("KERNEL32: OS2ExceptionHandler: continue search\n")); 1090 return (XCPT_CONTINUE_SEARCH);1086 goto continuesearch; 1091 1087 } 1092 1088 … … 1095 1091 dprintfException(pERepRec, pERegRec, pCtxRec, p); 1096 1092 SetExceptionChain((ULONG)-1); 1097 return (XCPT_CONTINUE_SEARCH);1093 goto continuesearch; 1098 1094 1099 1095 case XCPT_ACCESS_VIOLATION: … … 1126 1122 } 1127 1123 if(map->commitPage(offset, fWriteAccess) == TRUE) 1128 return (XCPT_CONTINUE_EXECUTION);1124 goto continueexecution; 1129 1125 1130 1126 //no break; … … 1177 1173 // recurse infinitely until we run out of stack space!! 1178 1174 if (pERepRec->fHandlerFlags & EH_NESTED_CALL) 1179 return XCPT_CONTINUE_SEARCH;1175 goto continuesearch; 1180 1176 1181 1177 #ifdef DEBUG … … 1189 1185 if(OSLibDispatchException(pERepRec, pERegRec, pCtxRec, p) == TRUE) 1190 1186 { 1191 return (XCPT_CONTINUE_EXECUTION);1187 goto continueexecution; 1192 1188 } 1193 1189 } 1194 else return XCPT_CONTINUE_SEARCH; //pass on to OS/2 RTL or app exception handler1190 else goto continuesearch; //pass on to OS/2 RTL or app exception handler 1195 1191 1196 1192 dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill\n")); … … 1199 1195 pCtxRec->ctx_RegEax = pERepRec->ExceptionNum; 1200 1196 pCtxRec->ctx_RegEbx = pCtxRec->ctx_RegEip; 1201 return (XCPT_CONTINUE_EXECUTION);1197 goto continueexecution; 1202 1198 1203 1199 //@@@PH: growing thread stacks might need special treatment 1204 1200 case XCPT_GUARD_PAGE_VIOLATION: 1205 dprintf(("KERNEL32: OS2ExceptionHandler: trying to grow stack (continue search)")); 1206 return (XCPT_CONTINUE_SEARCH); 1201 //SvL: don't print anything here -> fatal hang if happens inside fprintf 1202 //dprintf(("KERNEL32: OS2ExceptionHandler: trying to grow stack (continue search)")); 1203 goto continuesearch; 1207 1204 1208 1205 case XCPT_SIGNAL: 1209 if(pERepRec->ExceptionInfo[0] == XCPT_SIGNAL_KILLPROC) /* resolve signal information */1210 {1211 SetExceptionChain((ULONG)-1);1212 return (XCPT_CONTINUE_SEARCH);1213 }1214 goto CrashAndBurn;1206 if(pERepRec->ExceptionInfo[0] == XCPT_SIGNAL_KILLPROC) /* resolve signal information */ 1207 { 1208 SetExceptionChain((ULONG)-1); 1209 goto continuesearch; 1210 } 1211 goto CrashAndBurn; 1215 1212 1216 1213 default: //non-continuable exceptions 1217 1214 dprintfException(pERepRec, pERegRec, pCtxRec, p); 1218 return (XCPT_CONTINUE_SEARCH); 1219 } 1220 return (XCPT_CONTINUE_SEARCH); 1215 goto continuesearch; 1216 } 1217 continuesearch: 1218 LogException(LEAVE_EXCEPTION); 1219 return XCPT_CONTINUE_SEARCH; 1220 1221 continueexecution: 1222 LogException(LEAVE_EXCEPTION); 1223 return XCPT_CONTINUE_EXECUTION; 1221 1224 } 1222 1225 -
trunk/src/kernel32/exceptutil.h
r4189 r4496 1 /* $Id: exceptutil.h,v 1. 9 2000-09-04 18:24:42 sandervl Exp $ */1 /* $Id: exceptutil.h,v 1.10 2000-10-18 17:09:32 sandervl Exp $ */ 2 2 3 3 /* … … 49 49 #endif 50 50 51 #define ENTER_EXCEPTION 0 52 #define LEAVE_EXCEPTION 1 53 void LogException(int state); 54 51 55 #endif -
trunk/src/kernel32/hmfile.cpp
r4474 r4496 1 /* $Id: hmfile.cpp,v 1.2 2 2000-10-10 17:14:03sandervl Exp $ */1 /* $Id: hmfile.cpp,v 1.23 2000-10-18 17:09:32 sandervl Exp $ */ 2 2 3 3 /* … … 597 597 // } 598 598 599 //testestest!!!!600 dprintf(("%s", lpRealBuf));601 //testestest!!!!602 603 604 599 dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n", 605 600 bRC)); -
trunk/src/kernel32/initsystem.cpp
r4474 r4496 1 /* $Id: initsystem.cpp,v 1.1 8 2000-10-10 17:14:04sandervl Exp $ */1 /* $Id: initsystem.cpp,v 1.19 2000-10-18 17:09:32 sandervl Exp $ */ 2 2 /* 3 3 * Odin system initialization (registry, directories & environment) … … 568 568 */ 569 569 570 //[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\FileSystem] 571 //"Win31FileSystem"=dword:00000000 572 //"NtfsDisable8dot3NameCreation"=dword:00000000 573 //"Win95TruncatedExtensions"=dword:00000001 574 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\FileSystem",&hkey)!=ERROR_SUCCESS) { 575 goto initreg_error; 576 } 577 val = 0x0; 578 RegSetValueExA(hkey, "Win31FileSystem",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD)); 579 val = 0x0; 580 RegSetValueExA(hkey, "NtfsDisable8dot3NameCreation",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD)); 581 val = 0x1; 582 RegSetValueExA(hkey, "Win95TruncatedExtensions",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD)); 583 RegCloseKey(hkey); 584 570 585 return TRUE; 571 586 -
trunk/src/kernel32/misc.cpp
r4431 r4496 1 /* $Id: misc.cpp,v 1.2 6 2000-10-05 13:48:09sandervl Exp $ */1 /* $Id: misc.cpp,v 1.27 2000-10-18 17:09:33 sandervl Exp $ */ 2 2 3 3 /* … … 29 29 #include "initterm.h" 30 30 #include "logging.h" 31 #include "exceptutil.h" 31 32 #include <wprocess.h> 32 33 #include <versionos2.h> … … 251 252 #if defined(DEBUG) && defined(CHECK_ODINHEAP) 252 253 int checkOdinHeap = 1; 253 #define ODIN_HEAPCHECK() if(checkOdinHeap)_heap_check();254 #define ODIN_HEAPCHECK() if(checkOdinHeap) _heap_check(); 254 255 #else 255 256 #define ODIN_HEAPCHECK() … … 272 273 if(!getenv("NOWIN32LOG")) { 273 274 #endif 274 275 276 277 278 279 280 281 275 char logname[CCHMAXPATH]; 276 277 sprintf(logname, "odin32_%d.log", loadNr); 278 flog = fopen(logname, "w"); 279 if(flog == NULL) {//probably running exe on readonly device 280 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr); 281 flog = fopen(logname, "w"); 282 } 282 283 oldcrtmsghandle = _set_crt_msg_handle(fileno(flog)); 283 284 } … … 291 292 292 293 va_start(argptr, tekst); 293 if(thdb) { 294 294 if(thdb) { 295 thdb->logfile = (DWORD)flog; 295 296 if(sel == 0x150b && !fIsOS2Image) { 296 297 298 elsefprintf(flog, "t%d: ", thdb->threadId);297 fprintf(flog, "t%d: (FS=150B) ", thdb->threadId); 298 } 299 else fprintf(flog, "t%d: ", thdb->threadId); 299 300 } 300 301 vfprintf(flog, tekst, argptr); … … 326 327 if(!getenv("NOWIN32LOG")) { 327 328 #endif 328 329 330 331 332 333 334 335 329 char logname[CCHMAXPATH]; 330 331 sprintf(logname, "odin32_%d.log", loadNr); 332 flog = fopen(logname, "w"); 333 if(flog == NULL) {//probably running exe on readonly device 334 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr); 335 flog = fopen(logname, "w"); 336 } 336 337 } 337 338 else … … 344 345 345 346 va_start(argptr, tekst); 346 if(thdb) { 347 347 if(thdb) { 348 thdb->logfile = (DWORD)flog; 348 349 } 349 350 vfprintf(flog, tekst, argptr); … … 378 379 379 380 va_start(argptr, tekst); 381 if(thdb) { 382 thdb->logfile = (DWORD)flog; 383 } 380 384 vfprintf((FILE *)logfile, tekst, argptr); 381 385 if(thdb) thdb->logfile = 0; … … 390 394 } 391 395 //****************************************************************************** 392 // Check if the exception occurred inside a fprintf (logging THDB member set)393 // If true, decrease the lock count for that file stream394 // NOTE: HACK: DEPENDS ON COMPILER VERSION!!!!395 //****************************************************************************** 396 void CheckLogException()396 //WriteLog has to take special care to handle dprintfs inside our os/2 exception 397 //handler; if an exception occurs inside a dprintf, using dprintf in the exception 398 //handler will hang the process 399 //****************************************************************************** 400 void LogException(int state) 397 401 { 398 402 THDB *thdb = GetThreadTHDB(); … … 402 406 403 407 if(thdb->logfile) { 404 //oops, exception in vfprintf; let's clear the lock count 408 if(state == ENTER_EXCEPTION) { 405 409 #if (__IBMCPP__ == 300) || (__IBMC__ == 300) 406 410 lock = (USHORT *)(thdb->logfile+0x1C); 407 411 #else 408 412 #error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!! 409 413 #endif 410 (*lock)--; 414 (*lock)--; 415 } 416 else { //LEAVE_EXCEPTION 417 #if (__IBMCPP__ == 300) || (__IBMC__ == 300) 418 lock = (USHORT *)(thdb->logfile+0x1C); 419 #else 420 #error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!! 421 #endif 422 (*lock)++; 423 } 424 } 425 } 426 //****************************************************************************** 427 //Check if the exception occurred inside a fprintf (logging THDB member set) 428 //If true, decrease the lock count for that file stream 429 //NOTE: HACK: DEPENDS ON COMPILER VERSION!!!! 430 //****************************************************************************** 431 void CheckLogException() 432 { 433 THDB *thdb = GetThreadTHDB(); 434 USHORT *lock; 435 436 if(!thdb) return; 437 438 if(thdb->logfile) { 439 //oops, exception in vfprintf; let's clear the lock count 440 #if (__IBMCPP__ == 300) || (__IBMC__ == 300) 441 lock = (USHORT *)(thdb->logfile+0x1C); 442 #else 443 #error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!! 444 #endif 445 (*lock)--; 411 446 } 412 447 } … … 418 453 { 419 454 if(oldcrtmsghandle) 420 455 _set_crt_msg_handle(oldcrtmsghandle); 421 456 422 457 fclose(flog); … … 433 468 if(!getenv("NOWIN32LOG")) { 434 469 #endif 435 470 OpenPrivateLogFilePE(); 436 471 } 437 472 } … … 446 481 if(!getenv("NOWIN32LOG")) { 447 482 #endif 448 483 ClosePrivateLogFilePE(); 449 484 } 450 485 } -
trunk/src/kernel32/mmap.cpp
r4230 r4496 1 /* $Id: mmap.cpp,v 1.4 4 2000-09-10 21:54:07sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.45 2000-10-18 17:09:33 sandervl Exp $ */ 2 2 3 3 /* … … 34 34 #include <winimagepeldr.h> 35 35 36 #define DBG_LOCALLOG 36 #define DBG_LOCALLOG DBG_mmap 37 37 #include "dbglocal.h" 38 38 … … 69 69 70 70 if(lpszName) { 71 72 73 } 74 else 71 lpszMapName = (char *)_smalloc(strlen(lpszName)+1); 72 strcpy(lpszMapName, lpszName); 73 } 74 else lpszMapName = NULL; 75 75 } 76 76 //****************************************************************************** … … 105 105 { 106 106 #if 0 107 107 if(DuplicateHandle(mProcessId, hMemFile, GetCurrentProcess(), 108 108 &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) 109 109 #else 110 111 112 113 114 115 elsedwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE;116 117 110 DWORD dwOdinOptions; 111 112 if(!(mProtFlags & PAGE_READWRITE)) { 113 dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE; 114 } 115 else dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE; 116 117 if(HMDuplicateHandleOdin(mProcessId, hMemFile, GetCurrentProcess(), 118 118 &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS, dwOdinOptions) == FALSE) 119 119 #endif 120 121 122 123 124 125 126 127 128 129 130 120 { 121 dprintf(("Win32MemMap::Init: DuplicateHandle failed!")); 122 goto fail; 123 } 124 mSize = SetFilePointer(hMemFile, 0, NULL, FILE_BEGIN); 125 mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END); 126 if(mSize == -1) { 127 dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end")); 128 goto fail; 129 } 130 //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow 131 131 // one to reserve more than 450 MB (unless you override the virtual 132 132 // memory max limit) of continuous memory; (Warp 4 much less)) 133 134 135 133 if(mSize > 64*1024*1024) { 134 mSize = 64*1024*1024; 135 } 136 136 } 137 137 … … 154 154 mapMutex.enter(); 155 155 if(lpszMapName) { 156 156 free(lpszMapName); 157 157 } 158 158 if(pMapping && !image) { 159 160 161 162 elseVirtualFree(pMapping, mSize, MEM_RELEASE);163 164 159 if(lpszMapName) { 160 OSLibDosFreeMem(pMapping); 161 } 162 else VirtualFree(pMapping, mSize, MEM_RELEASE); 163 164 pMapping = NULL; 165 165 } 166 166 if(hMemFile != -1) { 167 CloseHandle(hMemFile); 168 hMemFile = -1; 167 dprintf(("Win32MemMap dtor: closing memory file %x", hMemFile)); 168 CloseHandle(hMemFile); 169 hMemFile = -1; 169 170 } 170 171 mapMutex.leave(); … … 174 175 175 176 if(map == this) { 176 177 memmaps = next; 177 178 } 178 179 else { 179 180 181 182 183 184 185 186 187 elsedprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));180 while(map->next) { 181 if(map->next == this) 182 break; 183 map = map->next; 184 } 185 if(map->next) { 186 map->next = next; 187 } 188 else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this)); 188 189 } 189 190 globalmapMutex.leave(&hGlobalMapMutex); 191 } 192 //****************************************************************************** 193 //If memory map has no more views left, then we can safely delete it when 194 //it's handle is closed 195 //****************************************************************************** 196 void Win32MemMap::close() 197 { 198 fClosed = TRUE; 199 if(nrMappings == 0) { 200 delete this; 201 } 190 202 } 191 203 //****************************************************************************** … … 205 217 206 218 if(image) { 207 219 return image->commitPage(pageAddr, fWriteAccess); 208 220 } 209 221 newProt = mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY); 210 222 211 223 dprintf(("Win32MemMap::commitPage %x (faultaddr %x)", pageAddr, lpPageFaultAddr)); 212 if(hMemFile != -1) 224 if(hMemFile != -1) 213 225 { 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 226 int faultsize = nrpages*PAGE_SIZE; 227 228 offset = pageAddr - (ULONG)pMapping; 229 if(offset + faultsize > mSize) { 230 faultsize = mSize - offset; 231 } 232 233 while(faultsize) { 234 if(VirtualQuery((LPSTR)pageAddr, &memInfo, sizeof(MEMORY_BASIC_INFORMATION)) == 0) { 235 dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed for %x", pageAddr, nrpages*PAGE_SIZE)); 236 goto fail; 237 } 238 memInfo.RegionSize = min(memInfo.RegionSize, faultsize); 239 //Only changes the state of the pages with the same attribute flags 240 //(returned in memInfo.RegionSize) 241 //If it's smaller than the mNrPages, it simply means one or more of the 242 //other pages have already been committed 243 if(!(memInfo.State & MEM_COMMIT)) 244 { 245 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, PAGE_READWRITE) == FALSE) { 246 goto fail; 247 } 248 if(!fWriteAccess) { 249 offset = pageAddr - (ULONG)pMapping; 250 size = memInfo.RegionSize; 251 if(offset + size > mSize) { 252 dprintf(("Adjusting size from %d to %d", size, mSize - offset)); 253 size = mSize - offset; 254 } 255 if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) { 256 dprintf(("Win32MemMap::commitPage: SetFilePointer failed to set pos to %x", offset)); 257 goto fail; 258 } 259 if(ReadFile(hMemFile, (LPSTR)pageAddr, size, &nrBytesRead, NULL) == FALSE) { 260 dprintf(("Win32MemMap::commitPage: ReadFile failed for %x", pageAddr)); 261 goto fail; 262 } 263 if(nrBytesRead != size) { 264 dprintf(("Win32MemMap::commitPage: ReadFile didn't read all bytes for %x", pageAddr)); 265 goto fail; 266 } 267 } 268 if(newProt != PAGE_READWRITE) { 269 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) { 270 goto fail; 271 } 272 } 273 } 274 faultsize -= memInfo.RegionSize; 275 pageAddr += memInfo.RegionSize; 276 } 265 277 } 266 278 else { 267 268 while(sizeleft) 269 270 271 272 273 274 275 276 277 278 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, newProt) == FALSE) 279 280 281 282 283 284 279 ULONG sizeleft = nrpages*PAGE_SIZE; 280 while(sizeleft) 281 { 282 if(VirtualQuery((LPSTR)pageAddr, &memInfo, sizeof(MEMORY_BASIC_INFORMATION)) == 0) { 283 dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed", pageAddr, sizeleft)); 284 goto fail; 285 } 286 memInfo.RegionSize = min(memInfo.RegionSize, sizeleft); 287 288 if(!(memInfo.State & MEM_COMMIT)) 289 {//if it's already committed, then the app tried to write to it 290 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, newProt) == FALSE) 291 goto fail; 292 } 293 memInfo.RegionSize = (memInfo.RegionSize+PAGE_SIZE-1) & ~0xfff; 294 pageAddr += memInfo.RegionSize; 295 sizeleft -= memInfo.RegionSize; 296 } 285 297 } 286 298 … … 299 311 300 312 if(nrMappings == 0) 301 313 goto fail; 302 314 303 315 delete view; 304 316 305 317 if(--nrMappings == 0) { 306 307 318 VirtualFree(pMapping, mSize, MEM_RELEASE); 319 pMapping = NULL; 308 320 } 309 321 mapMutex.leave(); 310 322 311 323 //if there are no more mappings left and the memory map's handle has been 312 324 //closed, then delete the object 313 325 if(nrMappings == 0 && fClosed) { 314 326 delete this; 315 327 } 316 328 return TRUE; 317 329 fail: 318 330 mapMutex.leave(); 331 if(nrMappings == 0 && fClosed) { 332 delete this; 333 } 319 334 return FALSE; 320 335 } … … 333 348 // Docs say FILE_MAP_ALL_ACCESS is same as FILE_MAP_WRITE. Doesn't match reality though. 334 349 if(fdwAccess & ~FILE_MAP_ALL_ACCESS) 335 350 goto parmfail; 336 351 if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE)) 337 352 goto parmfail; 338 353 if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY))) 339 354 goto parmfail; 340 355 341 356 //@@@PH … … 345 360 346 361 if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hMemFile == -1)) 347 362 goto parmfail; 348 363 349 364 //SvL: TODO: Doesn't work for multiple views 350 365 if(offset+size > mSize) { 351 366 mSize = offset+size; 352 367 } 353 368 … … 355 370 #if 0 356 371 if(mProtFlags & SEC_COMMIT) 357 372 fAlloc |= MEM_COMMIT; 358 373 else 359 374 if(mProtFlags & SEC_RESERVE) 360 375 fAlloc |= MEM_RESERVE; 361 376 #else 362 377 fAlloc = MEM_RESERVE; … … 365 380 //Memory has already been allocated for executable image maps (only used internally) 366 381 if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view 367 368 369 382 //SvL: Always read/write access or else ReadFile will crash once we 383 // start committing pages. 384 // This is most likely an OS/2 bug and doesn't happen in Aurora 370 385 // when allocating memory with the PAG_ANY bit set. (without this 371 386 // flag it will also crash) 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 387 if(hMemFile == -1 && lpszMapName) { 388 pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName); 389 } 390 else { 391 pMapping = VirtualAlloc(0, mSize, fAlloc, PAGE_READWRITE); 392 } 393 if(pMapping == NULL) { 394 dprintf(("Win32MemMap::mapFileView: VirtualAlloc %x %x %x failed!", mSize, fAlloc, memFlags)); 395 goto fail; 396 } 397 //Windows NT seems to commit memory for memory maps, regardsless of the SEC_COMMIT flag 398 if((hMemFile == -1 && !image)) {//commit memory 399 VirtualAlloc(pMapping, mSize, MEM_COMMIT, PAGE_READWRITE); 400 } 401 if(hMemFile != -1 && (mProtFlags & SEC_COMMIT)) { 402 DWORD nrPages = mSize >> PAGE_SHIFT; 403 if(mSize & 0xFFF) 404 nrPages++; 405 406 commitPage(0, FALSE, nrPages); 407 } 393 408 } 394 409 mapview = new Win32MemMapView(this, offset, (size == 0) ? mSize : size, fdwAccess); 395 410 if(mapview == NULL) { 396 411 goto fail; 397 412 } 398 413 if(mapview->everythingOk() == FALSE) { 399 400 401 414 dprintf(("Win32MemMap::mapFileView: !mapview->everythingOk")); 415 delete mapview; 416 goto fail; 402 417 } 403 418 nrMappings++; … … 428 443 429 444 if(image) //no flushing for image maps 430 445 return TRUE; 431 446 432 447 dprintf(("Win32MemMap::flushView: %x %x", lpvBase, cbFlush)); 433 448 if(nrMappings == 0) 434 449 goto parmfail; 435 450 436 451 if(cbFlush == 0) 437 452 cbFlush = mSize; 438 453 439 454 if(lpvBase < pMapping || (ULONG)lpvBase+cbFlush > (ULONG)pMapping+mSize) 440 455 goto parmfail; 441 456 442 457 if(mProtFlags & PAGE_READONLY) 443 458 goto parmfail; 444 459 445 460 if(hMemFile == -1) 446 461 goto success; //TODO: Return an error here? 447 462 448 463 while(cbFlush) { 449 450 451 452 453 464 if(VirtualQuery((LPSTR)lpvBase, &memInfo, sizeof(MEMORY_BASIC_INFORMATION)) == 0) { 465 dprintf(("Win32MemMap::flushView: VirtualQuery (%x,%x) failed for %x", lpvBase, cbFlush, (ULONG)lpvBase+i*PAGE_SIZE)); 466 goto fail; 467 } 468 //If a page (or range of pages) is reserved or write protected, we 454 469 //won't bother flushing it to disk 455 470 if(memInfo.State & MEM_COMMIT && 456 471 memInfo.AllocationProtect & (PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)) 457 472 {//committed and allowed for writing? 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 473 offset = (ULONG)lpvBase - (ULONG)pMapping; 474 size = memInfo.RegionSize; 475 if(size > cbFlush) { 476 size = cbFlush; 477 } 478 dprintf(("Win32MemMap::flushView for offset %x, size %d", offset, size)); 479 480 if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) { 481 dprintf(("Win32MemMap::flushView: SetFilePointer failed to set pos to %x", offset)); 482 goto fail; 483 } 484 if(WriteFile(hMemFile, (LPSTR)lpvBase, size, &nrBytesWritten, NULL) == FALSE) { 485 dprintf(("Win32MemMap::flushView: WriteFile failed for %x", (ULONG)lpvBase)); 486 goto fail; 487 } 488 if(nrBytesWritten != size) { 489 dprintf(("Win32MemMap::flushView: WriteFile didn't write all bytes for %x", (ULONG)lpvBase)); 490 goto fail; 491 } 492 } 493 lpvBase = (LPVOID)((ULONG)lpvBase + memInfo.RegionSize); 494 495 if(cbFlush < memInfo.RegionSize) 496 break; 497 498 cbFlush -= memInfo.RegionSize; 484 499 } 485 500 success: … … 496 511 { 497 512 if(lpszName == NULL) 498 513 return NULL; 499 514 500 515 globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex); … … 502 517 503 518 if(map != NULL) { 504 505 506 507 508 519 while(map) { 520 if(map->lpszMapName && !strcmp(map->lpszMapName, lpszName)) 521 break; 522 map = map->next; 523 } 509 524 } 510 525 globalmapMutex.leave(&hGlobalMapMutex); … … 520 535 521 536 if(map != NULL) { 522 523 537 while(map) { 538 if(map->pMapping && (ULONG)map->pMapping <= address && 524 539 (ULONG)map->pMapping + map->mSize > address) 525 526 527 528 529 540 { 541 break; 542 } 543 map = map->next; 544 } 530 545 } 531 546 globalmapMutex.leave(&hGlobalMapMutex); … … 542 557 globalviewMutex.enter(); 543 558 while(map) { 544 545 546 547 548 549 550 551 if(!map->isClosed()) 552 553 554 555 556 557 558 Win32MemMapView::deleteViews(map);559 560 559 nextmap = map->next; 560 if(map->getProcessId() == processId) { 561 //Delete map directly for executable images (only used internally) 562 if(map->getImage()) { 563 delete map; 564 } 565 else { 566 if(!map->isClosed()) 567 CloseHandle(memmaps->hMemMap); 568 else delete map; 569 } 570 } 571 else { 572 //delete all views created by this process for this map 573 Win32MemMapView::deleteViews(map); 574 } 575 map = nextmap; 561 576 } 562 577 globalviewMutex.leave(); … … 579 594 switch(fdwAccess) { 580 595 case FILE_MAP_READ: 581 582 583 596 accessAttr = PAG_READ; 597 mfAccess = MEMMAP_ACCESS_READ; 598 break; 584 599 case FILE_MAP_ALL_ACCESS: 585 600 case FILE_MAP_WRITE: 586 601 case FILE_MAP_WRITE|FILE_MAP_READ: 587 602 case FILE_MAP_COPY: 588 589 590 603 accessAttr = (PAG_READ|PAG_WRITE); 604 mfAccess = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE; 605 break; 591 606 } 592 607 if(map->getMemName() != NULL && map->getFileHandle() == -1) { 593 594 595 596 597 598 599 600 } 601 608 //shared memory map, so map it into our address space 609 if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) { 610 dprintf(("new OSLibDosGetNamedSharedMem FAILED")); 611 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 612 errorState = 1; 613 return; 614 } 615 } 616 602 617 //view == memory mapping for executable images (only used internally) 603 618 if(map->getImage()) { 604 619 pMapView = map->getMappingAddr(); 605 620 } 606 621 else { 607 608 609 610 611 612 622 if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) { 623 dprintf(("new OSLibDosAliasMem FAILED")); 624 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 625 errorState = 1; 626 return; 627 } 613 628 } 614 629 … … 617 632 globalviewMutex.enter(); 618 633 if(tmpview == NULL || tmpview->getViewAddr() > pMapView) { 619 620 634 next = mapviews; 635 mapviews = this; 621 636 } 622 637 else { 623 624 625 626 627 628 629 630 638 while(tmpview->next) { 639 if(tmpview->next->getViewAddr() > pMapView) { 640 break; 641 } 642 tmpview = tmpview->next; 643 } 644 next = tmpview->next; 645 tmpview->next = this; 631 646 } 632 647 globalviewMutex.leave(); … … 637 652 { 638 653 if(errorState != 0) 639 654 return; 640 655 641 656 dprintf(("Win32MemMapView dtor: deleting view %x %x", mOffset, mSize)); 642 657 643 658 if(mfAccess & MEMMAP_ACCESS_WRITE) 644 659 mParentMap->flushView(mOffset, mSize); 645 660 646 661 //Don't free memory for executable image map views (only used internally) 647 662 if(!mParentMap->getImage()) 648 663 OSLibDosFreeMem(pMapView); 649 664 650 665 globalviewMutex.enter(); … … 652 667 653 668 if(view == this) { 654 669 mapviews = next; 655 670 } 656 671 else { 657 658 659 660 661 662 663 664 665 elsedprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));672 while(view->next) { 673 if(view->next == this) 674 break; 675 view = view->next; 676 } 677 if(view->next) { 678 view->next = next; 679 } 680 else dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this)); 666 681 } 667 682 globalviewMutex.leave(); … … 675 690 676 691 if(view != NULL) { 677 678 679 680 681 682 683 684 685 686 692 while(view) { 693 nextview = view->next; 694 if(view->getParentMap() == map) 695 { 696 globalviewMutex.leave(); 697 delete view; 698 globalviewMutex.enter(); 699 } 700 view = nextview; 701 } 687 702 } 688 703 globalviewMutex.leave(); … … 700 715 701 716 if(view != NULL) { 702 703 717 while(view && (ULONG)view->getViewAddr() <= address) { 718 if((ULONG)view->getViewAddr() <= address && 704 719 (ULONG)view->getViewAddr() + view->getSize() > address && 705 720 view->getAccessFlags() >= accessType) 706 707 708 709 710 711 712 713 721 { 722 *offset = view->getOffset() + (address - (ULONG)view->getViewAddr()); 723 goto success; 724 } 725 view = view->next; 726 } 727 //failure if we get here 728 view = NULL; 714 729 } 715 730 success: 716 731 if(view && !view->getParentMap()->isImageMap()) 717 732 dprintf(("findMapByView %x %x -> %x off %x", address, accessType, view->getViewAddr(), *offset)); 718 733 719 734 globalviewMutex.leave(); … … 729 744 globalviewMutex.enter(); 730 745 if(view != NULL) { 731 732 733 734 735 736 737 746 while(view) { 747 if(view->getViewAddr() == address) 748 { 749 break; 750 } 751 view = view->next; 752 } 738 753 } 739 754 globalviewMutex.leave(); -
trunk/src/kernel32/mmap.h
r3609 r4496 1 /* $Id: mmap.h,v 1.1 6 2000-05-26 18:42:56sandervl Exp $ */1 /* $Id: mmap.h,v 1.17 2000-10-18 17:09:33 sandervl Exp $ */ 2 2 3 3 /* … … 61 61 void Release() { if(--referenced == 0) delete this; }; 62 62 63 void close() { fClosed = TRUE; };63 void close(); 64 64 BOOL isClosed() { return fClosed; }; 65 65 -
trunk/src/kernel32/process.cpp
r3074 r4496 1 /* $Id: process.cpp,v 1. 6 2000-03-10 16:12:00sandervl Exp $ */1 /* $Id: process.cpp,v 1.7 2000-10-18 17:09:33 sandervl Exp $ */ 2 2 3 3 /* … … 69 69 //****************************************************************************** 70 70 //****************************************************************************** 71 BOOL WIN32API GetExitCodeProcess(HANDLE arg1, LPDWORD arg2)71 BOOL WIN32API GetExitCodeProcess(HANDLE hProcess, LPDWORD arg2) 72 72 { 73 73 BOOL rc; 74 74 75 rc = O32_GetExitCodeProcess( arg1, arg2);76 dprintf(("KERNEL32: GetExitCodeProcess returned %d (%x)", rc, (arg2) ? *arg2 : 0));75 rc = O32_GetExitCodeProcess(hProcess, arg2); 76 dprintf(("KERNEL32: GetExitCodeProcess %x returned %d (%x)", hProcess, rc, (arg2) ? *arg2 : 0)); 77 77 return rc; 78 78 } -
trunk/src/kernel32/registry.cpp
r4398 r4496 1 /* $Id: registry.cpp,v 1. 4 2000-10-02 22:17:33 sandervl Exp $ */1 /* $Id: registry.cpp,v 1.5 2000-10-18 17:09:33 sandervl Exp $ */ 2 2 3 3 /* … … 644 644 LONG rc; 645 645 646 rc = O32_RegOpenKeyEx(ConvertKey(arg1),647 astring,648 arg3,649 arg4,650 arg5);646 rc = CALL_ODINFUNC(RegOpenKeyExA)(ConvertKey(arg1), 647 astring, 648 arg3, 649 arg4, 650 arg5); 651 651 //SvL: This fixes crashes in pmwinx.dll. (if an app doesn't check the 652 652 // return value and uses the whatever *arg5 contains) … … 800 800 LONG rc; 801 801 802 rc = O32_RegQueryValue(ConvertKey(hkey),803 astring1,804 (char *)lpszValue,805 pcbValue);802 rc = CALL_ODINFUNC(RegQueryValueA)(ConvertKey(hkey), 803 astring1, 804 (char *)lpszValue, 805 pcbValue); 806 806 if(rc == ERROR_SUCCESS) 807 807 { … … 837 837 LPDWORD,arg6) 838 838 { 839 dprintf(("ADVAPI32:Registry key=%s \n",840 arg2)); 839 dprintf(("ADVAPI32:Registry key=%s", arg2)); 840 841 841 return O32_RegQueryValueEx(ConvertKey(arg1), 842 842 arg2, … … 870 870 LONG rc; 871 871 872 rc = O32_RegQueryValueEx(ConvertKey(arg1),873 astring,874 arg3,875 arg4,876 arg5,877 arg6);872 rc = CALL_ODINFUNC(RegQueryValueExA)(ConvertKey(arg1), 873 astring, 874 arg3, 875 arg4, 876 arg5, 877 arg6); 878 878 FreeAsciiString(astring); 879 879 return(rc); -
trunk/src/kernel32/wprocess.cpp
r4486 r4496 1 /* $Id: wprocess.cpp,v 1.10 4 2000-10-16 11:05:15sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.105 2000-10-18 17:09:34 sandervl Exp $ */ 2 2 3 3 /* … … 792 792 * Endif 793 793 */ 794 //only call Open32 if dwFlags == 0 and (LX binary or win32k process)795 if( dwFlags == 0 && (!fPeLoader || fPE != ERROR_SUCCESS))794 //only call Open32 if LX binary or win32k process 795 if(!fPeLoader || fPE != ERROR_SUCCESS) 796 796 { 797 797 hDll = O32_LoadLibrary(szModname); … … 806 806 ((Win32LxDll *)pModule)->setDllHandleOS2(hDll); 807 807 if(fPeLoader) 808 {808 { 809 809 if(pModule->AddRef() == -1) {//-1 -> load failed (attachProcess) 810 dprintf(("Dll %s refused to be loaded; aborting", szModname));811 delete pModule;812 return 0;813 }810 dprintf(("Dll %s refused to be loaded; aborting", szModname)); 811 delete pModule; 812 return 0; 813 } 814 814 } 815 815 } … … 924 924 SetLastError(ERROR_DLL_INIT_FAILED); 925 925 delete peldrDll; 926 return NULL;926 return NULL; 927 927 } 928 928 } … … 933 933 SetLastError(ERROR_INVALID_EXE_SIGNATURE); 934 934 delete peldrDll; 935 return NULL;935 return NULL; 936 936 } 937 937 } … … 941 941 lpszLibFile, hFile, dwFlags, szModname, fPE)); 942 942 SetLastError(fPE); 943 return NULL;943 return NULL; 944 944 } 945 945
Note:
See TracChangeset
for help on using the changeset viewer.