Changeset 9653 for trunk/src


Ignore:
Timestamp:
Jan 10, 2003, 1:57:14 PM (23 years ago)
Author:
sandervl
Message:

implemented Get/SetHandleInformation; CloseHandle change for HANDLE_FLAG_PROTECT_FROM_CLOSE; inheritance support added to DuplicateHandle

Location:
trunk/src/kernel32
Files:
9 edited

Legend:

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

    r9235 r9653  
    1 /* $Id: HandleManager.cpp,v 1.91 2002-09-14 13:49:39 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.92 2003-01-10 12:57:11 sandervl Exp $ */
    22
    33/*
     
    268268        TabWin32Handles[ulLoop].hmHandleData.hWin32Handle   = (HANDLE)ulLoop;
    269269        TabWin32Handles[ulLoop].hmHandleData.lpDeviceData   = NULL;
     270        TabWin32Handles[ulLoop].hmHandleData.dwHandleInformation = 0;
    270271        handleMutex.leave();
    271272        return (ulLoop);                    /* OK, then return it to the caller */
     
    10831084    HMHandleTemp.hWin32Handle  = iIndexNew;
    10841085    HMHandleTemp.lpDeviceData  = pDevData;
     1086    HMHandleTemp.dwHandleInformation = 0;
    10851087  }
    10861088
     
    12861288}
    12871289
    1288 
     1290/*****************************************************************************
     1291 * Name      : DWORD HMGetHandleInformation
     1292 * Purpose   : The GetHandleInformation function obtains information about certain
     1293 *             properties of an object handle. The information is obtained as a set of bit flags.
     1294 * Parameters: HANDLE  hObject
     1295 *             LPDWORD lpdwFlags
     1296 * Variables :
     1297 * Result    : TRUE / FALSE
     1298 * Remark    :
     1299 * Status    :
     1300 *
     1301 * Author    : SvL
     1302 *****************************************************************************/
     1303BOOL HMGetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
     1304{
     1305  int       iIndex;                           /* index into the handle table */
     1306  BOOL      fResult;       /* result from the device handler's CloseHandle() */
     1307  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1308
     1309                                                          /* validate handle */
     1310  iIndex = _HMHandleQuery(hObject);                         /* get the index */
     1311  if (-1 == iIndex)                                               /* error ? */
     1312  {
     1313      SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1314      return (FALSE);                                        /* signal failure */
     1315  }
     1316
     1317  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1318
     1319  //Handle information is stored in the handle structure; return it here
     1320  if(lpdwFlags) {
     1321      *lpdwFlags = pHMHandle->hmHandleData.dwHandleInformation;
     1322  }
     1323
     1324  SetLastError(ERROR_SUCCESS);
     1325  return TRUE;                                   /* deliver return code */
     1326}
     1327
     1328/*****************************************************************************
     1329 * Name      : BOOL HMSetHandleInformation
     1330 * Purpose   : The SetHandleInformation function sets certain properties of an
     1331 *             object handle. The information is specified as a set of bit flags.
     1332 * Parameters: HANDLE hObject  handle to an object
     1333 *             DWORD  dwMask   specifies flags to change
     1334 *             DWORD  dwFlags  specifies new values for flags
     1335 * Variables :
     1336 * Result    : TRUE / FALSE
     1337 * Remark    :
     1338 * Status    :
     1339 *
     1340 * Author    : SvL
     1341 *****************************************************************************/
     1342BOOL   HMSetHandleInformation       (HANDLE hObject,
     1343                                     DWORD  dwMask,
     1344                                     DWORD  dwFlags)
     1345{
     1346  int       iIndex;                           /* index into the handle table */
     1347  BOOL      fResult;       /* result from the device handler's CloseHandle() */
     1348  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1349
     1350                                                          /* validate handle */
     1351  iIndex = _HMHandleQuery(hObject);                         /* get the index */
     1352  if (-1 == iIndex)                                               /* error ? */
     1353  {
     1354    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1355    return (FALSE);                                        /* signal failure */
     1356  }
     1357
     1358  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1359  //SvL: Check if pDeviceHandler is set
     1360  if (pHMHandle->pDeviceHandler)
     1361  {
     1362    fResult = pHMHandle->pDeviceHandler->SetHandleInformation(&pHMHandle->hmHandleData,
     1363                                                              dwMask, dwFlags);
     1364  }
     1365  else
     1366  {
     1367    dprintf(("HMSetHandleInformation(%08xh): pDeviceHandler not set", hObject));
     1368    fResult = TRUE;
     1369  }
     1370
     1371  if(fResult == TRUE) {
     1372      SetLastError(ERROR_SUCCESS);
     1373  }
     1374  return (fResult);                                   /* deliver return code */
     1375}
    12891376
    12901377/*****************************************************************************
     
    13241411
    13251412  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1413
     1414  if(pHMHandle->hmHandleData.dwHandleInformation & HANDLE_FLAG_PROTECT_FROM_CLOSE) {
     1415      dprintf(("Handle not close because of HANDLE_FLAG_PROTECT_FROM_CLOSE"));
     1416      SetLastError(ERROR_SUCCESS);
     1417      return TRUE;
     1418  }
     1419
    13261420  //SvL: Check if pDeviceHandler is set
    13271421  if (pHMHandle->pDeviceHandler)
  • trunk/src/kernel32/KERNEL32.CPP

    r7929 r9653  
    1 /* $Id: KERNEL32.CPP,v 1.72 2002-02-15 20:15:54 sandervl Exp $ */
     1/* $Id: KERNEL32.CPP,v 1.73 2003-01-10 12:57:12 sandervl Exp $ */
    22
    33/*
     
    5353
    5454
     55/*****************************************************************************
     56 * Name      : DWORD GetHandleInformation
     57 * Purpose   : The GetHandleInformation function obtains information about certain
     58 *             properties of an object handle. The information is obtained as a set of bit flags.
     59 * Parameters: HANDLE  hObject
     60 *             LPDWORD lpdwFlags
     61 * Variables :
     62 * Result    : TRUE / FALSE
     63 * Remark    :
     64 * Status    :
     65 *
     66 * Author    : SvL
     67 *****************************************************************************/
     68
     69BOOL WIN32API GetHandleInformation(HANDLE  hObject,
     70                                   LPDWORD lpdwFlags)
     71{
     72   return HMGetHandleInformation(hObject, lpdwFlags);
     73}
     74
     75/*****************************************************************************
     76 * Name      : BOOL SetHandleInformation
     77 * Purpose   : The SetHandleInformation function sets certain properties of an
     78 *             object handle. The information is specified as a set of bit flags.
     79 * Parameters: HANDLE hObject  handle to an object
     80 *             DWORD  dwMask   specifies flags to change
     81 *             DWORD  dwFlags  specifies new values for flags
     82 * Variables :
     83 * Result    : TRUE / FALSE
     84 * Remark    :
     85 * Status    :
     86 *
     87 * Author    : SvL
     88 *****************************************************************************/
     89
     90BOOL WIN32API SetHandleInformation(HANDLE hObject,
     91                                   DWORD  dwMask,
     92                                   DWORD  dwFlags)
     93{
     94   return HMSetHandleInformation(hObject, dwMask, dwFlags);
     95}
    5596/*****************************************************************************
    5697 * Name      : BOOL WIN32API CloseHandle
  • trunk/src/kernel32/hmdevice.cpp

    r8401 r9653  
    1 /* $Id: hmdevice.cpp,v 1.32 2002-05-10 14:55:11 sandervl Exp $ */
     1/* $Id: hmdevice.cpp,v 1.33 2003-01-10 12:57:12 sandervl Exp $ */
    22
    33/*
     
    200200{
    201201  dprintf(("KERNEL32:HandleManager::CloseHandle %s(%08x) - stub?\n",
     202           lpHMDeviceName,
     203           pHMHandleData));
     204
     205  SetLastError(ERROR_INVALID_FUNCTION);
     206  return FALSE;
     207}
     208
     209/*****************************************************************************
     210 * Name      : BOOL HMSetHandleInformation
     211 * Purpose   : The SetHandleInformation function sets certain properties of an
     212 *             object handle. The information is specified as a set of bit flags.
     213 * Parameters: HANDLE hObject  handle to an object
     214 *             DWORD  dwMask   specifies flags to change
     215 *             DWORD  dwFlags  specifies new values for flags
     216 * Variables :
     217 * Result    : TRUE / FALSE
     218 * Remark    :
     219 * Status    :
     220 *
     221 * Author    : SvL
     222 *****************************************************************************/
     223BOOL HMDeviceHandler::SetHandleInformation(PHMHANDLEDATA pHMHandleData,
     224                                           DWORD  dwMask,
     225                                           DWORD  dwFlags)
     226{
     227  dprintf(("KERNEL32:HandleManager::SetHandleInformation %s(%08x) - stub?\n",
    202228           lpHMDeviceName,
    203229           pHMHandleData));
  • trunk/src/kernel32/hmdevice.h

    r7549 r9653  
    1 /* $Id: hmdevice.h,v 1.32 2001-12-05 14:16:00 sandervl Exp $ */
     1/* $Id: hmdevice.h,v 1.33 2003-01-10 12:57:13 sandervl Exp $ */
    22
    33/*
     
    5555  DWORD           dwUserData;
    5656  DWORD           dwInternalType;
     57  DWORD           dwHandleInformation;               /* Set by SetHandleInformation */
    5758
    5859  LPVOID          lpHandlerData;    /* for private use of the device handler */
     
    114115  /* this is a handler method for calls to CloseHandle() */
    115116  virtual BOOL   CloseHandle(PHMHANDLEDATA pHMHandleData);
     117
     118  virtual BOOL   SetHandleInformation(PHMHANDLEDATA pHMHandleData,
     119                                      DWORD  dwMask,
     120                                      DWORD  dwFlags);
    116121
    117122  /* this is a handler method for calls to ReadFile/Ex */
  • trunk/src/kernel32/hmfile.cpp

    r9530 r9653  
    1 /* $Id: hmfile.cpp,v 1.37 2002-12-19 12:55:27 sandervl Exp $ */
     1/* $Id: hmfile.cpp,v 1.38 2003-01-10 12:57:13 sandervl Exp $ */
    22
    33/*
     
    351351        {
    352352            memcpy(pHMHandleData, &duphdata, sizeof(duphdata));
     353
     354            if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     355
    353356            SetLastError(ERROR_SUCCESS);
    354357            return TRUE;
     
    368371    if (rc)
    369372    {
    370       dprintf(("ERROR: DulicateHandle: OSLibDosDupHandle(%s) failed = %u\n",
    371                rc,
    372                srcfileinfo->lpszFileName));
     373      dprintf(("ERROR: DuplicateHandle: OSLibDosDupHandle(%s) failed = %u",
     374               srcfileinfo->lpszFileName, rc));
    373375      SetLastError(rc);
    374376      return FALSE;   // ERROR
    375377    }
    376378    else {
     379      if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     380
    377381      SetLastError(ERROR_SUCCESS);
    378382      pHMHandleData->hHMHandle = *desthandle;
     
    386390    return FALSE;
    387391  }
     392}
     393
     394/*****************************************************************************
     395 * Name      : BOOL HMDeviceFileClass::SetHandleInformation
     396 * Purpose   : The SetHandleInformation function sets certain properties of an
     397 *             object handle. The information is specified as a set of bit flags.
     398 * Parameters: HANDLE hObject  handle to an object
     399 *             DWORD  dwMask   specifies flags to change
     400 *             DWORD  dwFlags  specifies new values for flags
     401 * Variables :
     402 * Result    : TRUE / FALSE
     403 * Remark    :
     404 * Status    :
     405 *
     406 * Author    : SvL
     407 *****************************************************************************/
     408BOOL HMDeviceFileClass::SetHandleInformation(PHMHANDLEDATA pHMHandleData,
     409                                             DWORD  dwMask,
     410                                             DWORD  dwFlags)
     411{
     412    DWORD rc;
     413
     414    pHMHandleData->dwHandleInformation &= ~dwMask;
     415    pHMHandleData->dwHandleInformation |= (dwFlags & dwMask);
     416
     417    rc = OSLibDosSetFHState(pHMHandleData->hHMHandle,
     418                            pHMHandleData->dwHandleInformation);
     419    if (rc)
     420    {
     421        dprintf(("ERROR: SetHandleInformation: OSLibDosSetFHState failed with %d", rc));
     422
     423        SetLastError(rc);
     424        return FALSE;
     425    }
     426
     427    SetLastError(ERROR_SUCCESS);
     428    return TRUE;
    388429}
    389430
  • trunk/src/kernel32/hmfile.h

    r7549 r9653  
    1 /* $Id: hmfile.h,v 1.7 2001-12-05 14:16:01 sandervl Exp $ */
     1/* $Id: hmfile.h,v 1.8 2003-01-10 12:57:13 sandervl Exp $ */
    22
    33/*
     
    6464                               DWORD   fdwOptions,
    6565                               DWORD   fdwOdinOptions);
     66
     67  virtual BOOL   SetHandleInformation(PHMHANDLEDATA pHMHandleData,
     68                                      DWORD  dwMask,
     69                                      DWORD  dwFlags);
    6670
    6771                      /* this is a handler method for calls to CloseHandle() */
  • trunk/src/kernel32/oslibdos.cpp

    r9530 r9653  
    1 /* $Id: oslibdos.cpp,v 1.110 2002-12-19 12:55:27 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.111 2003-01-10 12:57:13 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    430430 HFILE  hFile;
    431431 ULONG  ulAction;
    432  DWORD  os2flags = OPEN_FLAGS_NOINHERIT;
     432 DWORD  os2flags = OPEN_FLAGS_NOINHERIT; //default is not inherited by child processes
    433433 char lOemFileName[260];
    434434
     
    843843   ULONG   fileAttr = FILE_NORMAL;
    844844   ULONG   openFlag = 0;
    845    ULONG   openMode = 0;
     845   ULONG   openMode = OPEN_FLAGS_NOINHERIT; //default is not inherited by child processes
    846846   APIRET  rc = ERROR_NOT_ENOUGH_MEMORY;;
    847847
     
    10201020   ULONG   fileAttr = FILE_NORMAL;
    10211021   ULONG   openFlag = 0;
    1022    ULONG   openMode = 0;
     1022   ULONG   openMode = OPEN_FLAGS_NOINHERIT; //default is not inherited by child processes
    10231023   APIRET  rc = ERROR_NOT_ENOUGH_MEMORY;
    10241024   HFILE   hFile;
     
    14711471}
    14721472//******************************************************************************
     1473//******************************************************************************
     1474DWORD OSLibDosSetFHState(DWORD hFile, DWORD dwFlags)
     1475{
     1476   DWORD  ulMode;
     1477   APIRET rc;
     1478   
     1479   rc = DosQueryFHState(hFile, &ulMode);
     1480   if(rc != NO_ERROR) return error2WinError(rc);
     1481
     1482   //turn off non-participating bits
     1483   ulMode &= 0x7F88;
     1484
     1485   if(dwFlags & HANDLE_FLAG_INHERIT_W) {
     1486       ulMode &= ~OPEN_FLAGS_NOINHERIT;
     1487   }
     1488   else
     1489       ulMode |= OPEN_FLAGS_NOINHERIT;
     1490
     1491   rc = DosSetFHState(hFile, ulMode);
     1492   return error2WinError(rc);
     1493}
     1494//******************************************************************************
    14731495//Returns time spent in kernel & user mode in milliseconds
    14741496//******************************************************************************
     
    15151537                               DWORD   nDefaultTimeOut,
    15161538                               LPSECURITY_ATTRIBUTES lpSecurityAttributes)
    1517 {  DWORD dwOS2Mode     = 0;
     1539{  DWORD dwOS2Mode     = NP_NOINHERIT; //default is not inherited by child processes
    15181540   DWORD dwOS2PipeMode = 0;
    15191541   LPSTR lpOS2Name;
     
    15741596  rc = DosOpen(lpOS2Name, &hPipe, &ulAction, 0, FILE_NORMAL, FILE_OPEN,
    15751597               ((dwOpenMode & PIPE_ACCESS_INBOUND_W) ? OPEN_ACCESS_READWRITE : OPEN_ACCESS_READONLY) |
    1576                OPEN_SHARE_DENYNONE, NULL);
     1598               OPEN_SHARE_DENYNONE | OPEN_FLAGS_NOINHERIT, NULL);
    15771599
    15781600  if(rc == NO_ERROR) {
     
    16461668  ULONG rc, ulAction;
    16471669  ULONG openFlag = 0;
    1648   ULONG openMode = 0;
     1670  ULONG openMode = OPEN_FLAGS_NOINHERIT; //default is not inherited by child processes
    16491671
    16501672
     
    26092631        if (DosOpen("\\DEV\\CD-ROM2$", &hCDRom2, &ulAction, 0,
    26102632                    FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
    2611                     OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL)
     2633                    OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY | OPEN_FLAGS_NOINHERIT, NULL)
    26122634            == NO_ERROR)
    26132635        {
     
    28642886        if (DosOpen("\\DEV\\CD-ROM2$", &hCDRom2, &ulAction, 0,
    28652887                    FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
    2866                     OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL)
     2888                    OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY | OPEN_FLAGS_NOINHERIT, NULL)
    28672889            == NO_ERROR)
    28682890        {
  • trunk/src/kernel32/oslibdos.h

    r9617 r9653  
    1 /* $Id: oslibdos.h,v 1.50 2003-01-05 12:31:24 sandervl Exp $ */
     1/* $Id: oslibdos.h,v 1.51 2003-01-10 12:57:14 sandervl Exp $ */
    22
    33/*
     
    113113
    114114DWORD OSLibDosDupHandle(DWORD hFile, DWORD *hNew);
     115DWORD OSLibDosSetFHState(DWORD hFile, DWORD dwFlags);
     116
    115117DWORD OSLibDosSetFilePtr2(DWORD hFile, DWORD offset, DWORD method);
    116118
  • trunk/src/kernel32/stubs.cpp

    r7555 r9653  
    1 /* $Id: stubs.cpp,v 1.36 2001-12-06 10:14:45 sandervl Exp $
     1/* $Id: stubs.cpp,v 1.37 2003-01-10 12:57:14 sandervl Exp $
    22 *
    33 * Win32 KERNEL32 Subsystem for OS/2
     
    870870
    871871
    872 /*****************************************************************************
    873  * Name      : DWORD GetHandleInformation
    874  * Purpose   : The GetHandleInformation function obtains information about certain
    875  *             properties of an object handle. The information is obtained as a set of bit flags.
    876  * Parameters: HANDLE  hObject
    877  *             LPDWORD lpdwFlags
    878  * Variables :
    879  * Result    : TRUE / FALSE
    880  * Remark    :
    881  * Status    : UNTESTED STUB
    882  *
    883  * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    884  *****************************************************************************/
    885 
    886 BOOL WIN32API GetHandleInformation(HANDLE  hObject,
    887                                       LPDWORD lpdwFlags)
    888 {
    889   dprintf(("KERNEL32: GetHandleInformation (%08xh, %08xh) not implemented\n",
    890            hObject,
    891            lpdwFlags));
    892 
    893   return (FALSE);
    894 }
    895 
    896 
    897 
    898872
    899873/*****************************************************************************
     
    13561330}
    13571331
    1358 
    1359 /*****************************************************************************
    1360  * Name      : BOOL SetHandleInformation
    1361  * Purpose   : The SetHandleInformation function sets certain properties of an
    1362  *             object handle. The information is specified as a set of bit flags.
    1363  * Parameters: HANDLE hObject  handle to an object
    1364  *             DWORD  dwMask   specifies flags to change
    1365  *             DWORD  dwFlags  specifies new values for flags
    1366  * Variables :
    1367  * Result    : TRUE / FALSE
    1368  * Remark    :
    1369  * Status    : UNTESTED STUB
    1370  *
    1371  * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    1372  *****************************************************************************/
    1373 
    1374 BOOL WIN32API SetHandleInformation(HANDLE hObject,
    1375                                       DWORD  dwMask,
    1376                                       DWORD  dwFlags)
    1377 {
    1378   dprintf(("KERNEL32: SetHandleInformation(%08xh,%08xh,%08xh) not implemented.\n",
    1379            hObject,
    1380            dwMask,
    1381            dwFlags));
    1382 
    1383   return (FALSE);
    1384 }
    1385 
    13861332/*****************************************************************************
    13871333 * Name      : BOOL SetSystemPowerState
Note: See TracChangeset for help on using the changeset viewer.