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

File:
1 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/*****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.