Ignore:
Timestamp:
Jul 5, 1999, 11:58:14 AM (26 years ago)
Author:
phaller
Message:

Fix: streamlined Handlemanager

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:00 phaller Exp $ */
     1/* $Id: HandleManager.cpp,v 1.5 1999-07-05 09:58:14 phaller Exp $ */
    22
    33/*
     
    5959
    6060                    /* 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
    6662
    6763
     
    129125  HMDeviceHandler *pHMOpen32;             /* default handle manager instance */
    130126
    131 
    132127  ULONG         ulHandleLast;                   /* index of last used handle */
    133   HMTRANSHANDLE TabTranslationHandles[MAX_TRANSLATION_HANDLES];
    134128} HMGlobals;
    135129
     
    143137
    144138                               /* get next free handle from the handle table */
    145 static int              _HMHandleGetFree(void);
     139static ULONG            _HMHandleGetFree(void);
    146140
    147141                                       /* get handle table entry from handle */
    148 static int              _HMHandleQuery(HANDLE hHandle);
     142static ULONG            _HMHandleQuery(HANDLE hHandle);
    149143
    150144
     
    193187 *****************************************************************************/
    194188
    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 */
     189static 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 */
    209203}
    210204
     
    223217 *****************************************************************************/
    224218
    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 */
     219static ULONG _HMHandleQuery(HANDLE hHandle)
     220{
     221  if (hHandle > MAX_OS2_HMHANDLES)                  /* check the table range */
     222    return (INVALID_HANDLE_VALUE);             /* nope, ERROR_INVALID_HANDLE */
    237223
    238224                                                   /* 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 */
    243229}
    244230
     
    258244
    259245DWORD   HMDeviceRegister(PSZ             pszDeviceName,
    260                                  HMDeviceHandler *pDeviceHandler)
     246                         HMDeviceHandler *pDeviceHandler)
    261247{
    262248  PHMDEVICE pHMDevice;                     /* our new device to be allocated */
     
    302288DWORD HMInitialize(void)
    303289{
     290  ULONG ulIndex;
     291
    304292  if (HMGlobals.fIsInitialized != TRUE)
    305293  {
    306294    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;
    307301
    308302    dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n"));
     
    369363
    370364DWORD  HMHandleAllocate (PULONG phHandle16,
    371                                  ULONG  hHandle32)
     365                         ULONG  hHandleOS2)
    372366{
    373367  register ULONG ulHandle;
     
    376370  dprintf(("KERNEL32: HMHandleAllocate (%08xh,%08xh)\n",
    377371           phHandle16,
    378            hHandle32));
     372           hHandleOS2));
    379373#endif
    380374
     
    384378  {
    385379                                                  /* check if handle is free */
    386     if (HMGlobals.TabTranslationHandles[ulHandle].hHandle32 == 0)
     380    if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
    387381    {
    388382      *phHandle16 = ulHandle;
    389       HMGlobals.TabTranslationHandles[ulHandle].hHandle32 = hHandle32;
     383      TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2;
    390384      HMGlobals.ulHandleLast = ulHandle;          /* to shorten search times */
    391385
     
    395389    ulHandle++;                                        /* skip to next entry */
    396390
    397     if (ulHandle >= MAX_TRANSLATION_HANDLES)               /* check boundary */
     391    if (ulHandle >= MAX_OS2_HMHANDLES)                     /* check boundary */
    398392      ulHandle = 0;
    399393  }
     
    430424    return (rc);                                    /* raise error condition */
    431425
    432   HMGlobals.TabTranslationHandles[hHandle16].hHandle32 = 0;      /* OK, done */
     426  TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     427                                                                 /* OK, done */
    433428
    434429  return (NO_ERROR);
     
    455450#endif
    456451
    457   if (hHandle16 >= MAX_TRANSLATION_HANDLES)                /* check boundary */
     452  if (hHandle16 >= MAX_OS2_HMHANDLES)                      /* check boundary */
    458453    return (ERROR_INVALID_HANDLE);                  /* raise error condition */
    459454
    460   if (HMGlobals.TabTranslationHandles[hHandle16].hHandle32 == 0)  /* valid ? */
     455  if (TabWin32Handles[hHandle16].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
     456                                                                  /* valid ? */
    461457    return (ERROR_INVALID_HANDLE);                  /* raise error condition */
    462458
     
    478474 *****************************************************************************/
    479475
    480 DWORD  HMHandleTranslateToWin (ULONG  hHandle32,
    481                                        PULONG phHandle16)
     476DWORD  HMHandleTranslateToWin (ULONG  hHandleOS2,
     477                               PULONG phHandle16)
    482478{
    483479           ULONG rc;                                       /* API returncode */
     
    486482#ifdef DEBUG_LOCAL
    487483  dprintf(("KERNEL32: HMHandleTranslateToWin (%08xh, %08xh)\n",
    488            hHandle32,
     484           hHandleOS2,
    489485           phHandle16));
    490486#endif
    491487
    492488  for (ulIndex = 0;
    493        ulIndex < MAX_TRANSLATION_HANDLES;
     489       ulIndex < MAX_OS2_HMHANDLES;
    494490       ulIndex++)
    495491  {
    496492                                                      /* look for the handle */
    497     if (HMGlobals.TabTranslationHandles[ulIndex].hHandle32 == hHandle32)
     493    if (TabWin32Handles[ulIndex].hmHandleData.hHMHandle == hHandleOS2)
    498494    {
    499495      *phHandle16 = ulIndex;                               /* deliver result */
     
    520516
    521517DWORD  HMHandleTranslateToOS2 (ULONG  hHandle16,
    522                                        PULONG phHandle32)
     518                               PULONG phHandleOS2)
    523519{
    524520#ifdef DEBUG_LOCAL
    525521  dprintf(("KERNEL32: HMHandleTranslateToOS2 (%08xh, %08xh)\n",
    526522           hHandle16,
    527            phHandle32));
     523           phHandleOS2));
    528524#endif
    529525
    530526  if (HMHandleValidate(hHandle16) == NO_ERROR)              /* verify handle */
    531527  {
    532     *phHandle32 = HMGlobals.TabTranslationHandles[hHandle16].hHandle32;
     528    *phHandleOS2 = TabWin32Handles[hHandle16].hmHandleData.hHMHandle;
    533529    return (NO_ERROR);
    534530  }
     
    557553#endif
    558554
    559   return(HMGlobals.TabTranslationHandles[hHandle16].hHandle32);
     555  return(TabWin32Handles[hHandle16].hmHandleData.hHMHandle);
    560556}
    561557
     
    708704
    709705          /* 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;
    712707  TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
    713708
     
    746741  dprintf(("KERNEL32/HandleManager: CreateFile(%s)=%08xh\n",
    747742           lpFileName,
    748            hResult));
     743           iIndexNew));
    749744#endif
    750745
    751   return hResult;                                     /* return valid handle */
     746  return (HFILE)iIndexNew;                             /* return valid handle */
    752747}
    753748
     
    786781      case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break;
    787782      case OF_SHARE_DENY_READ:  *sharing = FILE_SHARE_WRITE; break;
    788        case OF_SHARE_DENY_NONE:
     783      case OF_SHARE_DENY_NONE:
    789784      case OF_SHARE_COMPAT:
    790785      default:                  *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break;
     
    799794  int             iIndexNew;                  /* index into the handle table */
    800795  HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
    801   HANDLE          hResult;
    802796  PHMHANDLEDATA   pHMHandleData;
    803797  DWORD           rc;                                     /* API return code */
     
    839833
    840834          /* 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;
    843836  TabWin32Handles[iIndexNew].pDeviceHandler       = pDeviceHandler;
    844837
     
    849842
    850843#ifdef DEBUG_LOCAL
    851     dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh\n",
     844    dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh rc=%08xh\n",
    852845             lpFileName,
    853              HMHandleTemp.lpHandlerData));
     846             &TabWin32Handles[iIndexNew].hmHandleData.lpHandlerData,
     847             rc));
    854848#endif
    855849
     
    867861#endif
    868862
    869   return hResult;                                     /* return valid handle */
     863  return iIndexNew;                                   /* return valid handle */
    870864}
    871865
Note: See TracChangeset for help on using the changeset viewer.