Changeset 690 for trunk/src


Ignore:
Timestamp:
Aug 25, 1999, 4:27:07 PM (26 years ago)
Author:
sandervl
Message:

handle manager changes for DuplicateHandle + memory mapped file changes/bugfixes

Location:
trunk/src/kernel32
Files:
13 edited

Legend:

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

    r678 r690  
    1 /* $Id: HandleManager.cpp,v 1.15 1999-08-25 10:28:39 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.16 1999-08-25 14:27:04 sandervl Exp $ */
    22
    33/*
     
    5757#include "HMSemaphore.h"
    5858#include "HMMMap.h"
     59#include <winconst.h>
    5960
    6061/*****************************************************************************
     
    631632}
    632633
     634
     635/*****************************************************************************
     636 * Name      : HANDLE  HMDuplicateHandle
     637 * Purpose   : replacement for Open32's HMDuplicateHandle function
     638 * Parameters:
     639 *             
     640 * Variables :
     641 * Result    : BOOL fSuccess
     642 * Remark    :
     643 * Status    :
     644 *
     645 * Author    : Patrick Haller [Wed, 1998/02/12 20:44]
     646 *****************************************************************************/
     647BOOL HMDuplicateHandle(HANDLE  srcprocess,
     648                       HANDLE  srchandle,
     649                       HANDLE  destprocess,
     650                       PHANDLE desthandle,
     651                       DWORD   fdwAccess,
     652                       BOOL    fInherit,
     653                       DWORD   fdwOptions)
     654{
     655  int             iIndex;                     /* index into the handle table */
     656  int             iIndexNew;                  /* index into the handle table */
     657  HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
     658  PHMHANDLEDATA   pHMHandleData;
     659  DWORD           rc;                                     /* API return code */
     660
     661  if(HMHandleValidate(srchandle) != NO_ERROR) {
     662        dprintf(("HMDuplicateHandle: invalid handle %x", srchandle));
     663        SetLastError(ERROR_INVALID_HANDLE);      /* use this as error message */
     664        return FALSE;
     665  }
     666
     667  pDeviceHandler = TabWin32Handles[srchandle].pDeviceHandler;         /* device is predefined */
     668
     669  iIndexNew = _HMHandleGetFree();                         /* get free handle */
     670  if (-1 == iIndexNew)                            /* oops, no free handles ! */
     671  {
     672    SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
     673    return FALSE;                           /* signal error */
     674  }
     675
     676  /* initialize the complete HMHANDLEDATA structure */
     677  pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
     678  pHMHandleData->dwType     = TabWin32Handles[srchandle].hmHandleData.dwType;
     679  if (fdwOptions & DUPLICATE_SAME_ACCESS) {
     680        pHMHandleData->dwAccess   = TabWin32Handles[srchandle].hmHandleData.dwAccess;
     681  }
     682  else  pHMHandleData->dwAccess   = fdwAccess;
     683
     684  pHMHandleData->dwShare       = TabWin32Handles[srchandle].hmHandleData.dwShare;
     685  pHMHandleData->dwCreation    = TabWin32Handles[srchandle].hmHandleData.dwCreation;
     686  pHMHandleData->dwFlags       = TabWin32Handles[srchandle].hmHandleData.dwFlags;
     687  pHMHandleData->lpHandlerData = TabWin32Handles[srchandle].hmHandleData.lpHandlerData;
     688
     689
     690  /* we've got to mark the handle as occupied here, since another device */
     691  /* could be created within the device handler -> deadlock */
     692
     693  /* write appropriate entry into the handle table if open succeeded */
     694  TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
     695  TabWin32Handles[iIndexNew].pDeviceHandler         = pDeviceHandler;
     696
     697                                                  /* call the device handler */
     698  rc = pDeviceHandler->DuplicateHandle(&TabWin32Handles[iIndexNew].hmHandleData,
     699                                       srcprocess,
     700                                       &TabWin32Handles[srchandle].hmHandleData,
     701                                       destprocess, desthandle,
     702                                       fdwAccess, fInherit, fdwOptions & ~DUPLICATE_CLOSE_SOURCE);
     703
     704  //Don't let Open32 close it for us, but do it manually (regardless of error; see SDK docs))
     705  if (fdwOptions & DUPLICATE_CLOSE_SOURCE)
     706  {
     707        CloseHandle(srchandle);
     708  }
     709
     710  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
     711  {
     712    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     713    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
     714    return FALSE;                           /* signal error */
     715  }
     716  *desthandle = iIndexNew;
     717  return TRUE;                                   /* return valid handle */
     718}
    633719
    634720/*****************************************************************************
  • trunk/src/kernel32/KERNEL32.DEF

    r687 r690  
    1 ; $Id: KERNEL32.DEF,v 1.29 1999-08-25 12:30:47 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.30 1999-08-25 14:27:06 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    10061006    VIRTUAL_MapFileA           = _VIRTUAL_MapFileA@8              @1249
    10071007    VIRTUAL_MapFileW           = _VIRTUAL_MapFileW@8              @1250
     1008
     1009    OS2SetExceptionHandler   @1251
     1010    OS2UnsetExceptionHandler @1252
  • trunk/src/kernel32/exceptions.cpp

    r678 r690  
    1 /* $Id: exceptions.cpp,v 1.12 1999-08-25 10:28:40 sandervl Exp $ */
     1/* $Id: exceptions.cpp,v 1.13 1999-08-25 14:27:05 sandervl Exp $ */
    22
    33/*
     
    901901                goto continueFail;
    902902        }
    903         map = Win32MemMap::findMap(pERepRec->ExceptionInfo[0]);
     903        map = Win32MemMap::findMap(pERepRec->ExceptionInfo[1]);
    904904        if(map == NULL) {
    905905                goto continueFail;
  • trunk/src/kernel32/hmdevice.cpp

    r678 r690  
    1 /* $Id: hmdevice.cpp,v 1.6 1999-08-25 10:28:40 sandervl Exp $ */
     1/* $Id: hmdevice.cpp,v 1.7 1999-08-25 14:27:05 sandervl Exp $ */
    22
    33/*
     
    9191}
    9292
     93
     94/*****************************************************************************
     95 * Name      : HMDeviceHandler::DuplicateHandle
     96 * Purpose   : dummy version
     97 * Parameters:
     98 *             various parameters as required
     99 * Variables :
     100 * Result    :
     101 * Remark    : the standard behaviour is to return an error code for non-
     102 *             existant request codes
     103 * Status    :
     104 *
     105 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     106 *****************************************************************************/
     107BOOL HMDeviceHandler::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
     108                               PHMHANDLEDATA pHMSrcHandle,
     109                               HANDLE  destprocess,
     110                               PHANDLE desthandle,
     111                                DWORD   fdwAccess,
     112                                BOOL    fInherit,
     113                                DWORD   fdwOptions)
     114{
     115  dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n",
     116           lpHMDeviceName,
     117           pHMHandleData,
     118           srcprocess, pHMSrcHandle, destprocess, desthandle));
     119
     120  return(ERROR_INVALID_FUNCTION);
     121}
    93122
    94123/*****************************************************************************
  • trunk/src/kernel32/hmdevice.h

    r678 r690  
    1 /* $Id: hmdevice.h,v 1.7 1999-08-25 10:28:40 sandervl Exp $ */
     1/* $Id: hmdevice.h,v 1.8 1999-08-25 14:27:06 sandervl Exp $ */
    22
    33/*
     
    7878                                 ULONG         arg4);
    7979
     80  virtual BOOL DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
     81                               PHMHANDLEDATA pHMSrcHandle,
     82                               HANDLE  destprocess,
     83                               PHANDLE desthandle,
     84                               DWORD   fdwAccess,
     85                               BOOL    fInherit,
     86                               DWORD   fdwOptions);
     87
    8088                       /* this is a handler method for calls to CreateFile() */
    8189  virtual DWORD  CreateFile (LPCSTR        lpFileName,
  • trunk/src/kernel32/hmmmap.cpp

    r678 r690  
    1 /* $Id: hmmmap.cpp,v 1.4 1999-08-25 10:28:40 sandervl Exp $ */
     1/* $Id: hmmmap.cpp,v 1.5 1999-08-25 14:27:06 sandervl Exp $ */
    22
    33/*
     
    5757
    5858  if((hFile == -1 && size_low == 0) || size_high ||
    59      protect & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY|SEC_COMMIT|SEC_IMAGE|SEC_RESERVE|SEC_NOCACHE) ||
     59     protect & ~(PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY|SEC_COMMIT|SEC_IMAGE|SEC_RESERVE|SEC_NOCACHE) ||
    6060     (protect & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY)) == 0 ||
    6161     (hFile == -1 && (protect & SEC_COMMIT)) ||
     
    6464
    6565        dprintf(("CreateFileMappingA: invalid parameter (combination)!"));
    66         SetLastError(ERROR_INVALID_PARAMETER);
    67         return 0;       
     66        return ERROR_INVALID_PARAMETER;
    6867  }
    6968
     
    7978  }
    8079  map->AddRef();
    81   pHMHandleData->dwUserData = (ULONG)this;
     80  pHMHandleData->dwUserData = (ULONG)map;
    8281  pHMHandleData->dwInternalType = HMTYPE_MEMMAP;
    8382  return NO_ERROR;
     
    118117  }
    119118  map->AddRef();
    120   pHMHandleData->dwUserData = (ULONG)this;
     119  pHMHandleData->dwUserData = (ULONG)map;
    121120  pHMHandleData->dwInternalType = HMTYPE_MEMMAP;
    122121  return NO_ERROR;
  • trunk/src/kernel32/hmopen32.cpp

    r278 r690  
    1 /* $Id: hmopen32.cpp,v 1.8 1999-07-06 15:48:47 phaller Exp $ */
     1/* $Id: hmopen32.cpp,v 1.9 1999-08-25 14:27:06 sandervl Exp $ */
    22
    33/*
     
    6868}
    6969
     70
     71/*****************************************************************************
     72 * Name      : HMDeviceHandler::DuplicateHandle
     73 * Purpose   : dummy version
     74 * Parameters:
     75 *             various parameters as required
     76 * Variables :
     77 * Result    :
     78 * Remark    : the standard behaviour is to return an error code for non-
     79 *             existant request codes
     80 * Status    :
     81 *
     82 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     83 *****************************************************************************/
     84BOOL HMDeviceOpen32Class::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
     85                               PHMHANDLEDATA pHMSrcHandle,
     86                               HANDLE  destprocess,
     87                               PHANDLE desthandle,
     88                               DWORD   fdwAccess,
     89                               BOOL    fInherit,
     90                               DWORD   fdwOptions)
     91{
     92 BOOL rc;
     93
     94  dprintf(("KERNEL32:HandleManager::Open32::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x)\n",
     95           lpHMDeviceName,
     96           pHMHandleData,
     97           srcprocess, pHMSrcHandle->hHMHandle, destprocess, desthandle));
     98
     99  rc = O32_DuplicateHandle(srcprocess, pHMSrcHandle->hHMHandle, destprocess, desthandle, fdwAccess, fInherit, fdwOptions);
     100
     101  if(rc == TRUE) {
     102        pHMHandleData->hHMHandle = *desthandle;
     103        return (NO_ERROR);
     104  }
     105  else  return(O32_GetLastError());
     106}
    70107
    71108/*****************************************************************************
  • trunk/src/kernel32/hmopen32.h

    r278 r690  
    1 /* $Id: hmopen32.h,v 1.2 1999-07-06 15:48:47 phaller Exp $ */
     1/* $Id: hmopen32.h,v 1.3 1999-08-25 14:27:06 sandervl Exp $ */
    22
    33/*
     
    4141                                 ULONG         arg3,
    4242                                 ULONG         arg4);
     43
     44  virtual BOOL DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
     45                               PHMHANDLEDATA pHMSrcHandle,
     46                               HANDLE  destprocess,
     47                               PHANDLE desthandle,
     48                               DWORD   fdwAccess,
     49                               BOOL    fInherit,
     50                               DWORD   fdwOptions);
    4351
    4452                       /* this is a handler method for calls to CreateFile() */
  • trunk/src/kernel32/kernel32exp.def

    r687 r690  
    1 ; $Id: kernel32exp.def,v 1.15 1999-08-25 12:30:47 sandervl Exp $
     1; $Id: kernel32exp.def,v 1.16 1999-08-25 14:27:06 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    862862_HEAP_strdupA@12                 @1247
    863863_HEAP_strdupW@12                 @1248
     864
     865    OS2SetExceptionHandler   @1251
     866    OS2UnsetExceptionHandler @1252
  • trunk/src/kernel32/kobjects.cpp

    r278 r690  
    1 /* $Id: kobjects.cpp,v 1.2 1999-07-06 15:48:48 phaller Exp $ */
     1/* $Id: kobjects.cpp,v 1.3 1999-08-25 14:27:07 sandervl Exp $ */
    22
    33/*
     
    4040#define HMSetHandleCount           O32_SetHandleCount
    4141#define HMGetHandleCount           O32_GetHandleCount
    42 #define HMDuplicateHandle          O32_DuplicateHandle
     42//#define HMDuplicateHandle          O32_DuplicateHandle
    4343
    4444
  • trunk/src/kernel32/makefile

    r687 r690  
    1 # $Id: makefile,v 1.32 1999-08-25 12:30:48 sandervl Exp $
     1# $Id: makefile,v 1.33 1999-08-25 14:27:07 sandervl Exp $
    22
    33#
     
    258258        .\hmsemaphore.h \
    259259        .\hmmmap.h \
     260        $(PDWIN32_INCLUDE)\winconst.h \
    260261        $(PDWIN32_INCLUDE)\handlemanager.h
    261262
  • trunk/src/kernel32/mmap.cpp

    r684 r690  
    1 /* $Id: mmap.cpp,v 1.10 1999-08-25 11:40:18 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.11 1999-08-25 14:27:07 sandervl Exp $ */
    22
    33/*
     
    4040{
    4141  globalmapMutex.enter();
     42  next    = memmaps;
    4243  memmaps = this;
    43   next    = memmaps;
    4444  globalmapMutex.leave();
    4545
     
    6868                goto fail;
    6969        }
     70        mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END);
     71        if(mSize == -1) {
     72                dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end"));
     73                goto fail;
     74        }
    7075  }
    7176  this->hMemMap = hMemMap;
     
    143148//  mapMutex.enter();
    144149  newProt  = mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY);
    145   newProt |= MEM_COMMIT;
    146150
    147151  dprintf(("Win32MemMap::commitPage %x (faultaddr %x), nr of pages %d", pageAddr, lpPageFaultAddr, nrpages));
    148   if(VirtualProtect((LPVOID)pageAddr, nrpages*PAGE_SIZE, newProt, &oldProt) == FALSE) {
     152  if(VirtualAlloc((LPVOID)pageAddr, nrpages*PAGE_SIZE, MEM_COMMIT, newProt) == FALSE) {
    149153        goto fail;
    150154  }
     
    201205  LPVOID mapview;
    202206
    203   if(fdwAccess & (FILE_MAP_WRITE|FILE_MAP_ALL_ACCESS) && !(mProtFlags & PAGE_READWRITE))
    204         goto parmfail;
    205   if(fdwAccess & FILE_MAP_READ && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
    206         goto parmfail;
    207   if(fdwAccess & FILE_MAP_COPY && !(mProtFlags & PAGE_WRITECOPY))
     207  if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
     208        goto parmfail;
     209  if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
     210        goto parmfail;
     211  if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
    208212        goto parmfail;
    209213
  • trunk/src/kernel32/virtual.cpp

    r687 r690  
    1 /* $Id: virtual.cpp,v 1.6 1999-08-25 12:30:48 sandervl Exp $ */
     1/* $Id: virtual.cpp,v 1.7 1999-08-25 14:27:07 sandervl Exp $ */
    22
    33/*
     
    199199HANDLE WINAPI VIRTUAL_MapFileW( LPCWSTR name , LPVOID *lpMapping)
    200200{
    201     HANDLE hFile, hMapping = 0;
     201    HANDLE hFile, hMapping = -1;
    202202
    203203    hFile = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ, NULL,
     
    207207        hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
    208208        CloseHandle( hFile );
    209         if (hMapping)
     209        if (hMapping != INVALID_HANDLE_VALUE)
    210210        {
    211211            *lpMapping = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
     
    224224HANDLE WINAPI VIRTUAL_MapFileA( LPCSTR name , LPVOID *lpMapping)
    225225{
    226     HANDLE hFile, hMapping = 0;
     226    HANDLE hFile, hMapping = -1;
    227227
    228228    hFile = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ, NULL,
     
    232232        hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
    233233        CloseHandle( hFile );
    234         if (hMapping)
     234        if (hMapping != INVALID_HANDLE_VALUE)
    235235        {
    236236            *lpMapping = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
Note: See TracChangeset for help on using the changeset viewer.