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