Ignore:
Timestamp:
Aug 24, 1999, 8:48:10 PM (26 years ago)
Author:
sandervl
Message:

Memory mapped file changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/HandleManager.cpp

    r659 r664  
    1 /* $Id: HandleManager.cpp,v 1.12 1999-08-24 14:36:04 phaller Exp $ */
     1/* $Id: HandleManager.cpp,v 1.13 1999-08-24 18:46:38 sandervl Exp $ */
    22
    33/*
     
    5656#include "HMMutex.h"
    5757#include "HMSemaphore.h"
    58 #include "HMFileMapping.h"
    59 
     58#include "HMMMap.h"
    6059
    6160/*****************************************************************************
     
    122121  HMDeviceHandler        *pHMMutex;
    123122  HMDeviceHandler        *pHMSemaphore;
    124   HMDeviceHandler        *pHMFileMapping;
     123  HMDeviceHandler        *pHMFileMapping;        /* static instances of subsystems */
    125124
    126125  ULONG         ulHandleLast;                   /* index of last used handle */
     
    197196  {
    198197                                                       /* free handle found ? */
    199     if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle)
    200       return (ulLoop);                    /* OK, then return it to the caller */
     198    if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) {
     199        TabWin32Handles[ulLoop].hmHandleData.dwUserData     = 0;
     200        TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
     201        return (ulLoop);                    /* OK, then return it to the caller */
     202    }
    201203  }
    202204
     
    313315
    314316                        /* create handle manager instance for Open32 handles */
    315     HMGlobals.pHMOpen32       = new HMDeviceOpen32Class("\\\\.\\");
    316     HMGlobals.pHMEvent        = new HMDeviceEventClass("\\\\EVENT\\");
    317     HMGlobals.pHMMutex        = new HMDeviceMutexClass("\\\\MUTEX\\");
    318     HMGlobals.pHMSemaphore    = new HMDeviceSemaphoreClass("\\\\SEM\\");
    319     HMGlobals.pHMFileMapping  = new HMDeviceFileMappingClass("\\\\FILEMAPPING\\");
     317    HMGlobals.pHMOpen32     = new HMDeviceOpen32Class("\\\\.\\");
     318    HMGlobals.pHMEvent      = new HMDeviceEventClass("\\\\EVENT\\");
     319    HMGlobals.pHMMutex      = new HMDeviceMutexClass("\\\\MUTEX\\");
     320    HMGlobals.pHMSemaphore  = new HMDeviceSemaphoreClass("\\\\SEM\\");
     321    HMGlobals.pHMFileMapping = new HMDeviceMemMapClass("\\\\MEMMAP\\");
    320322  }
    321323  return (NO_ERROR);
     
    21512153
    21522154/*****************************************************************************
    2153  * Name      : HMWaitForMultipleObjects
    2154  * Purpose   : router function for WaitForMultipleObjects
    2155  * Parameters:
    2156  * Variables :
    2157  * Result    :
    2158  * Remark    :
    2159  * Status    :
    2160  *
    2161  * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
    2162  *****************************************************************************/
    2163 
    2164 DWORD HMWaitForMultipleObjects (DWORD   cObjects,
    2165                                 PHANDLE lphObjects,
    2166                                 BOOL    fWaitAll,
    2167                                 DWORD   dwTimeout)
    2168 {
    2169   ULONG   ulIndex;
    2170   PHANDLE pArrayOfHandles;
    2171   PHANDLE pLoop1 = lphObjects;
    2172   PHANDLE pLoop2;
    2173   DWORD   rc;
    2174 
    2175   // allocate array for handle table
    2176   pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE));
    2177   if (pArrayOfHandles == NULL)
    2178   {
    2179     O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    2180     return WAIT_FAILED;
    2181   }
    2182   else
    2183     pLoop2 = pArrayOfHandles;
    2184 
    2185   // convert array to odin handles
    2186   for (ulIndex = 0;
    2187 
    2188        ulIndex < cObjects;
    2189 
    2190        ulIndex++,
    2191        pLoop1++,
    2192        pLoop2++)
    2193   {
    2194     rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
    2195                                  pLoop2);
    2196 
    2197     if (rc != NO_ERROR)
    2198     {
    2199       free (pArrayOfHandles);             // free memory
    2200       O32_SetLastError(ERROR_INVALID_HANDLE);
    2201       return (WAIT_FAILED);
    2202     }
    2203   }
    2204 
    2205   // OK, now forward to Open32.
    2206   // @@@PH: Note this will fail on handles that do NOT belong to Open32
    2207   //        but to i.e. the console subsystem!
    2208   rc = O32_WaitForMultipleObjects(cObjects,
    2209                                   pArrayOfHandles,
    2210                                   fWaitAll,
    2211                                   dwTimeout);
    2212 
    2213   free(pArrayOfHandles);                  // free memory
    2214   return (rc);                            // OK, done
    2215 }
    2216 
    2217 
    2218 /*****************************************************************************
    2219  * Name      : HMWaitForMultipleObjectsEx
    2220  * Purpose   : router function for WaitForMultipleObjectsEx
    2221  * Parameters:
    2222  * Variables :
    2223  * Result    :
    2224  * Remark    :
    2225  * Status    :
    2226  *
    2227  * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
    2228  *****************************************************************************/
    2229 
    2230 DWORD HMWaitForMultipleObjectsEx (DWORD   cObjects,
    2231                                   PHANDLE lphObjects,
    2232                                   BOOL    fWaitAll,
    2233                                   DWORD   dwTimeout,
    2234                                   BOOL    fAlertable)
    2235 {
    2236   // @@@PH: Note: fAlertable is ignored !
    2237   return (HMWaitForMultipleObjects(cObjects,
    2238                                    lphObjects,
    2239                                    fWaitAll,
    2240                                    dwTimeout));
    2241 }
    2242 
    2243 
    2244 /*****************************************************************************
    22452155 * Name      : HANDLE  HMCreateFileMapping
    22462156 * Purpose   : Wrapper for the CreateFileMapping() API
     
    23502260  }
    23512261
    2352 
    2353                            /* initialize the complete HMHANDLEDATA structure */
     2262  /* initialize the complete HMHANDLEDATA structure */
    23542263  pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
    23552264  pHMHandleData->dwType     = FILE_TYPE_UNKNOWN;      /* unknown handle type */
     
    23612270
    23622271
    2363       /* we've got to mark the handle as occupied here, since another device */
    2364                    /* could be created within the device handler -> deadlock */
    2365 
    2366           /* write appropriate entry into the handle table if open succeeded */
     2272  /* we've got to mark the handle as occupied here, since another device */
     2273  /* could be created within the device handler -> deadlock */
     2274
     2275  /* write appropriate entry into the handle table if open succeeded */
    23672276  TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
    23682277  TabWin32Handles[iIndexNew].pDeviceHandler         = pDeviceHandler;
     
    23702279                                                  /* call the device handler */
    23712280  rc = pDeviceHandler->OpenFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
     2281                                       fdwAccess,
    23722282                                       fInherit,
    23732283                                       lpName);
     
    23812291  return iIndexNew;                                   /* return valid handle */
    23822292}
    2383 
    2384 
    2385 /*****************************************************************************
    2386  * Name      : HMMapViewOfFile
    2387  * Purpose   : router function for MapViewOfFile
    2388  * Parameters:
    2389  * Variables :
    2390  * Result    :
    2391  * Remark    :
    2392  * Status    :
    2393  *
    2394  * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
    2395  *****************************************************************************/
    2396 
    2397 LPVOID HMMapViewOfFile(HANDLE hFileMappingObject,
    2398                        DWORD  dwDesiredAccess,
    2399                        DWORD  dwFileOffsetHigh,
    2400                        DWORD  dwFileOffsetLow,
    2401                        DWORD  dwNumberOfBytesToMap)
    2402 {
    2403   int       iIndex;                           /* index into the handle table */
    2404   LPVOID    lpResult;                /* result from the device handler's API */
    2405   PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
    2406 
    2407                                                           /* validate handle */
    2408   iIndex = _HMHandleQuery(hFileMappingObject);              /* get the index */
    2409   if (-1 == iIndex)                                               /* error ? */
    2410   {
    2411     SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
    2412     return (NULL);                                         /* signal failure */
    2413   }
    2414 
    2415   pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
    2416   lpResult = pHMHandle->pDeviceHandler->MapViewOfFile(&pHMHandle->hmHandleData,
    2417                                                       dwDesiredAccess,
    2418                                                       dwFileOffsetHigh,
    2419                                                       dwFileOffsetLow,
    2420                                                       dwNumberOfBytesToMap);
    2421 
    2422   return (lpResult);                                  /* deliver return code */
    2423 }
    2424 
    24252293
    24262294
     
    24582326  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
    24592327  lpResult = pHMHandle->pDeviceHandler->MapViewOfFileEx(&pHMHandle->hmHandleData,
    2460                                                         dwDesiredAccess,
    2461                                                         dwFileOffsetHigh,
    2462                                                         dwFileOffsetLow,
    2463                                                         dwNumberOfBytesToMap,
    2464                                                         lpBaseAddress);
     2328                                                      dwDesiredAccess,
     2329                                                      dwFileOffsetHigh,
     2330                                                      dwFileOffsetLow,
     2331                                                      dwNumberOfBytesToMap,
     2332                                                      lpBaseAddress);
    24652333
    24662334  return (lpResult);                                  /* deliver return code */
    24672335}
    24682336
    2469 
    2470 /*****************************************************************************
    2471  * Name      : HMUnmapViewOfFile
    2472  * Purpose   : router function for UnmapViewOfFile
    2473  * Parameters:
    2474  * Variables :
    2475  * Result    :
    2476  * Remark    : No handle is specified, that makes things a bit more difficult!
    2477  *             We've got to identify the object by the base address and check
    2478  *             back with HandleManager manually!
     2337/*****************************************************************************
     2338 * Name      : HMWaitForMultipleObjects
     2339 * Purpose   : router function for WaitForMultipleObjects
     2340 * Parameters:
     2341 * Variables :
     2342 * Result    :
     2343 * Remark    :
    24792344 * Status    :
    24802345 *
     
    24822347 *****************************************************************************/
    24832348
    2484 BOOL HMUnmapViewOfFile(LPVOID lpBaseAddress)
    2485 {
    2486   int       iIndex;                           /* index into the handle table */
    2487   BOOL      flResult;                /* result from the device handler's API */
    2488   PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
    2489 
    2490   // Identify the correct handle by the base address. Thus call a special
    2491   // static function within the FileMapping class.
    2492   iIndex = HMDeviceFileMappingClass::findByBaseAddress(lpBaseAddress);                                                          /* validate handle */
    2493   if (-1 == iIndex)                                               /* error ? */
    2494   {
    2495     SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
    2496     return (FALSE);                                        /* signal failure */
    2497   }
    2498 
    2499   flResult = pHMHandle->pDeviceHandler->UnmapViewOfFile(&pHMHandle->hmHandleData,
    2500                                                         lpBaseAddress);
    2501 
    2502   // @@@PH automatically call CloseHandle of no more references to the object
    2503   //       are active.
    2504 
    2505   return (flResult);                                  /* deliver return code */
    2506 }
    2507 
    2508 
    2509 /*****************************************************************************
    2510  * Name      : HMFlushViewOfFile
    2511  * Purpose   : router function for FlushViewOfFile
    2512  * Parameters:
    2513  * Variables :
    2514  * Result    :
    2515  * Remark    : No handle is specified, that makes things a bit more difficult!
    2516  *             We've got to identify the object by the base address and check
    2517  *             back with HandleManager manually!
     2349DWORD HMWaitForMultipleObjects (DWORD   cObjects,
     2350                                PHANDLE lphObjects,
     2351                                BOOL    fWaitAll,
     2352                                DWORD   dwTimeout)
     2353{
     2354  ULONG   ulIndex;
     2355  PHANDLE pArrayOfHandles;
     2356  PHANDLE pLoop1 = lphObjects;
     2357  PHANDLE pLoop2;
     2358  DWORD   rc;
     2359
     2360  // allocate array for handle table
     2361  pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE));
     2362  if (pArrayOfHandles == NULL)
     2363  {
     2364    O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     2365    return WAIT_FAILED;
     2366  }
     2367  else
     2368    pLoop2 = pArrayOfHandles;
     2369
     2370  // convert array to odin handles
     2371  for (ulIndex = 0;
     2372
     2373       ulIndex < cObjects;
     2374
     2375       ulIndex++,
     2376       pLoop1++,
     2377       pLoop2++)
     2378  {
     2379    rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
     2380                                 pLoop2);
     2381
     2382    if (rc != NO_ERROR)
     2383    {
     2384      free (pArrayOfHandles);             // free memory
     2385      O32_SetLastError(ERROR_INVALID_HANDLE);
     2386      return (WAIT_FAILED);
     2387    }
     2388  }
     2389
     2390  // OK, now forward to Open32.
     2391  // @@@PH: Note this will fail on handles that do NOT belong to Open32
     2392  //        but to i.e. the console subsystem!
     2393  rc = O32_WaitForMultipleObjects(cObjects,
     2394                                  pArrayOfHandles,
     2395                                  fWaitAll,
     2396                                  dwTimeout);
     2397
     2398  free(pArrayOfHandles);                  // free memory
     2399  return (rc);                            // OK, done
     2400}
     2401
     2402
     2403/*****************************************************************************
     2404 * Name      : HMWaitForMultipleObjectsEx
     2405 * Purpose   : router function for WaitForMultipleObjectsEx
     2406 * Parameters:
     2407 * Variables :
     2408 * Result    :
     2409 * Remark    :
    25182410 * Status    :
    25192411 *
     
    25212413 *****************************************************************************/
    25222414
    2523 BOOL HMFlushViewOfFile(LPVOID lpBaseAddress,
    2524                        DWORD  dwNumberOfBytesToFlush)
    2525 {
    2526   int       iIndex;                           /* index into the handle table */
    2527   BOOL      flResult;                /* result from the device handler's API */
    2528   PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
    2529 
    2530   // Identify the correct handle by the base address. Thus call a special
    2531   // static function within the FileMapping class.
    2532   iIndex = HMDeviceFileMappingClass::findByBaseAddress(lpBaseAddress);                                                          /* validate handle */
    2533   if (-1 == iIndex)                                               /* error ? */
    2534   {
    2535     SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
    2536     return (FALSE);                                        /* signal failure */
    2537   }
    2538 
    2539   flResult = pHMHandle->pDeviceHandler->FlushViewOfFile(&pHMHandle->hmHandleData,
    2540                                                         lpBaseAddress,
    2541                                                         dwNumberOfBytesToFlush);
    2542 
    2543   return (flResult);                                  /* deliver return code */
    2544 }
     2415DWORD HMWaitForMultipleObjectsEx (DWORD   cObjects,
     2416                                  PHANDLE lphObjects,
     2417                                  BOOL    fWaitAll,
     2418                                  DWORD   dwTimeout,
     2419                                  BOOL    fAlertable)
     2420{
     2421  // @@@PH: Note: fAlertable is ignored !
     2422  return (HMWaitForMultipleObjects(cObjects,
     2423                                   lphObjects,
     2424                                   fWaitAll,
     2425                                   dwTimeout));
     2426}
     2427
Note: See TracChangeset for help on using the changeset viewer.