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