Changeset 271 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Jul 5, 1999, 11:58:14 AM (26 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.