Changeset 10073 for trunk/src


Ignore:
Timestamp:
May 6, 2003, 2:06:11 PM (22 years ago)
Author:
sandervl
Message:

Fixed closing of parent file handle by duplicate memory map; Compare file names instead of handles when checking for duplicate file maps

Location:
trunk/src/kernel32
Files:
8 edited

Legend:

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

    r10071 r10073  
    1 /* $Id: HandleManager.cpp,v 1.101 2003-05-06 10:12:00 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.102 2003-05-06 12:06:07 sandervl Exp $ */
    22
    33/*
     
    14061406
    14071407/*****************************************************************************
     1408 * Name      : HANDLE  HMGetFileNameFromHandle
     1409 * Purpose   : Query the name of the file associated with the system handle (if any)
     1410 * Parameters:
     1411 * Variables :
     1412 * Result    :
     1413 * Remark    :
     1414 * Status    :
     1415 *
     1416 * Author    : SvL
     1417 *****************************************************************************/
     1418BOOL HMGetFileNameFromHandle(HANDLE hObject, LPSTR lpszFileName, DWORD cbFileName)
     1419{
     1420  int       iIndex;                           /* index into the handle table */
     1421  BOOL      fResult;       /* result from the device handler's CloseHandle() */
     1422  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1423
     1424
     1425  if(lpszFileName == NULL) {
     1426      DebugInt3();
     1427      SetLastError(ERROR_INVALID_PARAMETER);
     1428      return FALSE;
     1429  }
     1430                                                          /* validate handle */
     1431  iIndex = _HMHandleQuery(hObject);                         /* get the index */
     1432  if (-1 == iIndex)                                               /* error ? */
     1433  {
     1434    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1435    return (FALSE);                                        /* signal failure */
     1436  }
     1437
     1438  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1439  //SvL: Check if pDeviceHandler is set
     1440  if (pHMHandle->pDeviceHandler)
     1441  {
     1442    fResult = pHMHandle->pDeviceHandler->GetFileNameFromHandle(&pHMHandle->hmHandleData,
     1443                                                               lpszFileName, cbFileName);
     1444  }
     1445  else
     1446  {
     1447    dprintf(("HMGetFileNameFromHandle(%08xh): pDeviceHandler not set", hObject));
     1448    fResult = FALSE;
     1449  }
     1450
     1451  if(fResult == TRUE) {
     1452      SetLastError(ERROR_SUCCESS);
     1453  }
     1454  return (fResult);                                   /* deliver return code */
     1455}
     1456
     1457/*****************************************************************************
    14081458 * Name      : HANDLE  HMCloseFile
    14091459 * Purpose   : Wrapper for the CloseHandle() API
  • trunk/src/kernel32/hmdevice.cpp

    r9975 r10073  
    1 /* $Id: hmdevice.cpp,v 1.35 2003-04-02 12:58:29 sandervl Exp $ */
     1/* $Id: hmdevice.cpp,v 1.36 2003-05-06 12:06:09 sandervl Exp $ */
    22
    33/*
     
    19201920    return WAIT_FAILED;
    19211921}
     1922
     1923
     1924/*****************************************************************************
     1925 * Name      : BOOL HMDeviceHandler::GetFileNameFromHandle
     1926 * Purpose   :
     1927 * Variables :
     1928 * Result    :
     1929 * Remark    :
     1930 * Status    :
     1931 *
     1932 * Author    : SvL
     1933 *****************************************************************************/
     1934BOOL HMDeviceHandler::GetFileNameFromHandle(PHMHANDLEDATA pHMHandleData, LPSTR lpszFileName, DWORD cbFileName)
     1935{
     1936    dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::GetFileNameFromHandle %08x %x %d",
     1937              pHMHandleData->hHMHandle, lpszFileName, cbFileName));
     1938
     1939    return FALSE;
     1940}
     1941
  • trunk/src/kernel32/hmdevice.h

    r9748 r10073  
    1 /* $Id: hmdevice.h,v 1.34 2003-02-04 11:28:56 sandervl Exp $ */
     1/* $Id: hmdevice.h,v 1.35 2003-05-06 12:06:09 sandervl Exp $ */
    22
    33/*
     
    465465  virtual BOOL SetMailslotInfo(PHMHANDLEDATA pHMHandleData,
    466466                               DWORD  dwReadTimeout);
     467
     468  virtual BOOL GetFileNameFromHandle(PHMHANDLEDATA pHMHandleData, LPSTR lpszFileName, DWORD cbFileName);
     469
    467470};
    468471
  • trunk/src/kernel32/hmfile.cpp

    r10071 r10073  
    1 /* $Id: hmfile.cpp,v 1.44 2003-05-06 10:12:00 sandervl Exp $ */
     1/* $Id: hmfile.cpp,v 1.45 2003-05-06 12:06:09 sandervl Exp $ */
    22
    33/*
     
    10831083//                                 arg4));
    10841084}
     1085/******************************************************************************
     1086 * Name      : DWORD HMDeviceFileClass::GetFileNameFromHandle
     1087 * Purpose   : the name of the file associated with the system handle (if any)
     1088 * Parameters: PHMHANDLEDATA pHMHandleData
     1089 * Variables :
     1090 * Result    : BOOLEAN
     1091 * Remark    :
     1092 * Status    :
     1093 *
     1094 * Author    : SvL
     1095 ******************************************************************************/
     1096BOOL HMDeviceFileClass::GetFileNameFromHandle(PHMHANDLEDATA pHMHandleData,
     1097                                              LPSTR lpszFileName, DWORD cbFileName)
     1098{
     1099  HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData;
     1100
     1101  if(fileInfo == NULL || strlen(fileInfo->lpszFileName) >= cbFileName) {
     1102      if(fileInfo) DebugInt3();
     1103      return FALSE;
     1104  }
     1105  strcpy(lpszFileName, fileInfo->lpszFileName);
     1106
     1107  return TRUE;
     1108}
    10851109
    10861110//******************************************************************************
     
    12611285}
    12621286/******************************************************************************
     1287 * Name      : DWORD HMDeviceFileClass::GetFileNameFromHandle
     1288 * Purpose   : the name of the file associated with the system handle (if any)
     1289 * Parameters: PHMHANDLEDATA pHMHandleData
     1290 * Variables :
     1291 * Result    : BOOLEAN
     1292 * Remark    :
     1293 * Status    :
     1294 *
     1295 * Author    : SvL
     1296 ******************************************************************************/
     1297BOOL HMDeviceInfoFileClass::GetFileNameFromHandle(PHMHANDLEDATA pHMHandleData,
     1298                                                  LPSTR lpszFileName, DWORD cbFileName)
     1299{
     1300  HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData;
     1301
     1302  if(fileInfo == NULL || strlen(fileInfo->lpszFileName) >= cbFileName) {
     1303      if(fileInfo) DebugInt3();
     1304      return FALSE;
     1305  }
     1306  strcpy(lpszFileName, fileInfo->lpszFileName);
     1307
     1308  return TRUE;
     1309}
     1310/******************************************************************************
    12631311 * Name      : DWORD HMDeviceFileClass::GetFileType
    12641312 * Purpose   : determine the handle type
  • trunk/src/kernel32/hmfile.h

    r10064 r10073  
    1 /* $Id: hmfile.h,v 1.10 2003-05-05 10:51:05 sandervl Exp $ */
     1/* $Id: hmfile.h,v 1.11 2003-05-06 12:06:10 sandervl Exp $ */
    22
    33/*
     
    158158                                   BOOL          arg4);
    159159
     160  virtual BOOL GetFileNameFromHandle(PHMHANDLEDATA pHMHandleData, LPSTR lpszFileName, DWORD cbFileName);
    160161};
    161162
     
    187188  /* this is a handler method for calls to GetFileType() */
    188189  virtual DWORD GetFileType (PHMHANDLEDATA pHMHandleData);
     190
     191  virtual BOOL GetFileNameFromHandle(PHMHANDLEDATA pHMHandleData, LPSTR lpszFileName, DWORD cbFileName);
     192
    189193};
    190194
  • trunk/src/kernel32/mmap.cpp

    r9971 r10073  
    1 /* $Id: mmap.cpp,v 1.65 2003-04-02 11:03:31 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.66 2003-05-06 12:06:10 sandervl Exp $ */
    22
    33/*
     
    7575Win32MemMap::Win32MemMap(HANDLE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName)
    7676               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0),
    77                  image(0), pWriteBitmap(NULL)
     77                 image(0), pWriteBitmap(NULL), lpszFileName(NULL)
    7878{
    7979    DosEnterCriticalSection(&globalmapcritsect);
     
    101101Win32MemMap::Win32MemMap(Win32PeLdrImage *pImage, ULONG baseAddress, ULONG size)
    102102               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0),
    103                  image(0), pWriteBitmap(NULL)
     103                 image(0), pWriteBitmap(NULL), lpszFileName(NULL)
    104104{
    105105    DosEnterCriticalSection(&globalmapcritsect);
     
    127127    if(hMemFile != -1)
    128128    {
     129        lpszFileName = (char *)_smalloc(MMAP_MAX_FILENAME_LENGTH);
     130        if(HMGetFileNameFromHandle(hMemFile, lpszFileName, MMAP_MAX_FILENAME_LENGTH) == FALSE) {
     131            return FALSE;
     132        }
    129133#if 0
    130134        if(DuplicateHandle(GetCurrentProcess(), hMemFile, GetCurrentProcess(),
     
    181185    if(lpszMapName) {
    182186        free(lpszMapName);
     187    }
     188    if(lpszFileName) {
     189        free(lpszFileName);
    183190    }
    184191    if(pMapping && !image) {
     
    917924Win32MemMap *Win32MemMap::findMapByFile(HANDLE hFile)
    918925{
     926  DWORD processId = GetCurrentProcessId();
     927  char  szFileName[260];
     928
    919929  if(hFile == -1)
     930    return NULL;
     931
     932  if(HMGetFileNameFromHandle(hFile, szFileName, sizeof(szFileName)) == FALSE)
    920933    return NULL;
    921934
     
    926939  {
    927940    while(map) {
    928         if(map->hOrgMemFile == hFile)
    929             break;
     941        //TODO: we currently don't support sharing file maps between processes
     942        if(map->mProcessId == processId && map->lpszFileName)
     943        {
     944            if(!strcmp(map->lpszFileName, szFileName))
     945                break;
     946        }
    930947        map = map->next;
    931948    }
  • trunk/src/kernel32/mmap.h

    r9971 r10073  
    1 /* $Id: mmap.h,v 1.28 2003-04-02 11:03:32 sandervl Exp $ */
     1/* $Id: mmap.h,v 1.29 2003-05-06 12:06:11 sandervl Exp $ */
    22
    33/*
     
    3737
    3838#define MMAP_FLUSHVIEW_ALL              0xFFFFFFFF
     39
     40#define MMAP_MAX_FILENAME_LENGTH        260
    3941
    4042typedef enum
     
    124126   HANDLE hMemFile;
    125127   HANDLE hOrgMemFile;
     128   LPSTR  lpszFileName;
    126129   ULONG  mSize;
    127130   ULONG  mProtFlags;
     
    169172            Win32MemMap *parent;
    170173
     174            HANDLE       hDupMemFile;
    171175private:
    172176};
  • trunk/src/kernel32/mmapdup.cpp

    r9971 r10073  
    1 /* $Id: mmapdup.cpp,v 1.2 2003-04-02 11:03:32 sandervl Exp $ */
     1/* $Id: mmapdup.cpp,v 1.3 2003-05-06 12:06:11 sandervl Exp $ */
    22
    33/*
     
    6767{
    6868    //copy values from original map
    69     mSize    = parent->getMapSize();
    70     hMemFile = parent->getFileHandle();
     69    mSize       = parent->getMapSize();
     70    //can't use hMemFile or else we'll close this file handle in the memmap dtor!!
     71    hDupMemFile = parent->getFileHandle();
    7172
    7273    //If the parent is a readonly map and we allow write access, then we must
     
    127128             goto parmfail;
    128129
    129     if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hMemFile == -1))
     130    if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hDupMemFile == -1))
    130131        goto parmfail;
    131132
Note: See TracChangeset for help on using the changeset viewer.