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