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