- Timestamp:
- Aug 25, 1999, 5:27:20 PM (26 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/mmap.cpp
r690 r695 1 /* $Id: mmap.cpp,v 1.1 1 1999-08-25 14:27:07sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.12 1999-08-25 15:27:19 sandervl Exp $ */ 2 2 3 3 /* … … 150 150 151 151 dprintf(("Win32MemMap::commitPage %x (faultaddr %x), nr of pages %d", pageAddr, lpPageFaultAddr, nrpages)); 152 if(VirtualAlloc((LPVOID)pageAddr, nrpages*PAGE_SIZE, MEM_COMMIT, newProt) == FALSE) {153 goto fail;154 }155 152 if(hMemFile != -1) { 153 if(VirtualAlloc((LPVOID)pageAddr, nrpages*PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE) == FALSE) { 154 goto fail; 155 } 156 156 offset = pageAddr - (ULONG)pMapping; 157 157 size = nrpages*PAGE_SIZE; … … 171 171 goto fail; 172 172 } 173 if(mProtFlags & PAGE_READONLY) { 174 //DosSetMem returns flags with EXECUTE bit set, even though the initial allocation is without this bit set! 175 //Also returns access denied when trying to set it back to READONLY 176 VirtualProtect((LPVOID)pageAddr, nrpages*PAGE_SIZE, newProt, &oldProt); 177 // if(VirtualProtect((LPVOID)pageAddr, nrpages*PAGE_SIZE, newProt, &oldProt) == FALSE) { 178 // goto fail; 179 // } 180 } 181 } 182 else { 183 if(VirtualAlloc((LPVOID)pageAddr, nrpages*PAGE_SIZE, MEM_COMMIT, newProt) == FALSE) { 184 goto fail; 185 } 173 186 } 174 187 … … 224 237 225 238 if(fMapped == FALSE) {//if not mapped, reserve/commit entire view 226 pMapping = VirtualAlloc(0, mSize, fAlloc, m ProtFlags);239 pMapping = VirtualAlloc(0, mSize, fAlloc, memFlags); 227 240 if(pMapping == NULL) { 228 241 dprintf(("Win32MemMap::mapFileView: VirtualAlloc %x %x %x failed!", mSize, fAlloc, memFlags)); … … 255 268 256 269 // mapMutex.enter(); 270 dprintf(("Win32MemMap::flushView: %x %x", lpvBase, cbFlush)); 257 271 if(fMapped == FALSE) 258 272 goto parmfail; -
trunk/src/kernel32/winimage.cpp
r651 r695 1 /* $Id: winimage.cpp,v 1.1 5 1999-08-23 17:02:35sandervl Exp $ */1 /* $Id: winimage.cpp,v 1.16 1999-08-25 15:27:20 sandervl Exp $ */ 2 2 3 3 /* … … 36 36 #include "os2util.h" 37 37 #include "initterm.h" 38 #include <win\virtual.h> 38 39 39 40 char szErrorTitle[] = "Win32 for OS/2"; … … 192 193 BOOL Win32Image::init(ULONG reservedMem) 193 194 { 194 HFILE win32handle; 195 ULONG ulAction = 0; /* Action taken by DosOpen */ 196 ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */ 197 APIRET rc = NO_ERROR; /* Return code */ 195 HANDLE fImgMapping = 0; 198 196 char szErrorMsg[64]; 199 197 LPVOID win32file = NULL; … … 203 201 int nSections, i; 204 202 205 rc = DosOpen(szFileName, /* File path name */ 206 &win32handle, /* File handle */ 207 &ulAction, /* Action taken */ 208 0L, /* File primary allocation */ 209 0L, /* File attribute */ 210 OPEN_ACTION_FAIL_IF_NEW | 211 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */ 212 OPEN_FLAGS_NOINHERIT | 213 OPEN_SHARE_DENYNONE | 214 OPEN_ACCESS_READONLY, /* Open mode of the file */ 215 0L); /* No extended attribute */ 216 217 if (rc != NO_ERROR) { 203 fImgMapping = VIRTUAL_MapFileA(szFileName, &win32file); 204 205 if (fImgMapping == -1) { 218 206 sprintf(szErrorMsg, "Unable to open %32s\n", szFileName); 219 207 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 220 errorState = ERROR_INTERNAL; 221 return(FALSE); 222 } 223 224 /* Move the file pointer back to the beginning of the file */ 225 DosSetFilePtr(win32handle, 0L, FILE_BEGIN, &ulLocal); 226 DosSetFilePtr(win32handle, 0L, FILE_END, &filesize); 227 DosSetFilePtr(win32handle, 0L, FILE_BEGIN, &ulLocal); 228 229 win32file = malloc(filesize); 230 if(win32file == NULL) { 231 fout << "Error allocating memory" << endl; 232 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 233 DosClose(win32handle); /* Close the file */ 234 errorState = ERROR_INTERNAL; 235 return(FALSE); 236 } 237 rc = DosRead(win32handle, win32file, filesize, &ulRead); 238 if(rc != NO_ERROR) { 239 fout << "DosRead returned " << rc << endl; 240 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szFileErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 241 DosClose(win32handle); /* Close the file */ 242 errorState = ERROR_INTERNAL; 243 return(FALSE); 208 goto failure; 244 209 } 245 210 … … 247 212 fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl; 248 213 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 249 DosClose(win32handle); /* Close the file */ 250 errorState = ERROR_INTERNAL; 251 return(FALSE); 214 goto failure; 252 215 } 253 216 … … 255 218 fout << "Not a valid PE file!" << endl; 256 219 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 257 DosClose(win32handle); /* Close the file */ 258 errorState = ERROR_INTERNAL; 259 return(FALSE); 220 goto failure; 260 221 } 261 222 if(fh.Machine != IMAGE_FILE_MACHINE_I386) { 262 223 fout << "You need a REAL CPU to run this code" << endl; 263 224 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 264 DosClose(win32handle); /* Close the file */ 265 errorState = ERROR_INTERNAL; 266 return(FALSE); 225 goto failure; 267 226 } 268 227 //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)? … … 270 229 fout << "Can't convert system files" << endl; 271 230 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 272 DosClose(win32handle); /* Close the file */ 273 errorState = ERROR_INTERNAL; 274 return(FALSE); 231 goto failure; 275 232 } 276 233 … … 405 362 } 406 363 fout << "Unknown section" << endl; 407 errorState = ERROR_INTERNAL; 408 return(FALSE); 409 } 364 goto failure; 365 } 410 366 } 411 367 fout << "*************************PE SECTIONS END **************************" << endl; … … 422 378 if(allocSections(reservedMem) == FALSE) { 423 379 fout << "Failed to allocate image memory, rc " << errorState << endl; 424 return(FALSE);380 goto failure; 425 381 } 426 382 fout << "OS/2 base address " << realBaseAddress << endl; 427 383 if(storeSections((char *)win32file) == FALSE) { 428 384 fout << "Failed to store sections, rc " << errorState << endl; 429 return(FALSE);385 goto failure; 430 386 } 431 387 if(oh.AddressOfEntryPoint) { … … 442 398 if(sect == NULL) { 443 399 fout << "Couldn't find TLS section!!" << endl; 444 return(FALSE);400 goto failure; 445 401 } 446 402 setTLSAddress((char *)(sect->realvirtaddr + (tlsDir->StartAddressOfRawData - sect->virtaddr))); … … 451 407 if(sect == NULL) { 452 408 fout << "Couldn't find TLS AddressOfIndex section!!" << endl; 453 return(FALSE);409 goto failure; 454 410 } 455 411 setTLSIndexAddr((LPDWORD)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfIndex - sect->virtaddr))); … … 458 414 if(sect == NULL) { 459 415 fout << "Couldn't find TLS AddressOfCallBacks section!!" << endl; 460 return(FALSE);416 goto failure; 461 417 } 462 418 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr))); … … 466 422 if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) { 467 423 fout << "Failed to set fixups" << endl; 468 return(FALSE);424 goto failure; 469 425 } 470 426 } … … 472 428 if(processImports((char *)win32file) == FALSE) { 473 429 fout << "Failed to process imports!" << endl; 474 return(FALSE);430 goto failure; 475 431 } 476 432 … … 478 434 if(processExports((char *)win32file) == FALSE) { 479 435 fout << "Failed to process exported apis" << endl; 480 return(FALSE);436 goto failure; 481 437 } 482 438 } … … 494 450 if(setMemFlags() == FALSE) { 495 451 fout << "Failed to set memory protection" << endl; 496 return(FALSE); 497 } 498 499 //Now it's safe to free win32file 500 free(win32file); 501 DosClose(win32handle); /* Close the file */ 452 goto failure; 453 } 454 455 CloseHandle(fImgMapping); 502 456 return(TRUE); 457 failure: 458 if(fImgMapping) CloseHandle(fImgMapping); 459 errorState = ERROR_INTERNAL; 460 return FALSE; 503 461 } 504 462 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.