| 1 | /* $Id: HandleManager.cpp,v 1.94 2003-02-04 11:28:55 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 Unified Handle Manager for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * 1998/02/11 PH Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 7 | *
|
|---|
| 8 | * @(#) HandleManager.Cpp 1.0.0 1998/02/11 PH start
|
|---|
| 9 | *
|
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 11 | *
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | //#undef DEBUG_LOCAL
|
|---|
| 15 | //#define DEBUG_LOCAL
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | /*****************************************************************************
|
|---|
| 19 | * Remark *
|
|---|
| 20 | *****************************************************************************
|
|---|
| 21 |
|
|---|
| 22 | 1998/02/11 PH Even overlapped I/O could be simulated by another subsystem
|
|---|
| 23 | thread with a request queue. We'll see if required ...
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | Flush (flush handle buffer)
|
|---|
| 27 | WaitForSingleObject
|
|---|
| 28 | WaitForMultipleObjects (?)
|
|---|
| 29 |
|
|---|
| 30 | 1998/02/12 PH IBM and Microsoft disagree about the definition of FILE_TYPE_xxx
|
|---|
| 31 | Interesting, Open32 returns Microsoft's values ...
|
|---|
| 32 |
|
|---|
| 33 | 1998/02/12 PH Handles should be equipped with a locking mechanism, in particular
|
|---|
| 34 | as we publish a pointer into the handle table via HMHandleQueryHandleData
|
|---|
| 35 |
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | /*****************************************************************************
|
|---|
| 40 | * Includes *
|
|---|
| 41 | *****************************************************************************/
|
|---|
| 42 |
|
|---|
| 43 | #include <os2win.h>
|
|---|
| 44 | #include <stdlib.h>
|
|---|
| 45 | #include <string.h>
|
|---|
| 46 |
|
|---|
| 47 | #include "unicode.h"
|
|---|
| 48 | #include "misc.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "HandleManager.H"
|
|---|
| 51 | #include "handlenames.h"
|
|---|
| 52 | #include "HMDevice.h"
|
|---|
| 53 | #include "HMDisk.h"
|
|---|
| 54 | #include "HMOpen32.h"
|
|---|
| 55 | #include "HMEvent.h"
|
|---|
| 56 | #include "HMFile.h"
|
|---|
| 57 | #include "HMMutex.h"
|
|---|
| 58 | #include "HMSemaphore.h"
|
|---|
| 59 | #include "HMMMap.h"
|
|---|
| 60 | #include "HMComm.h"
|
|---|
| 61 | #include "HMParPort.h"
|
|---|
| 62 | #include "HMNul.h"
|
|---|
| 63 | #include "HMToken.h"
|
|---|
| 64 | #include "HMThread.h"
|
|---|
| 65 | #include "HMNPipe.h"
|
|---|
| 66 | #include "HMStd.h"
|
|---|
| 67 | #include "HMMailslot.h"
|
|---|
| 68 |
|
|---|
| 69 | #include <vmutex.h>
|
|---|
| 70 | #include <win\thread.h>
|
|---|
| 71 |
|
|---|
| 72 | #define DBG_LOCALLOG DBG_handlemanager
|
|---|
| 73 | #include "dbglocal.h"
|
|---|
| 74 |
|
|---|
| 75 | /*****************************************************************************
|
|---|
| 76 | * Defines *
|
|---|
| 77 | *****************************************************************************/
|
|---|
| 78 |
|
|---|
| 79 | /* this is the size of our currently static handle table */
|
|---|
| 80 | #define MAX_OS2_HMHANDLES 4096
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | /*****************************************************************************
|
|---|
| 84 | * Structures *
|
|---|
| 85 | *****************************************************************************/
|
|---|
| 86 |
|
|---|
| 87 | typedef struct _HMHANDLE
|
|---|
| 88 | {
|
|---|
| 89 | HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */
|
|---|
| 90 | HMHANDLEDATA hmHandleData; /* attributes of the handle */
|
|---|
| 91 | } HMHANDLE, *PHMHANDLE;
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | typedef struct _HMDEVICE
|
|---|
| 95 | {
|
|---|
| 96 | struct _HMDEVICE *pNext; /* pointer to next device in chain */
|
|---|
| 97 |
|
|---|
| 98 | LPSTR pszDeviceName; /* name or alias of the pseudo-device */
|
|---|
| 99 | HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */
|
|---|
| 100 | VOID *pDevData; /* Pointer To Device data */
|
|---|
| 101 | } HMDEVICE, *PHMDEVICE;
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | /*****************************************************************************
|
|---|
| 105 | * This pseudo-device logs all device requests to the logfile and returns *
|
|---|
| 106 | * ERROR_INVALID_FUNCTION to virtually all requests -> debugging *
|
|---|
| 107 | *****************************************************************************/
|
|---|
| 108 | class HMDeviceDebugClass : public HMDeviceHandler
|
|---|
| 109 | {
|
|---|
| 110 | public:
|
|---|
| 111 | HMDeviceDebugClass(LPCSTR lpDeviceName) : HMDeviceHandler(lpDeviceName) {}
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | /*****************************************************************************
|
|---|
| 116 | * Process Global Structures *
|
|---|
| 117 | *****************************************************************************/
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | /* the device name is repeated here to enable device alias names */
|
|---|
| 121 | static PHMDEVICE TabWin32Devices = NULL;
|
|---|
| 122 |
|
|---|
| 123 | static HMHANDLE *TabWin32Handles = NULL; /* static handle table */
|
|---|
| 124 | VMutex handleMutex;
|
|---|
| 125 |
|
|---|
| 126 | struct _HMGlobals
|
|---|
| 127 | {
|
|---|
| 128 | HANDLE hStandardIn; /* stdin handle to CONIN$ */
|
|---|
| 129 | HANDLE hStandardOut; /* stdout handle to CONOUT$ */
|
|---|
| 130 | HANDLE hStandardError; /* stderr handle to CONOUT$ */
|
|---|
| 131 |
|
|---|
| 132 | BOOL fIsInitialized; /* if HM is initialized already ? */
|
|---|
| 133 | /* this MUST !!! be false initially */
|
|---|
| 134 |
|
|---|
| 135 | HMDeviceHandler *pHMStandard; /* default handle manager instance */
|
|---|
| 136 | HMDeviceHandler *pHMOpen32; /* default handle manager instance */
|
|---|
| 137 | HMDeviceHandler *pHMEvent; /* static instances of subsystems */
|
|---|
| 138 | HMDeviceHandler *pHMFile;
|
|---|
| 139 | HMDeviceHandler *pHMDisk;
|
|---|
| 140 | HMDeviceHandler *pHMMutex;
|
|---|
| 141 | HMDeviceHandler *pHMSemaphore;
|
|---|
| 142 | HMDeviceHandler *pHMFileMapping; /* static instances of subsystems */
|
|---|
| 143 | HMDeviceHandler *pHMComm; /* serial communication */
|
|---|
| 144 | HMDeviceHandler *pHMToken; /* security tokens */
|
|---|
| 145 | HMDeviceHandler *pHMThread;
|
|---|
| 146 | HMDeviceHandler *pHMNamedPipe;
|
|---|
| 147 | HMDeviceHandler *pHMMailslot;
|
|---|
| 148 | HMDeviceHandler *pHMParPort; /* parallel communication */
|
|---|
| 149 | HMDeviceHandler *pHMNul; /* nul device */
|
|---|
| 150 |
|
|---|
| 151 | ULONG ulHandleLast; /* index of last used handle */
|
|---|
| 152 | } HMGlobals;
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 | /*****************************************************************************
|
|---|
| 156 | * Local Prototypes *
|
|---|
| 157 | *****************************************************************************/
|
|---|
| 158 |
|
|---|
| 159 | /* get appropriate device handler by the device name */
|
|---|
| 160 | static HMDeviceHandler* _Optlink _HMDeviceFind(LPSTR pszDeviceName);
|
|---|
| 161 |
|
|---|
| 162 | /* get next free handle from the handle table */
|
|---|
| 163 | static ULONG _Optlink _HMHandleGetFree(void);
|
|---|
| 164 |
|
|---|
| 165 | /* get handle table entry from handle */
|
|---|
| 166 | static ULONG _Optlink _HMHandleQuery(HANDLE hHandle);
|
|---|
| 167 |
|
|---|
| 168 | // Get GlobalDeviceData
|
|---|
| 169 | static VOID *_HMDeviceGetData (LPSTR pszDeviceName);
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /*****************************************************************************
|
|---|
| 173 | * Name : static HMDeviceHandler * _HMDeviceFind
|
|---|
| 174 | * Purpose : obtain appropriate device handler from the table by searching
|
|---|
| 175 | * for a device name or alias
|
|---|
| 176 | * Parameters: PSZ pszDeviceName
|
|---|
| 177 | * Variables :
|
|---|
| 178 | * Result : HMDeviceHandler * - pointer to the handler object
|
|---|
| 179 | * Remark :
|
|---|
| 180 | * Status :
|
|---|
| 181 | *
|
|---|
| 182 | * Author : Patrick Haller [Wed, 1998/02/11 20:42]
|
|---|
| 183 | *****************************************************************************/
|
|---|
| 184 |
|
|---|
| 185 | static HMDeviceHandler *_HMDeviceFind (LPSTR pszDeviceName)
|
|---|
| 186 | {
|
|---|
| 187 | PHMDEVICE pHMDevice; /* iterator over the device table */
|
|---|
| 188 | int namelength = strlen(pszDeviceName);
|
|---|
| 189 |
|
|---|
| 190 | if (pszDeviceName != NULL)
|
|---|
| 191 | {
|
|---|
| 192 | for (pHMDevice = TabWin32Devices; /* loop over all devices in the table */
|
|---|
| 193 | pHMDevice != NULL;
|
|---|
| 194 | pHMDevice = pHMDevice->pNext)
|
|---|
| 195 | {
|
|---|
| 196 | if(pHMDevice->pDeviceHandler->FindDevice(pHMDevice->pszDeviceName, pszDeviceName, namelength) == TRUE)
|
|---|
| 197 | {
|
|---|
| 198 | return pHMDevice->pDeviceHandler;
|
|---|
| 199 | }
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 | return (HMGlobals.pHMOpen32); /* haven't found anything, return default */
|
|---|
| 203 | }
|
|---|
| 204 | /*****************************************************************************
|
|---|
| 205 | * Name : static VOID *_HMDeviceGetData
|
|---|
| 206 | * Purpose : obtain pointer to device data from the table by searching
|
|---|
| 207 | * for a device name or alias
|
|---|
| 208 | * Parameters: PSZ pszDeviceName
|
|---|
| 209 | * Variables :
|
|---|
| 210 | * Result : VOID * - pointer to the handlers device data
|
|---|
| 211 | * Remark :
|
|---|
| 212 | * Status :
|
|---|
| 213 | *
|
|---|
| 214 | * Author : Markus Montkowski
|
|---|
| 215 | *****************************************************************************/
|
|---|
| 216 |
|
|---|
| 217 | static VOID *_HMDeviceGetData (LPSTR pszDeviceName)
|
|---|
| 218 | {
|
|---|
| 219 | PHMDEVICE pHMDevice; /* iterator over the device table */
|
|---|
| 220 | int namelength = strlen(pszDeviceName);
|
|---|
| 221 |
|
|---|
| 222 | if (pszDeviceName != NULL)
|
|---|
| 223 | {
|
|---|
| 224 | for (pHMDevice = TabWin32Devices; /* loop over all devices in the table */
|
|---|
| 225 | pHMDevice != NULL;
|
|---|
| 226 | pHMDevice = pHMDevice->pNext)
|
|---|
| 227 | {
|
|---|
| 228 | if(pHMDevice->pDeviceHandler->FindDevice(pHMDevice->pszDeviceName, pszDeviceName, namelength) == TRUE)
|
|---|
| 229 | {
|
|---|
| 230 | return (pHMDevice->pDevData); /* OK, we've found our device */
|
|---|
| 231 | }
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 | return (NULL); /* haven't found anything, return NULL */
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | /*****************************************************************************
|
|---|
| 238 | * Name : static int _HMHandleGetFree
|
|---|
| 239 | * Purpose : get index to first free handle in the handle table
|
|---|
| 240 | * Parameters:
|
|---|
| 241 | * Variables :
|
|---|
| 242 | * Result : int iIndex - index to the table or -1 in case of error
|
|---|
| 243 | * Remark :
|
|---|
| 244 | * Status :
|
|---|
| 245 | *
|
|---|
| 246 | * Author : Patrick Haller [Wed, 1998/02/11 20:43]
|
|---|
| 247 | *****************************************************************************/
|
|---|
| 248 |
|
|---|
| 249 | static ULONG _HMHandleGetFree(void)
|
|---|
| 250 | {
|
|---|
| 251 | register ULONG ulLoop;
|
|---|
| 252 |
|
|---|
| 253 | handleMutex.enter();
|
|---|
| 254 |
|
|---|
| 255 | for (ulLoop = 1; // @@@PH Note, this is an experimental change
|
|---|
| 256 | // 0L as hHandle is sometimes considered invalid!
|
|---|
| 257 | // this will never return 0l as free handle now.
|
|---|
| 258 | ulLoop < MAX_OS2_HMHANDLES;
|
|---|
| 259 | ulLoop++)
|
|---|
| 260 | {
|
|---|
| 261 | /* free handle found ? */
|
|---|
| 262 | if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) {
|
|---|
| 263 | //SvL: Mark handle as allocated here. Doing it outside of this function
|
|---|
| 264 | // isn't thread safe. (and not very smart)
|
|---|
| 265 | TabWin32Handles[ulLoop].hmHandleData.hHMHandle = ulLoop;
|
|---|
| 266 | TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0;
|
|---|
| 267 | TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
|
|---|
| 268 | TabWin32Handles[ulLoop].hmHandleData.hWin32Handle = (HANDLE)ulLoop;
|
|---|
| 269 | TabWin32Handles[ulLoop].hmHandleData.lpDeviceData = NULL;
|
|---|
| 270 | TabWin32Handles[ulLoop].hmHandleData.dwHandleInformation = 0;
|
|---|
| 271 | handleMutex.leave();
|
|---|
| 272 | return (ulLoop); /* OK, then return it to the caller */
|
|---|
| 273 | }
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | handleMutex.leave();
|
|---|
| 277 | return (INVALID_HANDLE_VALUE); /* haven't found any free handle */
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 | /*****************************************************************************
|
|---|
| 282 | * Name : HMHandleGetUserData
|
|---|
| 283 | * Purpose : Get the dwUserData dword for a specific handle
|
|---|
| 284 | * Parameters: HANDLE hHandle
|
|---|
| 285 | * Variables :
|
|---|
| 286 | * Result : -1 or dwUserData
|
|---|
| 287 | * Remark :
|
|---|
| 288 | * Status :
|
|---|
| 289 | *
|
|---|
| 290 | * Author : SvL
|
|---|
| 291 | *****************************************************************************/
|
|---|
| 292 | DWORD HMHandleGetUserData(ULONG hHandle)
|
|---|
| 293 | {
|
|---|
| 294 | if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */
|
|---|
| 295 | return (-1);
|
|---|
| 296 | /* Oops, invalid handle ! */
|
|---|
| 297 | if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
|
|---|
| 298 | return (-1); /* nope, ERROR_INVALID_HANDLE */
|
|---|
| 299 |
|
|---|
| 300 | return TabWin32Handles[hHandle].hmHandleData.dwUserData;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | /*****************************************************************************
|
|---|
| 304 | * Name : HMHandleGetUserData
|
|---|
| 305 | * Purpose : Get the dwUserData dword for a specific handle
|
|---|
| 306 | * Parameters: HANDLE hHandle
|
|---|
| 307 | * Variables :
|
|---|
| 308 | * Result : -1 or dwUserData
|
|---|
| 309 | * Remark :
|
|---|
| 310 | * Status :
|
|---|
| 311 | *
|
|---|
| 312 | * Author : SvL
|
|---|
| 313 | *****************************************************************************/
|
|---|
| 314 | DWORD HMHandleSetUserData(ULONG hHandle, ULONG dwUserData)
|
|---|
| 315 | {
|
|---|
| 316 | if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */
|
|---|
| 317 | return (-1);
|
|---|
| 318 | /* Oops, invalid handle ! */
|
|---|
| 319 | if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
|
|---|
| 320 | return (-1); /* nope, ERROR_INVALID_HANDLE */
|
|---|
| 321 |
|
|---|
| 322 | TabWin32Handles[hHandle].hmHandleData.dwUserData = dwUserData;
|
|---|
| 323 | return NO_ERROR;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | /*****************************************************************************
|
|---|
| 327 | * Name : static int _HMHandleQuery
|
|---|
| 328 | * Purpose : gets the index of handle table entry as fast as possible from
|
|---|
| 329 | * the specified handle
|
|---|
| 330 | * Parameters: HANDLE hHandle
|
|---|
| 331 | * Variables :
|
|---|
| 332 | * Result : index or -1 in case of error
|
|---|
| 333 | * Remark : Should fail for standard handles (in/out/err)!!!!!!!!!!
|
|---|
| 334 | * HMGetFileType depends on this!!!
|
|---|
| 335 | * Status :
|
|---|
| 336 | *
|
|---|
| 337 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 338 | *****************************************************************************/
|
|---|
| 339 |
|
|---|
| 340 | static ULONG INLINE _HMHandleQuery(HANDLE hHandle)
|
|---|
| 341 | {
|
|---|
| 342 | if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */
|
|---|
| 343 | return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */
|
|---|
| 344 |
|
|---|
| 345 | /* Oops, invalid handle ! */
|
|---|
| 346 | if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
|
|---|
| 347 | return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */
|
|---|
| 348 |
|
|---|
| 349 | return ( hHandle); /* OK, we've got our handle index */
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 | /*****************************************************************************
|
|---|
| 354 | * Name : DWORD HMDeviceRegister
|
|---|
| 355 | * Purpose : register a device with the handle manager
|
|---|
| 356 | * Parameters: PSZ pszDeviceName
|
|---|
| 357 | * HMDeviceHandler *pDeviceHandler
|
|---|
| 358 | * Variables :
|
|---|
| 359 | * Result : API returncode
|
|---|
| 360 | * Remark :
|
|---|
| 361 | * Status :
|
|---|
| 362 | *
|
|---|
| 363 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 364 | *****************************************************************************/
|
|---|
| 365 |
|
|---|
| 366 | DWORD HMDeviceRegisterEx(LPSTR pszDeviceName,
|
|---|
| 367 | HMDeviceHandler *pDeviceHandler,
|
|---|
| 368 | VOID *pDevData)
|
|---|
| 369 | {
|
|---|
| 370 | PHMDEVICE pHMDevice; /* our new device to be allocated */
|
|---|
| 371 |
|
|---|
| 372 | if ( (pszDeviceName == NULL) || /* check parameters */
|
|---|
| 373 | (pDeviceHandler == NULL) )
|
|---|
| 374 | return (ERROR_INVALID_PARAMETER); /* raise error conditon */
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 | pHMDevice = (PHMDEVICE) malloc (sizeof (HMDEVICE) ); /* allocate memory */
|
|---|
| 378 | if (pHMDevice == NULL) /* check proper allocation */
|
|---|
| 379 | return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */
|
|---|
| 380 |
|
|---|
| 381 | pHMDevice->pszDeviceName = strdup(pszDeviceName); /* copy name */
|
|---|
| 382 | if (pHMDevice->pszDeviceName == NULL) /* check proper allocation */
|
|---|
| 383 | {
|
|---|
| 384 | free (pHMDevice); /* free previously allocated memory */
|
|---|
| 385 | return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | pHMDevice->pDeviceHandler = pDeviceHandler; /* store pointer to device */
|
|---|
| 389 | pHMDevice->pNext = TabWin32Devices; /* establish linkage */
|
|---|
| 390 | pHMDevice->pDevData = pDevData;
|
|---|
| 391 |
|
|---|
| 392 | TabWin32Devices = pHMDevice; /* insert new node as root in the list */
|
|---|
| 393 |
|
|---|
| 394 | return (NO_ERROR);
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | DWORD HMDeviceRegister(LPSTR pszDeviceName,
|
|---|
| 398 | HMDeviceHandler *pDeviceHandler)
|
|---|
| 399 | {
|
|---|
| 400 | return HMDeviceRegisterEx(pszDeviceName, pDeviceHandler, NULL);
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | /*****************************************************************************
|
|---|
| 404 | * Name : DWORD HMInitialize
|
|---|
| 405 | * Purpose : Initialize the handlemanager
|
|---|
| 406 | * Parameters: -
|
|---|
| 407 | * Variables : -
|
|---|
| 408 | * Result : always NO_ERROR
|
|---|
| 409 | * Remark : this routine just stores the standard handles in the
|
|---|
| 410 | * internal table within the HandleManager
|
|---|
| 411 | * Status :
|
|---|
| 412 | *
|
|---|
| 413 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 414 | *****************************************************************************/
|
|---|
| 415 |
|
|---|
| 416 | DWORD HMInitialize(void)
|
|---|
| 417 | {
|
|---|
| 418 | ULONG ulIndex;
|
|---|
| 419 |
|
|---|
| 420 | if (HMGlobals.fIsInitialized != TRUE)
|
|---|
| 421 | {
|
|---|
| 422 | handleMutex.enter();
|
|---|
| 423 |
|
|---|
| 424 | TabWin32Handles = (HMHANDLE *)malloc(MAX_OS2_HMHANDLES*sizeof(HMHANDLE));
|
|---|
| 425 | if(TabWin32Handles == NULL) {
|
|---|
| 426 | DebugInt3();
|
|---|
| 427 | return ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 428 | }
|
|---|
| 429 | memset(TabWin32Handles, 0, MAX_OS2_HMHANDLES*sizeof(HMHANDLE));
|
|---|
| 430 |
|
|---|
| 431 | // fill handle table
|
|---|
| 432 | for(ulIndex = 0; ulIndex < MAX_OS2_HMHANDLES; ulIndex++) {
|
|---|
| 433 | TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 434 | }
|
|---|
| 435 | handleMutex.leave();
|
|---|
| 436 |
|
|---|
| 437 | dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n"));
|
|---|
| 438 |
|
|---|
| 439 | memset(&HMGlobals, /* zero out the structure first */
|
|---|
| 440 | 0,
|
|---|
| 441 | sizeof(HMGlobals));
|
|---|
| 442 |
|
|---|
| 443 | HMGlobals.fIsInitialized = TRUE; /* OK, done */
|
|---|
| 444 |
|
|---|
| 445 | #if 1
|
|---|
| 446 | //This is a very bad idea. \\\\.\\NTICE -> NTICE, if the file exits, then
|
|---|
| 447 | //it will open the file instead of the device driver
|
|---|
| 448 | /* add standard symbolic links first, so local symbolic links in the
|
|---|
| 449 | * device handlers get precedence over the default here.
|
|---|
| 450 | *
|
|---|
| 451 | * Device handlers are supposed to place the appropriate
|
|---|
| 452 | * symbolic links such as "\\.\\COM1", "COM1"
|
|---|
| 453 | *
|
|---|
| 454 | * - "\\.\f:\temp\readme.txt" is a valid file
|
|---|
| 455 | * - "com1" is a valid device in case serial port 1 exists,
|
|---|
| 456 | * otherwise it'd be a valid file.
|
|---|
| 457 | * - "\\.\filename" is the only misleading case (to be verified)
|
|---|
| 458 | *
|
|---|
| 459 | * Note:
|
|---|
| 460 | * the Open32 "device" definately MUST be the last device to be
|
|---|
| 461 | * asked to accept the specified name.
|
|---|
| 462 | */
|
|---|
| 463 | {
|
|---|
| 464 | // strings are placed in read-only segment
|
|---|
| 465 | PSZ pszDrive = strdup("\\\\.\\x:");
|
|---|
| 466 | PSZ pszDrive2 = strdup("\\\\.\\x:");
|
|---|
| 467 | for (char ch = 'A'; ch <= 'Z'; ch++)
|
|---|
| 468 | {
|
|---|
| 469 | pszDrive[4] = ch;
|
|---|
| 470 | pszDrive2[4] = ch;
|
|---|
| 471 | HandleNamesAddSymbolicLink(pszDrive, pszDrive+4);
|
|---|
| 472 | HandleNamesAddSymbolicLink(pszDrive2, pszDrive2+4);
|
|---|
| 473 | }
|
|---|
| 474 | free(pszDrive);
|
|---|
| 475 | free(pszDrive2);
|
|---|
| 476 | HandleNamesAddSymbolicLink("\\\\?\\UNC\\", "\\\\");
|
|---|
| 477 | //SvL: Can be used in Windows 2000 to open device drivers
|
|---|
| 478 | HandleNamesAddSymbolicLink("\\\\.\\Global", "\\\\.");
|
|---|
| 479 | }
|
|---|
| 480 | #endif
|
|---|
| 481 |
|
|---|
| 482 | /* copy standard handles from OS/2's Open32 Subsystem */
|
|---|
| 483 | HMGlobals.pHMStandard = new HMDeviceStandardClass("\\\\STANDARD_HANDLE\\");
|
|---|
| 484 | HMSetStdHandle(STD_INPUT_HANDLE, O32_GetStdHandle(STD_INPUT_HANDLE));
|
|---|
| 485 | HMSetStdHandle(STD_OUTPUT_HANDLE, O32_GetStdHandle(STD_OUTPUT_HANDLE));
|
|---|
| 486 | HMSetStdHandle(STD_ERROR_HANDLE, O32_GetStdHandle(STD_ERROR_HANDLE));
|
|---|
| 487 |
|
|---|
| 488 | /* create handle manager instance for Open32 handles */
|
|---|
| 489 | HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\");
|
|---|
| 490 | HMGlobals.pHMEvent = new HMDeviceEventClass("\\\\EVENT\\");
|
|---|
| 491 | HMGlobals.pHMFile = new HMDeviceFileClass("\\\\FILE\\");
|
|---|
| 492 | HMGlobals.pHMDisk = new HMDeviceDiskClass("\\\\DISK\\");
|
|---|
| 493 | HMGlobals.pHMMutex = new HMDeviceMutexClass("\\\\MUTEX\\");
|
|---|
| 494 | HMGlobals.pHMSemaphore = new HMDeviceSemaphoreClass("\\\\SEM\\");
|
|---|
| 495 | HMGlobals.pHMFileMapping= new HMDeviceMemMapClass("\\\\MEMMAP\\");
|
|---|
| 496 | HMGlobals.pHMComm = new HMDeviceCommClass("\\\\COM\\");
|
|---|
| 497 | HMGlobals.pHMToken = new HMDeviceTokenClass("\\\\TOKEN\\");
|
|---|
| 498 | HMGlobals.pHMThread = new HMDeviceThreadClass("\\\\THREAD\\");
|
|---|
| 499 | HMGlobals.pHMNamedPipe = new HMDeviceNamedPipeClass("\\\\PIPE\\");
|
|---|
| 500 | HMGlobals.pHMMailslot = new HMMailslotClass("\\MAILSLOT\\");
|
|---|
| 501 | HMGlobals.pHMParPort = new HMDeviceParPortClass("\\\\LPT\\");
|
|---|
| 502 | HMGlobals.pHMNul = new HMDeviceNulClass("\\\\NUL\\");
|
|---|
| 503 | }
|
|---|
| 504 | return (NO_ERROR);
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 | /*****************************************************************************
|
|---|
| 509 | * Name : DWORD HMTerminate
|
|---|
| 510 | * Purpose : Terminate the handlemanager
|
|---|
| 511 | * Parameters:
|
|---|
| 512 | * Variables :
|
|---|
| 513 | * Result :
|
|---|
| 514 | * Remark :
|
|---|
| 515 | * Status :
|
|---|
| 516 | *
|
|---|
| 517 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 518 | *****************************************************************************/
|
|---|
| 519 |
|
|---|
| 520 | DWORD HMTerminate(void)
|
|---|
| 521 | {
|
|---|
| 522 | /* @@@PH we could deallocate the device list here */
|
|---|
| 523 |
|
|---|
| 524 | if(HMGlobals.pHMOpen32)
|
|---|
| 525 | delete HMGlobals.pHMOpen32;
|
|---|
| 526 | if(HMGlobals.pHMEvent)
|
|---|
| 527 | delete HMGlobals.pHMEvent;
|
|---|
| 528 | if(HMGlobals.pHMFile)
|
|---|
| 529 | delete HMGlobals.pHMFile;
|
|---|
| 530 | if(HMGlobals.pHMMutex)
|
|---|
| 531 | delete HMGlobals.pHMMutex;
|
|---|
| 532 | if(HMGlobals.pHMSemaphore)
|
|---|
| 533 | delete HMGlobals.pHMSemaphore;
|
|---|
| 534 | if(HMGlobals.pHMFileMapping)
|
|---|
| 535 | delete HMGlobals.pHMFileMapping;
|
|---|
| 536 | if(HMGlobals.pHMComm)
|
|---|
| 537 | delete HMGlobals.pHMComm;
|
|---|
| 538 | if(HMGlobals.pHMToken)
|
|---|
| 539 | delete HMGlobals.pHMToken;
|
|---|
| 540 | if(HMGlobals.pHMThread)
|
|---|
| 541 | delete HMGlobals.pHMThread;
|
|---|
| 542 | if(HMGlobals.pHMNamedPipe)
|
|---|
| 543 | delete HMGlobals.pHMNamedPipe;
|
|---|
| 544 | if(HMGlobals.pHMMailslot)
|
|---|
| 545 | delete HMGlobals.pHMMailslot;
|
|---|
| 546 | if(HMGlobals.pHMDisk)
|
|---|
| 547 | delete HMGlobals.pHMDisk;
|
|---|
| 548 | if(HMGlobals.pHMStandard);
|
|---|
| 549 | delete HMGlobals.pHMStandard;
|
|---|
| 550 | if(HMGlobals.pHMParPort)
|
|---|
| 551 | delete HMGlobals.pHMParPort;
|
|---|
| 552 | if(HMGlobals.pHMNul)
|
|---|
| 553 | delete HMGlobals.pHMNul;
|
|---|
| 554 |
|
|---|
| 555 | return (NO_ERROR);
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 | /*****************************************************************************/
|
|---|
| 560 | /* handle translation buffer management */
|
|---|
| 561 | /* */
|
|---|
| 562 | /* Since some Win32 applications rely (!) on 16-bit handles, we've got to do */
|
|---|
| 563 | /* 32-bit to 16-bit and vs vsa translation here. */
|
|---|
| 564 | /* Filehandle-based functions should be routed via the handlemanager instead */
|
|---|
| 565 | /* of going to Open32 directly. */
|
|---|
| 566 | /*****************************************************************************/
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 | /*****************************************************************************
|
|---|
| 570 | * Name : DWORD HMHandleAllocate
|
|---|
| 571 | * Purpose : allocate a handle in the translation table
|
|---|
| 572 | * Parameters: PULONG pHandle16 - to return the allocated handle
|
|---|
| 573 | * ULONG hHandle32 - the associated OS/2 handle
|
|---|
| 574 | * Variables :
|
|---|
| 575 | * Result : API returncode
|
|---|
| 576 | * Remark : no parameter checking is done, phHandle may not be invalid
|
|---|
| 577 | * hHandle32 shouldn't be 0
|
|---|
| 578 | * Should be protected with a HM-Mutex !
|
|---|
| 579 | * Status :
|
|---|
| 580 | *
|
|---|
| 581 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 582 | *****************************************************************************/
|
|---|
| 583 |
|
|---|
| 584 | DWORD HMHandleAllocate (PULONG phHandle16,
|
|---|
| 585 | ULONG hHandleOS2)
|
|---|
| 586 | {
|
|---|
| 587 | register ULONG ulHandle;
|
|---|
| 588 |
|
|---|
| 589 | #ifdef DEBUG_LOCAL
|
|---|
| 590 | dprintf(("KERNEL32: HMHandleAllocate (%08xh,%08xh)\n",
|
|---|
| 591 | phHandle16,
|
|---|
| 592 | hHandleOS2));
|
|---|
| 593 | #endif
|
|---|
| 594 |
|
|---|
| 595 | // @@@PH 2001-09-27
|
|---|
| 596 | // prevent too quick re-use of last handle
|
|---|
| 597 | ulHandle = HMGlobals.ulHandleLast + 1; /* get free handle */
|
|---|
| 598 |
|
|---|
| 599 | handleMutex.enter();
|
|---|
| 600 |
|
|---|
| 601 | if(ulHandle == 0) {
|
|---|
| 602 | ulHandle = 1; //SvL: Start searching from index 1
|
|---|
| 603 | }
|
|---|
| 604 | do
|
|---|
| 605 | {
|
|---|
| 606 | /* check if handle is free */
|
|---|
| 607 | if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
|
|---|
| 608 | {
|
|---|
| 609 | *phHandle16 = ulHandle;
|
|---|
| 610 | TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2;
|
|---|
| 611 | TabWin32Handles[ulHandle].hmHandleData.lpDeviceData = NULL;
|
|---|
| 612 | HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */
|
|---|
| 613 |
|
|---|
| 614 | handleMutex.leave();
|
|---|
| 615 | return (NO_ERROR); /* OK */
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | ulHandle++; /* skip to next entry */
|
|---|
| 619 |
|
|---|
| 620 | if (ulHandle >= MAX_OS2_HMHANDLES) /* check boundary */
|
|---|
| 621 | ulHandle = 1;
|
|---|
| 622 | }
|
|---|
| 623 | while (ulHandle != HMGlobals.ulHandleLast);
|
|---|
| 624 |
|
|---|
| 625 | handleMutex.leave();
|
|---|
| 626 |
|
|---|
| 627 | return (ERROR_TOO_MANY_OPEN_FILES); /* OK, we're done */
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 | /*****************************************************************************
|
|---|
| 632 | * Name : DWORD HMHandleFree
|
|---|
| 633 | * Purpose : free a handle from the translation table
|
|---|
| 634 | * Parameters: ULONG hHandle16 - the handle to be freed
|
|---|
| 635 | * Variables :
|
|---|
| 636 | * Result : API returncode
|
|---|
| 637 | * Remark : no parameter checking is done, hHandle16 MAY NEVER exceed
|
|---|
| 638 | * the MAX_TRANSLATION_HANDLES boundary
|
|---|
| 639 | * Status :
|
|---|
| 640 | *
|
|---|
| 641 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 642 | *****************************************************************************/
|
|---|
| 643 |
|
|---|
| 644 | DWORD HMHandleFree (ULONG hHandle16)
|
|---|
| 645 | {
|
|---|
| 646 | ULONG rc; /* API returncode */
|
|---|
| 647 |
|
|---|
| 648 | #ifdef DEBUG_LOCAL
|
|---|
| 649 | dprintf(("KERNEL32: HMHandleFree (%08xh)\n",
|
|---|
| 650 | hHandle16));
|
|---|
| 651 | #endif
|
|---|
| 652 |
|
|---|
| 653 | rc = HMHandleValidate(hHandle16); /* verify handle */
|
|---|
| 654 | if (rc != NO_ERROR) /* check errors */
|
|---|
| 655 | return (rc); /* raise error condition */
|
|---|
| 656 |
|
|---|
| 657 | TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 658 | /* OK, done */
|
|---|
| 659 |
|
|---|
| 660 | return (NO_ERROR);
|
|---|
| 661 | }
|
|---|
| 662 |
|
|---|
| 663 |
|
|---|
| 664 | /*****************************************************************************
|
|---|
| 665 | * Name : DWORD HMHandleValidate
|
|---|
| 666 | * Purpose : validate a handle through the translation table
|
|---|
| 667 | * Parameters: ULONG hHandle16 - the handle to be verified
|
|---|
| 668 | * Variables :
|
|---|
| 669 | * Result : API returncode
|
|---|
| 670 | * Remark :
|
|---|
| 671 | * Status :
|
|---|
| 672 | *
|
|---|
| 673 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 674 | *****************************************************************************/
|
|---|
| 675 |
|
|---|
| 676 | DWORD HMHandleValidate (ULONG hHandle16)
|
|---|
| 677 | {
|
|---|
| 678 | #ifdef DEBUG_LOCAL
|
|---|
| 679 | dprintf(("KERNEL32: HMHandleValidate (%08xh)\n",
|
|---|
| 680 | hHandle16));
|
|---|
| 681 | #endif
|
|---|
| 682 |
|
|---|
| 683 | if (hHandle16 >= MAX_OS2_HMHANDLES) /* check boundary */
|
|---|
| 684 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 685 |
|
|---|
| 686 | if (TabWin32Handles[hHandle16].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
|
|---|
| 687 | /* valid ? */
|
|---|
| 688 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 689 |
|
|---|
| 690 | return (NO_ERROR);
|
|---|
| 691 | }
|
|---|
| 692 | //*****************************************************************************
|
|---|
| 693 | //*****************************************************************************
|
|---|
| 694 | PHMHANDLEDATA HMQueryHandleData(HANDLE handle)
|
|---|
| 695 | {
|
|---|
| 696 | int iIndex;
|
|---|
| 697 |
|
|---|
| 698 | iIndex = _HMHandleQuery(handle); /* get the index */
|
|---|
| 699 | if (-1 == iIndex) /* error ? */
|
|---|
| 700 | {
|
|---|
| 701 | return NULL;
|
|---|
| 702 | }
|
|---|
| 703 | return &TabWin32Handles[iIndex].hmHandleData; /* call device handler */
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | /*****************************************************************************
|
|---|
| 707 | * Name : DWORD HMHandleTranslateToWin
|
|---|
| 708 | * Purpose : translate a 32-bit OS/2 handle to the associated windows handle
|
|---|
| 709 | * Parameters: ULONG hHandle32 - the OS/2 handle
|
|---|
| 710 | * PULONG phHandle16 - the associated windows handle
|
|---|
| 711 | * Variables :
|
|---|
| 712 | * Result : API returncode
|
|---|
| 713 | * Remark :
|
|---|
| 714 | * Status :
|
|---|
| 715 | *
|
|---|
| 716 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 717 | *****************************************************************************/
|
|---|
| 718 |
|
|---|
| 719 | DWORD HMHandleTranslateToWin (ULONG hHandleOS2,
|
|---|
| 720 | PULONG phHandle16)
|
|---|
| 721 | {
|
|---|
| 722 | ULONG rc; /* API returncode */
|
|---|
| 723 | register ULONG ulIndex; /* index counter over the table */
|
|---|
| 724 |
|
|---|
| 725 | #ifdef DEBUG_LOCAL
|
|---|
| 726 | dprintf(("KERNEL32: HMHandleTranslateToWin (%08xh, %08xh)\n",
|
|---|
| 727 | hHandleOS2,
|
|---|
| 728 | phHandle16));
|
|---|
| 729 | #endif
|
|---|
| 730 |
|
|---|
| 731 | for (ulIndex = 1;
|
|---|
| 732 | ulIndex < MAX_OS2_HMHANDLES;
|
|---|
| 733 | ulIndex++)
|
|---|
| 734 | {
|
|---|
| 735 | /* look for the handle */
|
|---|
| 736 | if (TabWin32Handles[ulIndex].hmHandleData.hHMHandle == hHandleOS2)
|
|---|
| 737 | {
|
|---|
| 738 | *phHandle16 = ulIndex; /* deliver result */
|
|---|
| 739 | return (NO_ERROR); /* OK */
|
|---|
| 740 | }
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 | /*****************************************************************************
|
|---|
| 748 | * Name : DWORD HMHandleTranslateToOS2
|
|---|
| 749 | * Purpose : translate a 16-bit Win32 handle to the associated OS/2 handle
|
|---|
| 750 | * Parameters: ULONG hHandle16 - the windows handle
|
|---|
| 751 | * PULONG phHandle32 - the associated OS/2 handle
|
|---|
| 752 | * Variables :
|
|---|
| 753 | * Result : API returncode
|
|---|
| 754 | * Remark :
|
|---|
| 755 | * Status :
|
|---|
| 756 | *
|
|---|
| 757 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 758 | *****************************************************************************/
|
|---|
| 759 |
|
|---|
| 760 | DWORD HMHandleTranslateToOS2 (ULONG hHandle16,
|
|---|
| 761 | PULONG phHandleOS2)
|
|---|
| 762 | {
|
|---|
| 763 | #ifdef DEBUG_LOCAL
|
|---|
| 764 | dprintf(("KERNEL32: HMHandleTranslateToOS2 (%08xh, %08xh)\n",
|
|---|
| 765 | hHandle16,
|
|---|
| 766 | phHandleOS2));
|
|---|
| 767 | #endif
|
|---|
| 768 |
|
|---|
| 769 | if (HMHandleValidate(hHandle16) == NO_ERROR) /* verify handle */
|
|---|
| 770 | {
|
|---|
| 771 | *phHandleOS2 = TabWin32Handles[hHandle16].hmHandleData.hHMHandle;
|
|---|
| 772 | return (NO_ERROR);
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 776 | }
|
|---|
| 777 |
|
|---|
| 778 |
|
|---|
| 779 | /*****************************************************************************
|
|---|
| 780 | * Name : DWORD HMHandleTranslateToOS2i
|
|---|
| 781 | * Purpose : translate a 16-bit Win32 handle to the associated OS/2 handle
|
|---|
| 782 | * Parameters: ULONG hHandle16 - the windows handle
|
|---|
| 783 | * Variables :
|
|---|
| 784 | * Result : OS/2 handle
|
|---|
| 785 | * Remark : no checkinf
|
|---|
| 786 | * Status :
|
|---|
| 787 | *
|
|---|
| 788 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 789 | *****************************************************************************/
|
|---|
| 790 |
|
|---|
| 791 | DWORD HMHandleTranslateToOS2i (ULONG hHandle16)
|
|---|
| 792 | {
|
|---|
| 793 | #ifdef DEBUG_LOCAL
|
|---|
| 794 | dprintf(("KERNEL32: HMHandleTranslateToOS2i (%08xh)\n",
|
|---|
| 795 | hHandle16));
|
|---|
| 796 | #endif
|
|---|
| 797 |
|
|---|
| 798 | return(TabWin32Handles[hHandle16].hmHandleData.hHMHandle);
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | /*****************************************************************************
|
|---|
| 802 | * Name : HANDLE _HMGetStdHandle
|
|---|
| 803 | * Purpose : replacement for Open32's GetStdHandle function
|
|---|
| 804 | * Parameters: DWORD nStdHandle
|
|---|
| 805 | * Variables :
|
|---|
| 806 | * Result : HANDLE to standard device
|
|---|
| 807 | * Remark :
|
|---|
| 808 | * Status :
|
|---|
| 809 | *
|
|---|
| 810 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 811 | *****************************************************************************/
|
|---|
| 812 |
|
|---|
| 813 | HANDLE HMGetStdHandle(DWORD nStdHandle)
|
|---|
| 814 | {
|
|---|
| 815 | switch (nStdHandle)
|
|---|
| 816 | {
|
|---|
| 817 | case STD_INPUT_HANDLE: return (HMGlobals.hStandardIn);
|
|---|
| 818 | case STD_OUTPUT_HANDLE: return (HMGlobals.hStandardOut);
|
|---|
| 819 | case STD_ERROR_HANDLE: return (HMGlobals.hStandardError);
|
|---|
| 820 |
|
|---|
| 821 | default:
|
|---|
| 822 | {
|
|---|
| 823 | SetLastError(ERROR_INVALID_PARAMETER); /* set error information */
|
|---|
| 824 | return (INVALID_HANDLE_VALUE); /* raise error condition */
|
|---|
| 825 | }
|
|---|
| 826 | }
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 |
|
|---|
| 830 | /*****************************************************************************
|
|---|
| 831 | * Name : HANDLE _HMSetStdHandle
|
|---|
| 832 | * Purpose : replacement for Open32's SetStdHandle function
|
|---|
| 833 | * Parameters: DWORD nStdHandle
|
|---|
| 834 | * HANDLE hHandle
|
|---|
| 835 | * Variables :
|
|---|
| 836 | * Result : BOOL fSuccess
|
|---|
| 837 | * Remark :
|
|---|
| 838 | * Status :
|
|---|
| 839 | *
|
|---|
| 840 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 841 | *****************************************************************************/
|
|---|
| 842 |
|
|---|
| 843 | BOOL HMSetStdHandle(DWORD nStdHandle, HANDLE hHandleOpen32)
|
|---|
| 844 | {
|
|---|
| 845 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 846 | HANDLE hHandle;
|
|---|
| 847 |
|
|---|
| 848 | hHandle = _HMHandleGetFree(); /* get free handle */
|
|---|
| 849 | if (hHandle == -1) /* oops, no free handles ! */
|
|---|
| 850 | {
|
|---|
| 851 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 852 | return 0;
|
|---|
| 853 | }
|
|---|
| 854 |
|
|---|
| 855 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 856 | pHMHandleData = &TabWin32Handles[hHandle].hmHandleData;
|
|---|
| 857 | pHMHandleData->dwAccess = 0;
|
|---|
| 858 | pHMHandleData->dwShare = 0;
|
|---|
| 859 | pHMHandleData->dwCreation = 0;
|
|---|
| 860 | pHMHandleData->dwFlags = 0;
|
|---|
| 861 | pHMHandleData->dwUserData = nStdHandle;
|
|---|
| 862 | pHMHandleData->hHMHandle = hHandleOpen32;
|
|---|
| 863 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 864 |
|
|---|
| 865 | TabWin32Handles[hHandle].pDeviceHandler = HMGlobals.pHMStandard;
|
|---|
| 866 |
|
|---|
| 867 | switch (nStdHandle)
|
|---|
| 868 | {
|
|---|
| 869 | case STD_INPUT_HANDLE: HMGlobals.hStandardIn = hHandle; return TRUE;
|
|---|
| 870 | case STD_OUTPUT_HANDLE: HMGlobals.hStandardOut = hHandle; return TRUE;
|
|---|
| 871 | case STD_ERROR_HANDLE: HMGlobals.hStandardError = hHandle; return TRUE;
|
|---|
| 872 |
|
|---|
| 873 | default:
|
|---|
| 874 | {
|
|---|
| 875 | SetLastError(ERROR_INVALID_PARAMETER); /* set error information */
|
|---|
| 876 | return (FALSE); /* raise error condition */
|
|---|
| 877 | }
|
|---|
| 878 | }
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 |
|
|---|
| 882 | /*****************************************************************************
|
|---|
| 883 | * Name : HANDLE HMDuplicateHandle
|
|---|
| 884 | * Purpose : replacement for Open32's HMDuplicateHandle function
|
|---|
| 885 | * Parameters:
|
|---|
| 886 | *
|
|---|
| 887 | * Variables :
|
|---|
| 888 | * Result : BOOL fSuccess
|
|---|
| 889 | * Remark :
|
|---|
| 890 | * Status :
|
|---|
| 891 | *
|
|---|
| 892 | * Author : Sander van Leeuwen [Wed, 1999/08/25 15:44]
|
|---|
| 893 | *****************************************************************************/
|
|---|
| 894 |
|
|---|
| 895 | BOOL HMDuplicateHandle(HANDLE srcprocess,
|
|---|
| 896 | HANDLE srchandle,
|
|---|
| 897 | HANDLE destprocess,
|
|---|
| 898 | PHANDLE desthandle,
|
|---|
| 899 | DWORD fdwAccess,
|
|---|
| 900 | BOOL fInherit,
|
|---|
| 901 | DWORD fdwOptions,
|
|---|
| 902 | DWORD fdwOdinOptions)
|
|---|
| 903 | {
|
|---|
| 904 | int iIndex; /* index into the handle table */
|
|---|
| 905 | int iIndexNew; /* index into the handle table */
|
|---|
| 906 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 907 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 908 | BOOL rc; /* API return code */
|
|---|
| 909 |
|
|---|
| 910 | if(HMHandleValidate(srchandle) != NO_ERROR)
|
|---|
| 911 | {
|
|---|
| 912 | dprintf(("KERNEL32: HMDuplicateHandle: invalid handle %x", srchandle));
|
|---|
| 913 | SetLastError(ERROR_INVALID_HANDLE); /* use this as error message */
|
|---|
| 914 | return FALSE;
|
|---|
| 915 | }
|
|---|
| 916 |
|
|---|
| 917 | pDeviceHandler = TabWin32Handles[srchandle].pDeviceHandler; /* device is predefined */
|
|---|
| 918 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 919 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 920 | {
|
|---|
| 921 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 922 | return FALSE; /* signal error */
|
|---|
| 923 | }
|
|---|
| 924 |
|
|---|
| 925 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 926 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 927 | if (fdwOptions & DUPLICATE_SAME_ACCESS)
|
|---|
| 928 | pHMHandleData->dwAccess = TabWin32Handles[srchandle].hmHandleData.dwAccess;
|
|---|
| 929 | else
|
|---|
| 930 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 931 |
|
|---|
| 932 | if((fdwOdinOptions & DUPLICATE_ACCESS_READWRITE) == DUPLICATE_ACCESS_READWRITE) {
|
|---|
| 933 | pHMHandleData->dwAccess = GENERIC_READ | GENERIC_WRITE;
|
|---|
| 934 | }
|
|---|
| 935 | else
|
|---|
| 936 | if(fdwOdinOptions & DUPLICATE_ACCESS_READ) {
|
|---|
| 937 | pHMHandleData->dwAccess = GENERIC_READ;
|
|---|
| 938 | }
|
|---|
| 939 |
|
|---|
| 940 | if(fdwOdinOptions & DUPLICATE_SHARE_READ) {
|
|---|
| 941 | pHMHandleData->dwShare = FILE_SHARE_READ;
|
|---|
| 942 | }
|
|---|
| 943 | else
|
|---|
| 944 | if(fdwOdinOptions & DUPLICATE_SHARE_DENYNONE) {
|
|---|
| 945 | pHMHandleData->dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
|---|
| 946 | }
|
|---|
| 947 | else pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare;
|
|---|
| 948 |
|
|---|
| 949 | pHMHandleData->dwCreation = TabWin32Handles[srchandle].hmHandleData.dwCreation;
|
|---|
| 950 | pHMHandleData->dwFlags = TabWin32Handles[srchandle].hmHandleData.dwFlags;
|
|---|
| 951 | pHMHandleData->lpHandlerData = TabWin32Handles[srchandle].hmHandleData.lpHandlerData;
|
|---|
| 952 |
|
|---|
| 953 |
|
|---|
| 954 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 955 | /* could be created within the device handler -> deadlock */
|
|---|
| 956 |
|
|---|
| 957 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 958 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 959 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 960 | /* call the device handler */
|
|---|
| 961 | rc = pDeviceHandler->DuplicateHandle(srchandle,
|
|---|
| 962 | &TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 963 | srcprocess,
|
|---|
| 964 | &TabWin32Handles[srchandle].hmHandleData,
|
|---|
| 965 | destprocess,
|
|---|
| 966 | desthandle,
|
|---|
| 967 | fdwAccess,
|
|---|
| 968 | fInherit,
|
|---|
| 969 | fdwOptions & ~DUPLICATE_CLOSE_SOURCE,
|
|---|
| 970 | fdwOdinOptions);
|
|---|
| 971 |
|
|---|
| 972 | //Don't let Open32 close it for us, but do it manually (regardless of error; see SDK docs))
|
|---|
| 973 | if (fdwOptions & DUPLICATE_CLOSE_SOURCE)
|
|---|
| 974 | HMCloseHandle(srchandle);
|
|---|
| 975 |
|
|---|
| 976 | if(rc == FALSE) /* oops, creation failed within the device handler */
|
|---|
| 977 | {
|
|---|
| 978 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 979 | return FALSE; /* signal error */
|
|---|
| 980 | }
|
|---|
| 981 | else
|
|---|
| 982 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 983 |
|
|---|
| 984 | *desthandle = iIndexNew;
|
|---|
| 985 | return TRUE; /* return valid handle */
|
|---|
| 986 | }
|
|---|
| 987 |
|
|---|
| 988 | /*****************************************************************************
|
|---|
| 989 | * Name : HANDLE HMCreateFile
|
|---|
| 990 | * Purpose : Wrapper for the CreateFile() API
|
|---|
| 991 | * Parameters:
|
|---|
| 992 | * Variables :
|
|---|
| 993 | * Result :
|
|---|
| 994 | * Remark : Fix parameters passed to the HMDeviceManager::CreateFile
|
|---|
| 995 | * Supply access mode and share mode validation routines
|
|---|
| 996 | * Status :
|
|---|
| 997 | *
|
|---|
| 998 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 999 | *****************************************************************************/
|
|---|
| 1000 |
|
|---|
| 1001 | HFILE HMCreateFile(LPCSTR lpFileName,
|
|---|
| 1002 | DWORD dwDesiredAccess,
|
|---|
| 1003 | DWORD dwShareMode,
|
|---|
| 1004 | LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
|---|
| 1005 | DWORD dwCreationDisposition,
|
|---|
| 1006 | DWORD dwFlagsAndAttributes,
|
|---|
| 1007 | HANDLE hTemplateFile)
|
|---|
| 1008 | {
|
|---|
| 1009 | int iIndex; /* index into the handle table */
|
|---|
| 1010 | int iIndexNew; /* index into the handle table */
|
|---|
| 1011 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 1012 | HANDLE hResult;
|
|---|
| 1013 | DWORD rc; /* API return code */
|
|---|
| 1014 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 1015 | HMHANDLEDATA HMHandleTemp; /* temporary buffer for handle data */
|
|---|
| 1016 | VOID *pDevData;
|
|---|
| 1017 |
|
|---|
| 1018 | /* create new handle by either lpFileName or hTemplateFile */
|
|---|
| 1019 | if (lpFileName == NULL) /* this indicates creation from template */
|
|---|
| 1020 | {
|
|---|
| 1021 | iIndex = _HMHandleQuery(hTemplateFile); /* query table for template */
|
|---|
| 1022 | if (-1 == iIndex) /* this device is unknown to us */
|
|---|
| 1023 | {
|
|---|
| 1024 | SetLastError (ERROR_INVALID_HANDLE);
|
|---|
| 1025 | return INVALID_HANDLE_VALUE;
|
|---|
| 1026 | }
|
|---|
| 1027 | else
|
|---|
| 1028 | {
|
|---|
| 1029 | /* to pass to handler */
|
|---|
| 1030 | pHMHandleData = &TabWin32Handles[iIndex].hmHandleData;
|
|---|
| 1031 | pDeviceHandler = TabWin32Handles[iIndex].pDeviceHandler;
|
|---|
| 1032 | }
|
|---|
| 1033 | }
|
|---|
| 1034 | else
|
|---|
| 1035 | {
|
|---|
| 1036 | // name resolving
|
|---|
| 1037 | CHAR szFilename[260];
|
|---|
| 1038 | if (TRUE == HandleNamesResolveName((PSZ)lpFileName,
|
|---|
| 1039 | szFilename,
|
|---|
| 1040 | sizeof(szFilename),
|
|---|
| 1041 | TRUE))
|
|---|
| 1042 | {
|
|---|
| 1043 | // use the resolved name
|
|---|
| 1044 | lpFileName = szFilename;
|
|---|
| 1045 | }
|
|---|
| 1046 |
|
|---|
| 1047 |
|
|---|
| 1048 | pDeviceHandler = _HMDeviceFind((LPSTR)lpFileName); /* find device */
|
|---|
| 1049 | if (NULL == pDeviceHandler) /* this name is unknown to us */
|
|---|
| 1050 | {
|
|---|
| 1051 | SetLastError(ERROR_FILE_NOT_FOUND);
|
|---|
| 1052 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 1053 | }
|
|---|
| 1054 | else
|
|---|
| 1055 | pHMHandleData = NULL;
|
|---|
| 1056 |
|
|---|
| 1057 | pDevData = _HMDeviceGetData((LPSTR)lpFileName);
|
|---|
| 1058 |
|
|---|
| 1059 | if(pDeviceHandler == HMGlobals.pHMOpen32) {
|
|---|
| 1060 | pDeviceHandler = HMGlobals.pHMFile;
|
|---|
| 1061 | }
|
|---|
| 1062 | }
|
|---|
| 1063 |
|
|---|
| 1064 |
|
|---|
| 1065 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 1066 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 1067 | {
|
|---|
| 1068 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 1069 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 1070 | }
|
|---|
| 1071 |
|
|---|
| 1072 |
|
|---|
| 1073 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 1074 | if (lpFileName == NULL) /* create from template */
|
|---|
| 1075 | memcpy (&HMHandleTemp,
|
|---|
| 1076 | &TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 1077 | sizeof(HMHANDLEDATA));
|
|---|
| 1078 | else
|
|---|
| 1079 | {
|
|---|
| 1080 | HMHandleTemp.dwAccess = dwDesiredAccess;
|
|---|
| 1081 | HMHandleTemp.dwShare = dwShareMode;
|
|---|
| 1082 | HMHandleTemp.dwCreation = dwCreationDisposition;
|
|---|
| 1083 | HMHandleTemp.dwFlags = dwFlagsAndAttributes;
|
|---|
| 1084 | HMHandleTemp.lpHandlerData = NULL;
|
|---|
| 1085 | HMHandleTemp.hWin32Handle = iIndexNew;
|
|---|
| 1086 | HMHandleTemp.lpDeviceData = pDevData;
|
|---|
| 1087 | HMHandleTemp.dwHandleInformation = 0;
|
|---|
| 1088 | }
|
|---|
| 1089 |
|
|---|
| 1090 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 1091 | /* could be created within the device handler -> deadlock */
|
|---|
| 1092 |
|
|---|
| 1093 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 1094 | HMHandleTemp.hHMHandle = iIndexNew;
|
|---|
| 1095 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 1096 | /* now copy back our temporary handle data */
|
|---|
| 1097 | memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 1098 | &HMHandleTemp,
|
|---|
| 1099 | sizeof(HMHANDLEDATA));
|
|---|
| 1100 |
|
|---|
| 1101 | rc = pDeviceHandler->CreateFile(lpFileName, /* call the device handler */
|
|---|
| 1102 | &HMHandleTemp,
|
|---|
| 1103 | lpSecurityAttributes,
|
|---|
| 1104 | pHMHandleData);
|
|---|
| 1105 |
|
|---|
| 1106 | #ifdef DEBUG_LOCAL
|
|---|
| 1107 | dprintf(("KERNEL32/HandleManager:CheckPoint2: %s lpHandlerData=%08xh\n",
|
|---|
| 1108 | lpFileName,
|
|---|
| 1109 | HMHandleTemp.lpHandlerData));
|
|---|
| 1110 | #endif
|
|---|
| 1111 |
|
|---|
| 1112 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 1113 | {
|
|---|
| 1114 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1115 |
|
|---|
| 1116 | // Note:
|
|---|
| 1117 | // device handlers have to return an Win32-style error code
|
|---|
| 1118 | // from CreateFile() !
|
|---|
| 1119 | SetLastError(rc);
|
|---|
| 1120 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 1121 | }
|
|---|
| 1122 | else
|
|---|
| 1123 | {
|
|---|
| 1124 | /* copy data fields that might have been modified by CreateFile */
|
|---|
| 1125 | memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 1126 | &HMHandleTemp,
|
|---|
| 1127 | sizeof(HMHANDLEDATA));
|
|---|
| 1128 |
|
|---|
| 1129 | if(lpSecurityAttributes && lpSecurityAttributes->bInheritHandle) {
|
|---|
| 1130 | dprintf(("Set inheritance for child processes"));
|
|---|
| 1131 | HMSetHandleInformation(iIndexNew, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
|---|
| 1132 | }
|
|---|
| 1133 |
|
|---|
| 1134 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | return (HFILE)iIndexNew; /* return valid handle */
|
|---|
| 1138 | }
|
|---|
| 1139 |
|
|---|
| 1140 |
|
|---|
| 1141 | /*****************************************************************************
|
|---|
| 1142 | * Name : HANDLE HMOpenFile
|
|---|
| 1143 | * Purpose : Wrapper for the OpenFile() API
|
|---|
| 1144 | * Parameters:
|
|---|
| 1145 | * Variables :
|
|---|
| 1146 | * Result :
|
|---|
| 1147 | * Remark : Fix parameters passed to the HMDeviceManager::OpenFile
|
|---|
| 1148 | * Supply access mode and share mode validation routines
|
|---|
| 1149 | * Status :
|
|---|
| 1150 | *
|
|---|
| 1151 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1152 | *****************************************************************************/
|
|---|
| 1153 |
|
|---|
| 1154 |
|
|---|
| 1155 | /***********************************************************************
|
|---|
| 1156 | * FILE_ConvertOFMode
|
|---|
| 1157 | *
|
|---|
| 1158 | * Convert OF_* mode into flags for CreateFile.
|
|---|
| 1159 | */
|
|---|
| 1160 | static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing )
|
|---|
| 1161 | {
|
|---|
| 1162 | switch(mode & 0x03)
|
|---|
| 1163 | {
|
|---|
| 1164 | case OF_READ: *access = GENERIC_READ; break;
|
|---|
| 1165 | case OF_WRITE: *access = GENERIC_WRITE; break;
|
|---|
| 1166 | case OF_READWRITE: *access = GENERIC_READ | GENERIC_WRITE; break;
|
|---|
| 1167 | default: *access = 0; break;
|
|---|
| 1168 | }
|
|---|
| 1169 | switch(mode & 0x70)
|
|---|
| 1170 | {
|
|---|
| 1171 | case OF_SHARE_EXCLUSIVE: *sharing = 0; break;
|
|---|
| 1172 | case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break;
|
|---|
| 1173 | case OF_SHARE_DENY_READ: *sharing = FILE_SHARE_WRITE; break;
|
|---|
| 1174 | case OF_SHARE_DENY_NONE:
|
|---|
| 1175 | case OF_SHARE_COMPAT:
|
|---|
| 1176 | default: *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break;
|
|---|
| 1177 | }
|
|---|
| 1178 | }
|
|---|
| 1179 |
|
|---|
| 1180 | HANDLE HMOpenFile(LPCSTR lpFileName,
|
|---|
| 1181 | OFSTRUCT* pOFStruct,
|
|---|
| 1182 | UINT fuMode)
|
|---|
| 1183 | {
|
|---|
| 1184 | int iIndex; /* index into the handle table */
|
|---|
| 1185 | int iIndexNew; /* index into the handle table */
|
|---|
| 1186 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 1187 | VOID *pDevData;
|
|---|
| 1188 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 1189 | DWORD rc; /* API return code */
|
|---|
| 1190 |
|
|---|
| 1191 | // name resolving
|
|---|
| 1192 | CHAR szFilename[260];
|
|---|
| 1193 | if (TRUE == HandleNamesResolveName((PSZ)lpFileName,
|
|---|
| 1194 | szFilename,
|
|---|
| 1195 | sizeof(szFilename),
|
|---|
| 1196 | TRUE))
|
|---|
| 1197 | {
|
|---|
| 1198 | // use the resolved name
|
|---|
| 1199 | lpFileName = szFilename;
|
|---|
| 1200 | }
|
|---|
| 1201 |
|
|---|
| 1202 |
|
|---|
| 1203 | if(fuMode & OF_REOPEN) {
|
|---|
| 1204 | pDeviceHandler = _HMDeviceFind((LPSTR)pOFStruct->szPathName); /* find device */
|
|---|
| 1205 | }
|
|---|
| 1206 | else pDeviceHandler = _HMDeviceFind((LPSTR)lpFileName); /* find device */
|
|---|
| 1207 | if (NULL == pDeviceHandler) /* this name is unknown to us */
|
|---|
| 1208 | {
|
|---|
| 1209 | SetLastError(ERROR_FILE_NOT_FOUND);
|
|---|
| 1210 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 1211 | }
|
|---|
| 1212 | else
|
|---|
| 1213 | pHMHandleData = NULL;
|
|---|
| 1214 |
|
|---|
| 1215 | if(fuMode & OF_REOPEN) {
|
|---|
| 1216 | pDevData = _HMDeviceGetData((LPSTR)pOFStruct->szPathName);
|
|---|
| 1217 | }
|
|---|
| 1218 | else pDevData = _HMDeviceGetData((LPSTR)lpFileName);
|
|---|
| 1219 |
|
|---|
| 1220 |
|
|---|
| 1221 | if(pDeviceHandler == HMGlobals.pHMOpen32) {
|
|---|
| 1222 | pDeviceHandler = HMGlobals.pHMFile;
|
|---|
| 1223 | }
|
|---|
| 1224 |
|
|---|
| 1225 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 1226 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 1227 | {
|
|---|
| 1228 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 1229 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 1230 | }
|
|---|
| 1231 |
|
|---|
| 1232 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 1233 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 1234 |
|
|---|
| 1235 | FILE_ConvertOFMode(fuMode, /* map OF_flags */
|
|---|
| 1236 | &pHMHandleData->dwAccess,
|
|---|
| 1237 | &pHMHandleData->dwShare);
|
|---|
| 1238 |
|
|---|
| 1239 | //SvL; Must be OPEN_EXISTING because mmaps depend on it (to duplicate
|
|---|
| 1240 | // the file handle when this handle is a parameter for CreateFileMappingA/W
|
|---|
| 1241 | pHMHandleData->dwCreation = OPEN_EXISTING;
|
|---|
| 1242 | pHMHandleData->dwFlags = 0;
|
|---|
| 1243 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 1244 | pHMHandleData->lpDeviceData = pDevData;
|
|---|
| 1245 |
|
|---|
| 1246 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 1247 | /* could be created within the device handler -> deadlock */
|
|---|
| 1248 |
|
|---|
| 1249 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 1250 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 1251 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 1252 |
|
|---|
| 1253 | rc = pDeviceHandler->OpenFile(lpFileName, /* call the device handler */
|
|---|
| 1254 | &TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 1255 | pOFStruct,
|
|---|
| 1256 | fuMode);
|
|---|
| 1257 |
|
|---|
| 1258 | #ifdef DEBUG_LOCAL
|
|---|
| 1259 | dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh rc=%08xh\n",
|
|---|
| 1260 | lpFileName,
|
|---|
| 1261 | &TabWin32Handles[iIndexNew].hmHandleData.lpHandlerData,
|
|---|
| 1262 | rc));
|
|---|
| 1263 | #endif
|
|---|
| 1264 |
|
|---|
| 1265 | if(rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 1266 | {
|
|---|
| 1267 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1268 | SetLastError(pOFStruct->nErrCode);
|
|---|
| 1269 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 1270 | }
|
|---|
| 1271 | else {
|
|---|
| 1272 | if(fuMode & (OF_DELETE|OF_EXIST)) {
|
|---|
| 1273 | //file handle already closed
|
|---|
| 1274 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1275 | return TRUE; //TODO: correct?
|
|---|
| 1276 | }
|
|---|
| 1277 | if(fuMode & OF_PARSE) {
|
|---|
| 1278 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1279 | return 0;
|
|---|
| 1280 | }
|
|---|
| 1281 | if(fuMode & OF_VERIFY) {
|
|---|
| 1282 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1283 | return 1; //TODO: correct?
|
|---|
| 1284 | }
|
|---|
| 1285 | }
|
|---|
| 1286 |
|
|---|
| 1287 | #ifdef DEBUG_LOCAL
|
|---|
| 1288 | dprintf(("KERNEL32/HandleManager: OpenFile(%s)=%08xh\n",
|
|---|
| 1289 | lpFileName,
|
|---|
| 1290 | iIndexNew));
|
|---|
| 1291 | #endif
|
|---|
| 1292 |
|
|---|
| 1293 | return iIndexNew; /* return valid handle */
|
|---|
| 1294 | }
|
|---|
| 1295 |
|
|---|
| 1296 | /*****************************************************************************
|
|---|
| 1297 | * Name : DWORD HMGetHandleInformation
|
|---|
| 1298 | * Purpose : The GetHandleInformation function obtains information about certain
|
|---|
| 1299 | * properties of an object handle. The information is obtained as a set of bit flags.
|
|---|
| 1300 | * Parameters: HANDLE hObject
|
|---|
| 1301 | * LPDWORD lpdwFlags
|
|---|
| 1302 | * Variables :
|
|---|
| 1303 | * Result : TRUE / FALSE
|
|---|
| 1304 | * Remark :
|
|---|
| 1305 | * Status :
|
|---|
| 1306 | *
|
|---|
| 1307 | * Author : SvL
|
|---|
| 1308 | *****************************************************************************/
|
|---|
| 1309 | BOOL HMGetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
|
|---|
| 1310 | {
|
|---|
| 1311 | int iIndex; /* index into the handle table */
|
|---|
| 1312 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1313 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1314 |
|
|---|
| 1315 | /* validate handle */
|
|---|
| 1316 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1317 | if (-1 == iIndex) /* error ? */
|
|---|
| 1318 | {
|
|---|
| 1319 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1320 | return (FALSE); /* signal failure */
|
|---|
| 1321 | }
|
|---|
| 1322 |
|
|---|
| 1323 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1324 |
|
|---|
| 1325 | //Handle information is stored in the handle structure; return it here
|
|---|
| 1326 | if(lpdwFlags) {
|
|---|
| 1327 | *lpdwFlags = pHMHandle->hmHandleData.dwHandleInformation;
|
|---|
| 1328 | }
|
|---|
| 1329 |
|
|---|
| 1330 | SetLastError(ERROR_SUCCESS);
|
|---|
| 1331 | return TRUE; /* deliver return code */
|
|---|
| 1332 | }
|
|---|
| 1333 |
|
|---|
| 1334 | /*****************************************************************************
|
|---|
| 1335 | * Name : BOOL HMSetHandleInformation
|
|---|
| 1336 | * Purpose : The SetHandleInformation function sets certain properties of an
|
|---|
| 1337 | * object handle. The information is specified as a set of bit flags.
|
|---|
| 1338 | * Parameters: HANDLE hObject handle to an object
|
|---|
| 1339 | * DWORD dwMask specifies flags to change
|
|---|
| 1340 | * DWORD dwFlags specifies new values for flags
|
|---|
| 1341 | * Variables :
|
|---|
| 1342 | * Result : TRUE / FALSE
|
|---|
| 1343 | * Remark :
|
|---|
| 1344 | * Status :
|
|---|
| 1345 | *
|
|---|
| 1346 | * Author : SvL
|
|---|
| 1347 | *****************************************************************************/
|
|---|
| 1348 | BOOL HMSetHandleInformation (HANDLE hObject,
|
|---|
| 1349 | DWORD dwMask,
|
|---|
| 1350 | DWORD dwFlags)
|
|---|
| 1351 | {
|
|---|
| 1352 | int iIndex; /* index into the handle table */
|
|---|
| 1353 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1354 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1355 |
|
|---|
| 1356 | /* validate handle */
|
|---|
| 1357 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1358 | if (-1 == iIndex) /* error ? */
|
|---|
| 1359 | {
|
|---|
| 1360 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1361 | return (FALSE); /* signal failure */
|
|---|
| 1362 | }
|
|---|
| 1363 |
|
|---|
| 1364 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1365 | //SvL: Check if pDeviceHandler is set
|
|---|
| 1366 | if (pHMHandle->pDeviceHandler)
|
|---|
| 1367 | {
|
|---|
| 1368 | fResult = pHMHandle->pDeviceHandler->SetHandleInformation(&pHMHandle->hmHandleData,
|
|---|
| 1369 | dwMask, dwFlags);
|
|---|
| 1370 | }
|
|---|
| 1371 | else
|
|---|
| 1372 | {
|
|---|
| 1373 | dprintf(("HMSetHandleInformation(%08xh): pDeviceHandler not set", hObject));
|
|---|
| 1374 | fResult = TRUE;
|
|---|
| 1375 | }
|
|---|
| 1376 |
|
|---|
| 1377 | if(fResult == TRUE) {
|
|---|
| 1378 | SetLastError(ERROR_SUCCESS);
|
|---|
| 1379 | }
|
|---|
| 1380 | return (fResult); /* deliver return code */
|
|---|
| 1381 | }
|
|---|
| 1382 |
|
|---|
| 1383 | /*****************************************************************************
|
|---|
| 1384 | * Name : HANDLE HMCloseFile
|
|---|
| 1385 | * Purpose : Wrapper for the CloseHandle() API
|
|---|
| 1386 | * Parameters:
|
|---|
| 1387 | * Variables :
|
|---|
| 1388 | * Result :
|
|---|
| 1389 | * Remark :
|
|---|
| 1390 | * Status :
|
|---|
| 1391 | *
|
|---|
| 1392 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1393 | *****************************************************************************/
|
|---|
| 1394 |
|
|---|
| 1395 | BOOL HMCloseHandle(HANDLE hObject)
|
|---|
| 1396 | {
|
|---|
| 1397 | int iIndex; /* index into the handle table */
|
|---|
| 1398 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1399 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1400 |
|
|---|
| 1401 | /* validate handle */
|
|---|
| 1402 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1403 | if (-1 == iIndex) /* error ? */
|
|---|
| 1404 | {
|
|---|
| 1405 | //@@@PH it may occur someone closes e.g. a semaphore handle
|
|---|
| 1406 | // which is not registered through the HandleManager yet.
|
|---|
| 1407 | // so we try to pass on to Open32 instead.
|
|---|
| 1408 | dprintf(("KERNEL32: HandleManager:HMCloseHandle(%08xh) passed on to Open32.\n",
|
|---|
| 1409 | hObject));
|
|---|
| 1410 |
|
|---|
| 1411 | fResult = O32_CloseHandle(hObject);
|
|---|
| 1412 | return (fResult);
|
|---|
| 1413 |
|
|---|
| 1414 | //SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1415 | //return (FALSE); /* signal failure */
|
|---|
| 1416 | }
|
|---|
| 1417 |
|
|---|
| 1418 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1419 |
|
|---|
| 1420 | if(pHMHandle->hmHandleData.dwHandleInformation & HANDLE_FLAG_PROTECT_FROM_CLOSE) {
|
|---|
| 1421 | dprintf(("Handle not close because of HANDLE_FLAG_PROTECT_FROM_CLOSE"));
|
|---|
| 1422 | SetLastError(ERROR_SUCCESS);
|
|---|
| 1423 | return TRUE;
|
|---|
| 1424 | }
|
|---|
| 1425 |
|
|---|
| 1426 | //SvL: Check if pDeviceHandler is set
|
|---|
| 1427 | if (pHMHandle->pDeviceHandler)
|
|---|
| 1428 | {
|
|---|
| 1429 | fResult = pHMHandle->pDeviceHandler->CloseHandle(&pHMHandle->hmHandleData);
|
|---|
| 1430 | }
|
|---|
| 1431 | else
|
|---|
| 1432 | {
|
|---|
| 1433 | dprintf(("HMCloseHAndle(%08xh): pDeviceHandler not set", hObject));
|
|---|
| 1434 | fResult = TRUE;
|
|---|
| 1435 | }
|
|---|
| 1436 |
|
|---|
| 1437 | if (fResult == TRUE) /* remove handle if close succeeded */
|
|---|
| 1438 | {
|
|---|
| 1439 | pHMHandle->hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; /* mark handle as free */
|
|---|
| 1440 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 1441 | }
|
|---|
| 1442 |
|
|---|
| 1443 | return (fResult); /* deliver return code */
|
|---|
| 1444 | }
|
|---|
| 1445 |
|
|---|
| 1446 |
|
|---|
| 1447 | /*****************************************************************************
|
|---|
| 1448 | * Name : HANDLE HMReadFile
|
|---|
| 1449 | * Purpose : Wrapper for the ReadHandle() API
|
|---|
| 1450 | * Parameters:
|
|---|
| 1451 | * Variables :
|
|---|
| 1452 | * Result :
|
|---|
| 1453 | * Remark :
|
|---|
| 1454 | * Status :
|
|---|
| 1455 | *
|
|---|
| 1456 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1457 | *****************************************************************************/
|
|---|
| 1458 |
|
|---|
| 1459 | BOOL HMReadFile(HANDLE hFile,
|
|---|
| 1460 | LPVOID lpBuffer,
|
|---|
| 1461 | DWORD nNumberOfBytesToRead,
|
|---|
| 1462 | LPDWORD lpNumberOfBytesRead,
|
|---|
| 1463 | LPOVERLAPPED lpOverlapped,
|
|---|
| 1464 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
|---|
| 1465 | {
|
|---|
| 1466 | int iIndex; /* index into the handle table */
|
|---|
| 1467 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1468 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1469 |
|
|---|
| 1470 | /* validate handle */
|
|---|
| 1471 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1472 | if (-1 == iIndex) /* error ? */
|
|---|
| 1473 | {
|
|---|
| 1474 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1475 | return (FALSE); /* signal failure */
|
|---|
| 1476 | }
|
|---|
| 1477 |
|
|---|
| 1478 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1479 | fResult = pHMHandle->pDeviceHandler->ReadFile(&pHMHandle->hmHandleData,
|
|---|
| 1480 | lpBuffer,
|
|---|
| 1481 | nNumberOfBytesToRead,
|
|---|
| 1482 | lpNumberOfBytesRead,
|
|---|
| 1483 | lpOverlapped, lpCompletionRoutine);
|
|---|
| 1484 |
|
|---|
| 1485 | return (fResult); /* deliver return code */
|
|---|
| 1486 | }
|
|---|
| 1487 |
|
|---|
| 1488 | /*****************************************************************************
|
|---|
| 1489 | * Name : HANDLE HMWriteFile
|
|---|
| 1490 | * Purpose : Wrapper for the WriteHandle() API
|
|---|
| 1491 | * Parameters:
|
|---|
| 1492 | * Variables :
|
|---|
| 1493 | * Result :
|
|---|
| 1494 | * Remark :
|
|---|
| 1495 | * Status :
|
|---|
| 1496 | *
|
|---|
| 1497 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1498 | *****************************************************************************/
|
|---|
| 1499 |
|
|---|
| 1500 | BOOL HMWriteFile(HANDLE hFile,
|
|---|
| 1501 | LPCVOID lpBuffer,
|
|---|
| 1502 | DWORD nNumberOfBytesToWrite,
|
|---|
| 1503 | LPDWORD lpNumberOfBytesWritten,
|
|---|
| 1504 | LPOVERLAPPED lpOverlapped,
|
|---|
| 1505 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
|---|
| 1506 | {
|
|---|
| 1507 | int iIndex; /* index into the handle table */
|
|---|
| 1508 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1509 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1510 |
|
|---|
| 1511 | /* validate handle */
|
|---|
| 1512 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1513 | if (-1 == iIndex) /* error ? */
|
|---|
| 1514 | {
|
|---|
| 1515 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1516 | return (FALSE); /* signal failure */
|
|---|
| 1517 | }
|
|---|
| 1518 |
|
|---|
| 1519 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1520 | fResult = pHMHandle->pDeviceHandler->WriteFile(&pHMHandle->hmHandleData,
|
|---|
| 1521 | lpBuffer,
|
|---|
| 1522 | nNumberOfBytesToWrite,
|
|---|
| 1523 | lpNumberOfBytesWritten,
|
|---|
| 1524 | lpOverlapped, lpCompletionRoutine);
|
|---|
| 1525 |
|
|---|
| 1526 | return (fResult); /* deliver return code */
|
|---|
| 1527 | }
|
|---|
| 1528 |
|
|---|
| 1529 |
|
|---|
| 1530 | /*****************************************************************************
|
|---|
| 1531 | * Name : HANDLE HMGetFileType
|
|---|
| 1532 | * Purpose : Wrapper for the GetFileType() API
|
|---|
| 1533 | * Parameters:
|
|---|
| 1534 | * Variables :
|
|---|
| 1535 | * Result :
|
|---|
| 1536 | * Remark :
|
|---|
| 1537 | * Status :
|
|---|
| 1538 | *
|
|---|
| 1539 | * Author : Patrick Haller [Wed, 1998/02/12 13:37]
|
|---|
| 1540 | *****************************************************************************/
|
|---|
| 1541 |
|
|---|
| 1542 | DWORD HMGetFileType(HANDLE hFile)
|
|---|
| 1543 | {
|
|---|
| 1544 | int iIndex; /* index into the handle table */
|
|---|
| 1545 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1546 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1547 |
|
|---|
| 1548 | /* validate handle */
|
|---|
| 1549 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1550 | if (-1 == iIndex) /* error ? */
|
|---|
| 1551 | {
|
|---|
| 1552 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1553 | return FILE_TYPE_UNKNOWN; /* signal failure */
|
|---|
| 1554 | }
|
|---|
| 1555 |
|
|---|
| 1556 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1557 | dwResult = pHMHandle->pDeviceHandler->GetFileType(&pHMHandle->hmHandleData);
|
|---|
| 1558 |
|
|---|
| 1559 | return (dwResult); /* deliver return code */
|
|---|
| 1560 | }
|
|---|
| 1561 |
|
|---|
| 1562 |
|
|---|
| 1563 | /*****************************************************************************
|
|---|
| 1564 | * Name : HMDeviceHandler::_DeviceReuqest
|
|---|
| 1565 | * Purpose : entry method for special request functions
|
|---|
| 1566 | * Parameters: ULONG ulRequestCode
|
|---|
| 1567 | * various parameters as required
|
|---|
| 1568 | * Variables :
|
|---|
| 1569 | * Result :
|
|---|
| 1570 | * Remark : the standard behaviour is to return an error code for non-
|
|---|
| 1571 | * existant request codes
|
|---|
| 1572 | * Status :
|
|---|
| 1573 | *
|
|---|
| 1574 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1575 | *****************************************************************************/
|
|---|
| 1576 |
|
|---|
| 1577 | DWORD HMDeviceRequest (HANDLE hFile,
|
|---|
| 1578 | ULONG ulRequestCode,
|
|---|
| 1579 | ULONG arg1,
|
|---|
| 1580 | ULONG arg2,
|
|---|
| 1581 | ULONG arg3,
|
|---|
| 1582 | ULONG arg4)
|
|---|
| 1583 | {
|
|---|
| 1584 | int iIndex; /* index into the handle table */
|
|---|
| 1585 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1586 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1587 |
|
|---|
| 1588 | /* validate handle */
|
|---|
| 1589 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1590 | if (-1 == iIndex) /* error ? */
|
|---|
| 1591 | {
|
|---|
| 1592 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1593 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
|---|
| 1594 | }
|
|---|
| 1595 |
|
|---|
| 1596 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1597 | dwResult = pHMHandle->pDeviceHandler->_DeviceRequest(&pHMHandle->hmHandleData,
|
|---|
| 1598 | ulRequestCode,
|
|---|
| 1599 | arg1,
|
|---|
| 1600 | arg2,
|
|---|
| 1601 | arg3,
|
|---|
| 1602 | arg4);
|
|---|
| 1603 |
|
|---|
| 1604 | return (dwResult); /* deliver return code */
|
|---|
| 1605 | }
|
|---|
| 1606 |
|
|---|
| 1607 |
|
|---|
| 1608 | /*****************************************************************************
|
|---|
| 1609 | * Name : HMDeviceHandler::GetFileInformationByHandle
|
|---|
| 1610 | * Purpose : router function for GetFileInformationByHandle
|
|---|
| 1611 | * Parameters:
|
|---|
| 1612 | * Variables :
|
|---|
| 1613 | * Result :
|
|---|
| 1614 | * Remark :
|
|---|
| 1615 | * Status :
|
|---|
| 1616 | *
|
|---|
| 1617 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1618 | *****************************************************************************/
|
|---|
| 1619 |
|
|---|
| 1620 | BOOL HMGetFileInformationByHandle (HANDLE hFile,
|
|---|
| 1621 | BY_HANDLE_FILE_INFORMATION *pHFI)
|
|---|
| 1622 | {
|
|---|
| 1623 | int iIndex; /* index into the handle table */
|
|---|
| 1624 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1625 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1626 |
|
|---|
| 1627 | /* validate handle */
|
|---|
| 1628 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1629 | if (-1 == iIndex) /* error ? */
|
|---|
| 1630 | {
|
|---|
| 1631 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1632 | return FALSE; /* signal failure */
|
|---|
| 1633 | }
|
|---|
| 1634 |
|
|---|
| 1635 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1636 | dwResult = pHMHandle->pDeviceHandler->GetFileInformationByHandle(&pHMHandle->hmHandleData,
|
|---|
| 1637 | pHFI);
|
|---|
| 1638 |
|
|---|
| 1639 | return (dwResult); /* deliver return code */
|
|---|
| 1640 | }
|
|---|
| 1641 |
|
|---|
| 1642 |
|
|---|
| 1643 | /*****************************************************************************
|
|---|
| 1644 | * Name : HMDeviceHandler::SetEndOfFile
|
|---|
| 1645 | * Purpose : router function for SetEndOfFile
|
|---|
| 1646 | * Parameters:
|
|---|
| 1647 | * Variables :
|
|---|
| 1648 | * Result :
|
|---|
| 1649 | * Remark :
|
|---|
| 1650 | * Status :
|
|---|
| 1651 | *
|
|---|
| 1652 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1653 | *****************************************************************************/
|
|---|
| 1654 |
|
|---|
| 1655 | BOOL HMSetEndOfFile (HANDLE hFile)
|
|---|
| 1656 | {
|
|---|
| 1657 | int iIndex; /* index into the handle table */
|
|---|
| 1658 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 1659 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1660 |
|
|---|
| 1661 | /* validate handle */
|
|---|
| 1662 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1663 | if (-1 == iIndex) /* error ? */
|
|---|
| 1664 | {
|
|---|
| 1665 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1666 | return FALSE; /* signal failure */
|
|---|
| 1667 | }
|
|---|
| 1668 |
|
|---|
| 1669 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1670 | bResult = pHMHandle->pDeviceHandler->SetEndOfFile(&pHMHandle->hmHandleData);
|
|---|
| 1671 |
|
|---|
| 1672 | return (bResult); /* deliver return code */
|
|---|
| 1673 | }
|
|---|
| 1674 |
|
|---|
| 1675 |
|
|---|
| 1676 | /*****************************************************************************
|
|---|
| 1677 | * Name : HMDeviceHandler::SetFileTime
|
|---|
| 1678 | * Purpose : router function for SetFileTime
|
|---|
| 1679 | * Parameters:
|
|---|
| 1680 | * Variables :
|
|---|
| 1681 | * Result :
|
|---|
| 1682 | * Remark :
|
|---|
| 1683 | * Status :
|
|---|
| 1684 | *
|
|---|
| 1685 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1686 | *****************************************************************************/
|
|---|
| 1687 |
|
|---|
| 1688 | BOOL HMSetFileTime (HANDLE hFile,
|
|---|
| 1689 | const FILETIME *pFT1,
|
|---|
| 1690 | const FILETIME *pFT2,
|
|---|
| 1691 | const FILETIME *pFT3)
|
|---|
| 1692 | {
|
|---|
| 1693 | int iIndex; /* index into the handle table */
|
|---|
| 1694 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 1695 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1696 |
|
|---|
| 1697 | /* validate handle */
|
|---|
| 1698 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1699 | if (-1 == iIndex) /* error ? */
|
|---|
| 1700 | {
|
|---|
| 1701 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1702 | return FALSE; /* signal failure */
|
|---|
| 1703 | }
|
|---|
| 1704 |
|
|---|
| 1705 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1706 | bResult = pHMHandle->pDeviceHandler->SetFileTime(&pHMHandle->hmHandleData,
|
|---|
| 1707 | (LPFILETIME)pFT1,
|
|---|
| 1708 | (LPFILETIME)pFT2,
|
|---|
| 1709 | (LPFILETIME)pFT3);
|
|---|
| 1710 |
|
|---|
| 1711 | return (bResult); /* deliver return code */
|
|---|
| 1712 | }
|
|---|
| 1713 |
|
|---|
| 1714 | /*****************************************************************************
|
|---|
| 1715 | * Name : HMDeviceHandler::GetFileTime
|
|---|
| 1716 | * Purpose : router function for SetFileTime
|
|---|
| 1717 | * Parameters:
|
|---|
| 1718 | * Variables :
|
|---|
| 1719 | * Result :
|
|---|
| 1720 | * Remark :
|
|---|
| 1721 | * Status :
|
|---|
| 1722 | *
|
|---|
| 1723 | * Author : SvL
|
|---|
| 1724 | *****************************************************************************/
|
|---|
| 1725 |
|
|---|
| 1726 | BOOL HMGetFileTime (HANDLE hFile,
|
|---|
| 1727 | const FILETIME *pFT1,
|
|---|
| 1728 | const FILETIME *pFT2,
|
|---|
| 1729 | const FILETIME *pFT3)
|
|---|
| 1730 | {
|
|---|
| 1731 | int iIndex; /* index into the handle table */
|
|---|
| 1732 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 1733 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1734 |
|
|---|
| 1735 | /* validate handle */
|
|---|
| 1736 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1737 | if (-1 == iIndex) /* error ? */
|
|---|
| 1738 | {
|
|---|
| 1739 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1740 | return FALSE; /* signal failure */
|
|---|
| 1741 | }
|
|---|
| 1742 |
|
|---|
| 1743 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1744 | bResult = pHMHandle->pDeviceHandler->GetFileTime(&pHMHandle->hmHandleData,
|
|---|
| 1745 | (LPFILETIME)pFT1,
|
|---|
| 1746 | (LPFILETIME)pFT2,
|
|---|
| 1747 | (LPFILETIME)pFT3);
|
|---|
| 1748 |
|
|---|
| 1749 | return (bResult); /* deliver return code */
|
|---|
| 1750 | }
|
|---|
| 1751 |
|
|---|
| 1752 |
|
|---|
| 1753 | /*****************************************************************************
|
|---|
| 1754 | * Name : HMDeviceHandler::GetFileSize
|
|---|
| 1755 | * Purpose : router function for GetFileSize
|
|---|
| 1756 | * Parameters:
|
|---|
| 1757 | * Variables :
|
|---|
| 1758 | * Result :
|
|---|
| 1759 | * Remark :
|
|---|
| 1760 | * Status :
|
|---|
| 1761 | *
|
|---|
| 1762 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1763 | *****************************************************************************/
|
|---|
| 1764 |
|
|---|
| 1765 | DWORD HMGetFileSize (HANDLE hFile,
|
|---|
| 1766 | PDWORD pSize)
|
|---|
| 1767 | {
|
|---|
| 1768 | int iIndex; /* index into the handle table */
|
|---|
| 1769 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1770 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1771 |
|
|---|
| 1772 | /* validate handle */
|
|---|
| 1773 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1774 | if (-1 == iIndex) /* error ? */
|
|---|
| 1775 | {
|
|---|
| 1776 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1777 | return -1; //INVALID_SET_FILE_POINTER
|
|---|
| 1778 | }
|
|---|
| 1779 |
|
|---|
| 1780 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1781 | dwResult = pHMHandle->pDeviceHandler->GetFileSize(&pHMHandle->hmHandleData,
|
|---|
| 1782 | pSize);
|
|---|
| 1783 |
|
|---|
| 1784 | return (dwResult); /* deliver return code */
|
|---|
| 1785 | }
|
|---|
| 1786 |
|
|---|
| 1787 |
|
|---|
| 1788 | /*****************************************************************************
|
|---|
| 1789 | * Name : HMDeviceHandler::SetFilePointer
|
|---|
| 1790 | * Purpose : router function for SetFilePointer
|
|---|
| 1791 | * Parameters:
|
|---|
| 1792 | * Variables :
|
|---|
| 1793 | * Result :
|
|---|
| 1794 | * Remark :
|
|---|
| 1795 | * Status :
|
|---|
| 1796 | *
|
|---|
| 1797 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1798 | *****************************************************************************/
|
|---|
| 1799 |
|
|---|
| 1800 | DWORD HMSetFilePointer (HANDLE hFile,
|
|---|
| 1801 | LONG lDistanceToMove,
|
|---|
| 1802 | PLONG lpDistanceToMoveHigh,
|
|---|
| 1803 | DWORD dwMoveMethod)
|
|---|
| 1804 | {
|
|---|
| 1805 | int iIndex; /* index into the handle table */
|
|---|
| 1806 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1807 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1808 |
|
|---|
| 1809 | /* validate handle */
|
|---|
| 1810 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1811 | if (-1 == iIndex) /* error ? */
|
|---|
| 1812 | {
|
|---|
| 1813 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1814 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
|---|
| 1815 | }
|
|---|
| 1816 |
|
|---|
| 1817 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1818 | dwResult = pHMHandle->pDeviceHandler->SetFilePointer(&pHMHandle->hmHandleData,
|
|---|
| 1819 | lDistanceToMove,
|
|---|
| 1820 | lpDistanceToMoveHigh,
|
|---|
| 1821 | dwMoveMethod);
|
|---|
| 1822 |
|
|---|
| 1823 | return (dwResult); /* deliver return code */
|
|---|
| 1824 | }
|
|---|
| 1825 |
|
|---|
| 1826 |
|
|---|
| 1827 | /*****************************************************************************
|
|---|
| 1828 | * Name : HMDeviceHandler::LockFile
|
|---|
| 1829 | * Purpose : router function for LockFile
|
|---|
| 1830 | * Parameters:
|
|---|
| 1831 | * Variables :
|
|---|
| 1832 | * Result :
|
|---|
| 1833 | * Remark :
|
|---|
| 1834 | * Status :
|
|---|
| 1835 | *
|
|---|
| 1836 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1837 | *****************************************************************************/
|
|---|
| 1838 |
|
|---|
| 1839 | BOOL HMLockFile (HFILE hFile,
|
|---|
| 1840 | DWORD arg2,
|
|---|
| 1841 | DWORD arg3,
|
|---|
| 1842 | DWORD arg4,
|
|---|
| 1843 | DWORD arg5)
|
|---|
| 1844 | {
|
|---|
| 1845 | int iIndex; /* index into the handle table */
|
|---|
| 1846 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1847 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1848 |
|
|---|
| 1849 | /* validate handle */
|
|---|
| 1850 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1851 | if (-1 == iIndex) /* error ? */
|
|---|
| 1852 | {
|
|---|
| 1853 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1854 | return FALSE; /* signal failure */
|
|---|
| 1855 | }
|
|---|
| 1856 |
|
|---|
| 1857 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1858 | dwResult = pHMHandle->pDeviceHandler->LockFile(&pHMHandle->hmHandleData,
|
|---|
| 1859 | arg2,
|
|---|
| 1860 | arg3,
|
|---|
| 1861 | arg4,
|
|---|
| 1862 | arg5);
|
|---|
| 1863 |
|
|---|
| 1864 | return (dwResult); /* deliver return code */
|
|---|
| 1865 | }
|
|---|
| 1866 |
|
|---|
| 1867 |
|
|---|
| 1868 | /*****************************************************************************
|
|---|
| 1869 | * Name : HMDeviceHandler::LockFileEx
|
|---|
| 1870 | * Purpose : router function for LockFileEx
|
|---|
| 1871 | * Parameters:
|
|---|
| 1872 | * Variables :
|
|---|
| 1873 | * Result :
|
|---|
| 1874 | * Remark :
|
|---|
| 1875 | * Status :
|
|---|
| 1876 | *
|
|---|
| 1877 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1878 | *****************************************************************************/
|
|---|
| 1879 |
|
|---|
| 1880 | BOOL HMLockFileEx(HANDLE hFile,
|
|---|
| 1881 | DWORD dwFlags,
|
|---|
| 1882 | DWORD dwReserved,
|
|---|
| 1883 | DWORD nNumberOfBytesToLockLow,
|
|---|
| 1884 | DWORD nNumberOfBytesToLockHigh,
|
|---|
| 1885 | LPOVERLAPPED lpOverlapped)
|
|---|
| 1886 | {
|
|---|
| 1887 | int iIndex; /* index into the handle table */
|
|---|
| 1888 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1889 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1890 |
|
|---|
| 1891 | /* validate handle */
|
|---|
| 1892 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1893 | if (-1 == iIndex) /* error ? */
|
|---|
| 1894 | {
|
|---|
| 1895 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1896 | return FALSE; /* signal failure */
|
|---|
| 1897 | }
|
|---|
| 1898 |
|
|---|
| 1899 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1900 | dwResult = pHMHandle->pDeviceHandler->LockFileEx(&pHMHandle->hmHandleData,
|
|---|
| 1901 | dwFlags,
|
|---|
| 1902 | dwReserved,
|
|---|
| 1903 | nNumberOfBytesToLockLow,
|
|---|
| 1904 | nNumberOfBytesToLockHigh,
|
|---|
| 1905 | lpOverlapped);
|
|---|
| 1906 |
|
|---|
| 1907 | return (dwResult); /* deliver return code */
|
|---|
| 1908 | }
|
|---|
| 1909 |
|
|---|
| 1910 |
|
|---|
| 1911 |
|
|---|
| 1912 | /*****************************************************************************
|
|---|
| 1913 | * Name : HMDeviceHandler::UnlockFile
|
|---|
| 1914 | * Purpose : router function for UnlockFile
|
|---|
| 1915 | * Parameters:
|
|---|
| 1916 | * Variables :
|
|---|
| 1917 | * Result :
|
|---|
| 1918 | * Remark :
|
|---|
| 1919 | * Status :
|
|---|
| 1920 | *
|
|---|
| 1921 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1922 | *****************************************************************************/
|
|---|
| 1923 |
|
|---|
| 1924 | BOOL HMUnlockFile (HFILE hFile,
|
|---|
| 1925 | DWORD arg2,
|
|---|
| 1926 | DWORD arg3,
|
|---|
| 1927 | DWORD arg4,
|
|---|
| 1928 | DWORD arg5)
|
|---|
| 1929 | {
|
|---|
| 1930 | int iIndex; /* index into the handle table */
|
|---|
| 1931 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1932 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1933 |
|
|---|
| 1934 | /* validate handle */
|
|---|
| 1935 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1936 | if (-1 == iIndex) /* error ? */
|
|---|
| 1937 | {
|
|---|
| 1938 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1939 | return FALSE; /* signal failure */
|
|---|
| 1940 | }
|
|---|
| 1941 |
|
|---|
| 1942 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1943 | dwResult = pHMHandle->pDeviceHandler->UnlockFile(&pHMHandle->hmHandleData,
|
|---|
| 1944 | arg2,
|
|---|
| 1945 | arg3,
|
|---|
| 1946 | arg4,
|
|---|
| 1947 | arg5);
|
|---|
| 1948 |
|
|---|
| 1949 | return (dwResult); /* deliver return code */
|
|---|
| 1950 | }
|
|---|
| 1951 |
|
|---|
| 1952 |
|
|---|
| 1953 | /*****************************************************************************
|
|---|
| 1954 | * Name : HMDeviceHandler::UnlockFileEx
|
|---|
| 1955 | * Purpose : router function for UnlockFileEx
|
|---|
| 1956 | * Parameters:
|
|---|
| 1957 | * Variables :
|
|---|
| 1958 | * Result :
|
|---|
| 1959 | * Remark :
|
|---|
| 1960 | * Status :
|
|---|
| 1961 | *
|
|---|
| 1962 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1963 | *****************************************************************************/
|
|---|
| 1964 |
|
|---|
| 1965 | BOOL HMUnlockFileEx(HANDLE hFile,
|
|---|
| 1966 | DWORD dwReserved,
|
|---|
| 1967 | DWORD nNumberOfBytesToLockLow,
|
|---|
| 1968 | DWORD nNumberOfBytesToLockHigh,
|
|---|
| 1969 | LPOVERLAPPED lpOverlapped)
|
|---|
| 1970 | {
|
|---|
| 1971 | int iIndex; /* index into the handle table */
|
|---|
| 1972 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1973 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1974 |
|
|---|
| 1975 | /* validate handle */
|
|---|
| 1976 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1977 | if (-1 == iIndex) /* error ? */
|
|---|
| 1978 | {
|
|---|
| 1979 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1980 | return FALSE; /* signal failure */
|
|---|
| 1981 | }
|
|---|
| 1982 |
|
|---|
| 1983 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1984 | dwResult = pHMHandle->pDeviceHandler->UnlockFileEx(&pHMHandle->hmHandleData,
|
|---|
| 1985 | dwReserved,
|
|---|
| 1986 | nNumberOfBytesToLockLow,
|
|---|
| 1987 | nNumberOfBytesToLockHigh,
|
|---|
| 1988 | lpOverlapped);
|
|---|
| 1989 |
|
|---|
| 1990 | return (dwResult); /* deliver return code */
|
|---|
| 1991 | }
|
|---|
| 1992 |
|
|---|
| 1993 |
|
|---|
| 1994 | /*****************************************************************************
|
|---|
| 1995 | * Name : HMDeviceHandler::WaitForSingleObject
|
|---|
| 1996 | * Purpose : router function for WaitForSingleObject
|
|---|
| 1997 | * Parameters:
|
|---|
| 1998 | * Variables :
|
|---|
| 1999 | * Result :
|
|---|
| 2000 | * Remark :
|
|---|
| 2001 | * Status :
|
|---|
| 2002 | *
|
|---|
| 2003 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2004 | *****************************************************************************/
|
|---|
| 2005 |
|
|---|
| 2006 | DWORD HMWaitForSingleObject(HANDLE hObject,
|
|---|
| 2007 | DWORD dwTimeout)
|
|---|
| 2008 | {
|
|---|
| 2009 | int iIndex; /* index into the handle table */
|
|---|
| 2010 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2011 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2012 |
|
|---|
| 2013 | /* validate handle */
|
|---|
| 2014 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 2015 | if (-1 == iIndex) /* error ? */
|
|---|
| 2016 | {
|
|---|
| 2017 | dprintf(("KERNEL32: HandleManager:HMWaitForSingleObject(%08xh) passed on to Open32.\n",
|
|---|
| 2018 | hObject));
|
|---|
| 2019 |
|
|---|
| 2020 | if(dwTimeout == INFINITE) {
|
|---|
| 2021 | //Workaround for applications that block the PM input queue
|
|---|
| 2022 | //while waiting for a child process to terminate.
|
|---|
| 2023 | //(WaitSingleObject now calls MsgWaitMultipleObjects and
|
|---|
| 2024 | // processes messages while waiting for the process to die)
|
|---|
| 2025 | //(Napster install now doesn't block PM anymore (forcing a reboot))
|
|---|
| 2026 |
|
|---|
| 2027 | HMODULE hUser32 = LoadLibraryA("USER32.DLL");
|
|---|
| 2028 |
|
|---|
| 2029 | BOOL (* WINAPI pfnPeekMessageA)(LPMSG,HWND,UINT,UINT,UINT);
|
|---|
| 2030 | LONG (* WINAPI pfnDispatchMessageA)(const MSG*);
|
|---|
| 2031 |
|
|---|
| 2032 | *(FARPROC *)&pfnPeekMessageA = GetProcAddress(hUser32,"PeekMessageA");
|
|---|
| 2033 | *(FARPROC *)&pfnDispatchMessageA = GetProcAddress(hUser32,"DispatchMessageA");
|
|---|
| 2034 |
|
|---|
| 2035 | TEB *teb = GetThreadTEB();
|
|---|
| 2036 |
|
|---|
| 2037 | if(!teb || !pfnPeekMessageA || !pfnDispatchMessageA) {
|
|---|
| 2038 | dprintf(("ERROR: !teb || !pfnPeekMessageA || !pfnDispatchMessageA"));
|
|---|
| 2039 | DebugInt3();
|
|---|
| 2040 | return WAIT_FAILED;
|
|---|
| 2041 | }
|
|---|
| 2042 |
|
|---|
| 2043 | //TODO: Ignoring all messages could be dangerous. But processing them,
|
|---|
| 2044 | //while the app doesn't expect any, isn't safe either.
|
|---|
| 2045 | //-> must active check in pmwindow.cpp if this is enabled again!
|
|---|
| 2046 | // teb->o.odin.fIgnoreMsgs = TRUE;
|
|---|
| 2047 |
|
|---|
| 2048 | while(TRUE) {
|
|---|
| 2049 | dwResult = HMMsgWaitForMultipleObjects(1, &hObject, FALSE,
|
|---|
| 2050 | INFINITE, QS_ALLINPUT);
|
|---|
| 2051 | if(dwResult == WAIT_OBJECT_0 + 1) {
|
|---|
| 2052 | MSG msg ;
|
|---|
| 2053 |
|
|---|
| 2054 | while (pfnPeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
|
|---|
| 2055 | {
|
|---|
| 2056 | if (msg.message == WM_QUIT) {
|
|---|
| 2057 | dprintf(("ERROR: WaitForSingleObject call abandoned because WM_QUIT msg was received!!"));
|
|---|
| 2058 | // teb->o.odin.fIgnoreMsgs = FALSE;
|
|---|
| 2059 | FreeLibrary(hUser32);
|
|---|
| 2060 | return WAIT_ABANDONED;
|
|---|
| 2061 | }
|
|---|
| 2062 |
|
|---|
| 2063 | /* otherwise dispatch it */
|
|---|
| 2064 | pfnDispatchMessageA(&msg);
|
|---|
| 2065 |
|
|---|
| 2066 | } // end of PeekMessage while loop
|
|---|
| 2067 | }
|
|---|
| 2068 | else {
|
|---|
| 2069 | dprintf(("WaitForSingleObject: Process %x terminated", hObject));
|
|---|
| 2070 | break;
|
|---|
| 2071 | }
|
|---|
| 2072 | }
|
|---|
| 2073 | // teb->o.odin.fIgnoreMsgs = FALSE;
|
|---|
| 2074 | FreeLibrary(hUser32);
|
|---|
| 2075 | return dwResult;
|
|---|
| 2076 | }
|
|---|
| 2077 | else {
|
|---|
| 2078 | // maybe handles from CreateProcess() ...
|
|---|
| 2079 | dwResult = O32_WaitForSingleObject(hObject, dwTimeout);
|
|---|
| 2080 | return (dwResult);
|
|---|
| 2081 | }
|
|---|
| 2082 | }
|
|---|
| 2083 |
|
|---|
| 2084 | //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
|
|---|
| 2085 | //return too late if the thread priority isn't time critical (time slices
|
|---|
| 2086 | //of 32 ms)
|
|---|
| 2087 | //To avoid this problem, we temporarily switch to time critical priority.
|
|---|
| 2088 | HANDLE hThread = GetCurrentThread();
|
|---|
| 2089 | DWORD dwThreadPriority = GetThreadPriority(hThread);
|
|---|
| 2090 |
|
|---|
| 2091 | if(dwTimeout && dwTimeout < 20 && dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL) {
|
|---|
| 2092 | dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));
|
|---|
| 2093 | SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
|---|
| 2094 | //round to 8 ms units to get more precise timeouts
|
|---|
| 2095 | if(dwTimeout > 8)
|
|---|
| 2096 | dwTimeout = (dwTimeout/8)*8;
|
|---|
| 2097 | }
|
|---|
| 2098 | else dwThreadPriority = -1;
|
|---|
| 2099 |
|
|---|
| 2100 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2101 | dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData,
|
|---|
| 2102 | dwTimeout);
|
|---|
| 2103 |
|
|---|
| 2104 | //Restore thread priority if we previously changed it
|
|---|
| 2105 | if(dwThreadPriority != -1) {
|
|---|
| 2106 | SetThreadPriority(hThread, dwThreadPriority);
|
|---|
| 2107 | }
|
|---|
| 2108 | return (dwResult); /* deliver return code */
|
|---|
| 2109 | }
|
|---|
| 2110 |
|
|---|
| 2111 |
|
|---|
| 2112 | /*****************************************************************************
|
|---|
| 2113 | * Name : HMDeviceHandler::WaitForSingleObjectEx
|
|---|
| 2114 | * Purpose : router function for WaitForSingleObjectEx
|
|---|
| 2115 | * Parameters:
|
|---|
| 2116 | * Variables :
|
|---|
| 2117 | * Result :
|
|---|
| 2118 | * Remark :
|
|---|
| 2119 | * Status :
|
|---|
| 2120 | *
|
|---|
| 2121 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2122 | *****************************************************************************/
|
|---|
| 2123 |
|
|---|
| 2124 | DWORD HMWaitForSingleObjectEx(HANDLE hObject,
|
|---|
| 2125 | DWORD dwTimeout,
|
|---|
| 2126 | BOOL fAlertable)
|
|---|
| 2127 | {
|
|---|
| 2128 | int iIndex; /* index into the handle table */
|
|---|
| 2129 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2130 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2131 |
|
|---|
| 2132 | /* validate handle */
|
|---|
| 2133 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 2134 | if (-1 == iIndex) /* error ? */
|
|---|
| 2135 | {
|
|---|
| 2136 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2137 | return WAIT_FAILED; /* signal failure */
|
|---|
| 2138 | }
|
|---|
| 2139 |
|
|---|
| 2140 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2141 | dwResult = pHMHandle->pDeviceHandler->WaitForSingleObjectEx(&pHMHandle->hmHandleData,
|
|---|
| 2142 | dwTimeout,
|
|---|
| 2143 | fAlertable);
|
|---|
| 2144 |
|
|---|
| 2145 | return (dwResult); /* deliver return code */
|
|---|
| 2146 | }
|
|---|
| 2147 |
|
|---|
| 2148 |
|
|---|
| 2149 | /*****************************************************************************
|
|---|
| 2150 | * Name : HMDeviceHandler::FlushFileBuffers
|
|---|
| 2151 | * Purpose : router function for FlushFileBuffers
|
|---|
| 2152 | * Parameters:
|
|---|
| 2153 | * Variables :
|
|---|
| 2154 | * Result :
|
|---|
| 2155 | * Remark :
|
|---|
| 2156 | * Status :
|
|---|
| 2157 | *
|
|---|
| 2158 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2159 | *****************************************************************************/
|
|---|
| 2160 |
|
|---|
| 2161 | BOOL HMFlushFileBuffers(HANDLE hFile)
|
|---|
| 2162 | {
|
|---|
| 2163 | int iIndex; /* index into the handle table */
|
|---|
| 2164 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2165 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2166 |
|
|---|
| 2167 | /* validate handle */
|
|---|
| 2168 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 2169 | if (-1 == iIndex) /* error ? */
|
|---|
| 2170 | {
|
|---|
| 2171 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2172 | return FALSE; /* signal failure */
|
|---|
| 2173 | }
|
|---|
| 2174 |
|
|---|
| 2175 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2176 | dwResult = pHMHandle->pDeviceHandler->FlushFileBuffers(&pHMHandle->hmHandleData);
|
|---|
| 2177 |
|
|---|
| 2178 | return (dwResult); /* deliver return code */
|
|---|
| 2179 | }
|
|---|
| 2180 |
|
|---|
| 2181 |
|
|---|
| 2182 | /*****************************************************************************
|
|---|
| 2183 | * Name : HMDeviceHandler::GetOverlappedResult
|
|---|
| 2184 | * Purpose : router function for GetOverlappedResult
|
|---|
| 2185 | * Parameters:
|
|---|
| 2186 | * Variables :
|
|---|
| 2187 | * Result :
|
|---|
| 2188 | * Remark :
|
|---|
| 2189 | * Status :
|
|---|
| 2190 | *
|
|---|
| 2191 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2192 | *****************************************************************************/
|
|---|
| 2193 |
|
|---|
| 2194 | BOOL HMGetOverlappedResult(HANDLE hObject,
|
|---|
| 2195 | LPOVERLAPPED lpOverlapped,
|
|---|
| 2196 | LPDWORD arg3,
|
|---|
| 2197 | BOOL arg4)
|
|---|
| 2198 | {
|
|---|
| 2199 | int iIndex; /* index into the handle table */
|
|---|
| 2200 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2201 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2202 |
|
|---|
| 2203 | /* validate handle */
|
|---|
| 2204 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 2205 | if (-1 == iIndex) /* error ? */
|
|---|
| 2206 | {
|
|---|
| 2207 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2208 | return FALSE; /* signal failure */
|
|---|
| 2209 | }
|
|---|
| 2210 |
|
|---|
| 2211 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2212 | dwResult = pHMHandle->pDeviceHandler->GetOverlappedResult(&pHMHandle->hmHandleData,
|
|---|
| 2213 | lpOverlapped,
|
|---|
| 2214 | arg3,
|
|---|
| 2215 | arg4);
|
|---|
| 2216 |
|
|---|
| 2217 | return (dwResult); /* deliver return code */
|
|---|
| 2218 | }
|
|---|
| 2219 |
|
|---|
| 2220 |
|
|---|
| 2221 | /*****************************************************************************
|
|---|
| 2222 | * Name : HMReleaseMutex
|
|---|
| 2223 | * Purpose : router function for ReleaseMutex
|
|---|
| 2224 | * Parameters:
|
|---|
| 2225 | * Variables :
|
|---|
| 2226 | * Result :
|
|---|
| 2227 | * Remark :
|
|---|
| 2228 | * Status :
|
|---|
| 2229 | *
|
|---|
| 2230 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2231 | *****************************************************************************/
|
|---|
| 2232 |
|
|---|
| 2233 | BOOL HMReleaseMutex(HANDLE hObject)
|
|---|
| 2234 | {
|
|---|
| 2235 | int iIndex; /* index into the handle table */
|
|---|
| 2236 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2237 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2238 |
|
|---|
| 2239 | /* validate handle */
|
|---|
| 2240 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 2241 | if (-1 == iIndex) /* error ? */
|
|---|
| 2242 | {
|
|---|
| 2243 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2244 | return FALSE; /* signal failure */
|
|---|
| 2245 | }
|
|---|
| 2246 |
|
|---|
| 2247 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2248 | dwResult = pHMHandle->pDeviceHandler->ReleaseMutex(&pHMHandle->hmHandleData);
|
|---|
| 2249 |
|
|---|
| 2250 | return (dwResult); /* deliver return code */
|
|---|
| 2251 | }
|
|---|
| 2252 |
|
|---|
| 2253 |
|
|---|
| 2254 | /*****************************************************************************
|
|---|
| 2255 | * Name : HMSetEvent
|
|---|
| 2256 | * Purpose : router function for SetEvent
|
|---|
| 2257 | * Parameters:
|
|---|
| 2258 | * Variables :
|
|---|
| 2259 | * Result :
|
|---|
| 2260 | * Remark :
|
|---|
| 2261 | * Status :
|
|---|
| 2262 | *
|
|---|
| 2263 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2264 | *****************************************************************************/
|
|---|
| 2265 |
|
|---|
| 2266 | BOOL HMSetEvent(HANDLE hEvent)
|
|---|
| 2267 | {
|
|---|
| 2268 | int iIndex; /* index into the handle table */
|
|---|
| 2269 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2270 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2271 |
|
|---|
| 2272 | /* validate handle */
|
|---|
| 2273 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 2274 | if (-1 == iIndex) /* error ? */
|
|---|
| 2275 | {
|
|---|
| 2276 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2277 | return FALSE; /* signal failure */
|
|---|
| 2278 | }
|
|---|
| 2279 |
|
|---|
| 2280 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2281 | dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData);
|
|---|
| 2282 |
|
|---|
| 2283 | return (dwResult); /* deliver return code */
|
|---|
| 2284 | }
|
|---|
| 2285 |
|
|---|
| 2286 |
|
|---|
| 2287 | /*****************************************************************************
|
|---|
| 2288 | * Name : HMPulseEvent
|
|---|
| 2289 | * Purpose : router function for PulseEvent
|
|---|
| 2290 | * Parameters:
|
|---|
| 2291 | * Variables :
|
|---|
| 2292 | * Result :
|
|---|
| 2293 | * Remark :
|
|---|
| 2294 | * Status :
|
|---|
| 2295 | *
|
|---|
| 2296 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2297 | *****************************************************************************/
|
|---|
| 2298 |
|
|---|
| 2299 | BOOL HMPulseEvent(HANDLE hEvent)
|
|---|
| 2300 | {
|
|---|
| 2301 | int iIndex; /* index into the handle table */
|
|---|
| 2302 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2303 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2304 |
|
|---|
| 2305 | /* validate handle */
|
|---|
| 2306 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 2307 | if (-1 == iIndex) /* error ? */
|
|---|
| 2308 | {
|
|---|
| 2309 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2310 | return FALSE; /* signal failure */
|
|---|
| 2311 | }
|
|---|
| 2312 |
|
|---|
| 2313 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2314 | dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData);
|
|---|
| 2315 |
|
|---|
| 2316 | return (dwResult); /* deliver return code */
|
|---|
| 2317 | }
|
|---|
| 2318 |
|
|---|
| 2319 |
|
|---|
| 2320 | /*****************************************************************************
|
|---|
| 2321 | * Name : HMResetEvent
|
|---|
| 2322 | * Purpose : router function for ResetEvent
|
|---|
| 2323 | * Parameters:
|
|---|
| 2324 | * Variables :
|
|---|
| 2325 | * Result :
|
|---|
| 2326 | * Remark :
|
|---|
| 2327 | * Status :
|
|---|
| 2328 | *
|
|---|
| 2329 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2330 | *****************************************************************************/
|
|---|
| 2331 |
|
|---|
| 2332 | BOOL HMResetEvent(HANDLE hEvent)
|
|---|
| 2333 | {
|
|---|
| 2334 | int iIndex; /* index into the handle table */
|
|---|
| 2335 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2336 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2337 |
|
|---|
| 2338 | /* validate handle */
|
|---|
| 2339 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 2340 | if (-1 == iIndex) /* error ? */
|
|---|
| 2341 | {
|
|---|
| 2342 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2343 | return FALSE; /* signal failure */
|
|---|
| 2344 | }
|
|---|
| 2345 |
|
|---|
| 2346 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2347 | dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData);
|
|---|
| 2348 |
|
|---|
| 2349 | return (dwResult); /* deliver return code */
|
|---|
| 2350 | }
|
|---|
| 2351 |
|
|---|
| 2352 |
|
|---|
| 2353 | /*****************************************************************************
|
|---|
| 2354 | * Name : HANDLE HMCreateEvent
|
|---|
| 2355 | * Purpose : Wrapper for the CreateEvent() API
|
|---|
| 2356 | * Parameters:
|
|---|
| 2357 | * Variables :
|
|---|
| 2358 | * Result :
|
|---|
| 2359 | * Remark :
|
|---|
| 2360 | * Status :
|
|---|
| 2361 | *
|
|---|
| 2362 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2363 | *****************************************************************************/
|
|---|
| 2364 |
|
|---|
| 2365 | HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 2366 | BOOL bManualReset,
|
|---|
| 2367 | BOOL bInitialState,
|
|---|
| 2368 | LPCTSTR lpName)
|
|---|
| 2369 | {
|
|---|
| 2370 | int iIndex; /* index into the handle table */
|
|---|
| 2371 | int iIndexNew; /* index into the handle table */
|
|---|
| 2372 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2373 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2374 | DWORD rc; /* API return code */
|
|---|
| 2375 |
|
|---|
| 2376 |
|
|---|
| 2377 | if(lpName) { //check if shared event semaphore already exists
|
|---|
| 2378 | //TODO: No inheritance??
|
|---|
| 2379 | HANDLE handle = HMOpenEvent(EVENT_ALL_ACCESS, FALSE, lpName);
|
|---|
| 2380 | if(handle) {
|
|---|
| 2381 | dprintf(("CreateEvent: return handle of existing event semaphore %x", handle));
|
|---|
| 2382 | SetLastError(ERROR_ALREADY_EXISTS);
|
|---|
| 2383 | return handle;
|
|---|
| 2384 | }
|
|---|
| 2385 | }
|
|---|
| 2386 |
|
|---|
| 2387 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
|---|
| 2388 |
|
|---|
| 2389 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2390 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2391 | {
|
|---|
| 2392 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2393 | return 0; /* signal error */
|
|---|
| 2394 | }
|
|---|
| 2395 |
|
|---|
| 2396 | /* Initialize the complete HMHANDLEDATA structure */
|
|---|
| 2397 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2398 | pHMHandleData->dwAccess = 0;
|
|---|
| 2399 | pHMHandleData->dwShare = 0;
|
|---|
| 2400 | pHMHandleData->dwCreation = 0;
|
|---|
| 2401 | pHMHandleData->dwFlags = 0;
|
|---|
| 2402 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2403 |
|
|---|
| 2404 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2405 | /* could be created within the device handler -> deadlock */
|
|---|
| 2406 |
|
|---|
| 2407 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2408 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2409 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2410 |
|
|---|
| 2411 | /* call the device handler */
|
|---|
| 2412 | rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2413 | lpsa,
|
|---|
| 2414 | bManualReset,
|
|---|
| 2415 | bInitialState,
|
|---|
| 2416 | lpName);
|
|---|
| 2417 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2418 | {
|
|---|
| 2419 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2420 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2421 | return 0; /* signal error */
|
|---|
| 2422 | }
|
|---|
| 2423 | else
|
|---|
| 2424 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2425 |
|
|---|
| 2426 | return iIndexNew; /* return valid handle */
|
|---|
| 2427 | }
|
|---|
| 2428 |
|
|---|
| 2429 |
|
|---|
| 2430 | /*****************************************************************************
|
|---|
| 2431 | * Name : HANDLE HMCreateMutex
|
|---|
| 2432 | * Purpose : Wrapper for the CreateMutex() API
|
|---|
| 2433 | * Parameters:
|
|---|
| 2434 | * Variables :
|
|---|
| 2435 | * Result :
|
|---|
| 2436 | * Remark :
|
|---|
| 2437 | * Status :
|
|---|
| 2438 | *
|
|---|
| 2439 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2440 | *****************************************************************************/
|
|---|
| 2441 |
|
|---|
| 2442 | HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 2443 | BOOL bInitialOwner,
|
|---|
| 2444 | LPCTSTR lpName)
|
|---|
| 2445 | {
|
|---|
| 2446 | int iIndex; /* index into the handle table */
|
|---|
| 2447 | int iIndexNew; /* index into the handle table */
|
|---|
| 2448 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2449 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2450 | DWORD rc; /* API return code */
|
|---|
| 2451 |
|
|---|
| 2452 |
|
|---|
| 2453 | if(lpName) { //check if shared mutex semaphore already exists
|
|---|
| 2454 | //TODO: No inheritance??
|
|---|
| 2455 | HANDLE handle = HMOpenMutex(MUTEX_ALL_ACCESS, FALSE, lpName);
|
|---|
| 2456 | if(handle) {
|
|---|
| 2457 | dprintf(("CreateMutex: return handle of existing mutex semaphore %x", handle));
|
|---|
| 2458 | SetLastError(ERROR_ALREADY_EXISTS);
|
|---|
| 2459 | return handle;
|
|---|
| 2460 | }
|
|---|
| 2461 | }
|
|---|
| 2462 |
|
|---|
| 2463 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
|---|
| 2464 |
|
|---|
| 2465 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2466 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2467 | {
|
|---|
| 2468 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2469 | return 0; /* signal error */
|
|---|
| 2470 | }
|
|---|
| 2471 |
|
|---|
| 2472 |
|
|---|
| 2473 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2474 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2475 | pHMHandleData->dwAccess = 0;
|
|---|
| 2476 | pHMHandleData->dwShare = 0;
|
|---|
| 2477 | pHMHandleData->dwCreation = 0;
|
|---|
| 2478 | pHMHandleData->dwFlags = 0;
|
|---|
| 2479 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2480 |
|
|---|
| 2481 |
|
|---|
| 2482 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2483 | /* could be created within the device handler -> deadlock */
|
|---|
| 2484 |
|
|---|
| 2485 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2486 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2487 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2488 |
|
|---|
| 2489 | /* call the device handler */
|
|---|
| 2490 | rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2491 | lpsa,
|
|---|
| 2492 | bInitialOwner,
|
|---|
| 2493 | lpName);
|
|---|
| 2494 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2495 | {
|
|---|
| 2496 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2497 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2498 | return 0; /* signal error */
|
|---|
| 2499 | }
|
|---|
| 2500 | else
|
|---|
| 2501 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2502 |
|
|---|
| 2503 | return iIndexNew; /* return valid handle */
|
|---|
| 2504 | }
|
|---|
| 2505 |
|
|---|
| 2506 |
|
|---|
| 2507 | /*****************************************************************************
|
|---|
| 2508 | * Name : HANDLE HMOpenEvent
|
|---|
| 2509 | * Purpose : Wrapper for the OpenEvent() API
|
|---|
| 2510 | * Parameters:
|
|---|
| 2511 | * Variables :
|
|---|
| 2512 | * Result :
|
|---|
| 2513 | * Remark :
|
|---|
| 2514 | * Status :
|
|---|
| 2515 | *
|
|---|
| 2516 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2517 | *****************************************************************************/
|
|---|
| 2518 |
|
|---|
| 2519 | HANDLE HMOpenEvent(DWORD fdwAccess,
|
|---|
| 2520 | BOOL fInherit,
|
|---|
| 2521 | LPCTSTR lpName)
|
|---|
| 2522 | {
|
|---|
| 2523 | int iIndex; /* index into the handle table */
|
|---|
| 2524 | int iIndexNew; /* index into the handle table */
|
|---|
| 2525 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2526 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2527 | DWORD rc; /* API return code */
|
|---|
| 2528 |
|
|---|
| 2529 |
|
|---|
| 2530 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
|---|
| 2531 |
|
|---|
| 2532 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2533 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2534 | {
|
|---|
| 2535 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2536 | return 0; /* signal error */
|
|---|
| 2537 | }
|
|---|
| 2538 |
|
|---|
| 2539 |
|
|---|
| 2540 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2541 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2542 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2543 | pHMHandleData->dwShare = 0;
|
|---|
| 2544 | pHMHandleData->dwCreation = 0;
|
|---|
| 2545 | pHMHandleData->dwFlags = 0;
|
|---|
| 2546 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2547 |
|
|---|
| 2548 |
|
|---|
| 2549 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2550 | /* could be created within the device handler -> deadlock */
|
|---|
| 2551 |
|
|---|
| 2552 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2553 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2554 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2555 |
|
|---|
| 2556 | /* call the device handler */
|
|---|
| 2557 | rc = pDeviceHandler->OpenEvent(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2558 | fInherit,
|
|---|
| 2559 | lpName);
|
|---|
| 2560 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2561 | {
|
|---|
| 2562 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2563 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2564 | return 0; /* signal error */
|
|---|
| 2565 | }
|
|---|
| 2566 | else
|
|---|
| 2567 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2568 |
|
|---|
| 2569 | return iIndexNew; /* return valid handle */
|
|---|
| 2570 | }
|
|---|
| 2571 |
|
|---|
| 2572 |
|
|---|
| 2573 | /*****************************************************************************
|
|---|
| 2574 | * Name : HANDLE HMOpenMutex
|
|---|
| 2575 | * Purpose : Wrapper for the OpenMutex() API
|
|---|
| 2576 | * Parameters:
|
|---|
| 2577 | * Variables :
|
|---|
| 2578 | * Result :
|
|---|
| 2579 | * Remark :
|
|---|
| 2580 | * Status :
|
|---|
| 2581 | *
|
|---|
| 2582 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2583 | *****************************************************************************/
|
|---|
| 2584 |
|
|---|
| 2585 | HANDLE HMOpenMutex(DWORD fdwAccess,
|
|---|
| 2586 | BOOL fInherit,
|
|---|
| 2587 | LPCTSTR lpName)
|
|---|
| 2588 | {
|
|---|
| 2589 | int iIndex; /* index into the handle table */
|
|---|
| 2590 | int iIndexNew; /* index into the handle table */
|
|---|
| 2591 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2592 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2593 | DWORD rc; /* API return code */
|
|---|
| 2594 |
|
|---|
| 2595 |
|
|---|
| 2596 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
|---|
| 2597 |
|
|---|
| 2598 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2599 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2600 | {
|
|---|
| 2601 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2602 | return 0; /* signal error */
|
|---|
| 2603 | }
|
|---|
| 2604 |
|
|---|
| 2605 |
|
|---|
| 2606 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2607 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2608 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2609 | pHMHandleData->dwShare = 0;
|
|---|
| 2610 | pHMHandleData->dwCreation = 0;
|
|---|
| 2611 | pHMHandleData->dwFlags = 0;
|
|---|
| 2612 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2613 |
|
|---|
| 2614 |
|
|---|
| 2615 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2616 | /* could be created within the device handler -> deadlock */
|
|---|
| 2617 |
|
|---|
| 2618 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2619 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2620 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2621 |
|
|---|
| 2622 | /* call the device handler */
|
|---|
| 2623 | rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2624 | fInherit,
|
|---|
| 2625 | lpName);
|
|---|
| 2626 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2627 | {
|
|---|
| 2628 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2629 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2630 | return 0; /* signal error */
|
|---|
| 2631 | }
|
|---|
| 2632 | else
|
|---|
| 2633 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2634 |
|
|---|
| 2635 | return iIndexNew; /* return valid handle */
|
|---|
| 2636 | }
|
|---|
| 2637 |
|
|---|
| 2638 |
|
|---|
| 2639 | /*****************************************************************************
|
|---|
| 2640 | * Name : HANDLE HMCreateSemaphore
|
|---|
| 2641 | * Purpose : Wrapper for the CreateSemaphore() API
|
|---|
| 2642 | * Parameters:
|
|---|
| 2643 | * Variables :
|
|---|
| 2644 | * Result :
|
|---|
| 2645 | * Remark :
|
|---|
| 2646 | * Status :
|
|---|
| 2647 | *
|
|---|
| 2648 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2649 | *****************************************************************************/
|
|---|
| 2650 |
|
|---|
| 2651 | HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 2652 | LONG lInitialCount,
|
|---|
| 2653 | LONG lMaximumCount,
|
|---|
| 2654 | LPCTSTR lpName)
|
|---|
| 2655 | {
|
|---|
| 2656 | int iIndex; /* index into the handle table */
|
|---|
| 2657 | int iIndexNew; /* index into the handle table */
|
|---|
| 2658 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2659 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2660 | DWORD rc; /* API return code */
|
|---|
| 2661 |
|
|---|
| 2662 | if(lpName) { //check if shared event semaphore already exists
|
|---|
| 2663 | //TODO: No inheritance??
|
|---|
| 2664 | HANDLE handle = HMOpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, lpName);
|
|---|
| 2665 | if(handle) {
|
|---|
| 2666 | dprintf(("CreateSemaphore: return handle of existing semaphore %x", handle));
|
|---|
| 2667 | SetLastError(ERROR_ALREADY_EXISTS);
|
|---|
| 2668 | return handle;
|
|---|
| 2669 | }
|
|---|
| 2670 | }
|
|---|
| 2671 |
|
|---|
| 2672 | pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */
|
|---|
| 2673 |
|
|---|
| 2674 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2675 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2676 | {
|
|---|
| 2677 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2678 | return 0; /* signal error */
|
|---|
| 2679 | }
|
|---|
| 2680 |
|
|---|
| 2681 |
|
|---|
| 2682 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2683 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2684 | pHMHandleData->dwAccess = 0;
|
|---|
| 2685 | pHMHandleData->dwShare = 0;
|
|---|
| 2686 | pHMHandleData->dwCreation = 0;
|
|---|
| 2687 | pHMHandleData->dwFlags = 0;
|
|---|
| 2688 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2689 |
|
|---|
| 2690 |
|
|---|
| 2691 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2692 | /* could be created within the device handler -> deadlock */
|
|---|
| 2693 |
|
|---|
| 2694 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2695 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2696 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2697 |
|
|---|
| 2698 | /* call the device handler */
|
|---|
| 2699 | rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2700 | lpsa,
|
|---|
| 2701 | lInitialCount,
|
|---|
| 2702 | lMaximumCount,
|
|---|
| 2703 | lpName);
|
|---|
| 2704 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2705 | {
|
|---|
| 2706 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2707 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2708 | return 0; /* signal failure */
|
|---|
| 2709 | }
|
|---|
| 2710 | else
|
|---|
| 2711 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2712 |
|
|---|
| 2713 | return iIndexNew; /* return valid handle */
|
|---|
| 2714 | }
|
|---|
| 2715 |
|
|---|
| 2716 |
|
|---|
| 2717 | /*****************************************************************************
|
|---|
| 2718 | * Name : HANDLE HMOpenSemaphore
|
|---|
| 2719 | * Purpose : Wrapper for the OpenSemaphore() API
|
|---|
| 2720 | * Parameters:
|
|---|
| 2721 | * Variables :
|
|---|
| 2722 | * Result :
|
|---|
| 2723 | * Remark :
|
|---|
| 2724 | * Status :
|
|---|
| 2725 | *
|
|---|
| 2726 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2727 | *****************************************************************************/
|
|---|
| 2728 |
|
|---|
| 2729 | HANDLE HMOpenSemaphore(DWORD fdwAccess,
|
|---|
| 2730 | BOOL fInherit,
|
|---|
| 2731 | LPCTSTR lpName)
|
|---|
| 2732 | {
|
|---|
| 2733 | int iIndex; /* index into the handle table */
|
|---|
| 2734 | int iIndexNew; /* index into the handle table */
|
|---|
| 2735 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2736 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2737 | DWORD rc; /* API return code */
|
|---|
| 2738 |
|
|---|
| 2739 |
|
|---|
| 2740 | pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */
|
|---|
| 2741 |
|
|---|
| 2742 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2743 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2744 | {
|
|---|
| 2745 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2746 | return 0; /* signal error */
|
|---|
| 2747 | }
|
|---|
| 2748 |
|
|---|
| 2749 |
|
|---|
| 2750 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2751 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2752 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2753 | pHMHandleData->dwShare = 0;
|
|---|
| 2754 | pHMHandleData->dwCreation = 0;
|
|---|
| 2755 | pHMHandleData->dwFlags = 0;
|
|---|
| 2756 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2757 |
|
|---|
| 2758 |
|
|---|
| 2759 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2760 | /* could be created within the device handler -> deadlock */
|
|---|
| 2761 |
|
|---|
| 2762 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2763 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2764 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2765 |
|
|---|
| 2766 | /* call the device handler */
|
|---|
| 2767 | rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2768 | fInherit,
|
|---|
| 2769 | lpName);
|
|---|
| 2770 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2771 | {
|
|---|
| 2772 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2773 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2774 | return 0; /* signal failure */
|
|---|
| 2775 | }
|
|---|
| 2776 | else
|
|---|
| 2777 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2778 |
|
|---|
| 2779 | return iIndexNew; /* return valid handle */
|
|---|
| 2780 | }
|
|---|
| 2781 |
|
|---|
| 2782 |
|
|---|
| 2783 | /*****************************************************************************
|
|---|
| 2784 | * Name : HMReleaseSemaphore
|
|---|
| 2785 | * Purpose : router function for ReleaseSemaphore
|
|---|
| 2786 | * Parameters:
|
|---|
| 2787 | * Variables :
|
|---|
| 2788 | * Result :
|
|---|
| 2789 | * Remark :
|
|---|
| 2790 | * Status :
|
|---|
| 2791 | *
|
|---|
| 2792 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2793 | *****************************************************************************/
|
|---|
| 2794 |
|
|---|
| 2795 | BOOL HMReleaseSemaphore(HANDLE hEvent,
|
|---|
| 2796 | LONG cReleaseCount,
|
|---|
| 2797 | LPLONG lpPreviousCount)
|
|---|
| 2798 | {
|
|---|
| 2799 | int iIndex; /* index into the handle table */
|
|---|
| 2800 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2801 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2802 |
|
|---|
| 2803 | /* validate handle */
|
|---|
| 2804 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 2805 | if (-1 == iIndex) /* error ? */
|
|---|
| 2806 | {
|
|---|
| 2807 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2808 | return 0; /* signal failure */
|
|---|
| 2809 | }
|
|---|
| 2810 | else
|
|---|
| 2811 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2812 |
|
|---|
| 2813 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2814 | dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData,
|
|---|
| 2815 | cReleaseCount,
|
|---|
| 2816 | lpPreviousCount);
|
|---|
| 2817 |
|
|---|
| 2818 | return (dwResult); /* deliver return code */
|
|---|
| 2819 | }
|
|---|
| 2820 |
|
|---|
| 2821 |
|
|---|
| 2822 | /*****************************************************************************
|
|---|
| 2823 | * Name : HANDLE HMCreateFileMapping
|
|---|
| 2824 | * Purpose : Wrapper for the CreateFileMapping() API
|
|---|
| 2825 | * Parameters:
|
|---|
| 2826 | * Variables :
|
|---|
| 2827 | * Result :
|
|---|
| 2828 | * Remark :
|
|---|
| 2829 | * Status :
|
|---|
| 2830 | *
|
|---|
| 2831 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2832 | *****************************************************************************/
|
|---|
| 2833 |
|
|---|
| 2834 | HANDLE HMCreateFileMapping(HANDLE hFile,
|
|---|
| 2835 | LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
|
|---|
| 2836 | DWORD flProtect,
|
|---|
| 2837 | DWORD dwMaximumSizeHigh,
|
|---|
| 2838 | DWORD dwMaximumSizeLow,
|
|---|
| 2839 | LPCTSTR lpName)
|
|---|
| 2840 | {
|
|---|
| 2841 | int iIndex; /* index into the handle table */
|
|---|
| 2842 | int iIndexNew; /* index into the handle table */
|
|---|
| 2843 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2844 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2845 | DWORD rc; /* API return code */
|
|---|
| 2846 |
|
|---|
| 2847 | pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */
|
|---|
| 2848 |
|
|---|
| 2849 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2850 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2851 | {
|
|---|
| 2852 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2853 | return 0; /* signal error */
|
|---|
| 2854 | }
|
|---|
| 2855 |
|
|---|
| 2856 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2857 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2858 | pHMHandleData->dwAccess = 0;
|
|---|
| 2859 | pHMHandleData->dwShare = 0;
|
|---|
| 2860 | pHMHandleData->dwCreation = 0;
|
|---|
| 2861 | pHMHandleData->dwFlags = 0;
|
|---|
| 2862 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2863 |
|
|---|
| 2864 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2865 | /* could be created within the device handler -> deadlock */
|
|---|
| 2866 |
|
|---|
| 2867 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2868 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2869 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2870 |
|
|---|
| 2871 | /* call the device handler */
|
|---|
| 2872 |
|
|---|
| 2873 | // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
|
|---|
| 2874 | // a valid HandleManager-internal handle!
|
|---|
| 2875 | rc = pDeviceHandler->CreateFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2876 | hFile,
|
|---|
| 2877 | lpFileMappingAttributes,
|
|---|
| 2878 | flProtect,
|
|---|
| 2879 | dwMaximumSizeHigh,
|
|---|
| 2880 | dwMaximumSizeLow,
|
|---|
| 2881 | lpName);
|
|---|
| 2882 |
|
|---|
| 2883 | if(rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2884 | {
|
|---|
| 2885 | if(rc != ERROR_ALREADY_EXISTS) {
|
|---|
| 2886 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2887 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2888 | return (NULL); /* signal error */
|
|---|
| 2889 | }
|
|---|
| 2890 | SetLastError(ERROR_ALREADY_EXISTS);
|
|---|
| 2891 | return iIndexNew; /* return valid handle */
|
|---|
| 2892 | }
|
|---|
| 2893 | else
|
|---|
| 2894 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2895 |
|
|---|
| 2896 | return iIndexNew; /* return valid handle */
|
|---|
| 2897 | }
|
|---|
| 2898 |
|
|---|
| 2899 |
|
|---|
| 2900 | /*****************************************************************************
|
|---|
| 2901 | * Name : HANDLE HMOpenFileMapping
|
|---|
| 2902 | * Purpose : Wrapper for the OpenFileMapping() API
|
|---|
| 2903 | * Parameters:
|
|---|
| 2904 | * Variables :
|
|---|
| 2905 | * Result : HANDLE if succeeded,
|
|---|
| 2906 | * NULL if failed.
|
|---|
| 2907 | * Remark :
|
|---|
| 2908 | * Status :
|
|---|
| 2909 | *
|
|---|
| 2910 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2911 | *****************************************************************************/
|
|---|
| 2912 |
|
|---|
| 2913 | HANDLE HMOpenFileMapping(DWORD fdwAccess,
|
|---|
| 2914 | BOOL fInherit,
|
|---|
| 2915 | LPCTSTR lpName)
|
|---|
| 2916 | {
|
|---|
| 2917 | int iIndex; /* index into the handle table */
|
|---|
| 2918 | int iIndexNew; /* index into the handle table */
|
|---|
| 2919 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2920 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2921 | DWORD rc; /* API return code */
|
|---|
| 2922 |
|
|---|
| 2923 |
|
|---|
| 2924 | pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */
|
|---|
| 2925 |
|
|---|
| 2926 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2927 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2928 | {
|
|---|
| 2929 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2930 | return (NULL); /* signal error */
|
|---|
| 2931 | }
|
|---|
| 2932 |
|
|---|
| 2933 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2934 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2935 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2936 | pHMHandleData->dwShare = 0;
|
|---|
| 2937 | pHMHandleData->dwCreation = 0;
|
|---|
| 2938 | pHMHandleData->dwFlags = 0;
|
|---|
| 2939 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2940 |
|
|---|
| 2941 |
|
|---|
| 2942 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2943 | /* could be created within the device handler -> deadlock */
|
|---|
| 2944 |
|
|---|
| 2945 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2946 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2947 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2948 |
|
|---|
| 2949 | /* call the device handler */
|
|---|
| 2950 | rc = pDeviceHandler->OpenFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2951 | fdwAccess,
|
|---|
| 2952 | fInherit,
|
|---|
| 2953 | lpName);
|
|---|
| 2954 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2955 | {
|
|---|
| 2956 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2957 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2958 | return (NULL); /* signal error */
|
|---|
| 2959 | }
|
|---|
| 2960 | else
|
|---|
| 2961 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2962 |
|
|---|
| 2963 | return iIndexNew; /* return valid handle */
|
|---|
| 2964 | }
|
|---|
| 2965 |
|
|---|
| 2966 |
|
|---|
| 2967 | /*****************************************************************************
|
|---|
| 2968 | * Name : HMMapViewOfFileEx
|
|---|
| 2969 | * Purpose : router function for MapViewOfFileEx
|
|---|
| 2970 | * Parameters:
|
|---|
| 2971 | * Variables :
|
|---|
| 2972 | * Result :
|
|---|
| 2973 | * Remark :
|
|---|
| 2974 | * Status :
|
|---|
| 2975 | *
|
|---|
| 2976 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2977 | *****************************************************************************/
|
|---|
| 2978 |
|
|---|
| 2979 | LPVOID HMMapViewOfFileEx(HANDLE hFileMappingObject,
|
|---|
| 2980 | DWORD dwDesiredAccess,
|
|---|
| 2981 | DWORD dwFileOffsetHigh,
|
|---|
| 2982 | DWORD dwFileOffsetLow,
|
|---|
| 2983 | DWORD dwNumberOfBytesToMap,
|
|---|
| 2984 | LPVOID lpBaseAddress)
|
|---|
| 2985 | {
|
|---|
| 2986 | int iIndex; /* index into the handle table */
|
|---|
| 2987 | LPVOID lpResult; /* result from the device handler's API */
|
|---|
| 2988 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2989 |
|
|---|
| 2990 | /* validate handle */
|
|---|
| 2991 | iIndex = _HMHandleQuery(hFileMappingObject); /* get the index */
|
|---|
| 2992 | if (-1 == iIndex) /* error ? */
|
|---|
| 2993 | {
|
|---|
| 2994 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2995 | return (NULL); /* signal failure */
|
|---|
| 2996 | }
|
|---|
| 2997 |
|
|---|
| 2998 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2999 | lpResult = pHMHandle->pDeviceHandler->MapViewOfFileEx(&pHMHandle->hmHandleData,
|
|---|
| 3000 | dwDesiredAccess,
|
|---|
| 3001 | dwFileOffsetHigh,
|
|---|
| 3002 | dwFileOffsetLow,
|
|---|
| 3003 | dwNumberOfBytesToMap,
|
|---|
| 3004 | lpBaseAddress);
|
|---|
| 3005 |
|
|---|
| 3006 | return (lpResult); /* deliver return code */
|
|---|
| 3007 | }
|
|---|
| 3008 |
|
|---|
| 3009 | /*****************************************************************************
|
|---|
| 3010 | * Name : HMWaitForMultipleObjects
|
|---|
| 3011 | * Purpose : router function for WaitForMultipleObjects
|
|---|
| 3012 | * Parameters:
|
|---|
| 3013 | * Variables :
|
|---|
| 3014 | * Result :
|
|---|
| 3015 | * Remark :
|
|---|
| 3016 | * Status :
|
|---|
| 3017 | *
|
|---|
| 3018 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 3019 | *****************************************************************************/
|
|---|
| 3020 |
|
|---|
| 3021 | DWORD HMWaitForMultipleObjects (DWORD cObjects,
|
|---|
| 3022 | PHANDLE lphObjects,
|
|---|
| 3023 | BOOL fWaitAll,
|
|---|
| 3024 | DWORD dwTimeout)
|
|---|
| 3025 | {
|
|---|
| 3026 | #ifdef USE_OS2SEMAPHORES
|
|---|
| 3027 | int iIndex; /* index into the handle table */
|
|---|
| 3028 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 3029 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3030 |
|
|---|
| 3031 | if(cObjects == 1) {
|
|---|
| 3032 | return HMWaitForSingleObject(*lphObjects, dwTimeout);
|
|---|
| 3033 | }
|
|---|
| 3034 |
|
|---|
| 3035 | if(cObjects > MAXIMUM_WAIT_OBJECTS) {
|
|---|
| 3036 | dprintf(("KERNEL32: HMWaitForMultipleObjects: Too many objects (%d)", cObjects));
|
|---|
| 3037 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3038 | return WAIT_FAILED;
|
|---|
| 3039 | }
|
|---|
| 3040 |
|
|---|
| 3041 | /* validate handle */
|
|---|
| 3042 | iIndex = _HMHandleQuery(*lphObjects); /* get the index */
|
|---|
| 3043 | if (-1 == iIndex) /* error ? */
|
|---|
| 3044 | {//oh, oh. possible problem here
|
|---|
| 3045 | //TODO: rewrite handling of other handles; don't forward to open32
|
|---|
| 3046 | dprintf(("WANRING: HMWaitForMultipleObjects: unknown handle passed on to Open32 -> will not work if other handles are semaphores"));
|
|---|
| 3047 | return O32_WaitForMultipleObjects(cObjects, lphObjects, fWaitAll, dwTimeout);
|
|---|
| 3048 | }
|
|---|
| 3049 |
|
|---|
| 3050 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3051 | dwResult = pHMHandle->pDeviceHandler->WaitForMultipleObjects(&pHMHandle->hmHandleData,
|
|---|
| 3052 | cObjects, lphObjects, fWaitAll,
|
|---|
| 3053 | dwTimeout);
|
|---|
| 3054 |
|
|---|
| 3055 | return (dwResult); /* deliver return code */
|
|---|
| 3056 | #else
|
|---|
| 3057 | ULONG ulIndex;
|
|---|
| 3058 | PHANDLE pArrayOfHandles;
|
|---|
| 3059 | PHANDLE pLoop1 = lphObjects;
|
|---|
| 3060 | PHANDLE pLoop2;
|
|---|
| 3061 | DWORD rc;
|
|---|
| 3062 |
|
|---|
| 3063 | // allocate array for handle table
|
|---|
| 3064 | pArrayOfHandles = (PHANDLE)alloca(cObjects * sizeof(HANDLE));
|
|---|
| 3065 | if (pArrayOfHandles == NULL)
|
|---|
| 3066 | {
|
|---|
| 3067 | dprintf(("ERROR: HMWaitForMultipleObjects: alloca failed to allocate %d handles", cObjects));
|
|---|
| 3068 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|---|
| 3069 | return WAIT_FAILED;
|
|---|
| 3070 | }
|
|---|
| 3071 | else
|
|---|
| 3072 | pLoop2 = pArrayOfHandles;
|
|---|
| 3073 |
|
|---|
| 3074 | // convert array to odin handles
|
|---|
| 3075 | for (ulIndex = 0;
|
|---|
| 3076 |
|
|---|
| 3077 | ulIndex < cObjects;
|
|---|
| 3078 |
|
|---|
| 3079 | ulIndex++,
|
|---|
| 3080 | pLoop1++,
|
|---|
| 3081 | pLoop2++)
|
|---|
| 3082 | {
|
|---|
| 3083 | rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
|
|---|
| 3084 | pLoop2);
|
|---|
| 3085 |
|
|---|
| 3086 | dprintf(("KERNEL32: HMWaitForMultipleObjects: handle %3i: ODIN-%08xh, Open32-%08xh\n",
|
|---|
| 3087 | ulIndex,
|
|---|
| 3088 | *pLoop1,
|
|---|
| 3089 | *pLoop2));
|
|---|
| 3090 |
|
|---|
| 3091 | // @@@PH to imlpement: check handle type!
|
|---|
| 3092 | // SvL: We still use Open32 handles for threads & processes -> don't fail here!
|
|---|
| 3093 | if (rc != NO_ERROR)
|
|---|
| 3094 | {
|
|---|
| 3095 | dprintf(("KERNEL32: HMWaitForMultipleObjects - WARNING: handle %08xh is NOT an Odin handle (probably Open32 thread or process)\n",
|
|---|
| 3096 | *pLoop1));
|
|---|
| 3097 |
|
|---|
| 3098 | *pLoop2 = *pLoop1;
|
|---|
| 3099 | //// SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 3100 | //// return (WAIT_FAILED);
|
|---|
| 3101 | }
|
|---|
| 3102 | }
|
|---|
| 3103 |
|
|---|
| 3104 | //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
|
|---|
| 3105 | //return too late if the thread priority isn't time critical (time slices
|
|---|
| 3106 | //of 32 ms)
|
|---|
| 3107 | //To avoid this problem, we temporarily switch to time critical priority.
|
|---|
| 3108 | HANDLE hThread = GetCurrentThread();
|
|---|
| 3109 | DWORD dwThreadPriority = GetThreadPriority(hThread);
|
|---|
| 3110 |
|
|---|
| 3111 | if(dwTimeout && dwTimeout < 20 && dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL) {
|
|---|
| 3112 | dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));
|
|---|
| 3113 | SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
|---|
| 3114 | //round to 8 ms units to get more precise timeouts
|
|---|
| 3115 | if(dwTimeout > 8)
|
|---|
| 3116 | dwTimeout = (dwTimeout/8)*8;
|
|---|
| 3117 | }
|
|---|
| 3118 | else dwThreadPriority = -1;
|
|---|
| 3119 |
|
|---|
| 3120 | // OK, now forward to Open32.
|
|---|
| 3121 | // @@@PH: Note this will fail on handles that do NOT belong to Open32
|
|---|
| 3122 | // but to i.e. the console subsystem!
|
|---|
| 3123 | rc = O32_WaitForMultipleObjects(cObjects,
|
|---|
| 3124 | pArrayOfHandles,
|
|---|
| 3125 | fWaitAll,
|
|---|
| 3126 | dwTimeout);
|
|---|
| 3127 |
|
|---|
| 3128 | //Restore old thread priority if we changed it before
|
|---|
| 3129 | if(dwThreadPriority != -1) {
|
|---|
| 3130 | SetThreadPriority(hThread, dwThreadPriority);
|
|---|
| 3131 | }
|
|---|
| 3132 |
|
|---|
| 3133 | return (rc); // OK, done
|
|---|
| 3134 | #endif
|
|---|
| 3135 | }
|
|---|
| 3136 |
|
|---|
| 3137 |
|
|---|
| 3138 | /*****************************************************************************
|
|---|
| 3139 | * Name : HMWaitForMultipleObjectsEx
|
|---|
| 3140 | * Purpose : router function for WaitForMultipleObjectsEx
|
|---|
| 3141 | * Parameters:
|
|---|
| 3142 | * Variables :
|
|---|
| 3143 | * Result :
|
|---|
| 3144 | * Remark :
|
|---|
| 3145 | * Status :
|
|---|
| 3146 | *
|
|---|
| 3147 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 3148 | *****************************************************************************/
|
|---|
| 3149 |
|
|---|
| 3150 | DWORD HMWaitForMultipleObjectsEx (DWORD cObjects,
|
|---|
| 3151 | PHANDLE lphObjects,
|
|---|
| 3152 | BOOL fWaitAll,
|
|---|
| 3153 | DWORD dwTimeout,
|
|---|
| 3154 | BOOL fAlertable)
|
|---|
| 3155 | {
|
|---|
| 3156 | // @@@PH: Note: fAlertable is ignored !
|
|---|
| 3157 | return (HMWaitForMultipleObjects(cObjects,
|
|---|
| 3158 | lphObjects,
|
|---|
| 3159 | fWaitAll,
|
|---|
| 3160 | dwTimeout));
|
|---|
| 3161 | }
|
|---|
| 3162 |
|
|---|
| 3163 | /*****************************************************************************
|
|---|
| 3164 | * Name : HMMsgWaitForMultipleObjects
|
|---|
| 3165 | * Purpose : router function for MsgWaitForMultipleObjects
|
|---|
| 3166 | * Parameters:
|
|---|
| 3167 | * Variables :
|
|---|
| 3168 | * Result :
|
|---|
| 3169 | * Remark : Open32 doesn't implement this properly! (doesn't check dwWakeMask)
|
|---|
| 3170 | * Status :
|
|---|
| 3171 | *
|
|---|
| 3172 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 3173 | *****************************************************************************/
|
|---|
| 3174 |
|
|---|
| 3175 | DWORD HMMsgWaitForMultipleObjects (DWORD cObjects,
|
|---|
| 3176 | LPHANDLE lphObjects,
|
|---|
| 3177 | BOOL fWaitAll,
|
|---|
| 3178 | DWORD dwTimeout,
|
|---|
| 3179 | DWORD dwWakeMask)
|
|---|
| 3180 | {
|
|---|
| 3181 | #ifdef USE_OS2SEMAPHORES
|
|---|
| 3182 | int iIndex; /* index into the handle table */
|
|---|
| 3183 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 3184 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3185 |
|
|---|
| 3186 |
|
|---|
| 3187 | if(dwWakeMask == 0) {
|
|---|
| 3188 | dprintf(("WARNING: wakemask == 0 -> calling WaitForMultipleObjects"));
|
|---|
| 3189 | return HMWaitForMultipleObjects(cObjects, lphObjects, fWaitAll, dwTimeout);
|
|---|
| 3190 | }
|
|---|
| 3191 | /* validate handle */
|
|---|
| 3192 | iIndex = _HMHandleQuery(*lphObjects); /* get the index */
|
|---|
| 3193 | if (-1 == iIndex) /* error ? */
|
|---|
| 3194 | {//oh, oh. possible problem here
|
|---|
| 3195 | //TODO: rewrite handling of other handles; don't forward to open32
|
|---|
| 3196 | dprintf(("WANRING: HMWaitForMultipleObjects: unknown handle passed on to Open32 -> will not work if other handles are semaphores"));
|
|---|
| 3197 | return O32_MsgWaitForMultipleObjects(cObjects, lphObjects, fWaitAll, dwTimeout, dwWakeMask);
|
|---|
| 3198 | }
|
|---|
| 3199 |
|
|---|
| 3200 | if(cObjects > MAXIMUM_WAIT_OBJECTS) {
|
|---|
| 3201 | dprintf(("KERNEL32: HMMsgWaitForMultipleObjects: Too many objects (%d)", cObjects));
|
|---|
| 3202 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3203 | return WAIT_FAILED;
|
|---|
| 3204 | }
|
|---|
| 3205 |
|
|---|
| 3206 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3207 | dwResult = pHMHandle->pDeviceHandler->MsgWaitForMultipleObjects(&pHMHandle->hmHandleData,
|
|---|
| 3208 | cObjects, lphObjects, fWaitAll,
|
|---|
| 3209 | dwTimeout, dwWakeMask);
|
|---|
| 3210 |
|
|---|
| 3211 | return (dwResult); /* deliver return code */
|
|---|
| 3212 | #else
|
|---|
| 3213 | ULONG ulIndex;
|
|---|
| 3214 | PHANDLE pArrayOfHandles;
|
|---|
| 3215 | PHANDLE pLoop1 = lphObjects;
|
|---|
| 3216 | PHANDLE pLoop2;
|
|---|
| 3217 | DWORD rc;
|
|---|
| 3218 |
|
|---|
| 3219 | // allocate array for handle table
|
|---|
| 3220 | pArrayOfHandles = (PHANDLE)alloca(cObjects * sizeof(HANDLE));
|
|---|
| 3221 | if (pArrayOfHandles == NULL)
|
|---|
| 3222 | {
|
|---|
| 3223 | dprintf(("ERROR: HMMsgWaitForMultipleObjects: alloca failed to allocate %d handles", cObjects));
|
|---|
| 3224 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|---|
| 3225 | return WAIT_FAILED;
|
|---|
| 3226 | }
|
|---|
| 3227 | else
|
|---|
| 3228 | pLoop2 = pArrayOfHandles;
|
|---|
| 3229 |
|
|---|
| 3230 | // convert array to odin handles
|
|---|
| 3231 | for (ulIndex = 0;
|
|---|
| 3232 |
|
|---|
| 3233 | ulIndex < cObjects;
|
|---|
| 3234 |
|
|---|
| 3235 | ulIndex++,
|
|---|
| 3236 | pLoop1++,
|
|---|
| 3237 | pLoop2++)
|
|---|
| 3238 | {
|
|---|
| 3239 | rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
|
|---|
| 3240 | pLoop2);
|
|---|
| 3241 |
|
|---|
| 3242 | dprintf2(("MsgWaitForMultipleObjects handle %x->%x", *pLoop1, *pLoop2));
|
|---|
| 3243 | // SvL: We still use Open32 handles for threads & processes -> don't fail here!
|
|---|
| 3244 | if (rc != NO_ERROR)
|
|---|
| 3245 | {
|
|---|
| 3246 | dprintf(("KERNEL32: HMMsgWaitForMultipleObjects - WARNING: handle %08xh is NOT an Odin handle (probably Open32 thread or process)\n",
|
|---|
| 3247 | *pLoop1));
|
|---|
| 3248 |
|
|---|
| 3249 | *pLoop2 = *pLoop1;
|
|---|
| 3250 | //// SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 3251 | //// return (WAIT_FAILED);
|
|---|
| 3252 | }
|
|---|
| 3253 | }
|
|---|
| 3254 |
|
|---|
| 3255 | //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
|
|---|
| 3256 | //return too late if the thread priority isn't time critical (time slices
|
|---|
| 3257 | //of 32 ms)
|
|---|
| 3258 | //To avoid this problem, we temporarily switch to time critical priority.
|
|---|
| 3259 | HANDLE hThread = GetCurrentThread();
|
|---|
| 3260 | DWORD dwThreadPriority = GetThreadPriority(hThread);
|
|---|
| 3261 |
|
|---|
| 3262 | if(dwTimeout && dwTimeout < 20 && dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL) {
|
|---|
| 3263 | dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));
|
|---|
| 3264 | SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
|---|
| 3265 | //round to 8 ms units to get more precise timeouts
|
|---|
| 3266 | if(dwTimeout > 8)
|
|---|
| 3267 | dwTimeout = (dwTimeout/8)*8;
|
|---|
| 3268 | }
|
|---|
| 3269 | else dwThreadPriority = -1;
|
|---|
| 3270 |
|
|---|
| 3271 | // OK, now forward to Open32.
|
|---|
| 3272 | // @@@PH: Note this will fail on handles that do NOT belong to Open32
|
|---|
| 3273 | // but to i.e. the console subsystem!
|
|---|
| 3274 | rc = O32_MsgWaitForMultipleObjects(cObjects,
|
|---|
| 3275 | pArrayOfHandles,
|
|---|
| 3276 | fWaitAll, dwTimeout,
|
|---|
| 3277 | dwWakeMask);
|
|---|
| 3278 |
|
|---|
| 3279 | //Restore old thread priority if we changed it before
|
|---|
| 3280 | if(dwThreadPriority != -1) {
|
|---|
| 3281 | SetThreadPriority(hThread, dwThreadPriority);
|
|---|
| 3282 | }
|
|---|
| 3283 |
|
|---|
| 3284 | dprintf2(("MsgWaitForMultipleObjects returned %d", rc));
|
|---|
| 3285 | return (rc); // OK, done
|
|---|
| 3286 | #endif
|
|---|
| 3287 | }
|
|---|
| 3288 | /*****************************************************************************
|
|---|
| 3289 | * Name : HMDeviceIoControl
|
|---|
| 3290 | * Purpose : router function for DeviceIoControl
|
|---|
| 3291 | * Parameters:
|
|---|
| 3292 | * Variables :
|
|---|
| 3293 | * Result :
|
|---|
| 3294 | * Remark :
|
|---|
| 3295 | * Status :
|
|---|
| 3296 | *
|
|---|
| 3297 | * Author : Sander van Leeuwen
|
|---|
| 3298 | *****************************************************************************/
|
|---|
| 3299 |
|
|---|
| 3300 | BOOL HMDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
|
|---|
| 3301 | LPVOID lpInBuffer, DWORD nInBufferSize,
|
|---|
| 3302 | LPVOID lpOutBuffer, DWORD nOutBufferSize,
|
|---|
| 3303 | LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
|
|---|
| 3304 | {
|
|---|
| 3305 | int iIndex; /* index into the handle table */
|
|---|
| 3306 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 3307 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3308 |
|
|---|
| 3309 | /* validate handle */
|
|---|
| 3310 | iIndex = _HMHandleQuery(hDevice); /* get the index */
|
|---|
| 3311 | if (-1 == iIndex) /* error ? */
|
|---|
| 3312 | {
|
|---|
| 3313 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3314 | return (FALSE); /* signal failure */
|
|---|
| 3315 | }
|
|---|
| 3316 |
|
|---|
| 3317 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3318 | fResult = pHMHandle->pDeviceHandler->DeviceIoControl(&pHMHandle->hmHandleData,
|
|---|
| 3319 | dwIoControlCode,
|
|---|
| 3320 | lpInBuffer, nInBufferSize,
|
|---|
| 3321 | lpOutBuffer, nOutBufferSize,
|
|---|
| 3322 | lpBytesReturned, lpOverlapped);
|
|---|
| 3323 |
|
|---|
| 3324 | return (fResult); /* deliver return code */
|
|---|
| 3325 | }
|
|---|
| 3326 | /*****************************************************************************
|
|---|
| 3327 | * Name : HMCancelIo
|
|---|
| 3328 | * Purpose : router function for CancelIo
|
|---|
| 3329 | * Parameters:
|
|---|
| 3330 | * Variables :
|
|---|
| 3331 | * Result :
|
|---|
| 3332 | * Remark :
|
|---|
| 3333 | * Status :
|
|---|
| 3334 | *
|
|---|
| 3335 | * Author : Sander van Leeuwen
|
|---|
| 3336 | *****************************************************************************/
|
|---|
| 3337 | BOOL HMCancelIo(HANDLE hDevice)
|
|---|
| 3338 | {
|
|---|
| 3339 | int iIndex; /* index into the handle table */
|
|---|
| 3340 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 3341 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3342 |
|
|---|
| 3343 | /* validate handle */
|
|---|
| 3344 | iIndex = _HMHandleQuery(hDevice); /* get the index */
|
|---|
| 3345 | if (-1 == iIndex) /* error ? */
|
|---|
| 3346 | {
|
|---|
| 3347 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3348 | return (FALSE); /* signal failure */
|
|---|
| 3349 | }
|
|---|
| 3350 |
|
|---|
| 3351 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3352 | fResult = pHMHandle->pDeviceHandler->CancelIo(&pHMHandle->hmHandleData);
|
|---|
| 3353 |
|
|---|
| 3354 | return (fResult); /* deliver return code */
|
|---|
| 3355 | }
|
|---|
| 3356 | /*****************************************************************************
|
|---|
| 3357 | * Name : HMCOMGetCommState
|
|---|
| 3358 | * Purpose : router function for GetCommState
|
|---|
| 3359 | * Parameters:
|
|---|
| 3360 | * Variables :
|
|---|
| 3361 | * Result :
|
|---|
| 3362 | * Remark :
|
|---|
| 3363 | * Status :
|
|---|
| 3364 | *
|
|---|
| 3365 | * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40]
|
|---|
| 3366 | *****************************************************************************/
|
|---|
| 3367 |
|
|---|
| 3368 | BOOL HMCommGetCommState(HANDLE hCommDev, LPDCB lpdcb)
|
|---|
| 3369 | {
|
|---|
| 3370 | int iIndex; /* index into the handle table */
|
|---|
| 3371 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3372 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3373 |
|
|---|
| 3374 | /* validate handle */
|
|---|
| 3375 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3376 | if (-1 == iIndex) /* error ? */
|
|---|
| 3377 | {
|
|---|
| 3378 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3379 | return (NULL); /* signal failure */
|
|---|
| 3380 | }
|
|---|
| 3381 |
|
|---|
| 3382 | if(IsBadWritePtr(lpdcb,sizeof(DCB)))
|
|---|
| 3383 | {
|
|---|
| 3384 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3385 | return FALSE;
|
|---|
| 3386 | }
|
|---|
| 3387 |
|
|---|
| 3388 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3389 | bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData,
|
|---|
| 3390 | lpdcb);
|
|---|
| 3391 |
|
|---|
| 3392 | return (bResult); /* deliver return code */
|
|---|
| 3393 | }
|
|---|
| 3394 |
|
|---|
| 3395 | BOOL HMCommWaitCommEvent( HANDLE hCommDev,
|
|---|
| 3396 | LPDWORD lpfdwEvtMask,
|
|---|
| 3397 | LPOVERLAPPED lpo)
|
|---|
| 3398 | {
|
|---|
| 3399 | int iIndex; /* index into the handle table */
|
|---|
| 3400 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3401 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3402 |
|
|---|
| 3403 | /* validate handle */
|
|---|
| 3404 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3405 | if (-1 == iIndex) /* error ? */
|
|---|
| 3406 | {
|
|---|
| 3407 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3408 | return FALSE; /* signal failure */
|
|---|
| 3409 | }
|
|---|
| 3410 |
|
|---|
| 3411 | if(NULL!=lpo && IsBadReadPtr(lpo,sizeof(OVERLAPPED)) )
|
|---|
| 3412 | {
|
|---|
| 3413 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3414 | return FALSE;
|
|---|
| 3415 | }
|
|---|
| 3416 |
|
|---|
| 3417 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3418 | bResult = pHMHandle->pDeviceHandler->WaitCommEvent( &pHMHandle->hmHandleData,
|
|---|
| 3419 | lpfdwEvtMask,
|
|---|
| 3420 | lpo);
|
|---|
| 3421 |
|
|---|
| 3422 | return (bResult); /* deliver return code */
|
|---|
| 3423 | }
|
|---|
| 3424 |
|
|---|
| 3425 | BOOL HMCommGetCommProperties( HANDLE hCommDev,
|
|---|
| 3426 | LPCOMMPROP lpcmmp)
|
|---|
| 3427 | {
|
|---|
| 3428 | int iIndex; /* index into the handle table */
|
|---|
| 3429 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3430 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3431 |
|
|---|
| 3432 | /* validate handle */
|
|---|
| 3433 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3434 | if (-1 == iIndex) /* error ? */
|
|---|
| 3435 | {
|
|---|
| 3436 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3437 | return (NULL); /* signal failure */
|
|---|
| 3438 | }
|
|---|
| 3439 |
|
|---|
| 3440 | if(IsBadWritePtr(lpcmmp,sizeof(COMMPROP)) )
|
|---|
| 3441 | {
|
|---|
| 3442 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3443 | return FALSE;
|
|---|
| 3444 | }
|
|---|
| 3445 |
|
|---|
| 3446 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3447 | bResult = pHMHandle->pDeviceHandler->GetCommProperties( &pHMHandle->hmHandleData,
|
|---|
| 3448 | lpcmmp);
|
|---|
| 3449 |
|
|---|
| 3450 | return (bResult); /* deliver return code */
|
|---|
| 3451 | }
|
|---|
| 3452 |
|
|---|
| 3453 | BOOL HMCommGetCommMask( HANDLE hCommDev,
|
|---|
| 3454 | LPDWORD lpfdwEvtMask)
|
|---|
| 3455 | {
|
|---|
| 3456 | int iIndex; /* index into the handle table */
|
|---|
| 3457 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3458 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3459 |
|
|---|
| 3460 | /* validate handle */
|
|---|
| 3461 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3462 | if (-1 == iIndex) /* error ? */
|
|---|
| 3463 | {
|
|---|
| 3464 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3465 | return (NULL); /* signal failure */
|
|---|
| 3466 | }
|
|---|
| 3467 |
|
|---|
| 3468 | if(IsBadWritePtr(lpfdwEvtMask,sizeof(DWORD)) )
|
|---|
| 3469 | {
|
|---|
| 3470 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3471 | return FALSE;
|
|---|
| 3472 | }
|
|---|
| 3473 |
|
|---|
| 3474 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3475 | bResult = pHMHandle->pDeviceHandler->GetCommMask( &pHMHandle->hmHandleData,
|
|---|
| 3476 | lpfdwEvtMask);
|
|---|
| 3477 |
|
|---|
| 3478 | return (bResult); /* deliver return code */
|
|---|
| 3479 | }
|
|---|
| 3480 |
|
|---|
| 3481 | BOOL HMCommSetCommMask( HANDLE hCommDev,
|
|---|
| 3482 | DWORD fdwEvtMask)
|
|---|
| 3483 | {
|
|---|
| 3484 | int iIndex; /* index into the handle table */
|
|---|
| 3485 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3486 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3487 |
|
|---|
| 3488 | /* validate handle */
|
|---|
| 3489 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3490 | if (-1 == iIndex) /* error ? */
|
|---|
| 3491 | {
|
|---|
| 3492 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3493 | return (NULL); /* signal failure */
|
|---|
| 3494 | }
|
|---|
| 3495 |
|
|---|
| 3496 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3497 | bResult = pHMHandle->pDeviceHandler->SetCommMask( &pHMHandle->hmHandleData,
|
|---|
| 3498 | fdwEvtMask);
|
|---|
| 3499 |
|
|---|
| 3500 | return (bResult); /* deliver return code */
|
|---|
| 3501 | }
|
|---|
| 3502 |
|
|---|
| 3503 | BOOL HMCommPurgeComm( HANDLE hCommDev,
|
|---|
| 3504 | DWORD fdwAction)
|
|---|
| 3505 | {
|
|---|
| 3506 | int iIndex; /* index into the handle table */
|
|---|
| 3507 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3508 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3509 |
|
|---|
| 3510 | /* validate handle */
|
|---|
| 3511 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3512 | if (-1 == iIndex) /* error ? */
|
|---|
| 3513 | {
|
|---|
| 3514 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3515 | return (NULL); /* signal failure */
|
|---|
| 3516 | }
|
|---|
| 3517 |
|
|---|
| 3518 |
|
|---|
| 3519 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3520 | bResult = pHMHandle->pDeviceHandler->PurgeComm( &pHMHandle->hmHandleData,
|
|---|
| 3521 | fdwAction);
|
|---|
| 3522 |
|
|---|
| 3523 | return (bResult); /* deliver return code */
|
|---|
| 3524 | }
|
|---|
| 3525 |
|
|---|
| 3526 | BOOL HMCommClearCommError( HANDLE hCommDev,
|
|---|
| 3527 | LPDWORD lpdwErrors,
|
|---|
| 3528 | LPCOMSTAT lpcst)
|
|---|
| 3529 | {
|
|---|
| 3530 | int iIndex; /* index into the handle table */
|
|---|
| 3531 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3532 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3533 |
|
|---|
| 3534 | /* validate handle */
|
|---|
| 3535 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3536 | if (-1 == iIndex) /* error ? */
|
|---|
| 3537 | {
|
|---|
| 3538 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3539 | return (NULL); /* signal failure */
|
|---|
| 3540 | }
|
|---|
| 3541 |
|
|---|
| 3542 | if(IsBadWritePtr(lpdwErrors,sizeof(DWORD)) ||
|
|---|
| 3543 | (NULL!=lpcst && IsBadWritePtr(lpcst,sizeof(COMSTAT)) ) )
|
|---|
| 3544 | {
|
|---|
| 3545 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3546 | return FALSE;
|
|---|
| 3547 | }
|
|---|
| 3548 |
|
|---|
| 3549 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3550 | bResult = pHMHandle->pDeviceHandler->ClearCommError(&pHMHandle->hmHandleData,
|
|---|
| 3551 | lpdwErrors,
|
|---|
| 3552 | lpcst);
|
|---|
| 3553 |
|
|---|
| 3554 | return (bResult); /* deliver return code */
|
|---|
| 3555 | }
|
|---|
| 3556 |
|
|---|
| 3557 | BOOL HMCommSetCommState( HANDLE hCommDev,
|
|---|
| 3558 | LPDCB lpdcb)
|
|---|
| 3559 | {
|
|---|
| 3560 | int iIndex; /* index into the handle table */
|
|---|
| 3561 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3562 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3563 |
|
|---|
| 3564 | /* validate handle */
|
|---|
| 3565 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3566 | if (-1 == iIndex) /* error ? */
|
|---|
| 3567 | {
|
|---|
| 3568 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3569 | return (NULL); /* signal failure */
|
|---|
| 3570 | }
|
|---|
| 3571 |
|
|---|
| 3572 | if(IsBadReadPtr(lpdcb,sizeof(DCB)) )
|
|---|
| 3573 | {
|
|---|
| 3574 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3575 | return FALSE;
|
|---|
| 3576 | }
|
|---|
| 3577 |
|
|---|
| 3578 |
|
|---|
| 3579 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3580 | bResult = pHMHandle->pDeviceHandler->SetCommState(&pHMHandle->hmHandleData,
|
|---|
| 3581 | lpdcb);
|
|---|
| 3582 |
|
|---|
| 3583 | return (bResult); /* deliver return code */
|
|---|
| 3584 | }
|
|---|
| 3585 |
|
|---|
| 3586 |
|
|---|
| 3587 | BOOL HMCommGetCommTimeouts( HANDLE hCommDev,
|
|---|
| 3588 | LPCOMMTIMEOUTS lpctmo)
|
|---|
| 3589 | {
|
|---|
| 3590 | int iIndex; /* index into the handle table */
|
|---|
| 3591 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3592 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3593 |
|
|---|
| 3594 | /* validate handle */
|
|---|
| 3595 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3596 | if (-1 == iIndex) /* error ? */
|
|---|
| 3597 | {
|
|---|
| 3598 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3599 | return (NULL); /* signal failure */
|
|---|
| 3600 | }
|
|---|
| 3601 |
|
|---|
| 3602 | if(IsBadWritePtr(lpctmo,sizeof(COMMTIMEOUTS)) )
|
|---|
| 3603 | {
|
|---|
| 3604 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3605 | return FALSE;
|
|---|
| 3606 | }
|
|---|
| 3607 |
|
|---|
| 3608 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3609 | bResult = pHMHandle->pDeviceHandler->GetCommTimeouts( &pHMHandle->hmHandleData,
|
|---|
| 3610 | lpctmo);
|
|---|
| 3611 |
|
|---|
| 3612 | return (bResult); /* deliver return code */
|
|---|
| 3613 | }
|
|---|
| 3614 | BOOL HMCommGetCommModemStatus( HANDLE hCommDev,
|
|---|
| 3615 | LPDWORD lpModemStat )
|
|---|
| 3616 | {
|
|---|
| 3617 | int iIndex; /* index into the handle table */
|
|---|
| 3618 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3619 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3620 |
|
|---|
| 3621 | /* validate handle */
|
|---|
| 3622 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3623 | if (-1 == iIndex) /* error ? */
|
|---|
| 3624 | {
|
|---|
| 3625 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3626 | return (NULL); /* signal failure */
|
|---|
| 3627 | }
|
|---|
| 3628 |
|
|---|
| 3629 | if(IsBadWritePtr(lpModemStat,sizeof(DWORD)) )
|
|---|
| 3630 | {
|
|---|
| 3631 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3632 | return FALSE;
|
|---|
| 3633 | }
|
|---|
| 3634 |
|
|---|
| 3635 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3636 | bResult = pHMHandle->pDeviceHandler->GetCommModemStatus( &pHMHandle->hmHandleData,
|
|---|
| 3637 | lpModemStat);
|
|---|
| 3638 |
|
|---|
| 3639 | return (bResult); /* deliver return code */
|
|---|
| 3640 | }
|
|---|
| 3641 |
|
|---|
| 3642 | BOOL HMCommSetCommTimeouts( HANDLE hCommDev,
|
|---|
| 3643 | LPCOMMTIMEOUTS lpctmo)
|
|---|
| 3644 | {
|
|---|
| 3645 | int iIndex; /* index into the handle table */
|
|---|
| 3646 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3647 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3648 |
|
|---|
| 3649 | /* validate handle */
|
|---|
| 3650 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3651 | if (-1 == iIndex) /* error ? */
|
|---|
| 3652 | {
|
|---|
| 3653 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3654 | return (NULL); /* signal failure */
|
|---|
| 3655 | }
|
|---|
| 3656 |
|
|---|
| 3657 | if(IsBadReadPtr(lpctmo,sizeof(COMMTIMEOUTS)) )
|
|---|
| 3658 | {
|
|---|
| 3659 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3660 | return FALSE;
|
|---|
| 3661 | }
|
|---|
| 3662 |
|
|---|
| 3663 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3664 | bResult = pHMHandle->pDeviceHandler->SetCommTimeouts( &pHMHandle->hmHandleData,
|
|---|
| 3665 | lpctmo);
|
|---|
| 3666 |
|
|---|
| 3667 | return (bResult); /* deliver return code */
|
|---|
| 3668 | }
|
|---|
| 3669 |
|
|---|
| 3670 | BOOL HMCommTransmitCommChar( HANDLE hCommDev,
|
|---|
| 3671 | CHAR cChar )
|
|---|
| 3672 | {
|
|---|
| 3673 | int iIndex; /* index into the handle table */
|
|---|
| 3674 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3675 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3676 |
|
|---|
| 3677 | /* validate handle */
|
|---|
| 3678 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3679 | if (-1 == iIndex) /* error ? */
|
|---|
| 3680 | {
|
|---|
| 3681 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3682 | return (NULL); /* signal failure */
|
|---|
| 3683 | }
|
|---|
| 3684 |
|
|---|
| 3685 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3686 | bResult = pHMHandle->pDeviceHandler->TransmitCommChar( &pHMHandle->hmHandleData,
|
|---|
| 3687 | cChar);
|
|---|
| 3688 |
|
|---|
| 3689 | return (bResult); /* deliver return code */
|
|---|
| 3690 | }
|
|---|
| 3691 |
|
|---|
| 3692 | BOOL HMCommSetCommConfig( HANDLE hCommDev,
|
|---|
| 3693 | LPCOMMCONFIG lpCC,
|
|---|
| 3694 | DWORD dwSize )
|
|---|
| 3695 | {
|
|---|
| 3696 | int iIndex; /* index into the handle table */
|
|---|
| 3697 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3698 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3699 |
|
|---|
| 3700 | /* validate handle */
|
|---|
| 3701 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3702 | if (-1 == iIndex) /* error ? */
|
|---|
| 3703 | {
|
|---|
| 3704 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3705 | return (NULL); /* signal failure */
|
|---|
| 3706 | }
|
|---|
| 3707 |
|
|---|
| 3708 | if( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||
|
|---|
| 3709 | dwSize < sizeof(COMMCONFIG) )
|
|---|
| 3710 | {
|
|---|
| 3711 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3712 | return FALSE;
|
|---|
| 3713 | }
|
|---|
| 3714 |
|
|---|
| 3715 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3716 | bResult = pHMHandle->pDeviceHandler->SetCommConfig( &pHMHandle->hmHandleData,
|
|---|
| 3717 | lpCC,
|
|---|
| 3718 | dwSize);
|
|---|
| 3719 |
|
|---|
| 3720 | return (bResult); /* deliver return code */
|
|---|
| 3721 | }
|
|---|
| 3722 |
|
|---|
| 3723 | BOOL HMCommSetCommBreak( HANDLE hCommDev )
|
|---|
| 3724 | {
|
|---|
| 3725 | int iIndex; /* index into the handle table */
|
|---|
| 3726 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3727 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3728 |
|
|---|
| 3729 | /* validate handle */
|
|---|
| 3730 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3731 | if (-1 == iIndex) /* error ? */
|
|---|
| 3732 | {
|
|---|
| 3733 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3734 | return (NULL); /* signal failure */
|
|---|
| 3735 | }
|
|---|
| 3736 |
|
|---|
| 3737 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3738 | bResult = pHMHandle->pDeviceHandler->SetCommBreak( &pHMHandle->hmHandleData);
|
|---|
| 3739 |
|
|---|
| 3740 | return (bResult); /* deliver return code */
|
|---|
| 3741 | }
|
|---|
| 3742 |
|
|---|
| 3743 | BOOL HMCommGetCommConfig( HANDLE hCommDev,
|
|---|
| 3744 | LPCOMMCONFIG lpCC,
|
|---|
| 3745 | LPDWORD lpdwSize )
|
|---|
| 3746 | {
|
|---|
| 3747 | int iIndex; /* index into the handle table */
|
|---|
| 3748 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3749 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3750 |
|
|---|
| 3751 | /* validate handle */
|
|---|
| 3752 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3753 | if (-1 == iIndex) /* error ? */
|
|---|
| 3754 | {
|
|---|
| 3755 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3756 | return (NULL); /* signal failure */
|
|---|
| 3757 | }
|
|---|
| 3758 |
|
|---|
| 3759 | if(IsBadWritePtr(lpdwSize,sizeof(DWORD)) )
|
|---|
| 3760 | {
|
|---|
| 3761 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3762 | return FALSE;
|
|---|
| 3763 | }
|
|---|
| 3764 |
|
|---|
| 3765 | if( IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
|
|---|
| 3766 | *lpdwSize< sizeof(COMMCONFIG) )
|
|---|
| 3767 | {
|
|---|
| 3768 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|---|
| 3769 | *lpdwSize= sizeof(COMMCONFIG);
|
|---|
| 3770 | return FALSE;
|
|---|
| 3771 | }
|
|---|
| 3772 |
|
|---|
| 3773 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3774 | bResult = pHMHandle->pDeviceHandler->GetCommConfig( &pHMHandle->hmHandleData,
|
|---|
| 3775 | lpCC,
|
|---|
| 3776 | lpdwSize);
|
|---|
| 3777 |
|
|---|
| 3778 | return (bResult); /* deliver return code */
|
|---|
| 3779 | }
|
|---|
| 3780 |
|
|---|
| 3781 | BOOL HMCommEscapeCommFunction( HANDLE hCommDev,
|
|---|
| 3782 | UINT dwFunc )
|
|---|
| 3783 | {
|
|---|
| 3784 | int iIndex; /* index into the handle table */
|
|---|
| 3785 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3786 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3787 |
|
|---|
| 3788 | /* validate handle */
|
|---|
| 3789 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3790 | if (-1 == iIndex) /* error ? */
|
|---|
| 3791 | {
|
|---|
| 3792 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3793 | return (NULL); /* signal failure */
|
|---|
| 3794 | }
|
|---|
| 3795 |
|
|---|
| 3796 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3797 |
|
|---|
| 3798 | switch(dwFunc)
|
|---|
| 3799 | {
|
|---|
| 3800 | case CLRDTR:
|
|---|
| 3801 | case CLRRTS:
|
|---|
| 3802 | case SETDTR:
|
|---|
| 3803 | case SETRTS:
|
|---|
| 3804 | case SETXOFF:
|
|---|
| 3805 | case SETXON:
|
|---|
| 3806 | bResult = pHMHandle->pDeviceHandler->EscapeCommFunction( &pHMHandle->hmHandleData,
|
|---|
| 3807 | dwFunc);
|
|---|
| 3808 | break;
|
|---|
| 3809 | case SETBREAK:
|
|---|
| 3810 | bResult = pHMHandle->pDeviceHandler->SetCommBreak(&pHMHandle->hmHandleData);
|
|---|
| 3811 | break;
|
|---|
| 3812 | case CLRBREAK:
|
|---|
| 3813 | bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);
|
|---|
| 3814 | break;
|
|---|
| 3815 | default:
|
|---|
| 3816 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3817 | bResult = FALSE;
|
|---|
| 3818 | }
|
|---|
| 3819 |
|
|---|
| 3820 |
|
|---|
| 3821 | return (bResult); /* deliver return code */
|
|---|
| 3822 | }
|
|---|
| 3823 |
|
|---|
| 3824 | BOOL HMCommSetupComm( HANDLE hCommDev,
|
|---|
| 3825 | DWORD dwInQueue,
|
|---|
| 3826 | DWORD dwOutQueue)
|
|---|
| 3827 | {
|
|---|
| 3828 | int iIndex; /* index into the handle table */
|
|---|
| 3829 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3830 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3831 |
|
|---|
| 3832 | /* validate handle */
|
|---|
| 3833 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3834 | if (-1 == iIndex) /* error ? */
|
|---|
| 3835 | {
|
|---|
| 3836 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3837 | return (NULL); /* signal failure */
|
|---|
| 3838 | }
|
|---|
| 3839 |
|
|---|
| 3840 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3841 | bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,
|
|---|
| 3842 | dwInQueue,
|
|---|
| 3843 | dwOutQueue);
|
|---|
| 3844 |
|
|---|
| 3845 | return (bResult); /* deliver return code */
|
|---|
| 3846 | }
|
|---|
| 3847 |
|
|---|
| 3848 | BOOL HMCommClearCommBreak(HANDLE hCommDev)
|
|---|
| 3849 | {
|
|---|
| 3850 | int iIndex; /* index into the handle table */
|
|---|
| 3851 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3852 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3853 |
|
|---|
| 3854 | /* validate handle */
|
|---|
| 3855 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3856 | if (-1 == iIndex) /* error ? */
|
|---|
| 3857 | {
|
|---|
| 3858 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3859 | return (NULL); /* signal failure */
|
|---|
| 3860 | }
|
|---|
| 3861 |
|
|---|
| 3862 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3863 | bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);
|
|---|
| 3864 |
|
|---|
| 3865 | return (bResult); /* deliver return code */
|
|---|
| 3866 | }
|
|---|
| 3867 |
|
|---|
| 3868 | BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev,
|
|---|
| 3869 | LPCOMMCONFIG lpCC,
|
|---|
| 3870 | DWORD dwSize)
|
|---|
| 3871 | {
|
|---|
| 3872 | int iIndex; /* index into the handle table */
|
|---|
| 3873 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3874 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3875 |
|
|---|
| 3876 | /* validate handle */
|
|---|
| 3877 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3878 | if (-1 == iIndex) /* error ? */
|
|---|
| 3879 | {
|
|---|
| 3880 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3881 | return (NULL); /* signal failure */
|
|---|
| 3882 | }
|
|---|
| 3883 |
|
|---|
| 3884 | if( (lpCC!=NULL) &&
|
|---|
| 3885 | ( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||
|
|---|
| 3886 | dwSize != sizeof(COMMCONFIG) ) )
|
|---|
| 3887 | {
|
|---|
| 3888 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3889 | return FALSE;
|
|---|
| 3890 | }
|
|---|
| 3891 |
|
|---|
| 3892 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3893 | bResult = pHMHandle->pDeviceHandler->SetDefaultCommConfig(&pHMHandle->hmHandleData,
|
|---|
| 3894 | lpCC,
|
|---|
| 3895 | dwSize);
|
|---|
| 3896 |
|
|---|
| 3897 | return (bResult); /* deliver return code */
|
|---|
| 3898 | }
|
|---|
| 3899 |
|
|---|
| 3900 | BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev,
|
|---|
| 3901 | LPCOMMCONFIG lpCC,
|
|---|
| 3902 | LPDWORD lpdwSize)
|
|---|
| 3903 | {
|
|---|
| 3904 | int iIndex; /* index into the handle table */
|
|---|
| 3905 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 3906 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 3907 |
|
|---|
| 3908 | /* validate handle */
|
|---|
| 3909 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 3910 | if (-1 == iIndex) /* error ? */
|
|---|
| 3911 | {
|
|---|
| 3912 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 3913 | return (NULL); /* signal failure */
|
|---|
| 3914 | }
|
|---|
| 3915 |
|
|---|
| 3916 | if(IsBadWritePtr(lpdwSize,sizeof(DWORD)))
|
|---|
| 3917 | {
|
|---|
| 3918 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 3919 | return FALSE;
|
|---|
| 3920 | }
|
|---|
| 3921 |
|
|---|
| 3922 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 3923 | bResult = pHMHandle->pDeviceHandler->GetDefaultCommConfig( &pHMHandle->hmHandleData,
|
|---|
| 3924 | lpCC,
|
|---|
| 3925 | lpdwSize);
|
|---|
| 3926 |
|
|---|
| 3927 | return (bResult); /* deliver return code */
|
|---|
| 3928 | }
|
|---|
| 3929 |
|
|---|
| 3930 | /*****************************************************************************
|
|---|
| 3931 | * Name : HMOpenThreadToken
|
|---|
| 3932 | * Purpose : router function for NtOpenThreadToken
|
|---|
| 3933 | * Parameters:
|
|---|
| 3934 | * Variables :
|
|---|
| 3935 | * Result :
|
|---|
| 3936 | * Remark :
|
|---|
| 3937 | * Status :
|
|---|
| 3938 | *
|
|---|
| 3939 | * Author : SvL
|
|---|
| 3940 | *****************************************************************************/
|
|---|
| 3941 |
|
|---|
| 3942 | DWORD HMOpenThreadToken(HANDLE ThreadHandle,
|
|---|
| 3943 | DWORD DesiredAccess,
|
|---|
| 3944 | DWORD OpenAsSelf,
|
|---|
| 3945 | HANDLE *TokenHandle)
|
|---|
| 3946 | {
|
|---|
| 3947 | int iIndex; /* index into the handle table */
|
|---|
| 3948 | int iIndexNew; /* index into the handle table */
|
|---|
| 3949 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 3950 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 3951 | DWORD rc; /* API return code */
|
|---|
| 3952 |
|
|---|
| 3953 | pDeviceHandler = HMGlobals.pHMToken; /* device is predefined */
|
|---|
| 3954 |
|
|---|
| 3955 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 3956 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 3957 | {
|
|---|
| 3958 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 3959 | return ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 3960 | }
|
|---|
| 3961 |
|
|---|
| 3962 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 3963 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 3964 | pHMHandleData->dwAccess = DesiredAccess;
|
|---|
| 3965 | pHMHandleData->dwShare = 0;
|
|---|
| 3966 | pHMHandleData->dwCreation = 0;
|
|---|
| 3967 | pHMHandleData->dwFlags = 0;
|
|---|
| 3968 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 3969 |
|
|---|
| 3970 |
|
|---|
| 3971 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 3972 | /* could be created within the device handler -> deadlock */
|
|---|
| 3973 |
|
|---|
| 3974 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 3975 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 3976 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 3977 |
|
|---|
| 3978 | /* call the device handler */
|
|---|
| 3979 |
|
|---|
| 3980 | // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
|
|---|
| 3981 | // a valid HandleManager-internal handle!
|
|---|
| 3982 | rc = pDeviceHandler->OpenThreadToken(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 3983 | ThreadHandle,
|
|---|
| 3984 | OpenAsSelf);
|
|---|
| 3985 |
|
|---|
| 3986 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 3987 | {
|
|---|
| 3988 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 3989 | return (rc); /* signal error */
|
|---|
| 3990 | }
|
|---|
| 3991 | else
|
|---|
| 3992 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 3993 |
|
|---|
| 3994 | *TokenHandle = iIndexNew; /* return valid handle */
|
|---|
| 3995 | return STATUS_SUCCESS;
|
|---|
| 3996 | }
|
|---|
| 3997 |
|
|---|
| 3998 | /*****************************************************************************
|
|---|
| 3999 | * Name : HMOpenProcessToken
|
|---|
| 4000 | * Purpose : router function for NtOpenProcessToken
|
|---|
| 4001 | * Parameters:
|
|---|
| 4002 | * Variables :
|
|---|
| 4003 | * Result :
|
|---|
| 4004 | * Remark :
|
|---|
| 4005 | * Status :
|
|---|
| 4006 | *
|
|---|
| 4007 | * Author : SvL
|
|---|
| 4008 | *****************************************************************************/
|
|---|
| 4009 | DWORD HMOpenProcessToken(HANDLE ProcessHandle,
|
|---|
| 4010 | DWORD DesiredAccess,
|
|---|
| 4011 | DWORD dwUserData,
|
|---|
| 4012 | HANDLE *TokenHandle)
|
|---|
| 4013 | {
|
|---|
| 4014 | int iIndex; /* index into the handle table */
|
|---|
| 4015 | int iIndexNew; /* index into the handle table */
|
|---|
| 4016 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 4017 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 4018 | DWORD rc; /* API return code */
|
|---|
| 4019 |
|
|---|
| 4020 | pDeviceHandler = HMGlobals.pHMToken; /* device is predefined */
|
|---|
| 4021 |
|
|---|
| 4022 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 4023 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 4024 | {
|
|---|
| 4025 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 4026 | return ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 4027 | }
|
|---|
| 4028 |
|
|---|
| 4029 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 4030 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 4031 | pHMHandleData->dwAccess = DesiredAccess;
|
|---|
| 4032 | pHMHandleData->dwShare = 0;
|
|---|
| 4033 | pHMHandleData->dwCreation = 0;
|
|---|
| 4034 | pHMHandleData->dwFlags = 0;
|
|---|
| 4035 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 4036 |
|
|---|
| 4037 |
|
|---|
| 4038 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 4039 | /* could be created within the device handler -> deadlock */
|
|---|
| 4040 |
|
|---|
| 4041 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 4042 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 4043 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 4044 |
|
|---|
| 4045 | /* call the device handler */
|
|---|
| 4046 |
|
|---|
| 4047 | // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
|
|---|
| 4048 | // a valid HandleManager-internal handle!
|
|---|
| 4049 | rc = pDeviceHandler->OpenProcessToken(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 4050 | dwUserData,
|
|---|
| 4051 | ProcessHandle);
|
|---|
| 4052 |
|
|---|
| 4053 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 4054 | {
|
|---|
| 4055 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 4056 | return (rc); /* signal error */
|
|---|
| 4057 | }
|
|---|
| 4058 | else
|
|---|
| 4059 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 4060 |
|
|---|
| 4061 | *TokenHandle = iIndexNew; /* return valid handle */
|
|---|
| 4062 | return STATUS_SUCCESS;
|
|---|
| 4063 | }
|
|---|
| 4064 | /*****************************************************************************
|
|---|
| 4065 | * Name : HMCreateThread
|
|---|
| 4066 | * Purpose : router function for CreateThread
|
|---|
| 4067 | * Parameters:
|
|---|
| 4068 | * Variables :
|
|---|
| 4069 | * Result :
|
|---|
| 4070 | * Remark :
|
|---|
| 4071 | * Status :
|
|---|
| 4072 | *
|
|---|
| 4073 | * Author : SvL
|
|---|
| 4074 | *****************************************************************************/
|
|---|
| 4075 | HANDLE HMCreateThread(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 4076 | DWORD cbStack,
|
|---|
| 4077 | LPTHREAD_START_ROUTINE lpStartAddr,
|
|---|
| 4078 | LPVOID lpvThreadParm,
|
|---|
| 4079 | DWORD fdwCreate,
|
|---|
| 4080 | LPDWORD lpIDThread,
|
|---|
| 4081 | BOOL fFirstThread)
|
|---|
| 4082 | {
|
|---|
| 4083 | int iIndex; /* index into the handle table */
|
|---|
| 4084 | int iIndexNew; /* index into the handle table */
|
|---|
| 4085 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 4086 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 4087 | HANDLE rc; /* API return code */
|
|---|
| 4088 |
|
|---|
| 4089 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4090 |
|
|---|
| 4091 | pDeviceHandler = HMGlobals.pHMThread; /* device is predefined */
|
|---|
| 4092 |
|
|---|
| 4093 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 4094 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 4095 | {
|
|---|
| 4096 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 4097 | return 0;
|
|---|
| 4098 | }
|
|---|
| 4099 |
|
|---|
| 4100 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 4101 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 4102 | pHMHandleData->dwAccess = 0;
|
|---|
| 4103 | pHMHandleData->dwShare = 0;
|
|---|
| 4104 | pHMHandleData->dwCreation = 0;
|
|---|
| 4105 | pHMHandleData->dwFlags = 0;
|
|---|
| 4106 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 4107 |
|
|---|
| 4108 |
|
|---|
| 4109 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 4110 | /* could be created within the device handler -> deadlock */
|
|---|
| 4111 |
|
|---|
| 4112 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 4113 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 4114 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 4115 |
|
|---|
| 4116 | /* call the device handler */
|
|---|
| 4117 |
|
|---|
| 4118 | // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
|
|---|
| 4119 | // a valid HandleManager-internal handle!
|
|---|
| 4120 | rc = pDeviceHandler->CreateThread(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 4121 | lpsa, cbStack, lpStartAddr,
|
|---|
| 4122 | lpvThreadParm, fdwCreate, lpIDThread, fFirstThread);
|
|---|
| 4123 |
|
|---|
| 4124 | if (rc == 0) /* oops, creation failed within the device handler */
|
|---|
| 4125 | {
|
|---|
| 4126 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 4127 | return 0; /* signal error */
|
|---|
| 4128 | }
|
|---|
| 4129 |
|
|---|
| 4130 | return iIndexNew;
|
|---|
| 4131 | }
|
|---|
| 4132 | /*****************************************************************************
|
|---|
| 4133 | * Name : HMGetThreadPriority
|
|---|
| 4134 | * Purpose : router function for GetThreadPriority
|
|---|
| 4135 | * Parameters:
|
|---|
| 4136 | * Variables :
|
|---|
| 4137 | * Result :
|
|---|
| 4138 | * Remark :
|
|---|
| 4139 | * Status :
|
|---|
| 4140 | *
|
|---|
| 4141 | * Author : SvL
|
|---|
| 4142 | *****************************************************************************/
|
|---|
| 4143 | INT HMGetThreadPriority(HANDLE hThread)
|
|---|
| 4144 | {
|
|---|
| 4145 | int iIndex; /* index into the handle table */
|
|---|
| 4146 | INT lpResult; /* result from the device handler's API */
|
|---|
| 4147 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4148 |
|
|---|
| 4149 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4150 | /* validate handle */
|
|---|
| 4151 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4152 | if (-1 == iIndex) /* error ? */
|
|---|
| 4153 | {
|
|---|
| 4154 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4155 | return (-1); /* signal failure */
|
|---|
| 4156 | }
|
|---|
| 4157 |
|
|---|
| 4158 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4159 | lpResult = pHMHandle->pDeviceHandler->GetThreadPriority(hThread, &TabWin32Handles[iIndex].hmHandleData);
|
|---|
| 4160 |
|
|---|
| 4161 | return (lpResult); /* deliver return code */
|
|---|
| 4162 | }
|
|---|
| 4163 | /*****************************************************************************
|
|---|
| 4164 | * Name : HMSuspendThread
|
|---|
| 4165 | * Purpose : router function for SuspendThread
|
|---|
| 4166 | * Parameters:
|
|---|
| 4167 | * Variables :
|
|---|
| 4168 | * Result :
|
|---|
| 4169 | * Remark :
|
|---|
| 4170 | * Status :
|
|---|
| 4171 | *
|
|---|
| 4172 | * Author : SvL
|
|---|
| 4173 | *****************************************************************************/
|
|---|
| 4174 | DWORD HMSuspendThread(HANDLE hThread)
|
|---|
| 4175 | {
|
|---|
| 4176 | int iIndex; /* index into the handle table */
|
|---|
| 4177 | HANDLE lpResult; /* result from the device handler's API */
|
|---|
| 4178 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4179 |
|
|---|
| 4180 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4181 | /* validate handle */
|
|---|
| 4182 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4183 | if (-1 == iIndex) /* error ? */
|
|---|
| 4184 | {
|
|---|
| 4185 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4186 | return -1; /* signal failure */
|
|---|
| 4187 | }
|
|---|
| 4188 |
|
|---|
| 4189 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4190 | lpResult = pHMHandle->pDeviceHandler->SuspendThread(hThread, &TabWin32Handles[iIndex].hmHandleData);
|
|---|
| 4191 |
|
|---|
| 4192 | return (lpResult); /* deliver return code */
|
|---|
| 4193 | }
|
|---|
| 4194 | /*****************************************************************************
|
|---|
| 4195 | * Name : HMSetThreadPriority
|
|---|
| 4196 | * Purpose : router function for SetThreadPriority
|
|---|
| 4197 | * Parameters:
|
|---|
| 4198 | * Variables :
|
|---|
| 4199 | * Result :
|
|---|
| 4200 | * Remark :
|
|---|
| 4201 | * Status :
|
|---|
| 4202 | *
|
|---|
| 4203 | * Author : SvL
|
|---|
| 4204 | *****************************************************************************/
|
|---|
| 4205 | BOOL HMSetThreadPriority(HANDLE hThread, int priority)
|
|---|
| 4206 | {
|
|---|
| 4207 | int iIndex; /* index into the handle table */
|
|---|
| 4208 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4209 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4210 |
|
|---|
| 4211 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4212 | /* validate handle */
|
|---|
| 4213 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4214 | if (-1 == iIndex) /* error ? */
|
|---|
| 4215 | {
|
|---|
| 4216 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4217 | return FALSE; /* signal failure */
|
|---|
| 4218 | }
|
|---|
| 4219 |
|
|---|
| 4220 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4221 | lpResult = pHMHandle->pDeviceHandler->SetThreadPriority(hThread, &TabWin32Handles[iIndex].hmHandleData, priority);
|
|---|
| 4222 |
|
|---|
| 4223 | return (lpResult); /* deliver return code */
|
|---|
| 4224 | }
|
|---|
| 4225 | /*****************************************************************************
|
|---|
| 4226 | * Name : HMGetThreadContext
|
|---|
| 4227 | * Purpose : router function for GetThreadContext
|
|---|
| 4228 | * Parameters:
|
|---|
| 4229 | * Variables :
|
|---|
| 4230 | * Result :
|
|---|
| 4231 | * Remark :
|
|---|
| 4232 | * Status :
|
|---|
| 4233 | *
|
|---|
| 4234 | * Author : SvL
|
|---|
| 4235 | *****************************************************************************/
|
|---|
| 4236 | BOOL HMGetThreadContext(HANDLE hThread, CONTEXT *lpContext)
|
|---|
| 4237 | {
|
|---|
| 4238 | int iIndex; /* index into the handle table */
|
|---|
| 4239 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4240 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4241 |
|
|---|
| 4242 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4243 | /* validate handle */
|
|---|
| 4244 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4245 | if (-1 == iIndex) /* error ? */
|
|---|
| 4246 | {
|
|---|
| 4247 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4248 | return FALSE; /* signal failure */
|
|---|
| 4249 | }
|
|---|
| 4250 |
|
|---|
| 4251 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4252 | lpResult = pHMHandle->pDeviceHandler->GetThreadContext(hThread, &TabWin32Handles[iIndex].hmHandleData, lpContext);
|
|---|
| 4253 |
|
|---|
| 4254 | return (lpResult); /* deliver return code */
|
|---|
| 4255 | }
|
|---|
| 4256 | /*****************************************************************************
|
|---|
| 4257 | * Name : HMSetThreadContext
|
|---|
| 4258 | * Purpose : router function for SetThreadContext
|
|---|
| 4259 | * Parameters:
|
|---|
| 4260 | * Variables :
|
|---|
| 4261 | * Result :
|
|---|
| 4262 | * Remark :
|
|---|
| 4263 | * Status :
|
|---|
| 4264 | *
|
|---|
| 4265 | * Author : SvL
|
|---|
| 4266 | *****************************************************************************/
|
|---|
| 4267 | BOOL HMSetThreadContext(HANDLE hThread, const CONTEXT *lpContext)
|
|---|
| 4268 | {
|
|---|
| 4269 | int iIndex; /* index into the handle table */
|
|---|
| 4270 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4271 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4272 |
|
|---|
| 4273 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4274 | /* validate handle */
|
|---|
| 4275 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4276 | if (-1 == iIndex) /* error ? */
|
|---|
| 4277 | {
|
|---|
| 4278 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4279 | return FALSE; /* signal failure */
|
|---|
| 4280 | }
|
|---|
| 4281 |
|
|---|
| 4282 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4283 | lpResult = pHMHandle->pDeviceHandler->SetThreadContext(hThread, &TabWin32Handles[iIndex].hmHandleData, lpContext);
|
|---|
| 4284 |
|
|---|
| 4285 | return (lpResult); /* deliver return code */
|
|---|
| 4286 | }
|
|---|
| 4287 | /*****************************************************************************
|
|---|
| 4288 | * Name : HMGetThreadTimes
|
|---|
| 4289 | * Purpose : router function for HMGetThreadTimes
|
|---|
| 4290 | * Parameters:
|
|---|
| 4291 | * Variables :
|
|---|
| 4292 | * Result :
|
|---|
| 4293 | * Remark :
|
|---|
| 4294 | * Status :
|
|---|
| 4295 | *
|
|---|
| 4296 | * Author : SvL
|
|---|
| 4297 | *****************************************************************************/
|
|---|
| 4298 | BOOL HMGetThreadTimes(HANDLE hThread, LPFILETIME lpCreationTime,
|
|---|
| 4299 | LPFILETIME lpExitTime, LPFILETIME lpKernelTime,
|
|---|
| 4300 | LPFILETIME lpUserTime)
|
|---|
| 4301 | {
|
|---|
| 4302 | int iIndex; /* index into the handle table */
|
|---|
| 4303 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4304 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4305 |
|
|---|
| 4306 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4307 | /* validate handle */
|
|---|
| 4308 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4309 | if (-1 == iIndex) /* error ? */
|
|---|
| 4310 | {
|
|---|
| 4311 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4312 | return FALSE; /* signal failure */
|
|---|
| 4313 | }
|
|---|
| 4314 |
|
|---|
| 4315 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4316 | lpResult = pHMHandle->pDeviceHandler->GetThreadTimes(hThread, &TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4317 | lpCreationTime, lpExitTime,
|
|---|
| 4318 | lpKernelTime, lpUserTime);
|
|---|
| 4319 |
|
|---|
| 4320 | return (lpResult); /* deliver return code */
|
|---|
| 4321 | }
|
|---|
| 4322 | /*****************************************************************************
|
|---|
| 4323 | * Name : HMTerminateThread
|
|---|
| 4324 | * Purpose : router function for TerminateThread
|
|---|
| 4325 | * Parameters:
|
|---|
| 4326 | * Variables :
|
|---|
| 4327 | * Result :
|
|---|
| 4328 | * Remark :
|
|---|
| 4329 | * Status :
|
|---|
| 4330 | *
|
|---|
| 4331 | * Author : SvL
|
|---|
| 4332 | *****************************************************************************/
|
|---|
| 4333 | BOOL HMTerminateThread(HANDLE hThread, DWORD exitcode)
|
|---|
| 4334 | {
|
|---|
| 4335 | int iIndex; /* index into the handle table */
|
|---|
| 4336 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4337 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4338 |
|
|---|
| 4339 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4340 | /* validate handle */
|
|---|
| 4341 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4342 | if (-1 == iIndex) /* error ? */
|
|---|
| 4343 | {
|
|---|
| 4344 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4345 | return FALSE; /* signal failure */
|
|---|
| 4346 | }
|
|---|
| 4347 |
|
|---|
| 4348 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4349 | lpResult = pHMHandle->pDeviceHandler->TerminateThread(hThread, &TabWin32Handles[iIndex].hmHandleData, exitcode);
|
|---|
| 4350 |
|
|---|
| 4351 | return (lpResult); /* deliver return code */
|
|---|
| 4352 | }
|
|---|
| 4353 | /*****************************************************************************
|
|---|
| 4354 | * Name : HMResumeThread
|
|---|
| 4355 | * Purpose : router function for ResumeThread
|
|---|
| 4356 | * Parameters:
|
|---|
| 4357 | * Variables :
|
|---|
| 4358 | * Result :
|
|---|
| 4359 | * Remark :
|
|---|
| 4360 | * Status :
|
|---|
| 4361 | *
|
|---|
| 4362 | * Author : SvL
|
|---|
| 4363 | *****************************************************************************/
|
|---|
| 4364 | DWORD HMResumeThread(HANDLE hThread)
|
|---|
| 4365 | {
|
|---|
| 4366 | int iIndex; /* index into the handle table */
|
|---|
| 4367 | DWORD lpResult; /* result from the device handler's API */
|
|---|
| 4368 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4369 |
|
|---|
| 4370 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4371 | /* validate handle */
|
|---|
| 4372 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4373 | if (-1 == iIndex) /* error ? */
|
|---|
| 4374 | {
|
|---|
| 4375 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4376 | return -1; /* signal failure */
|
|---|
| 4377 | }
|
|---|
| 4378 |
|
|---|
| 4379 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4380 | lpResult = pHMHandle->pDeviceHandler->ResumeThread(hThread, &TabWin32Handles[iIndex].hmHandleData);
|
|---|
| 4381 |
|
|---|
| 4382 | return (lpResult); /* deliver return code */
|
|---|
| 4383 | }
|
|---|
| 4384 |
|
|---|
| 4385 | /*****************************************************************************
|
|---|
| 4386 | * Name : HMGetExitCodeThread
|
|---|
| 4387 | * Purpose : router function for GetExitCodeThread
|
|---|
| 4388 | * Parameters:
|
|---|
| 4389 | * Variables :
|
|---|
| 4390 | * Result :
|
|---|
| 4391 | * Remark :
|
|---|
| 4392 | * Status :
|
|---|
| 4393 | *
|
|---|
| 4394 | * Author : SvL
|
|---|
| 4395 | *****************************************************************************/
|
|---|
| 4396 | BOOL HMGetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode)
|
|---|
| 4397 | {
|
|---|
| 4398 | int iIndex; /* index into the handle table */
|
|---|
| 4399 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4400 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4401 |
|
|---|
| 4402 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4403 | /* validate handle */
|
|---|
| 4404 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4405 | if (-1 == iIndex) /* error ? */
|
|---|
| 4406 | {
|
|---|
| 4407 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4408 | return FALSE; /* signal failure */
|
|---|
| 4409 | }
|
|---|
| 4410 |
|
|---|
| 4411 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4412 | lpResult = pHMHandle->pDeviceHandler->GetExitCodeThread(hThread, &TabWin32Handles[iIndex].hmHandleData, lpExitCode);
|
|---|
| 4413 |
|
|---|
| 4414 | return (lpResult); /* deliver return code */
|
|---|
| 4415 | }
|
|---|
| 4416 | /*****************************************************************************
|
|---|
| 4417 | * Name : HMSetThreadTerminated
|
|---|
| 4418 | * Purpose :
|
|---|
| 4419 | * Parameters:
|
|---|
| 4420 | * Variables :
|
|---|
| 4421 | * Result :
|
|---|
| 4422 | * Remark :
|
|---|
| 4423 | * Status :
|
|---|
| 4424 | *
|
|---|
| 4425 | * Author : SvL
|
|---|
| 4426 | *****************************************************************************/
|
|---|
| 4427 | BOOL HMSetThreadTerminated(HANDLE hThread)
|
|---|
| 4428 | {
|
|---|
| 4429 | int iIndex; /* index into the handle table */
|
|---|
| 4430 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4431 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4432 |
|
|---|
| 4433 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4434 | /* validate handle */
|
|---|
| 4435 | iIndex = _HMHandleQuery(hThread); /* get the index */
|
|---|
| 4436 | if (-1 == iIndex) /* error ? */
|
|---|
| 4437 | {
|
|---|
| 4438 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4439 | return FALSE; /* signal failure */
|
|---|
| 4440 | }
|
|---|
| 4441 |
|
|---|
| 4442 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4443 | lpResult = pHMHandle->pDeviceHandler->SetThreadTerminated(hThread, &TabWin32Handles[iIndex].hmHandleData);
|
|---|
| 4444 |
|
|---|
| 4445 | return (lpResult); /* deliver return code */
|
|---|
| 4446 | }
|
|---|
| 4447 |
|
|---|
| 4448 | /*****************************************************************************
|
|---|
| 4449 | * Name : HMPeekNamedPipe
|
|---|
| 4450 | * Purpose :
|
|---|
| 4451 | * Parameters:
|
|---|
| 4452 | * Variables :
|
|---|
| 4453 | * Result :
|
|---|
| 4454 | * Remark :
|
|---|
| 4455 | * Status :
|
|---|
| 4456 | *
|
|---|
| 4457 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4458 | *****************************************************************************/
|
|---|
| 4459 | BOOL HMPeekNamedPipe(HANDLE hPipe,
|
|---|
| 4460 | LPVOID lpvBuffer,
|
|---|
| 4461 | DWORD cbBuffer,
|
|---|
| 4462 | LPDWORD lpcbRead,
|
|---|
| 4463 | LPDWORD lpcbAvail,
|
|---|
| 4464 | LPDWORD lpcbMessage)
|
|---|
| 4465 | {
|
|---|
| 4466 | int iIndex; /* index into the handle table */
|
|---|
| 4467 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4468 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4469 |
|
|---|
| 4470 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4471 | /* validate handle */
|
|---|
| 4472 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4473 | if (-1 == iIndex) /* error ? */
|
|---|
| 4474 | {
|
|---|
| 4475 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4476 | return FALSE; /* signal failure */
|
|---|
| 4477 | }
|
|---|
| 4478 |
|
|---|
| 4479 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4480 | lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4481 | lpvBuffer,
|
|---|
| 4482 | cbBuffer,
|
|---|
| 4483 | lpcbRead,
|
|---|
| 4484 | lpcbAvail,
|
|---|
| 4485 | lpcbMessage);
|
|---|
| 4486 |
|
|---|
| 4487 | return (lpResult); /* deliver return code */
|
|---|
| 4488 | }
|
|---|
| 4489 |
|
|---|
| 4490 | /*****************************************************************************
|
|---|
| 4491 | * Name : HMCreateNamedPipe
|
|---|
| 4492 | * Purpose :
|
|---|
| 4493 | * Parameters:
|
|---|
| 4494 | * Variables :
|
|---|
| 4495 | * Result :
|
|---|
| 4496 | * Remark :
|
|---|
| 4497 | * Status :
|
|---|
| 4498 | *
|
|---|
| 4499 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4500 | *****************************************************************************/
|
|---|
| 4501 | DWORD HMCreateNamedPipe(LPCTSTR lpName,
|
|---|
| 4502 | DWORD dwOpenMode,
|
|---|
| 4503 | DWORD dwPipeMode,
|
|---|
| 4504 | DWORD nMaxInstances,
|
|---|
| 4505 | DWORD nOutBufferSize,
|
|---|
| 4506 | DWORD nInBufferSize,
|
|---|
| 4507 | DWORD nDefaultTimeOut,
|
|---|
| 4508 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
|---|
| 4509 | {
|
|---|
| 4510 | int iIndex; /* index into the handle table */
|
|---|
| 4511 | int iIndexNew; /* index into the handle table */
|
|---|
| 4512 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 4513 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 4514 | HANDLE rc; /* API return code */
|
|---|
| 4515 |
|
|---|
| 4516 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4517 |
|
|---|
| 4518 | pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */
|
|---|
| 4519 |
|
|---|
| 4520 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 4521 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 4522 | {
|
|---|
| 4523 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 4524 | return 0;
|
|---|
| 4525 | }
|
|---|
| 4526 |
|
|---|
| 4527 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 4528 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 4529 | pHMHandleData->dwAccess = 0;
|
|---|
| 4530 | pHMHandleData->dwShare = 0;
|
|---|
| 4531 | pHMHandleData->dwCreation = 0;
|
|---|
| 4532 | pHMHandleData->dwFlags = 0;
|
|---|
| 4533 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 4534 |
|
|---|
| 4535 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 4536 | /* could be created within the device handler -> deadlock */
|
|---|
| 4537 |
|
|---|
| 4538 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 4539 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 4540 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 4541 |
|
|---|
| 4542 | /* call the device handler */
|
|---|
| 4543 |
|
|---|
| 4544 | rc = pDeviceHandler->CreateNamedPipe(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 4545 | lpName,dwOpenMode,
|
|---|
| 4546 | dwPipeMode,nMaxInstances,
|
|---|
| 4547 | nOutBufferSize,nInBufferSize,
|
|---|
| 4548 | nDefaultTimeOut,lpSecurityAttributes);
|
|---|
| 4549 |
|
|---|
| 4550 | if (rc == -1) /* oops, creation failed within the device handler */
|
|---|
| 4551 | {
|
|---|
| 4552 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 4553 | return 0; /* signal error */
|
|---|
| 4554 | }
|
|---|
| 4555 |
|
|---|
| 4556 | dprintf(("Named pipe %x", iIndexNew));
|
|---|
| 4557 | if(lpSecurityAttributes && lpSecurityAttributes->bInheritHandle) {
|
|---|
| 4558 | dprintf(("Set inheritance for child processes"));
|
|---|
| 4559 | HMSetHandleInformation(iIndexNew, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
|---|
| 4560 | }
|
|---|
| 4561 |
|
|---|
| 4562 | return iIndexNew;
|
|---|
| 4563 | }
|
|---|
| 4564 |
|
|---|
| 4565 | /*****************************************************************************
|
|---|
| 4566 | * Name : HMConnectNamedPipe
|
|---|
| 4567 | * Purpose :
|
|---|
| 4568 | * Parameters:
|
|---|
| 4569 | * Variables :
|
|---|
| 4570 | * Result :
|
|---|
| 4571 | * Remark :
|
|---|
| 4572 | * Status :
|
|---|
| 4573 | *
|
|---|
| 4574 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4575 | *****************************************************************************/
|
|---|
| 4576 | BOOL HMConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED lpOverlapped)
|
|---|
| 4577 | {
|
|---|
| 4578 | int iIndex; /* index into the handle table */
|
|---|
| 4579 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4580 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4581 |
|
|---|
| 4582 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4583 | /* validate handle */
|
|---|
| 4584 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4585 | if (-1 == iIndex) /* error ? */
|
|---|
| 4586 | {
|
|---|
| 4587 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4588 | return FALSE; /* signal failure */
|
|---|
| 4589 | }
|
|---|
| 4590 |
|
|---|
| 4591 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4592 | lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4593 | lpOverlapped);
|
|---|
| 4594 |
|
|---|
| 4595 | return (lpResult); /* deliver return code */
|
|---|
| 4596 | }
|
|---|
| 4597 |
|
|---|
| 4598 | /*****************************************************************************
|
|---|
| 4599 | * Name : HMDisconnectNamedPipe
|
|---|
| 4600 | * Purpose :
|
|---|
| 4601 | * Parameters:
|
|---|
| 4602 | * Variables :
|
|---|
| 4603 | * Result :
|
|---|
| 4604 | * Remark :
|
|---|
| 4605 | * Status :
|
|---|
| 4606 | *
|
|---|
| 4607 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4608 | *****************************************************************************/
|
|---|
| 4609 | BOOL HMDisconnectNamedPipe(HANDLE hPipe)
|
|---|
| 4610 | {
|
|---|
| 4611 | int iIndex; /* index into the handle table */
|
|---|
| 4612 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4613 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4614 |
|
|---|
| 4615 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4616 | /* validate handle */
|
|---|
| 4617 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4618 | if (-1 == iIndex) /* error ? */
|
|---|
| 4619 | {
|
|---|
| 4620 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4621 | return FALSE; /* signal failure */
|
|---|
| 4622 | }
|
|---|
| 4623 |
|
|---|
| 4624 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4625 | lpResult = pHMHandle->pDeviceHandler->DisconnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData);
|
|---|
| 4626 |
|
|---|
| 4627 | return (lpResult); /* deliver return code */
|
|---|
| 4628 | }
|
|---|
| 4629 |
|
|---|
| 4630 | /*****************************************************************************
|
|---|
| 4631 | * Name : HMGetNamedPipeHandleState
|
|---|
| 4632 | * Purpose :
|
|---|
| 4633 | * Parameters:
|
|---|
| 4634 | * Variables :
|
|---|
| 4635 | * Result :
|
|---|
| 4636 | * Remark :
|
|---|
| 4637 | * Status :
|
|---|
| 4638 | *
|
|---|
| 4639 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4640 | *****************************************************************************/
|
|---|
| 4641 | BOOL HMGetNamedPipeHandleState(HANDLE hPipe,
|
|---|
| 4642 | LPDWORD lpState,
|
|---|
| 4643 | LPDWORD lpCurInstances,
|
|---|
| 4644 | LPDWORD lpMaxCollectionCount,
|
|---|
| 4645 | LPDWORD lpCollectDataTimeout,
|
|---|
| 4646 | LPTSTR lpUserName,
|
|---|
| 4647 | DWORD nMaxUserNameSize)
|
|---|
| 4648 | {
|
|---|
| 4649 | int iIndex; /* index into the handle table */
|
|---|
| 4650 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4651 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4652 |
|
|---|
| 4653 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4654 | /* validate handle */
|
|---|
| 4655 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4656 | if (-1 == iIndex) /* error ? */
|
|---|
| 4657 | {
|
|---|
| 4658 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4659 | return FALSE; /* signal failure */
|
|---|
| 4660 | }
|
|---|
| 4661 |
|
|---|
| 4662 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4663 | lpResult = pHMHandle->pDeviceHandler->GetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4664 | lpState,
|
|---|
| 4665 | lpCurInstances,
|
|---|
| 4666 | lpMaxCollectionCount,
|
|---|
| 4667 | lpCollectDataTimeout,
|
|---|
| 4668 | lpUserName,
|
|---|
| 4669 | nMaxUserNameSize);
|
|---|
| 4670 |
|
|---|
| 4671 |
|
|---|
| 4672 | return (lpResult); /* deliver return code */
|
|---|
| 4673 | }
|
|---|
| 4674 |
|
|---|
| 4675 | /*****************************************************************************
|
|---|
| 4676 | * Name : HMGetNamedPipeInfo
|
|---|
| 4677 | * Purpose :
|
|---|
| 4678 | * Parameters:
|
|---|
| 4679 | * Variables :
|
|---|
| 4680 | * Result :
|
|---|
| 4681 | * Remark :
|
|---|
| 4682 | * Status :
|
|---|
| 4683 | *
|
|---|
| 4684 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4685 | *****************************************************************************/
|
|---|
| 4686 | BOOL HMGetNamedPipeInfo(HANDLE hPipe,
|
|---|
| 4687 | LPDWORD lpFlags,
|
|---|
| 4688 | LPDWORD lpOutBufferSize,
|
|---|
| 4689 | LPDWORD lpInBufferSize,
|
|---|
| 4690 | LPDWORD lpMaxInstances)
|
|---|
| 4691 | {
|
|---|
| 4692 | int iIndex; /* index into the handle table */
|
|---|
| 4693 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4694 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4695 |
|
|---|
| 4696 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4697 | /* validate handle */
|
|---|
| 4698 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4699 | if (-1 == iIndex) /* error ? */
|
|---|
| 4700 | {
|
|---|
| 4701 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4702 | return FALSE; /* signal failure */
|
|---|
| 4703 | }
|
|---|
| 4704 |
|
|---|
| 4705 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4706 | lpResult = pHMHandle->pDeviceHandler->GetNamedPipeInfo(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4707 | lpFlags,
|
|---|
| 4708 | lpOutBufferSize,
|
|---|
| 4709 | lpInBufferSize,
|
|---|
| 4710 | lpMaxInstances);
|
|---|
| 4711 |
|
|---|
| 4712 | return (lpResult); /* deliver return code */
|
|---|
| 4713 | }
|
|---|
| 4714 |
|
|---|
| 4715 | /*****************************************************************************
|
|---|
| 4716 | * Name : HMTransactNamedPipe
|
|---|
| 4717 | * Purpose :
|
|---|
| 4718 | * Parameters:
|
|---|
| 4719 | * Variables :
|
|---|
| 4720 | * Result :
|
|---|
| 4721 | * Remark :
|
|---|
| 4722 | * Status :
|
|---|
| 4723 | *
|
|---|
| 4724 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4725 | *****************************************************************************/
|
|---|
| 4726 | DWORD HMTransactNamedPipe(HANDLE hPipe,
|
|---|
| 4727 | LPVOID lpvWriteBuf,
|
|---|
| 4728 | DWORD cbWriteBuf,
|
|---|
| 4729 | LPVOID lpvReadBuf,
|
|---|
| 4730 | DWORD cbReadBuf,
|
|---|
| 4731 | LPDWORD lpcbRead,
|
|---|
| 4732 | LPOVERLAPPED lpo)
|
|---|
| 4733 | {
|
|---|
| 4734 | int iIndex; /* index into the handle table */
|
|---|
| 4735 | DWORD lpResult; /* result from the device handler's API */
|
|---|
| 4736 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4737 |
|
|---|
| 4738 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4739 | /* validate handle */
|
|---|
| 4740 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4741 | if (-1 == iIndex) /* error ? */
|
|---|
| 4742 | {
|
|---|
| 4743 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4744 | return FALSE; /* signal failure */
|
|---|
| 4745 | }
|
|---|
| 4746 |
|
|---|
| 4747 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4748 | lpResult = pHMHandle->pDeviceHandler->TransactNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4749 | lpvWriteBuf,
|
|---|
| 4750 | cbWriteBuf,
|
|---|
| 4751 | lpvReadBuf,
|
|---|
| 4752 | cbReadBuf,
|
|---|
| 4753 | lpcbRead,
|
|---|
| 4754 | lpo);
|
|---|
| 4755 |
|
|---|
| 4756 | return (lpResult); /* deliver return code */
|
|---|
| 4757 | }
|
|---|
| 4758 |
|
|---|
| 4759 | /*****************************************************************************
|
|---|
| 4760 | * Name : HMSetNamedPipeHandleState
|
|---|
| 4761 | * Purpose :
|
|---|
| 4762 | * Parameters:
|
|---|
| 4763 | * Variables :
|
|---|
| 4764 | * Result :
|
|---|
| 4765 | * Remark :
|
|---|
| 4766 | * Status :
|
|---|
| 4767 | *
|
|---|
| 4768 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4769 | *****************************************************************************/
|
|---|
| 4770 | BOOL HMSetNamedPipeHandleState(HANDLE hPipe,
|
|---|
| 4771 | LPDWORD lpdwMode,
|
|---|
| 4772 | LPDWORD lpcbMaxCollect,
|
|---|
| 4773 | LPDWORD lpdwCollectDataTimeout)
|
|---|
| 4774 | {
|
|---|
| 4775 | int iIndex; /* index into the handle table */
|
|---|
| 4776 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4777 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4778 |
|
|---|
| 4779 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4780 | /* validate handle */
|
|---|
| 4781 | iIndex = _HMHandleQuery(hPipe); /* get the index */
|
|---|
| 4782 | if (-1 == iIndex) /* error ? */
|
|---|
| 4783 | {
|
|---|
| 4784 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4785 | return FALSE; /* signal failure */
|
|---|
| 4786 | }
|
|---|
| 4787 |
|
|---|
| 4788 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4789 | lpResult = pHMHandle->pDeviceHandler->SetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4790 | lpdwMode,
|
|---|
| 4791 | lpcbMaxCollect,
|
|---|
| 4792 | lpdwCollectDataTimeout);
|
|---|
| 4793 |
|
|---|
| 4794 | return (lpResult); /* deliver return code */
|
|---|
| 4795 | }
|
|---|
| 4796 |
|
|---|
| 4797 | /*****************************************************************************
|
|---|
| 4798 | * Name : HMCreatePipe
|
|---|
| 4799 | * Purpose :
|
|---|
| 4800 | * Parameters:
|
|---|
| 4801 | * Variables :
|
|---|
| 4802 | * Result :
|
|---|
| 4803 | * Remark :
|
|---|
| 4804 | * Status : NOT TESTED!
|
|---|
| 4805 | *
|
|---|
| 4806 | * Author : Przemyslaw Dobrowolski
|
|---|
| 4807 | *****************************************************************************/
|
|---|
| 4808 | BOOL HMCreatePipe(PHANDLE phRead,
|
|---|
| 4809 | PHANDLE phWrite,
|
|---|
| 4810 | LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 4811 | DWORD cbPipe)
|
|---|
| 4812 | {
|
|---|
| 4813 | int iIndex; /* index into the handle table */
|
|---|
| 4814 | int iIndexNewRead; /* index into the handle table */
|
|---|
| 4815 | int iIndexNewWrite; /* index into the handle table */
|
|---|
| 4816 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 4817 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 4818 | HANDLE rc; /* API return code */
|
|---|
| 4819 |
|
|---|
| 4820 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4821 |
|
|---|
| 4822 | pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */
|
|---|
| 4823 |
|
|---|
| 4824 | iIndexNewRead = _HMHandleGetFree(); /* get free handle */
|
|---|
| 4825 | if (-1 == iIndexNewRead) /* oops, no free handles ! */
|
|---|
| 4826 | {
|
|---|
| 4827 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 4828 | return 0;
|
|---|
| 4829 | }
|
|---|
| 4830 |
|
|---|
| 4831 | iIndexNewWrite = _HMHandleGetFree(); /* get free handle */
|
|---|
| 4832 | if (-1 == iIndexNewWrite) /* oops, no free handles ! */
|
|---|
| 4833 | {
|
|---|
| 4834 | HMHandleFree(iIndexNewRead);
|
|---|
| 4835 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 4836 | return 0;
|
|---|
| 4837 | }
|
|---|
| 4838 |
|
|---|
| 4839 |
|
|---|
| 4840 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 4841 | pHMHandleData = &TabWin32Handles[iIndexNewRead].hmHandleData;
|
|---|
| 4842 | pHMHandleData->dwAccess = 0;
|
|---|
| 4843 | pHMHandleData->dwShare = 0;
|
|---|
| 4844 | pHMHandleData->dwCreation = 0;
|
|---|
| 4845 | pHMHandleData->dwFlags = 0;
|
|---|
| 4846 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 4847 |
|
|---|
| 4848 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 4849 | /* could be created within the device handler -> deadlock */
|
|---|
| 4850 |
|
|---|
| 4851 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 4852 | TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = iIndexNewRead;
|
|---|
| 4853 | TabWin32Handles[iIndexNewRead].pDeviceHandler = pDeviceHandler;
|
|---|
| 4854 |
|
|---|
| 4855 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 4856 | pHMHandleData = &TabWin32Handles[iIndexNewWrite].hmHandleData;
|
|---|
| 4857 | pHMHandleData->dwAccess = 0;
|
|---|
| 4858 | pHMHandleData->dwShare = 0;
|
|---|
| 4859 | pHMHandleData->dwCreation = 0;
|
|---|
| 4860 | pHMHandleData->dwFlags = 0;
|
|---|
| 4861 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 4862 |
|
|---|
| 4863 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 4864 | /* could be created within the device handler -> deadlock */
|
|---|
| 4865 |
|
|---|
| 4866 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 4867 | TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = iIndexNewWrite;
|
|---|
| 4868 | TabWin32Handles[iIndexNewWrite].pDeviceHandler = pDeviceHandler;
|
|---|
| 4869 | /* call the device handler */
|
|---|
| 4870 |
|
|---|
| 4871 | rc = pDeviceHandler->CreatePipe(&TabWin32Handles[iIndexNewRead].hmHandleData,
|
|---|
| 4872 | &TabWin32Handles[iIndexNewWrite].hmHandleData,
|
|---|
| 4873 | lpsa,
|
|---|
| 4874 | cbPipe);
|
|---|
| 4875 |
|
|---|
| 4876 | if (rc == 0) /* oops, creation failed within the device handler */
|
|---|
| 4877 | {
|
|---|
| 4878 | HMHandleFree(iIndexNewRead);
|
|---|
| 4879 | HMHandleFree(iIndexNewWrite);
|
|---|
| 4880 | return FALSE; /* signal error */
|
|---|
| 4881 | }
|
|---|
| 4882 |
|
|---|
| 4883 | dprintf(("Read pipe %x, Write pipe %x", iIndexNewRead, iIndexNewWrite));
|
|---|
| 4884 | if(lpsa && lpsa->bInheritHandle) {
|
|---|
| 4885 | dprintf(("Set inheritance for child processes"));
|
|---|
| 4886 | HMSetHandleInformation(iIndexNewRead, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
|---|
| 4887 | HMSetHandleInformation(iIndexNewWrite, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
|---|
| 4888 | }
|
|---|
| 4889 |
|
|---|
| 4890 | *phRead = iIndexNewRead;
|
|---|
| 4891 | *phWrite = iIndexNewWrite;
|
|---|
| 4892 |
|
|---|
| 4893 | return TRUE;
|
|---|
| 4894 | }
|
|---|
| 4895 |
|
|---|
| 4896 | /*****************************************************************************
|
|---|
| 4897 | * Name : HMCreateMailslotA
|
|---|
| 4898 | * Purpose :
|
|---|
| 4899 | * Parameters:
|
|---|
| 4900 | * Variables :
|
|---|
| 4901 | * Result :
|
|---|
| 4902 | * Remark :
|
|---|
| 4903 | * Status :
|
|---|
| 4904 | *
|
|---|
| 4905 | * Author : SvL
|
|---|
| 4906 | *****************************************************************************/
|
|---|
| 4907 | HANDLE HMCreateMailslotA(LPCSTR lpName, DWORD nMaxMessageSize,
|
|---|
| 4908 | DWORD lReadTimeout,
|
|---|
| 4909 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
|---|
| 4910 | {
|
|---|
| 4911 | int iIndex; /* index into the handle table */
|
|---|
| 4912 | int iIndexNew; /* index into the handle table */
|
|---|
| 4913 | HMMailslotClass *pDeviceHandler; /* device handler for this handle */
|
|---|
| 4914 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 4915 | BOOL rc; /* API return code */
|
|---|
| 4916 |
|
|---|
| 4917 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4918 |
|
|---|
| 4919 | pDeviceHandler = (HMMailslotClass *)HMGlobals.pHMMailslot; /* device is predefined */
|
|---|
| 4920 |
|
|---|
| 4921 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 4922 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 4923 | {
|
|---|
| 4924 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 4925 | return 0;
|
|---|
| 4926 | }
|
|---|
| 4927 |
|
|---|
| 4928 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 4929 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 4930 | pHMHandleData->dwAccess = 0;
|
|---|
| 4931 | pHMHandleData->dwShare = 0;
|
|---|
| 4932 | pHMHandleData->dwCreation = 0;
|
|---|
| 4933 | pHMHandleData->dwFlags = 0;
|
|---|
| 4934 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 4935 |
|
|---|
| 4936 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 4937 | /* could be created within the device handler -> deadlock */
|
|---|
| 4938 |
|
|---|
| 4939 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 4940 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 4941 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 4942 |
|
|---|
| 4943 | /* call the device handler */
|
|---|
| 4944 |
|
|---|
| 4945 | rc = pDeviceHandler->CreateMailslotA(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 4946 | lpName, nMaxMessageSize,
|
|---|
| 4947 | lReadTimeout, lpSecurityAttributes);
|
|---|
| 4948 |
|
|---|
| 4949 | if (rc == FALSE) /* oops, creation failed within the device handler */
|
|---|
| 4950 | {
|
|---|
| 4951 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 4952 | return 0; /* signal error */
|
|---|
| 4953 | }
|
|---|
| 4954 |
|
|---|
| 4955 | return iIndexNew;
|
|---|
| 4956 | }
|
|---|
| 4957 | /*****************************************************************************
|
|---|
| 4958 | * Name : HMGetMailslotInfo
|
|---|
| 4959 | * Purpose :
|
|---|
| 4960 | * Parameters:
|
|---|
| 4961 | * Variables :
|
|---|
| 4962 | * Result :
|
|---|
| 4963 | * Remark :
|
|---|
| 4964 | * Status :
|
|---|
| 4965 | *
|
|---|
| 4966 | * Author : SvL
|
|---|
| 4967 | *****************************************************************************/
|
|---|
| 4968 | BOOL HMGetMailslotInfo(HANDLE hMailslot,
|
|---|
| 4969 | LPDWORD lpMaxMessageSize,
|
|---|
| 4970 | LPDWORD lpNextSize,
|
|---|
| 4971 | LPDWORD lpMessageCount,
|
|---|
| 4972 | LPDWORD lpReadTimeout)
|
|---|
| 4973 | {
|
|---|
| 4974 | int iIndex; /* index into the handle table */
|
|---|
| 4975 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 4976 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 4977 |
|
|---|
| 4978 | SetLastError(ERROR_SUCCESS);
|
|---|
| 4979 | /* validate handle */
|
|---|
| 4980 | iIndex = _HMHandleQuery(hMailslot); /* get the index */
|
|---|
| 4981 | if (-1 == iIndex) /* error ? */
|
|---|
| 4982 | {
|
|---|
| 4983 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 4984 | return FALSE; /* signal failure */
|
|---|
| 4985 | }
|
|---|
| 4986 |
|
|---|
| 4987 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 4988 | lpResult = pHMHandle->pDeviceHandler->GetMailslotInfo(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 4989 | lpMaxMessageSize,
|
|---|
| 4990 | lpNextSize,
|
|---|
| 4991 | lpMessageCount,
|
|---|
| 4992 | lpReadTimeout);
|
|---|
| 4993 | return (lpResult); /* deliver return code */
|
|---|
| 4994 | }
|
|---|
| 4995 | /*****************************************************************************
|
|---|
| 4996 | * Name : HMSetMailslotInfo
|
|---|
| 4997 | * Purpose :
|
|---|
| 4998 | * Parameters:
|
|---|
| 4999 | * Variables :
|
|---|
| 5000 | * Result :
|
|---|
| 5001 | * Remark :
|
|---|
| 5002 | * Status :
|
|---|
| 5003 | *
|
|---|
| 5004 | * Author : SvL
|
|---|
| 5005 | *****************************************************************************/
|
|---|
| 5006 | BOOL HMSetMailslotInfo(HANDLE hMailslot,
|
|---|
| 5007 | DWORD dwReadTimeout)
|
|---|
| 5008 | {
|
|---|
| 5009 | int iIndex; /* index into the handle table */
|
|---|
| 5010 | BOOL lpResult; /* result from the device handler's API */
|
|---|
| 5011 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 5012 |
|
|---|
| 5013 | SetLastError(ERROR_SUCCESS);
|
|---|
| 5014 | /* validate handle */
|
|---|
| 5015 | iIndex = _HMHandleQuery(hMailslot); /* get the index */
|
|---|
| 5016 | if (-1 == iIndex) /* error ? */
|
|---|
| 5017 | {
|
|---|
| 5018 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 5019 | return FALSE; /* signal failure */
|
|---|
| 5020 | }
|
|---|
| 5021 |
|
|---|
| 5022 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 5023 | lpResult = pHMHandle->pDeviceHandler->SetMailslotInfo(&TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 5024 | dwReadTimeout);
|
|---|
| 5025 |
|
|---|
| 5026 | return (lpResult); /* deliver return code */
|
|---|
| 5027 | }
|
|---|