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