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