- Timestamp:
- Jul 5, 1999, 11:58:14 AM (26 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r114 r271 1 /* $Id: HandleManager.cpp,v 1. 4 1999-06-17 21:52:00phaller Exp $ */1 /* $Id: HandleManager.cpp,v 1.5 1999-07-05 09:58:14 phaller Exp $ */ 2 2 3 3 /* … … 59 59 60 60 /* this is the size of our currently static handle table */ 61 #define MAX_OS2_HMHANDLES 256 62 63 /* this is for the handle translation table, could by dynamic though */ 64 #define MAX_TRANSLATION_HANDLES 8192 65 61 #define MAX_OS2_HMHANDLES 1024 66 62 67 63 … … 129 125 HMDeviceHandler *pHMOpen32; /* default handle manager instance */ 130 126 131 132 127 ULONG ulHandleLast; /* index of last used handle */ 133 HMTRANSHANDLE TabTranslationHandles[MAX_TRANSLATION_HANDLES];134 128 } HMGlobals; 135 129 … … 143 137 144 138 /* get next free handle from the handle table */ 145 static int_HMHandleGetFree(void);139 static ULONG _HMHandleGetFree(void); 146 140 147 141 /* get handle table entry from handle */ 148 static int_HMHandleQuery(HANDLE hHandle);142 static ULONG _HMHandleQuery(HANDLE hHandle); 149 143 150 144 … … 193 187 *****************************************************************************/ 194 188 195 static int_HMHandleGetFree(void)196 { 197 int iLoop;198 199 for ( iLoop = 0;200 iLoop < MAX_OS2_HMHANDLES;201 iLoop++)202 { 203 /* free handle found ? */204 if ( 0 == TabWin32Handles[iLoop].hmHandleData.hHMHandle)205 return ( iLoop); /* OK, then return it to the caller */206 } 207 208 return ( -1);/* haven't found any free handle */189 static ULONG _HMHandleGetFree(void) 190 { 191 register ULONG ulLoop; 192 193 for (ulLoop = 0; 194 ulLoop < MAX_OS2_HMHANDLES; 195 ulLoop++) 196 { 197 /* free handle found ? */ 198 if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) 199 return (ulLoop); /* OK, then return it to the caller */ 200 } 201 202 return (INVALID_HANDLE_VALUE); /* haven't found any free handle */ 209 203 } 210 204 … … 223 217 *****************************************************************************/ 224 218 225 static int _HMHandleQuery(HANDLE hHandle) 226 { 227 ULONG ulIndex; /* index into the handle table */ 228 229 /* check the handle */ 230 ulIndex = hHandle & ~HM_HANDLE_MASK; /* mask out the signature bits */ 231 if (ulIndex != HM_HANDLE_ID) /* one of our handles ? */ 232 return (-1); /* nope, ERROR_INVALID_HANDLE */ 233 234 ulIndex = hHandle & HM_HANDLE_MASK; /* get the relevant bits */ 235 if (ulIndex > MAX_OS2_HMHANDLES) /* check the table range */ 236 return (-1); /* nope, ERROR_INVALID_HANDLE */ 219 static ULONG _HMHandleQuery(HANDLE hHandle) 220 { 221 if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */ 222 return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 237 223 238 224 /* Oops, invalid handle ! */ 239 if ( TabWin32Handles[ulIndex].hmHandleData.hHMHandle != hHandle)240 return ( -1);/* nope, ERROR_INVALID_HANDLE */241 242 return ( (int) ulIndex);/* OK, we've got our handle index */225 if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle) 226 return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 227 228 return ( hHandle); /* OK, we've got our handle index */ 243 229 } 244 230 … … 258 244 259 245 DWORD HMDeviceRegister(PSZ pszDeviceName, 260 246 HMDeviceHandler *pDeviceHandler) 261 247 { 262 248 PHMDEVICE pHMDevice; /* our new device to be allocated */ … … 302 288 DWORD HMInitialize(void) 303 289 { 290 ULONG ulIndex; 291 304 292 if (HMGlobals.fIsInitialized != TRUE) 305 293 { 306 294 HMGlobals.fIsInitialized = TRUE; /* OK, done */ 295 296 // fill handle table 297 for (ulIndex = 0; 298 ulIndex < MAX_OS2_HMHANDLES; 299 ulIndex++) 300 TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 307 301 308 302 dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n")); … … 369 363 370 364 DWORD HMHandleAllocate (PULONG phHandle16, 371 ULONG hHandle32)365 ULONG hHandleOS2) 372 366 { 373 367 register ULONG ulHandle; … … 376 370 dprintf(("KERNEL32: HMHandleAllocate (%08xh,%08xh)\n", 377 371 phHandle16, 378 hHandle 32));372 hHandleOS2)); 379 373 #endif 380 374 … … 384 378 { 385 379 /* check if handle is free */ 386 if ( HMGlobals.TabTranslationHandles[ulHandle].hHandle32 == 0)380 if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE) 387 381 { 388 382 *phHandle16 = ulHandle; 389 HMGlobals.TabTranslationHandles[ulHandle].hHandle32 = hHandle32;383 TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2; 390 384 HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */ 391 385 … … 395 389 ulHandle++; /* skip to next entry */ 396 390 397 if (ulHandle >= MAX_ TRANSLATION_HANDLES)/* check boundary */391 if (ulHandle >= MAX_OS2_HMHANDLES) /* check boundary */ 398 392 ulHandle = 0; 399 393 } … … 430 424 return (rc); /* raise error condition */ 431 425 432 HMGlobals.TabTranslationHandles[hHandle16].hHandle32 = 0; /* OK, done */ 426 TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 427 /* OK, done */ 433 428 434 429 return (NO_ERROR); … … 455 450 #endif 456 451 457 if (hHandle16 >= MAX_ TRANSLATION_HANDLES)/* check boundary */452 if (hHandle16 >= MAX_OS2_HMHANDLES) /* check boundary */ 458 453 return (ERROR_INVALID_HANDLE); /* raise error condition */ 459 454 460 if (HMGlobals.TabTranslationHandles[hHandle16].hHandle32 == 0) /* valid ? */ 455 if (TabWin32Handles[hHandle16].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE) 456 /* valid ? */ 461 457 return (ERROR_INVALID_HANDLE); /* raise error condition */ 462 458 … … 478 474 *****************************************************************************/ 479 475 480 DWORD HMHandleTranslateToWin (ULONG hHandle 32,481 476 DWORD HMHandleTranslateToWin (ULONG hHandleOS2, 477 PULONG phHandle16) 482 478 { 483 479 ULONG rc; /* API returncode */ … … 486 482 #ifdef DEBUG_LOCAL 487 483 dprintf(("KERNEL32: HMHandleTranslateToWin (%08xh, %08xh)\n", 488 hHandle 32,484 hHandleOS2, 489 485 phHandle16)); 490 486 #endif 491 487 492 488 for (ulIndex = 0; 493 ulIndex < MAX_ TRANSLATION_HANDLES;489 ulIndex < MAX_OS2_HMHANDLES; 494 490 ulIndex++) 495 491 { 496 492 /* look for the handle */ 497 if ( HMGlobals.TabTranslationHandles[ulIndex].hHandle32 == hHandle32)493 if (TabWin32Handles[ulIndex].hmHandleData.hHMHandle == hHandleOS2) 498 494 { 499 495 *phHandle16 = ulIndex; /* deliver result */ … … 520 516 521 517 DWORD HMHandleTranslateToOS2 (ULONG hHandle16, 522 PULONG phHandle32)518 PULONG phHandleOS2) 523 519 { 524 520 #ifdef DEBUG_LOCAL 525 521 dprintf(("KERNEL32: HMHandleTranslateToOS2 (%08xh, %08xh)\n", 526 522 hHandle16, 527 phHandle 32));523 phHandleOS2)); 528 524 #endif 529 525 530 526 if (HMHandleValidate(hHandle16) == NO_ERROR) /* verify handle */ 531 527 { 532 *phHandle 32 = HMGlobals.TabTranslationHandles[hHandle16].hHandle32;528 *phHandleOS2 = TabWin32Handles[hHandle16].hmHandleData.hHMHandle; 533 529 return (NO_ERROR); 534 530 } … … 557 553 #endif 558 554 559 return( HMGlobals.TabTranslationHandles[hHandle16].hHandle32);555 return(TabWin32Handles[hHandle16].hmHandleData.hHMHandle); 560 556 } 561 557 … … 708 704 709 705 /* write appropriate entry into the handle table if open succeeded */ 710 hResult = (ULONG)iIndexNew | HM_HANDLE_ID; 711 HMHandleTemp.hHMHandle = hResult; 706 HMHandleTemp.hHMHandle = iIndexNew; 712 707 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 713 708 … … 746 741 dprintf(("KERNEL32/HandleManager: CreateFile(%s)=%08xh\n", 747 742 lpFileName, 748 hResult));743 iIndexNew)); 749 744 #endif 750 745 751 return hResult;/* return valid handle */746 return (HFILE)iIndexNew; /* return valid handle */ 752 747 } 753 748 … … 786 781 case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break; 787 782 case OF_SHARE_DENY_READ: *sharing = FILE_SHARE_WRITE; break; 788 783 case OF_SHARE_DENY_NONE: 789 784 case OF_SHARE_COMPAT: 790 785 default: *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break; … … 799 794 int iIndexNew; /* index into the handle table */ 800 795 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 801 HANDLE hResult;802 796 PHMHANDLEDATA pHMHandleData; 803 797 DWORD rc; /* API return code */ … … 839 833 840 834 /* write appropriate entry into the handle table if open succeeded */ 841 hResult = (ULONG)iIndexNew | HM_HANDLE_ID; 842 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = hResult; 835 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 843 836 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 844 837 … … 849 842 850 843 #ifdef DEBUG_LOCAL 851 dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh \n",844 dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh rc=%08xh\n", 852 845 lpFileName, 853 HMHandleTemp.lpHandlerData)); 846 &TabWin32Handles[iIndexNew].hmHandleData.lpHandlerData, 847 rc)); 854 848 #endif 855 849 … … 867 861 #endif 868 862 869 return hResult;/* return valid handle */863 return iIndexNew; /* return valid handle */ 870 864 } 871 865 -
trunk/src/kernel32/hmdevice.h
r111 r271 1 /* $Id: hmdevice.h,v 1. 1 1999-06-17 18:21:43phaller Exp $ */1 /* $Id: hmdevice.h,v 1.2 1999-07-05 09:58:14 phaller Exp $ */ 2 2 3 3 /* … … 25 25 * Structures * 26 26 *****************************************************************************/ 27 28 typedef struct _HMHANDLEDATA 29 { 30 HANDLE hHMHandle; /* a copy of the OS/2 system handle */ 31 32 DWORD dwType; /* handle type identifier */ 33 34 DWORD dwAccess; /* access mode of the handle */ 35 DWORD dwShare; /* share mode of the handle */ 36 DWORD dwCreation; /* dwCreationDisposition */ 37 DWORD dwFlags; /* flags and attributes */ 38 39 LPVOID lpHandlerData; /* for private use of the device handler */ 40 } HMHANDLEDATA, *PHMHANDLEDATA; 41 42 27 43 28 44 class HMDeviceHandler -
trunk/src/kernel32/hmopen32.cpp
r269 r271 1 /* $Id: hmopen32.cpp,v 1. 6 1999-07-05 07:55:10phaller Exp $ */1 /* $Id: hmopen32.cpp,v 1.7 1999-07-05 09:58:14 phaller Exp $ */ 2 2 3 3 /* … … 108 108 // create from template 109 109 if (pHMHandleDataTemplate != NULL) 110 hTemplate = pHMHandleDataTemplate->h WinHandle;110 hTemplate = pHMHandleDataTemplate->hHMHandle; 111 111 else 112 112 hTemplate = 0; … … 122 122 if (hFile != INVALID_HANDLE_ERROR) 123 123 { 124 pHMHandleData->h WinHandle = hFile;124 pHMHandleData->hHMHandle = hFile; 125 125 return (NO_ERROR); 126 126 } … … 147 147 148 148 dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle(%08x)\n", 149 pHMHandleData->h WinHandle));150 151 bRC = O32_CloseHandle(pHMHandleData->h WinHandle);149 pHMHandleData->hHMHandle)); 150 151 bRC = O32_CloseHandle(pHMHandleData->hHMHandle); 152 152 153 153 dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle returned %08xh\n", … … 190 190 lpOverlapped)); 191 191 192 bRC = O32_ReadFile(pHMHandleData->h WinHandle,192 bRC = O32_ReadFile(pHMHandleData->hHMHandle, 193 193 (PVOID)lpBuffer, 194 194 nNumberOfBytesToRead, … … 235 235 lpOverlapped)); 236 236 237 bRC = O32_WriteFile(pHMHandleData->h WinHandle,237 bRC = O32_WriteFile(pHMHandleData->hHMHandle, 238 238 lpBuffer, 239 239 nNumberOfBytesToWrite, … … 266 266 pHMHandleData)); 267 267 268 return O32_GetFileType(pHMHandleData->h WinHandle);268 return O32_GetFileType(pHMHandleData->hHMHandle); 269 269 } 270 270 … … 291 291 pHFI)); 292 292 293 return O32_GetFileInformationByHandle(pHMHandleData->h WinHandle,293 return O32_GetFileInformationByHandle(pHMHandleData->hHMHandle, 294 294 pHFI); 295 295 } … … 314 314 pHMHandleData)); 315 315 316 return O32_SetEndOfFile(pHMHandleData->h WinHandle);316 return O32_SetEndOfFile(pHMHandleData->hHMHandle); 317 317 } 318 318 … … 345 345 pFT3)); 346 346 347 return O32_SetFileTime(pHMHandleData->h WinHandle,347 return O32_SetFileTime(pHMHandleData->hHMHandle, 348 348 pFT1, 349 349 pFT2, … … 373 373 pSize)); 374 374 375 return O32_GetFileSize(pHMHandleData->h WinHandle,375 return O32_GetFileSize(pHMHandleData->hHMHandle, 376 376 pSize); 377 377 } … … 405 405 dwMoveMethod)); 406 406 407 return O32_SetFilePointer(pHMHandleData->h WinHandle,407 return O32_SetFilePointer(pHMHandleData->hHMHandle, 408 408 lDistanceToMove, 409 409 lpDistanceToMoveHigh, … … 442 442 arg5)); 443 443 444 return O32_LockFile(pHMHandleData->h WinHandle,444 return O32_LockFile(pHMHandleData->hHMHandle, 445 445 arg2, 446 446 arg3, … … 486 486 487 487 488 return(O32_LockFile(pHMHandleData->h WinHandle,488 return(O32_LockFile(pHMHandleData->hHMHandle, 489 489 lpOverlapped->Offset, 490 490 lpOverlapped->OffsetHigh, … … 540 540 if (hFile != INVALID_HANDLE_ERROR) 541 541 { 542 pHMHandleData->hWinHandle = hFile; 542 pHMHandleData->hHMHandle = hFile; 543 543 544 GetFileTime(hFile, 544 545 NULL, … … 551 552 filedatetime, 552 553 sizeof(pOFStruct->reserved) ); 554 553 555 return (NO_ERROR); 554 556 } 555 557 556 558 // error branch 557 hFile = O32_GetLastError(); 558 pOFStruct->nErrCode = hFile; 559 pOFStruct->nErrCode = O32_GetLastError(); 559 560 dprintf(("KERNEL32: HandleManager::Open32::OpenFile Error %08xh\n", 560 561 pOFStruct->nErrCode)); 561 562 563 // return != NO_ERROR => error code 562 564 return(hFile); 563 565 } … … 594 596 arg5)); 595 597 596 return O32_UnlockFile(pHMHandleData->h WinHandle,598 return O32_UnlockFile(pHMHandleData->hHMHandle, 597 599 arg2, 598 600 arg3, … … 637 639 lpOverlapped)); 638 640 639 return(O32_UnlockFile(pHMHandleData->h WinHandle,641 return(O32_UnlockFile(pHMHandleData->hHMHandle, 640 642 lpOverlapped->Offset, 641 643 lpOverlapped->OffsetHigh,
Note:
See TracChangeset
for help on using the changeset viewer.