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