Changeset 271 for trunk/src


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

Fix: streamlined Handlemanager

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: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
  • trunk/src/kernel32/hmdevice.h

    r111 r271  
    1 /* $Id: hmdevice.h,v 1.1 1999-06-17 18:21:43 phaller Exp $ */
     1/* $Id: hmdevice.h,v 1.2 1999-07-05 09:58:14 phaller Exp $ */
    22
    33/*
     
    2525 * Structures                                                                *
    2626 *****************************************************************************/
     27
     28typedef 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
    2743
    2844class HMDeviceHandler
  • trunk/src/kernel32/hmopen32.cpp

    r269 r271  
    1 /* $Id: hmopen32.cpp,v 1.6 1999-07-05 07:55:10 phaller Exp $ */
     1/* $Id: hmopen32.cpp,v 1.7 1999-07-05 09:58:14 phaller Exp $ */
    22
    33/*
     
    108108  // create from template
    109109  if (pHMHandleDataTemplate != NULL)
    110      hTemplate = pHMHandleDataTemplate->hWinHandle;
     110     hTemplate = pHMHandleDataTemplate->hHMHandle;
    111111  else
    112112     hTemplate = 0;
     
    122122  if (hFile != INVALID_HANDLE_ERROR)
    123123  {
    124      pHMHandleData->hWinHandle = hFile;
     124     pHMHandleData->hHMHandle = hFile;
    125125     return (NO_ERROR);
    126126  }
     
    147147
    148148  dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle(%08x)\n",
    149            pHMHandleData->hWinHandle));
    150 
    151   bRC = O32_CloseHandle(pHMHandleData->hWinHandle);
     149           pHMHandleData->hHMHandle));
     150
     151  bRC = O32_CloseHandle(pHMHandleData->hHMHandle);
    152152
    153153  dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle returned %08xh\n",
     
    190190           lpOverlapped));
    191191
    192   bRC = O32_ReadFile(pHMHandleData->hWinHandle,
     192  bRC = O32_ReadFile(pHMHandleData->hHMHandle,
    193193                     (PVOID)lpBuffer,
    194194                     nNumberOfBytesToRead,
     
    235235           lpOverlapped));
    236236
    237   bRC = O32_WriteFile(pHMHandleData->hWinHandle,
     237  bRC = O32_WriteFile(pHMHandleData->hHMHandle,
    238238                      lpBuffer,
    239239                      nNumberOfBytesToWrite,
     
    266266           pHMHandleData));
    267267
    268   return O32_GetFileType(pHMHandleData->hWinHandle);
     268  return O32_GetFileType(pHMHandleData->hHMHandle);
    269269}
    270270
     
    291291           pHFI));
    292292
    293   return O32_GetFileInformationByHandle(pHMHandleData->hWinHandle,
     293  return O32_GetFileInformationByHandle(pHMHandleData->hHMHandle,
    294294                                        pHFI);
    295295}
     
    314314           pHMHandleData));
    315315
    316   return O32_SetEndOfFile(pHMHandleData->hWinHandle);
     316  return O32_SetEndOfFile(pHMHandleData->hHMHandle);
    317317}
    318318
     
    345345           pFT3));
    346346
    347   return O32_SetFileTime(pHMHandleData->hWinHandle,
     347  return O32_SetFileTime(pHMHandleData->hHMHandle,
    348348                         pFT1,
    349349                         pFT2,
     
    373373           pSize));
    374374
    375   return O32_GetFileSize(pHMHandleData->hWinHandle,
     375  return O32_GetFileSize(pHMHandleData->hHMHandle,
    376376                         pSize);
    377377}
     
    405405           dwMoveMethod));
    406406
    407   return O32_SetFilePointer(pHMHandleData->hWinHandle,
     407  return O32_SetFilePointer(pHMHandleData->hHMHandle,
    408408                            lDistanceToMove,
    409409                            lpDistanceToMoveHigh,
     
    442442           arg5));
    443443
    444   return O32_LockFile(pHMHandleData->hWinHandle,
     444  return O32_LockFile(pHMHandleData->hHMHandle,
    445445                      arg2,
    446446                      arg3,
     
    486486
    487487
    488   return(O32_LockFile(pHMHandleData->hWinHandle,
     488  return(O32_LockFile(pHMHandleData->hHMHandle,
    489489                      lpOverlapped->Offset,
    490490                      lpOverlapped->OffsetHigh,
     
    540540  if (hFile != INVALID_HANDLE_ERROR)
    541541  {
    542     pHMHandleData->hWinHandle = hFile;
     542    pHMHandleData->hHMHandle = hFile;
     543
    543544    GetFileTime(hFile,
    544545                NULL,
     
    551552           filedatetime,
    552553           sizeof(pOFStruct->reserved) );
     554
    553555    return (NO_ERROR);
    554556  }
    555557
    556558  // error branch
    557   hFile = O32_GetLastError();
    558   pOFStruct->nErrCode = hFile;
     559  pOFStruct->nErrCode = O32_GetLastError();
    559560  dprintf(("KERNEL32: HandleManager::Open32::OpenFile Error %08xh\n",
    560561            pOFStruct->nErrCode));
    561562
     563  // return != NO_ERROR => error code
    562564  return(hFile);
    563565}
     
    594596           arg5));
    595597
    596   return O32_UnlockFile(pHMHandleData->hWinHandle,
     598  return O32_UnlockFile(pHMHandleData->hHMHandle,
    597599                        arg2,
    598600                        arg3,
     
    637639           lpOverlapped));
    638640
    639   return(O32_UnlockFile(pHMHandleData->hWinHandle,
     641  return(O32_UnlockFile(pHMHandleData->hHMHandle,
    640642                   lpOverlapped->Offset,
    641643                   lpOverlapped->OffsetHigh,
Note: See TracChangeset for help on using the changeset viewer.