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