| 1 | /* $Id: HandleManager.cpp,v 1.28 1999-11-27 12:48:25 achimha Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 Unified Handle Manager for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * 1998/02/11 PH Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 7 | *
|
|---|
| 8 | * @(#) HandleManager.Cpp 1.0.0 1998/02/11 PH start
|
|---|
| 9 | *
|
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 11 | *
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #undef DEBUG_LOCAL
|
|---|
| 15 | //#define DEBUG_LOCAL
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | /*****************************************************************************
|
|---|
| 19 | * Remark *
|
|---|
| 20 | *****************************************************************************
|
|---|
| 21 |
|
|---|
| 22 | 1998/02/11 PH Even overlapped I/O could be simulated by another subsystem
|
|---|
| 23 | thread with a request queue. We'll see if required ...
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | Flush (flush handle buffer)
|
|---|
| 27 | WaitForSingleObject
|
|---|
| 28 | WaitForMultipleObjects (?)
|
|---|
| 29 |
|
|---|
| 30 | 1998/02/12 PH IBM and Microsoft disagree about the definition of FILE_TYPE_xxx
|
|---|
| 31 | Interesting, Open32 returns Microsoft's values ...
|
|---|
| 32 |
|
|---|
| 33 | 1998/02/12 PH Handles should be equipped with a locking mechanism, in particular
|
|---|
| 34 | as we publish a pointer into the handle table via HMHandleQueryHandleData
|
|---|
| 35 |
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | /*****************************************************************************
|
|---|
| 40 | * Includes *
|
|---|
| 41 | *****************************************************************************/
|
|---|
| 42 |
|
|---|
| 43 | #include <os2win.h>
|
|---|
| 44 | #include <stdlib.h>
|
|---|
| 45 | #include <string.h>
|
|---|
| 46 |
|
|---|
| 47 | #include "unicode.h"
|
|---|
| 48 | #include "misc.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "HandleManager.H"
|
|---|
| 51 | #include "HMDevice.h"
|
|---|
| 52 | #include "HMOpen32.h"
|
|---|
| 53 | #include "HMEvent.h"
|
|---|
| 54 | #include "HMMutex.h"
|
|---|
| 55 | #include "HMSemaphore.h"
|
|---|
| 56 | #include "HMMMap.h"
|
|---|
| 57 | #include "HMComm.h"
|
|---|
| 58 | #include <winconst.h>
|
|---|
| 59 |
|
|---|
| 60 | /*****************************************************************************
|
|---|
| 61 | * Defines *
|
|---|
| 62 | *****************************************************************************/
|
|---|
| 63 |
|
|---|
| 64 | /* this is the size of our currently static handle table */
|
|---|
| 65 | #define MAX_OS2_HMHANDLES 2048
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | /*****************************************************************************
|
|---|
| 69 | * Structures *
|
|---|
| 70 | *****************************************************************************/
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | typedef struct _HMHANDLE
|
|---|
| 74 | {
|
|---|
| 75 | HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */
|
|---|
| 76 | HMHANDLEDATA hmHandleData; /* attributes of the handle */
|
|---|
| 77 | } HMHANDLE, *PHMHANDLE;
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | typedef struct _HMDEVICE
|
|---|
| 81 | {
|
|---|
| 82 | struct _HMDEVICE *pNext; /* pointer to next device in chain */
|
|---|
| 83 |
|
|---|
| 84 | LPSTR pszDeviceName; /* name or alias of the pseudo-device */
|
|---|
| 85 | HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */
|
|---|
| 86 | } HMDEVICE, *PHMDEVICE;
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | /*****************************************************************************
|
|---|
| 90 | * This pseudo-device logs all device requests to the logfile and returns *
|
|---|
| 91 | * ERROR_INVALID_FUNCTION to virtually all requests -> debugging *
|
|---|
| 92 | *****************************************************************************/
|
|---|
| 93 | class HMDeviceDebugClass : public HMDeviceHandler
|
|---|
| 94 | {
|
|---|
| 95 | public:
|
|---|
| 96 | HMDeviceDebugClass(LPCSTR lpDeviceName) : HMDeviceHandler(lpDeviceName) {}
|
|---|
| 97 | };
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /*****************************************************************************
|
|---|
| 101 | * Process Global Structures *
|
|---|
| 102 | *****************************************************************************/
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | /* the device name is repeated here to enable device alias names */
|
|---|
| 106 | static PHMDEVICE TabWin32Devices = NULL;
|
|---|
| 107 | static HMHANDLE TabWin32Handles[MAX_OS2_HMHANDLES]; /* static handle table */
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | struct _HMGlobals
|
|---|
| 111 | {
|
|---|
| 112 | HANDLE hStandardIn; /* stdin handle to CONIN$ */
|
|---|
| 113 | HANDLE hStandardOut; /* stdout handle to CONOUT$ */
|
|---|
| 114 | HANDLE hStandardError; /* stderr handle to CONOUT$ */
|
|---|
| 115 |
|
|---|
| 116 | BOOL fIsInitialized; /* if HM is initialized already ? */
|
|---|
| 117 | /* this MUST !!! be false initially */
|
|---|
| 118 |
|
|---|
| 119 | HMDeviceHandler *pHMOpen32; /* default handle manager instance */
|
|---|
| 120 | HMDeviceHandler *pHMEvent; /* static instances of subsystems */
|
|---|
| 121 | HMDeviceHandler *pHMMutex;
|
|---|
| 122 | HMDeviceHandler *pHMSemaphore;
|
|---|
| 123 | HMDeviceHandler *pHMFileMapping; /* static instances of subsystems */
|
|---|
| 124 | HMDeviceHandler *pHMComm; /* serial communication */
|
|---|
| 125 |
|
|---|
| 126 | ULONG ulHandleLast; /* index of last used handle */
|
|---|
| 127 | } HMGlobals;
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | /*****************************************************************************
|
|---|
| 131 | * Local Prototypes *
|
|---|
| 132 | *****************************************************************************/
|
|---|
| 133 |
|
|---|
| 134 | /* get appropriate device handler by the device name */
|
|---|
| 135 | static HMDeviceHandler* _Optlink _HMDeviceFind(LPSTR pszDeviceName);
|
|---|
| 136 |
|
|---|
| 137 | /* get next free handle from the handle table */
|
|---|
| 138 | static ULONG _Optlink _HMHandleGetFree(void);
|
|---|
| 139 |
|
|---|
| 140 | /* get handle table entry from handle */
|
|---|
| 141 | static ULONG _Optlink _HMHandleQuery(HANDLE hHandle);
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | /*****************************************************************************
|
|---|
| 146 | * Name : static HMDeviceHandler * _HMDeviceFind
|
|---|
| 147 | * Purpose : obtain appropriate device handler from the table by searching
|
|---|
| 148 | * for a device name or alias
|
|---|
| 149 | * Parameters: PSZ pszDeviceName
|
|---|
| 150 | * Variables :
|
|---|
| 151 | * Result : HMDeviceHandler * - pointer to the handler object
|
|---|
| 152 | * Remark :
|
|---|
| 153 | * Status :
|
|---|
| 154 | *
|
|---|
| 155 | * Author : Patrick Haller [Wed, 1998/02/11 20:42]
|
|---|
| 156 | *****************************************************************************/
|
|---|
| 157 |
|
|---|
| 158 | static HMDeviceHandler *_HMDeviceFind (LPSTR pszDeviceName)
|
|---|
| 159 | {
|
|---|
| 160 | PHMDEVICE pHMDevice; /* iterator over the device table */
|
|---|
| 161 |
|
|---|
| 162 | if (pszDeviceName != NULL)
|
|---|
| 163 | for (pHMDevice = TabWin32Devices; /* loop over all devices in the table */
|
|---|
| 164 | pHMDevice != NULL;
|
|---|
| 165 | pHMDevice = pHMDevice->pNext)
|
|---|
| 166 | {
|
|---|
| 167 | if (stricmp(pHMDevice->pszDeviceName, /* case-insensitive search */
|
|---|
| 168 | pszDeviceName) == 0)
|
|---|
| 169 | return (pHMDevice->pDeviceHandler); /* OK, we've found our device */
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | return (HMGlobals.pHMOpen32); /* haven't found anything, return default */
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 | /*****************************************************************************
|
|---|
| 177 | * Name : static int _HMHandleGetFree
|
|---|
| 178 | * Purpose : get index to first free handle in the handle table
|
|---|
| 179 | * Parameters:
|
|---|
| 180 | * Variables :
|
|---|
| 181 | * Result : int iIndex - index to the table or -1 in case of error
|
|---|
| 182 | * Remark :
|
|---|
| 183 | * Status :
|
|---|
| 184 | *
|
|---|
| 185 | * Author : Patrick Haller [Wed, 1998/02/11 20:43]
|
|---|
| 186 | *****************************************************************************/
|
|---|
| 187 |
|
|---|
| 188 | static ULONG _HMHandleGetFree(void)
|
|---|
| 189 | {
|
|---|
| 190 | register ULONG ulLoop;
|
|---|
| 191 |
|
|---|
| 192 | for (ulLoop = 1; // @@@PH Note, this is an experimental change
|
|---|
| 193 | // 0L as hHandle is sometimes considered invalid!
|
|---|
| 194 | // this will never return 0l as free handle now.
|
|---|
| 195 | ulLoop < MAX_OS2_HMHANDLES;
|
|---|
| 196 | ulLoop++)
|
|---|
| 197 | {
|
|---|
| 198 | /* free handle found ? */
|
|---|
| 199 | if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) {
|
|---|
| 200 | TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0;
|
|---|
| 201 | TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
|
|---|
| 202 | return (ulLoop); /* OK, then return it to the caller */
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | return (INVALID_HANDLE_VALUE); /* haven't found any free handle */
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | /*****************************************************************************
|
|---|
| 211 | * Name : static int _HMHandleQuery
|
|---|
| 212 | * Purpose : gets the index of handle table entry as fast as possible from
|
|---|
| 213 | * the specified handle
|
|---|
| 214 | * Parameters: HANDLE hHandle
|
|---|
| 215 | * Variables :
|
|---|
| 216 | * Result : index or -1 in case of error
|
|---|
| 217 | * Remark :
|
|---|
| 218 | * Status :
|
|---|
| 219 | *
|
|---|
| 220 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 221 | *****************************************************************************/
|
|---|
| 222 |
|
|---|
| 223 | static ULONG _HMHandleQuery(HANDLE hHandle)
|
|---|
| 224 | {
|
|---|
| 225 | if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */
|
|---|
| 226 | return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */
|
|---|
| 227 |
|
|---|
| 228 | /* Oops, invalid handle ! */
|
|---|
| 229 | if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
|
|---|
| 230 | return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */
|
|---|
| 231 |
|
|---|
| 232 | return ( hHandle); /* OK, we've got our handle index */
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 | /*****************************************************************************
|
|---|
| 237 | * Name : DWORD HMDeviceRegister
|
|---|
| 238 | * Purpose : register a device with the handle manager
|
|---|
| 239 | * Parameters: PSZ pszDeviceName
|
|---|
| 240 | * HMDeviceHandler *pDeviceHandler
|
|---|
| 241 | * Variables :
|
|---|
| 242 | * Result : API returncode
|
|---|
| 243 | * Remark :
|
|---|
| 244 | * Status :
|
|---|
| 245 | *
|
|---|
| 246 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 247 | *****************************************************************************/
|
|---|
| 248 |
|
|---|
| 249 | DWORD HMDeviceRegister(LPSTR pszDeviceName,
|
|---|
| 250 | HMDeviceHandler *pDeviceHandler)
|
|---|
| 251 | {
|
|---|
| 252 | PHMDEVICE pHMDevice; /* our new device to be allocated */
|
|---|
| 253 |
|
|---|
| 254 | if ( (pszDeviceName == NULL) || /* check parameters */
|
|---|
| 255 | (pDeviceHandler == NULL) )
|
|---|
| 256 | return (ERROR_INVALID_PARAMETER); /* raise error conditon */
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 | pHMDevice = (PHMDEVICE) malloc (sizeof (HMDEVICE) ); /* allocate memory */
|
|---|
| 260 | if (pHMDevice == NULL) /* check proper allocation */
|
|---|
| 261 | return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */
|
|---|
| 262 |
|
|---|
| 263 | pHMDevice->pszDeviceName = strdup(pszDeviceName); /* copy name */
|
|---|
| 264 | if (pHMDevice->pszDeviceName == NULL) /* check proper allocation */
|
|---|
| 265 | {
|
|---|
| 266 | free (pHMDevice); /* free previously allocated memory */
|
|---|
| 267 | return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | pHMDevice->pDeviceHandler = pDeviceHandler; /* store pointer to device */
|
|---|
| 271 | pHMDevice->pNext = TabWin32Devices; /* establish linkage */
|
|---|
| 272 |
|
|---|
| 273 | TabWin32Devices = pHMDevice; /* insert new node as root in the list */
|
|---|
| 274 |
|
|---|
| 275 | return (NO_ERROR);
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 | /*****************************************************************************
|
|---|
| 280 | * Name : DWORD HMInitialize
|
|---|
| 281 | * Purpose : Initialize the handlemanager
|
|---|
| 282 | * Parameters: -
|
|---|
| 283 | * Variables : -
|
|---|
| 284 | * Result : always NO_ERROR
|
|---|
| 285 | * Remark : this routine just stores the standard handles in the
|
|---|
| 286 | * internal table within the HandleManager
|
|---|
| 287 | * Status :
|
|---|
| 288 | *
|
|---|
| 289 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 290 | *****************************************************************************/
|
|---|
| 291 |
|
|---|
| 292 | DWORD HMInitialize(void)
|
|---|
| 293 | {
|
|---|
| 294 | ULONG ulIndex;
|
|---|
| 295 |
|
|---|
| 296 | if (HMGlobals.fIsInitialized != TRUE)
|
|---|
| 297 | {
|
|---|
| 298 | HMGlobals.fIsInitialized = TRUE; /* OK, done */
|
|---|
| 299 |
|
|---|
| 300 | // fill handle table
|
|---|
| 301 | for (ulIndex = 0;
|
|---|
| 302 | ulIndex < MAX_OS2_HMHANDLES;
|
|---|
| 303 | ulIndex++)
|
|---|
| 304 | TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 305 |
|
|---|
| 306 | dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n"));
|
|---|
| 307 |
|
|---|
| 308 | memset(&HMGlobals, /* zero out the structure first */
|
|---|
| 309 | 0,
|
|---|
| 310 | sizeof(HMGlobals));
|
|---|
| 311 |
|
|---|
| 312 | /* copy standard handles from OS/2's Open32 Subsystem */
|
|---|
| 313 | HMSetStdHandle(STD_INPUT_HANDLE, GetStdHandle(STD_INPUT_HANDLE));
|
|---|
| 314 | HMSetStdHandle(STD_OUTPUT_HANDLE, GetStdHandle(STD_OUTPUT_HANDLE));
|
|---|
| 315 | HMSetStdHandle(STD_ERROR_HANDLE, GetStdHandle(STD_ERROR_HANDLE));
|
|---|
| 316 |
|
|---|
| 317 | /* create handle manager instance for Open32 handles */
|
|---|
| 318 | HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\");
|
|---|
| 319 | HMGlobals.pHMEvent = new HMDeviceEventClass("\\\\EVENT\\");
|
|---|
| 320 | HMGlobals.pHMMutex = new HMDeviceMutexClass("\\\\MUTEX\\");
|
|---|
| 321 | HMGlobals.pHMSemaphore = new HMDeviceSemaphoreClass("\\\\SEM\\");
|
|---|
| 322 | HMGlobals.pHMFileMapping= new HMDeviceMemMapClass("\\\\MEMMAP\\");
|
|---|
| 323 | HMGlobals.pHMComm = new HMDeviceCommClass("\\\\COM\\");
|
|---|
| 324 | }
|
|---|
| 325 | return (NO_ERROR);
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 | /*****************************************************************************
|
|---|
| 330 | * Name : DWORD HMTerminate
|
|---|
| 331 | * Purpose : Terminate the handlemanager
|
|---|
| 332 | * Parameters:
|
|---|
| 333 | * Variables :
|
|---|
| 334 | * Result :
|
|---|
| 335 | * Remark :
|
|---|
| 336 | * Status :
|
|---|
| 337 | *
|
|---|
| 338 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 339 | *****************************************************************************/
|
|---|
| 340 |
|
|---|
| 341 | DWORD HMTerminate(void)
|
|---|
| 342 | {
|
|---|
| 343 | /* @@@PH we could deallocate the device list here */
|
|---|
| 344 |
|
|---|
| 345 | delete HMGlobals.pHMOpen32;
|
|---|
| 346 | delete HMGlobals.pHMEvent;
|
|---|
| 347 | delete HMGlobals.pHMMutex;
|
|---|
| 348 | delete HMGlobals.pHMSemaphore;
|
|---|
| 349 | delete HMGlobals.pHMFileMapping;
|
|---|
| 350 | delete HMGlobals.pHMComm;
|
|---|
| 351 |
|
|---|
| 352 | return (NO_ERROR);
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 | /*****************************************************************************/
|
|---|
| 357 | /* handle translation buffer management */
|
|---|
| 358 | /* */
|
|---|
| 359 | /* Since some Win32 applications rely (!) on 16-bit handles, we've got to do */
|
|---|
| 360 | /* 32-bit to 16-bit and vs vsa translation here. */
|
|---|
| 361 | /* Filehandle-based functions should be routed via the handlemanager instead */
|
|---|
| 362 | /* of going to Open32 directly. */
|
|---|
| 363 | /*****************************************************************************/
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 | /*****************************************************************************
|
|---|
| 367 | * Name : DWORD HMHandleAllocate
|
|---|
| 368 | * Purpose : allocate a handle in the translation table
|
|---|
| 369 | * Parameters: PULONG pHandle16 - to return the allocated handle
|
|---|
| 370 | * ULONG hHandle32 - the associated OS/2 handle
|
|---|
| 371 | * Variables :
|
|---|
| 372 | * Result : API returncode
|
|---|
| 373 | * Remark : no parameter checking is done, phHandle may not be invalid
|
|---|
| 374 | * hHandle32 shouldn't be 0
|
|---|
| 375 | * Should be protected with a HM-Mutex !
|
|---|
| 376 | * Status :
|
|---|
| 377 | *
|
|---|
| 378 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 379 | *****************************************************************************/
|
|---|
| 380 |
|
|---|
| 381 | DWORD HMHandleAllocate (PULONG phHandle16,
|
|---|
| 382 | ULONG hHandleOS2)
|
|---|
| 383 | {
|
|---|
| 384 | register ULONG ulHandle;
|
|---|
| 385 |
|
|---|
| 386 | #ifdef DEBUG_LOCAL
|
|---|
| 387 | dprintf(("KERNEL32: HMHandleAllocate (%08xh,%08xh)\n",
|
|---|
| 388 | phHandle16,
|
|---|
| 389 | hHandleOS2));
|
|---|
| 390 | #endif
|
|---|
| 391 |
|
|---|
| 392 | ulHandle = HMGlobals.ulHandleLast; /* get free handle */
|
|---|
| 393 |
|
|---|
| 394 | do
|
|---|
| 395 | {
|
|---|
| 396 | /* check if handle is free */
|
|---|
| 397 | if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
|
|---|
| 398 | {
|
|---|
| 399 | *phHandle16 = ulHandle;
|
|---|
| 400 | TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2;
|
|---|
| 401 | HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */
|
|---|
| 402 |
|
|---|
| 403 | return (NO_ERROR); /* OK */
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | ulHandle++; /* skip to next entry */
|
|---|
| 407 |
|
|---|
| 408 | if (ulHandle >= MAX_OS2_HMHANDLES) /* check boundary */
|
|---|
| 409 | ulHandle = 1;
|
|---|
| 410 | }
|
|---|
| 411 | while (ulHandle != HMGlobals.ulHandleLast);
|
|---|
| 412 |
|
|---|
| 413 | return (ERROR_TOO_MANY_OPEN_FILES); /* OK, we're done */
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 | /*****************************************************************************
|
|---|
| 418 | * Name : DWORD HMHandleFree
|
|---|
| 419 | * Purpose : free a handle from the translation table
|
|---|
| 420 | * Parameters: ULONG hHandle16 - the handle to be freed
|
|---|
| 421 | * Variables :
|
|---|
| 422 | * Result : API returncode
|
|---|
| 423 | * Remark : no parameter checking is done, hHandle16 MAY NEVER exceed
|
|---|
| 424 | * the MAX_TRANSLATION_HANDLES boundary
|
|---|
| 425 | * Status :
|
|---|
| 426 | *
|
|---|
| 427 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 428 | *****************************************************************************/
|
|---|
| 429 |
|
|---|
| 430 | DWORD HMHandleFree (ULONG hHandle16)
|
|---|
| 431 | {
|
|---|
| 432 | ULONG rc; /* API returncode */
|
|---|
| 433 |
|
|---|
| 434 | #ifdef DEBUG_LOCAL
|
|---|
| 435 | dprintf(("KERNEL32: HMHandleFree (%08xh)\n",
|
|---|
| 436 | hHandle16));
|
|---|
| 437 | #endif
|
|---|
| 438 |
|
|---|
| 439 | rc = HMHandleValidate(hHandle16); /* verify handle */
|
|---|
| 440 | if (rc != NO_ERROR) /* check errors */
|
|---|
| 441 | return (rc); /* raise error condition */
|
|---|
| 442 |
|
|---|
| 443 | TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 444 | /* OK, done */
|
|---|
| 445 |
|
|---|
| 446 | return (NO_ERROR);
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 | /*****************************************************************************
|
|---|
| 451 | * Name : DWORD HMHandleValidate
|
|---|
| 452 | * Purpose : validate a handle through the translation table
|
|---|
| 453 | * Parameters: ULONG hHandle16 - the handle to be verified
|
|---|
| 454 | * Variables :
|
|---|
| 455 | * Result : API returncode
|
|---|
| 456 | * Remark :
|
|---|
| 457 | * Status :
|
|---|
| 458 | *
|
|---|
| 459 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 460 | *****************************************************************************/
|
|---|
| 461 |
|
|---|
| 462 | DWORD HMHandleValidate (ULONG hHandle16)
|
|---|
| 463 | {
|
|---|
| 464 | #ifdef DEBUG_LOCAL
|
|---|
| 465 | dprintf(("KERNEL32: HMHandleValidate (%08xh)\n",
|
|---|
| 466 | hHandle16));
|
|---|
| 467 | #endif
|
|---|
| 468 |
|
|---|
| 469 | if (hHandle16 >= MAX_OS2_HMHANDLES) /* check boundary */
|
|---|
| 470 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 471 |
|
|---|
| 472 | if (TabWin32Handles[hHandle16].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
|
|---|
| 473 | /* valid ? */
|
|---|
| 474 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 475 |
|
|---|
| 476 | return (NO_ERROR);
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 | /*****************************************************************************
|
|---|
| 481 | * Name : DWORD HMHandleTranslateToWin
|
|---|
| 482 | * Purpose : translate a 32-bit OS/2 handle to the associated windows handle
|
|---|
| 483 | * Parameters: ULONG hHandle32 - the OS/2 handle
|
|---|
| 484 | * PULONG phHandle16 - the associated windows handle
|
|---|
| 485 | * Variables :
|
|---|
| 486 | * Result : API returncode
|
|---|
| 487 | * Remark :
|
|---|
| 488 | * Status :
|
|---|
| 489 | *
|
|---|
| 490 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 491 | *****************************************************************************/
|
|---|
| 492 |
|
|---|
| 493 | DWORD HMHandleTranslateToWin (ULONG hHandleOS2,
|
|---|
| 494 | PULONG phHandle16)
|
|---|
| 495 | {
|
|---|
| 496 | ULONG rc; /* API returncode */
|
|---|
| 497 | register ULONG ulIndex; /* index counter over the table */
|
|---|
| 498 |
|
|---|
| 499 | #ifdef DEBUG_LOCAL
|
|---|
| 500 | dprintf(("KERNEL32: HMHandleTranslateToWin (%08xh, %08xh)\n",
|
|---|
| 501 | hHandleOS2,
|
|---|
| 502 | phHandle16));
|
|---|
| 503 | #endif
|
|---|
| 504 |
|
|---|
| 505 | for (ulIndex = 1;
|
|---|
| 506 | ulIndex < MAX_OS2_HMHANDLES;
|
|---|
| 507 | ulIndex++)
|
|---|
| 508 | {
|
|---|
| 509 | /* look for the handle */
|
|---|
| 510 | if (TabWin32Handles[ulIndex].hmHandleData.hHMHandle == hHandleOS2)
|
|---|
| 511 | {
|
|---|
| 512 | *phHandle16 = ulIndex; /* deliver result */
|
|---|
| 513 | return (NO_ERROR); /* OK */
|
|---|
| 514 | }
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 | /*****************************************************************************
|
|---|
| 522 | * Name : DWORD HMHandleTranslateToOS2
|
|---|
| 523 | * Purpose : translate a 16-bit Win32 handle to the associated OS/2 handle
|
|---|
| 524 | * Parameters: ULONG hHandle16 - the windows handle
|
|---|
| 525 | * PULONG phHandle32 - the associated OS/2 handle
|
|---|
| 526 | * Variables :
|
|---|
| 527 | * Result : API returncode
|
|---|
| 528 | * Remark :
|
|---|
| 529 | * Status :
|
|---|
| 530 | *
|
|---|
| 531 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 532 | *****************************************************************************/
|
|---|
| 533 |
|
|---|
| 534 | DWORD HMHandleTranslateToOS2 (ULONG hHandle16,
|
|---|
| 535 | PULONG phHandleOS2)
|
|---|
| 536 | {
|
|---|
| 537 | #ifdef DEBUG_LOCAL
|
|---|
| 538 | dprintf(("KERNEL32: HMHandleTranslateToOS2 (%08xh, %08xh)\n",
|
|---|
| 539 | hHandle16,
|
|---|
| 540 | phHandleOS2));
|
|---|
| 541 | #endif
|
|---|
| 542 |
|
|---|
| 543 | if (HMHandleValidate(hHandle16) == NO_ERROR) /* verify handle */
|
|---|
| 544 | {
|
|---|
| 545 | *phHandleOS2 = TabWin32Handles[hHandle16].hmHandleData.hHMHandle;
|
|---|
| 546 | return (NO_ERROR);
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
|---|
| 550 | }
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 | /*****************************************************************************
|
|---|
| 554 | * Name : DWORD HMHandleTranslateToOS2i
|
|---|
| 555 | * Purpose : translate a 16-bit Win32 handle to the associated OS/2 handle
|
|---|
| 556 | * Parameters: ULONG hHandle16 - the windows handle
|
|---|
| 557 | * Variables :
|
|---|
| 558 | * Result : OS/2 handle
|
|---|
| 559 | * Remark : no checkinf
|
|---|
| 560 | * Status :
|
|---|
| 561 | *
|
|---|
| 562 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 563 | *****************************************************************************/
|
|---|
| 564 |
|
|---|
| 565 | DWORD HMHandleTranslateToOS2i (ULONG hHandle16)
|
|---|
| 566 | {
|
|---|
| 567 | #ifdef DEBUG_LOCAL
|
|---|
| 568 | dprintf(("KERNEL32: HMHandleTranslateToOS2i (%08xh)\n",
|
|---|
| 569 | hHandle16));
|
|---|
| 570 | #endif
|
|---|
| 571 |
|
|---|
| 572 | return(TabWin32Handles[hHandle16].hmHandleData.hHMHandle);
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 | /*****************************************************************************
|
|---|
| 578 | * Name : HANDLE _HMGetStdHandle
|
|---|
| 579 | * Purpose : replacement for Open32's GetStdHandle function
|
|---|
| 580 | * Parameters: DWORD nStdHandle
|
|---|
| 581 | * Variables :
|
|---|
| 582 | * Result : HANDLE to standard device
|
|---|
| 583 | * Remark :
|
|---|
| 584 | * Status :
|
|---|
| 585 | *
|
|---|
| 586 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 587 | *****************************************************************************/
|
|---|
| 588 |
|
|---|
| 589 | HANDLE HMGetStdHandle(DWORD nStdHandle)
|
|---|
| 590 | {
|
|---|
| 591 | switch (nStdHandle)
|
|---|
| 592 | {
|
|---|
| 593 | case STD_INPUT_HANDLE: return (HMGlobals.hStandardIn);
|
|---|
| 594 | case STD_OUTPUT_HANDLE: return (HMGlobals.hStandardOut);
|
|---|
| 595 | case STD_ERROR_HANDLE: return (HMGlobals.hStandardError);
|
|---|
| 596 |
|
|---|
| 597 | default:
|
|---|
| 598 | {
|
|---|
| 599 | SetLastError(ERROR_INVALID_PARAMETER); /* set error information */
|
|---|
| 600 | return (INVALID_HANDLE_VALUE); /* raise error condition */
|
|---|
| 601 | }
|
|---|
| 602 | }
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 | /*****************************************************************************
|
|---|
| 607 | * Name : HANDLE _HMSetStdHandle
|
|---|
| 608 | * Purpose : replacement for Open32's SetStdHandle function
|
|---|
| 609 | * Parameters: DWORD nStdHandle
|
|---|
| 610 | * HANDLE hHandle
|
|---|
| 611 | * Variables :
|
|---|
| 612 | * Result : BOOL fSuccess
|
|---|
| 613 | * Remark :
|
|---|
| 614 | * Status :
|
|---|
| 615 | *
|
|---|
| 616 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
|---|
| 617 | *****************************************************************************/
|
|---|
| 618 |
|
|---|
| 619 | BOOL HMSetStdHandle(DWORD nStdHandle,
|
|---|
| 620 | HANDLE hHandle)
|
|---|
| 621 | {
|
|---|
| 622 | switch (nStdHandle)
|
|---|
| 623 | {
|
|---|
| 624 | case STD_INPUT_HANDLE: HMGlobals.hStandardIn = hHandle; return TRUE;
|
|---|
| 625 | case STD_OUTPUT_HANDLE: HMGlobals.hStandardOut = hHandle; return TRUE;
|
|---|
| 626 | case STD_ERROR_HANDLE: HMGlobals.hStandardError = hHandle; return TRUE;
|
|---|
| 627 |
|
|---|
| 628 | default:
|
|---|
| 629 | {
|
|---|
| 630 | SetLastError(ERROR_INVALID_PARAMETER); /* set error information */
|
|---|
| 631 | return (FALSE); /* raise error condition */
|
|---|
| 632 | }
|
|---|
| 633 | }
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 | /*****************************************************************************
|
|---|
| 638 | * Name : HANDLE HMDuplicateHandle
|
|---|
| 639 | * Purpose : replacement for Open32's HMDuplicateHandle function
|
|---|
| 640 | * Parameters:
|
|---|
| 641 | *
|
|---|
| 642 | * Variables :
|
|---|
| 643 | * Result : BOOL fSuccess
|
|---|
| 644 | * Remark :
|
|---|
| 645 | * Status :
|
|---|
| 646 | *
|
|---|
| 647 | * Author : Sander van Leeuwen [Wed, 1999/08/25 15:44]
|
|---|
| 648 | *****************************************************************************/
|
|---|
| 649 |
|
|---|
| 650 | BOOL HMDuplicateHandle(HANDLE srcprocess,
|
|---|
| 651 | HANDLE srchandle,
|
|---|
| 652 | HANDLE destprocess,
|
|---|
| 653 | PHANDLE desthandle,
|
|---|
| 654 | DWORD fdwAccess,
|
|---|
| 655 | BOOL fInherit,
|
|---|
| 656 | DWORD fdwOptions)
|
|---|
| 657 | {
|
|---|
| 658 | int iIndex; /* index into the handle table */
|
|---|
| 659 | int iIndexNew; /* index into the handle table */
|
|---|
| 660 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 661 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 662 | DWORD rc; /* API return code */
|
|---|
| 663 |
|
|---|
| 664 | if(HMHandleValidate(srchandle) != NO_ERROR)
|
|---|
| 665 | {
|
|---|
| 666 | dprintf(("KERNEL32: HMDuplicateHandle: invalid handle %x", srchandle));
|
|---|
| 667 | SetLastError(ERROR_INVALID_HANDLE); /* use this as error message */
|
|---|
| 668 | return FALSE;
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | pDeviceHandler = TabWin32Handles[srchandle].pDeviceHandler; /* device is predefined */
|
|---|
| 672 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 673 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 674 | {
|
|---|
| 675 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 676 | return FALSE; /* signal error */
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 680 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 681 | pHMHandleData->dwType = TabWin32Handles[srchandle].hmHandleData.dwType;
|
|---|
| 682 | if (fdwOptions & DUPLICATE_SAME_ACCESS)
|
|---|
| 683 | pHMHandleData->dwAccess = TabWin32Handles[srchandle].hmHandleData.dwAccess;
|
|---|
| 684 | else
|
|---|
| 685 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 686 |
|
|---|
| 687 | pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare;
|
|---|
| 688 | pHMHandleData->dwCreation = TabWin32Handles[srchandle].hmHandleData.dwCreation;
|
|---|
| 689 | pHMHandleData->dwFlags = TabWin32Handles[srchandle].hmHandleData.dwFlags;
|
|---|
| 690 | pHMHandleData->lpHandlerData = TabWin32Handles[srchandle].hmHandleData.lpHandlerData;
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 694 | /* could be created within the device handler -> deadlock */
|
|---|
| 695 |
|
|---|
| 696 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 697 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 698 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 699 |
|
|---|
| 700 | /* call the device handler */
|
|---|
| 701 | rc = pDeviceHandler->DuplicateHandle(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 702 | srcprocess,
|
|---|
| 703 | &TabWin32Handles[srchandle].hmHandleData,
|
|---|
| 704 | destprocess,
|
|---|
| 705 | desthandle,
|
|---|
| 706 | fdwAccess,
|
|---|
| 707 | fInherit,
|
|---|
| 708 | fdwOptions & ~DUPLICATE_CLOSE_SOURCE);
|
|---|
| 709 |
|
|---|
| 710 | //Don't let Open32 close it for us, but do it manually (regardless of error; see SDK docs))
|
|---|
| 711 | if (fdwOptions & DUPLICATE_CLOSE_SOURCE)
|
|---|
| 712 | HMCloseHandle(srchandle);
|
|---|
| 713 |
|
|---|
| 714 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 715 | {
|
|---|
| 716 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 717 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 718 | return FALSE; /* signal error */
|
|---|
| 719 | }
|
|---|
| 720 | else
|
|---|
| 721 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 722 |
|
|---|
| 723 | *desthandle = iIndexNew;
|
|---|
| 724 | return TRUE; /* return valid handle */
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | /*****************************************************************************
|
|---|
| 728 | * Name : HANDLE HMCreateFile
|
|---|
| 729 | * Purpose : Wrapper for the CreateFile() API
|
|---|
| 730 | * Parameters:
|
|---|
| 731 | * Variables :
|
|---|
| 732 | * Result :
|
|---|
| 733 | * Remark : Fix parameters passed to the HMDeviceManager::CreateFile
|
|---|
| 734 | * Supply access mode and share mode validation routines
|
|---|
| 735 | * Status :
|
|---|
| 736 | *
|
|---|
| 737 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 738 | *****************************************************************************/
|
|---|
| 739 |
|
|---|
| 740 | HFILE HMCreateFile(LPCSTR lpFileName,
|
|---|
| 741 | DWORD dwDesiredAccess,
|
|---|
| 742 | DWORD dwShareMode,
|
|---|
| 743 | LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
|---|
| 744 | DWORD dwCreationDisposition,
|
|---|
| 745 | DWORD dwFlagsAndAttributes,
|
|---|
| 746 | HANDLE hTemplateFile)
|
|---|
| 747 | {
|
|---|
| 748 | int iIndex; /* index into the handle table */
|
|---|
| 749 | int iIndexNew; /* index into the handle table */
|
|---|
| 750 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 751 | HANDLE hResult;
|
|---|
| 752 | DWORD rc; /* API return code */
|
|---|
| 753 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 754 | HMHANDLEDATA HMHandleTemp; /* temporary buffer for handle data */
|
|---|
| 755 |
|
|---|
| 756 | /* create new handle by either lpFileName or hTemplateFile */
|
|---|
| 757 | if (lpFileName == NULL) /* this indicates creation from template */
|
|---|
| 758 | {
|
|---|
| 759 | iIndex = _HMHandleQuery(hTemplateFile); /* query table for template */
|
|---|
| 760 | if (-1 == iIndex) /* this device is unknown to us */
|
|---|
| 761 | {
|
|---|
| 762 | SetLastError (ERROR_INVALID_HANDLE);
|
|---|
| 763 | return INVALID_HANDLE_VALUE;
|
|---|
| 764 | }
|
|---|
| 765 | else
|
|---|
| 766 | {
|
|---|
| 767 | /* to pass to handler */
|
|---|
| 768 | pHMHandleData = &TabWin32Handles[iIndex].hmHandleData;
|
|---|
| 769 | pDeviceHandler = TabWin32Handles[iIndex].pDeviceHandler;
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 | else
|
|---|
| 773 | {
|
|---|
| 774 | pDeviceHandler = _HMDeviceFind((LPSTR)lpFileName); /* find device */
|
|---|
| 775 |
|
|---|
| 776 | if (NULL == pDeviceHandler) /* this name is unknown to us */
|
|---|
| 777 | {
|
|---|
| 778 | SetLastError(ERROR_FILE_NOT_FOUND);
|
|---|
| 779 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 780 | }
|
|---|
| 781 | else
|
|---|
| 782 | pHMHandleData = NULL;
|
|---|
| 783 | }
|
|---|
| 784 |
|
|---|
| 785 |
|
|---|
| 786 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 787 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 788 | {
|
|---|
| 789 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 790 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 |
|
|---|
| 794 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 795 | if (lpFileName == NULL) /* create from template */
|
|---|
| 796 | memcpy (&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 797 | &TabWin32Handles[iIndex].hmHandleData,
|
|---|
| 798 | sizeof(HMHANDLEDATA));
|
|---|
| 799 | else
|
|---|
| 800 | {
|
|---|
| 801 | HMHandleTemp.dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 802 | HMHandleTemp.dwAccess = dwDesiredAccess;
|
|---|
| 803 | HMHandleTemp.dwShare = dwShareMode;
|
|---|
| 804 | HMHandleTemp.dwCreation = dwCreationDisposition;
|
|---|
| 805 | HMHandleTemp.dwFlags = dwFlagsAndAttributes;
|
|---|
| 806 | HMHandleTemp.lpHandlerData = NULL;
|
|---|
| 807 | }
|
|---|
| 808 |
|
|---|
| 809 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 810 | /* could be created within the device handler -> deadlock */
|
|---|
| 811 |
|
|---|
| 812 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 813 | HMHandleTemp.hHMHandle = iIndexNew;
|
|---|
| 814 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 815 |
|
|---|
| 816 | /* now copy back our temporary handle data */
|
|---|
| 817 | memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 818 | &HMHandleTemp,
|
|---|
| 819 | sizeof(HMHANDLEDATA));
|
|---|
| 820 |
|
|---|
| 821 | rc = pDeviceHandler->CreateFile(lpFileName, /* call the device handler */
|
|---|
| 822 | &HMHandleTemp,
|
|---|
| 823 | lpSecurityAttributes,
|
|---|
| 824 | pHMHandleData);
|
|---|
| 825 |
|
|---|
| 826 | #ifdef DEBUG_LOCAL
|
|---|
| 827 | dprintf(("KERNEL32/HandleManager:CheckPoint2: %s lpHandlerData=%08xh\n",
|
|---|
| 828 | lpFileName,
|
|---|
| 829 | HMHandleTemp.lpHandlerData));
|
|---|
| 830 | #endif
|
|---|
| 831 |
|
|---|
| 832 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 833 | {
|
|---|
| 834 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 835 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 836 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 837 | }
|
|---|
| 838 | else
|
|---|
| 839 | {
|
|---|
| 840 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 841 |
|
|---|
| 842 | /* copy data fields that might have been modified by CreateFile */
|
|---|
| 843 | memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 844 | &HMHandleTemp,
|
|---|
| 845 | sizeof(HMHANDLEDATA));
|
|---|
| 846 | }
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 | #ifdef DEBUG_LOCAL
|
|---|
| 850 | dprintf(("KERNEL32/HandleManager: CreateFile(%s)=%08xh\n",
|
|---|
| 851 | lpFileName,
|
|---|
| 852 | iIndexNew));
|
|---|
| 853 | #endif
|
|---|
| 854 |
|
|---|
| 855 | return (HFILE)iIndexNew; /* return valid handle */
|
|---|
| 856 | }
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 | /*****************************************************************************
|
|---|
| 860 | * Name : HANDLE HMOpenFile
|
|---|
| 861 | * Purpose : Wrapper for the OpenFile() API
|
|---|
| 862 | * Parameters:
|
|---|
| 863 | * Variables :
|
|---|
| 864 | * Result :
|
|---|
| 865 | * Remark : Fix parameters passed to the HMDeviceManager::OpenFile
|
|---|
| 866 | * Supply access mode and share mode validation routines
|
|---|
| 867 | * Status :
|
|---|
| 868 | *
|
|---|
| 869 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 870 | *****************************************************************************/
|
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 | /***********************************************************************
|
|---|
| 874 | * FILE_ConvertOFMode
|
|---|
| 875 | *
|
|---|
| 876 | * Convert OF_* mode into flags for CreateFile.
|
|---|
| 877 | */
|
|---|
| 878 | static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing )
|
|---|
| 879 | {
|
|---|
| 880 | switch(mode & 0x03)
|
|---|
| 881 | {
|
|---|
| 882 | case OF_READ: *access = GENERIC_READ; break;
|
|---|
| 883 | case OF_WRITE: *access = GENERIC_WRITE; break;
|
|---|
| 884 | case OF_READWRITE: *access = GENERIC_READ | GENERIC_WRITE; break;
|
|---|
| 885 | default: *access = 0; break;
|
|---|
| 886 | }
|
|---|
| 887 | switch(mode & 0x70)
|
|---|
| 888 | {
|
|---|
| 889 | case OF_SHARE_EXCLUSIVE: *sharing = 0; break;
|
|---|
| 890 | case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break;
|
|---|
| 891 | case OF_SHARE_DENY_READ: *sharing = FILE_SHARE_WRITE; break;
|
|---|
| 892 | case OF_SHARE_DENY_NONE:
|
|---|
| 893 | case OF_SHARE_COMPAT:
|
|---|
| 894 | default: *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break;
|
|---|
| 895 | }
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | HANDLE HMOpenFile(LPCSTR lpFileName,
|
|---|
| 899 | OFSTRUCT* pOFStruct,
|
|---|
| 900 | UINT fuMode)
|
|---|
| 901 | {
|
|---|
| 902 | int iIndex; /* index into the handle table */
|
|---|
| 903 | int iIndexNew; /* index into the handle table */
|
|---|
| 904 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 905 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 906 | DWORD rc; /* API return code */
|
|---|
| 907 |
|
|---|
| 908 |
|
|---|
| 909 | pDeviceHandler = _HMDeviceFind((LPSTR)lpFileName); /* find device */
|
|---|
| 910 | if (NULL == pDeviceHandler) /* this name is unknown to us */
|
|---|
| 911 | {
|
|---|
| 912 | SetLastError(ERROR_FILE_NOT_FOUND);
|
|---|
| 913 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 914 | }
|
|---|
| 915 | else
|
|---|
| 916 | pHMHandleData = NULL;
|
|---|
| 917 |
|
|---|
| 918 |
|
|---|
| 919 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 920 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 921 | {
|
|---|
| 922 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 923 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 924 | }
|
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 928 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 929 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 930 |
|
|---|
| 931 | FILE_ConvertOFMode(fuMode, /* map OF_flags */
|
|---|
| 932 | &pHMHandleData->dwAccess,
|
|---|
| 933 | &pHMHandleData->dwShare);
|
|---|
| 934 |
|
|---|
| 935 | pHMHandleData->dwCreation = 0;
|
|---|
| 936 | pHMHandleData->dwFlags = 0;
|
|---|
| 937 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 938 |
|
|---|
| 939 |
|
|---|
| 940 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 941 | /* could be created within the device handler -> deadlock */
|
|---|
| 942 |
|
|---|
| 943 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 944 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 945 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 946 |
|
|---|
| 947 | rc = pDeviceHandler->OpenFile (lpFileName, /* call the device handler */
|
|---|
| 948 | &TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 949 | pOFStruct,
|
|---|
| 950 | fuMode);
|
|---|
| 951 |
|
|---|
| 952 | #ifdef DEBUG_LOCAL
|
|---|
| 953 | dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh rc=%08xh\n",
|
|---|
| 954 | lpFileName,
|
|---|
| 955 | &TabWin32Handles[iIndexNew].hmHandleData.lpHandlerData,
|
|---|
| 956 | rc));
|
|---|
| 957 | #endif
|
|---|
| 958 |
|
|---|
| 959 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 960 | {
|
|---|
| 961 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 962 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 963 | return (INVALID_HANDLE_VALUE); /* signal error */
|
|---|
| 964 | }
|
|---|
| 965 | else
|
|---|
| 966 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 967 |
|
|---|
| 968 | #ifdef DEBUG_LOCAL
|
|---|
| 969 | dprintf(("KERNEL32/HandleManager: OpenFile(%s)=%08xh\n",
|
|---|
| 970 | lpFileName,
|
|---|
| 971 | hResult));
|
|---|
| 972 | #endif
|
|---|
| 973 |
|
|---|
| 974 | return iIndexNew; /* return valid handle */
|
|---|
| 975 | }
|
|---|
| 976 |
|
|---|
| 977 |
|
|---|
| 978 |
|
|---|
| 979 | /*****************************************************************************
|
|---|
| 980 | * Name : HANDLE HMCloseFile
|
|---|
| 981 | * Purpose : Wrapper for the CloseHandle() API
|
|---|
| 982 | * Parameters:
|
|---|
| 983 | * Variables :
|
|---|
| 984 | * Result :
|
|---|
| 985 | * Remark :
|
|---|
| 986 | * Status :
|
|---|
| 987 | *
|
|---|
| 988 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 989 | *****************************************************************************/
|
|---|
| 990 |
|
|---|
| 991 | BOOL HMCloseHandle(HANDLE hObject)
|
|---|
| 992 | {
|
|---|
| 993 | int iIndex; /* index into the handle table */
|
|---|
| 994 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 995 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 996 |
|
|---|
| 997 | /* validate handle */
|
|---|
| 998 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 999 | if (-1 == iIndex) /* error ? */
|
|---|
| 1000 | {
|
|---|
| 1001 | //@@@PH it may occur someone closes e.g. a semaphore handle
|
|---|
| 1002 | // which is not registered through the HandleManager yet.
|
|---|
| 1003 | // so we try to pass on to Open32 instead.
|
|---|
| 1004 | dprintf(("KERNEL32: HandleManager:HMCloseHandle(%08xh) passed on to Open32.\n",
|
|---|
| 1005 | hObject));
|
|---|
| 1006 |
|
|---|
| 1007 | fResult = O32_CloseHandle(hObject);
|
|---|
| 1008 | return (fResult);
|
|---|
| 1009 |
|
|---|
| 1010 | //SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1011 | //return (FALSE); /* signal failure */
|
|---|
| 1012 | }
|
|---|
| 1013 |
|
|---|
| 1014 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1015 | //SvL: Check if pDeviceHandler is set
|
|---|
| 1016 | if (pHMHandle->pDeviceHandler)
|
|---|
| 1017 | {
|
|---|
| 1018 | fResult = pHMHandle->pDeviceHandler->CloseHandle(&pHMHandle->hmHandleData);
|
|---|
| 1019 | }
|
|---|
| 1020 | else
|
|---|
| 1021 | {
|
|---|
| 1022 | dprintf(("HMCloseHAndle(%08xh): pDeviceHandler not set", hObject));
|
|---|
| 1023 | fResult = TRUE;
|
|---|
| 1024 | }
|
|---|
| 1025 |
|
|---|
| 1026 | if (fResult == TRUE) /* remove handle if close succeeded */
|
|---|
| 1027 | {
|
|---|
| 1028 | pHMHandle->hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; /* mark handle as free */
|
|---|
| 1029 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | return (fResult); /* deliver return code */
|
|---|
| 1033 | }
|
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 | /*****************************************************************************
|
|---|
| 1037 | * Name : HANDLE HMReadFile
|
|---|
| 1038 | * Purpose : Wrapper for the ReadHandle() API
|
|---|
| 1039 | * Parameters:
|
|---|
| 1040 | * Variables :
|
|---|
| 1041 | * Result :
|
|---|
| 1042 | * Remark :
|
|---|
| 1043 | * Status :
|
|---|
| 1044 | *
|
|---|
| 1045 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1046 | *****************************************************************************/
|
|---|
| 1047 |
|
|---|
| 1048 | BOOL HMReadFile(HANDLE hFile,
|
|---|
| 1049 | LPVOID lpBuffer,
|
|---|
| 1050 | DWORD nNumberOfBytesToRead,
|
|---|
| 1051 | LPDWORD lpNumberOfBytesRead,
|
|---|
| 1052 | LPOVERLAPPED lpOverlapped)
|
|---|
| 1053 | {
|
|---|
| 1054 | int iIndex; /* index into the handle table */
|
|---|
| 1055 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1056 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1057 |
|
|---|
| 1058 | /* validate handle */
|
|---|
| 1059 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1060 | if (-1 == iIndex) /* error ? */
|
|---|
| 1061 | {
|
|---|
| 1062 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1063 | return (FALSE); /* signal failure */
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1067 | fResult = pHMHandle->pDeviceHandler->ReadFile(&pHMHandle->hmHandleData,
|
|---|
| 1068 | lpBuffer,
|
|---|
| 1069 | nNumberOfBytesToRead,
|
|---|
| 1070 | lpNumberOfBytesRead,
|
|---|
| 1071 | lpOverlapped);
|
|---|
| 1072 |
|
|---|
| 1073 | return (fResult); /* deliver return code */
|
|---|
| 1074 | }
|
|---|
| 1075 |
|
|---|
| 1076 |
|
|---|
| 1077 | /*****************************************************************************
|
|---|
| 1078 | * Name : HANDLE HMWriteFile
|
|---|
| 1079 | * Purpose : Wrapper for the WriteHandle() API
|
|---|
| 1080 | * Parameters:
|
|---|
| 1081 | * Variables :
|
|---|
| 1082 | * Result :
|
|---|
| 1083 | * Remark :
|
|---|
| 1084 | * Status :
|
|---|
| 1085 | *
|
|---|
| 1086 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1087 | *****************************************************************************/
|
|---|
| 1088 |
|
|---|
| 1089 | BOOL HMWriteFile(HANDLE hFile,
|
|---|
| 1090 | LPCVOID lpBuffer,
|
|---|
| 1091 | DWORD nNumberOfBytesToWrite,
|
|---|
| 1092 | LPDWORD lpNumberOfBytesWritten,
|
|---|
| 1093 | LPOVERLAPPED lpOverlapped)
|
|---|
| 1094 | {
|
|---|
| 1095 | int iIndex; /* index into the handle table */
|
|---|
| 1096 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 1097 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1098 |
|
|---|
| 1099 | /* validate handle */
|
|---|
| 1100 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1101 | if (-1 == iIndex) /* error ? */
|
|---|
| 1102 | {
|
|---|
| 1103 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1104 | return (FALSE); /* signal failure */
|
|---|
| 1105 | }
|
|---|
| 1106 |
|
|---|
| 1107 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1108 | fResult = pHMHandle->pDeviceHandler->WriteFile(&pHMHandle->hmHandleData,
|
|---|
| 1109 | lpBuffer,
|
|---|
| 1110 | nNumberOfBytesToWrite,
|
|---|
| 1111 | lpNumberOfBytesWritten,
|
|---|
| 1112 | lpOverlapped);
|
|---|
| 1113 |
|
|---|
| 1114 | return (fResult); /* deliver return code */
|
|---|
| 1115 | }
|
|---|
| 1116 |
|
|---|
| 1117 |
|
|---|
| 1118 | /*****************************************************************************
|
|---|
| 1119 | * Name : HANDLE HMGetFileType
|
|---|
| 1120 | * Purpose : Wrapper for the GetFileType() API
|
|---|
| 1121 | * Parameters:
|
|---|
| 1122 | * Variables :
|
|---|
| 1123 | * Result :
|
|---|
| 1124 | * Remark :
|
|---|
| 1125 | * Status :
|
|---|
| 1126 | *
|
|---|
| 1127 | * Author : Patrick Haller [Wed, 1998/02/12 13:37]
|
|---|
| 1128 | *****************************************************************************/
|
|---|
| 1129 |
|
|---|
| 1130 | DWORD HMGetFileType(HANDLE hFile)
|
|---|
| 1131 | {
|
|---|
| 1132 | int iIndex; /* index into the handle table */
|
|---|
| 1133 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1134 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1135 |
|
|---|
| 1136 | /* validate handle */
|
|---|
| 1137 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1138 | if (-1 == iIndex) /* error ? */
|
|---|
| 1139 | {
|
|---|
| 1140 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1141 | return FILE_TYPE_UNKNOWN; /* signal failure */
|
|---|
| 1142 | }
|
|---|
| 1143 |
|
|---|
| 1144 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1145 | dwResult = pHMHandle->pDeviceHandler->GetFileType(&pHMHandle->hmHandleData);
|
|---|
| 1146 |
|
|---|
| 1147 | return (dwResult); /* deliver return code */
|
|---|
| 1148 | }
|
|---|
| 1149 |
|
|---|
| 1150 |
|
|---|
| 1151 | /*****************************************************************************
|
|---|
| 1152 | * Name : HMDeviceHandler::_DeviceReuqest
|
|---|
| 1153 | * Purpose : entry method for special request functions
|
|---|
| 1154 | * Parameters: ULONG ulRequestCode
|
|---|
| 1155 | * various parameters as required
|
|---|
| 1156 | * Variables :
|
|---|
| 1157 | * Result :
|
|---|
| 1158 | * Remark : the standard behaviour is to return an error code for non-
|
|---|
| 1159 | * existant request codes
|
|---|
| 1160 | * Status :
|
|---|
| 1161 | *
|
|---|
| 1162 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1163 | *****************************************************************************/
|
|---|
| 1164 |
|
|---|
| 1165 | DWORD HMDeviceRequest (HANDLE hFile,
|
|---|
| 1166 | ULONG ulRequestCode,
|
|---|
| 1167 | ULONG arg1,
|
|---|
| 1168 | ULONG arg2,
|
|---|
| 1169 | ULONG arg3,
|
|---|
| 1170 | ULONG arg4)
|
|---|
| 1171 | {
|
|---|
| 1172 | int iIndex; /* index into the handle table */
|
|---|
| 1173 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1174 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1175 |
|
|---|
| 1176 | /* validate handle */
|
|---|
| 1177 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1178 | if (-1 == iIndex) /* error ? */
|
|---|
| 1179 | {
|
|---|
| 1180 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1181 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
|---|
| 1182 | }
|
|---|
| 1183 |
|
|---|
| 1184 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1185 | dwResult = pHMHandle->pDeviceHandler->_DeviceRequest(&pHMHandle->hmHandleData,
|
|---|
| 1186 | ulRequestCode,
|
|---|
| 1187 | arg1,
|
|---|
| 1188 | arg2,
|
|---|
| 1189 | arg3,
|
|---|
| 1190 | arg4);
|
|---|
| 1191 |
|
|---|
| 1192 | return (dwResult); /* deliver return code */
|
|---|
| 1193 | }
|
|---|
| 1194 |
|
|---|
| 1195 |
|
|---|
| 1196 | /*****************************************************************************
|
|---|
| 1197 | * Name : HMDeviceHandler::GetFileInformationByHandle
|
|---|
| 1198 | * Purpose : router function for GetFileInformationByHandle
|
|---|
| 1199 | * Parameters:
|
|---|
| 1200 | * Variables :
|
|---|
| 1201 | * Result :
|
|---|
| 1202 | * Remark :
|
|---|
| 1203 | * Status :
|
|---|
| 1204 | *
|
|---|
| 1205 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1206 | *****************************************************************************/
|
|---|
| 1207 |
|
|---|
| 1208 | BOOL HMGetFileInformationByHandle (HANDLE hFile,
|
|---|
| 1209 | BY_HANDLE_FILE_INFORMATION *pHFI)
|
|---|
| 1210 | {
|
|---|
| 1211 | int iIndex; /* index into the handle table */
|
|---|
| 1212 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1213 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1214 |
|
|---|
| 1215 | /* validate handle */
|
|---|
| 1216 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1217 | if (-1 == iIndex) /* error ? */
|
|---|
| 1218 | {
|
|---|
| 1219 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1220 | return FALSE; /* signal failure */
|
|---|
| 1221 | }
|
|---|
| 1222 |
|
|---|
| 1223 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1224 | dwResult = pHMHandle->pDeviceHandler->GetFileInformationByHandle(&pHMHandle->hmHandleData,
|
|---|
| 1225 | pHFI);
|
|---|
| 1226 |
|
|---|
| 1227 | return (dwResult); /* deliver return code */
|
|---|
| 1228 | }
|
|---|
| 1229 |
|
|---|
| 1230 |
|
|---|
| 1231 | /*****************************************************************************
|
|---|
| 1232 | * Name : HMDeviceHandler::SetEndOfFile
|
|---|
| 1233 | * Purpose : router function for SetEndOfFile
|
|---|
| 1234 | * Parameters:
|
|---|
| 1235 | * Variables :
|
|---|
| 1236 | * Result :
|
|---|
| 1237 | * Remark :
|
|---|
| 1238 | * Status :
|
|---|
| 1239 | *
|
|---|
| 1240 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1241 | *****************************************************************************/
|
|---|
| 1242 |
|
|---|
| 1243 | BOOL HMSetEndOfFile (HANDLE hFile)
|
|---|
| 1244 | {
|
|---|
| 1245 | int iIndex; /* index into the handle table */
|
|---|
| 1246 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 1247 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1248 |
|
|---|
| 1249 | /* validate handle */
|
|---|
| 1250 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1251 | if (-1 == iIndex) /* error ? */
|
|---|
| 1252 | {
|
|---|
| 1253 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1254 | return FALSE; /* signal failure */
|
|---|
| 1255 | }
|
|---|
| 1256 |
|
|---|
| 1257 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1258 | bResult = pHMHandle->pDeviceHandler->SetEndOfFile(&pHMHandle->hmHandleData);
|
|---|
| 1259 |
|
|---|
| 1260 | return (bResult); /* deliver return code */
|
|---|
| 1261 | }
|
|---|
| 1262 |
|
|---|
| 1263 |
|
|---|
| 1264 | /*****************************************************************************
|
|---|
| 1265 | * Name : HMDeviceHandler::SetFileTime
|
|---|
| 1266 | * Purpose : router function for SetFileTime
|
|---|
| 1267 | * Parameters:
|
|---|
| 1268 | * Variables :
|
|---|
| 1269 | * Result :
|
|---|
| 1270 | * Remark :
|
|---|
| 1271 | * Status :
|
|---|
| 1272 | *
|
|---|
| 1273 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1274 | *****************************************************************************/
|
|---|
| 1275 |
|
|---|
| 1276 | BOOL HMSetFileTime (HANDLE hFile,
|
|---|
| 1277 | const FILETIME *pFT1,
|
|---|
| 1278 | const FILETIME *pFT2,
|
|---|
| 1279 | const FILETIME *pFT3)
|
|---|
| 1280 | {
|
|---|
| 1281 | int iIndex; /* index into the handle table */
|
|---|
| 1282 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 1283 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1284 |
|
|---|
| 1285 | /* validate handle */
|
|---|
| 1286 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1287 | if (-1 == iIndex) /* error ? */
|
|---|
| 1288 | {
|
|---|
| 1289 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1290 | return FALSE; /* signal failure */
|
|---|
| 1291 | }
|
|---|
| 1292 |
|
|---|
| 1293 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1294 | bResult = pHMHandle->pDeviceHandler->SetFileTime(&pHMHandle->hmHandleData,
|
|---|
| 1295 | (LPFILETIME)pFT1,
|
|---|
| 1296 | (LPFILETIME)pFT2,
|
|---|
| 1297 | (LPFILETIME)pFT3);
|
|---|
| 1298 |
|
|---|
| 1299 | return (bResult); /* deliver return code */
|
|---|
| 1300 | }
|
|---|
| 1301 |
|
|---|
| 1302 |
|
|---|
| 1303 | /*****************************************************************************
|
|---|
| 1304 | * Name : HMDeviceHandler::GetFileSize
|
|---|
| 1305 | * Purpose : router function for GetFileSize
|
|---|
| 1306 | * Parameters:
|
|---|
| 1307 | * Variables :
|
|---|
| 1308 | * Result :
|
|---|
| 1309 | * Remark :
|
|---|
| 1310 | * Status :
|
|---|
| 1311 | *
|
|---|
| 1312 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1313 | *****************************************************************************/
|
|---|
| 1314 |
|
|---|
| 1315 | DWORD HMGetFileSize (HANDLE hFile,
|
|---|
| 1316 | PDWORD pSize)
|
|---|
| 1317 | {
|
|---|
| 1318 | int iIndex; /* index into the handle table */
|
|---|
| 1319 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1320 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1321 |
|
|---|
| 1322 | /* validate handle */
|
|---|
| 1323 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1324 | if (-1 == iIndex) /* error ? */
|
|---|
| 1325 | {
|
|---|
| 1326 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1327 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
|---|
| 1328 | }
|
|---|
| 1329 |
|
|---|
| 1330 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1331 | dwResult = pHMHandle->pDeviceHandler->GetFileSize(&pHMHandle->hmHandleData,
|
|---|
| 1332 | pSize);
|
|---|
| 1333 |
|
|---|
| 1334 | return (dwResult); /* deliver return code */
|
|---|
| 1335 | }
|
|---|
| 1336 |
|
|---|
| 1337 |
|
|---|
| 1338 | /*****************************************************************************
|
|---|
| 1339 | * Name : HMDeviceHandler::SetFilePointer
|
|---|
| 1340 | * Purpose : router function for SetFilePointer
|
|---|
| 1341 | * Parameters:
|
|---|
| 1342 | * Variables :
|
|---|
| 1343 | * Result :
|
|---|
| 1344 | * Remark :
|
|---|
| 1345 | * Status :
|
|---|
| 1346 | *
|
|---|
| 1347 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1348 | *****************************************************************************/
|
|---|
| 1349 |
|
|---|
| 1350 | DWORD HMSetFilePointer (HANDLE hFile,
|
|---|
| 1351 | LONG lDistanceToMove,
|
|---|
| 1352 | PLONG lpDistanceToMoveHigh,
|
|---|
| 1353 | DWORD dwMoveMethod)
|
|---|
| 1354 | {
|
|---|
| 1355 | int iIndex; /* index into the handle table */
|
|---|
| 1356 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1357 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1358 |
|
|---|
| 1359 | /* validate handle */
|
|---|
| 1360 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1361 | if (-1 == iIndex) /* error ? */
|
|---|
| 1362 | {
|
|---|
| 1363 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1364 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
|---|
| 1365 | }
|
|---|
| 1366 |
|
|---|
| 1367 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1368 | dwResult = pHMHandle->pDeviceHandler->SetFilePointer(&pHMHandle->hmHandleData,
|
|---|
| 1369 | lDistanceToMove,
|
|---|
| 1370 | lpDistanceToMoveHigh,
|
|---|
| 1371 | dwMoveMethod);
|
|---|
| 1372 |
|
|---|
| 1373 | return (dwResult); /* deliver return code */
|
|---|
| 1374 | }
|
|---|
| 1375 |
|
|---|
| 1376 |
|
|---|
| 1377 | /*****************************************************************************
|
|---|
| 1378 | * Name : HMDeviceHandler::LockFile
|
|---|
| 1379 | * Purpose : router function for LockFile
|
|---|
| 1380 | * Parameters:
|
|---|
| 1381 | * Variables :
|
|---|
| 1382 | * Result :
|
|---|
| 1383 | * Remark :
|
|---|
| 1384 | * Status :
|
|---|
| 1385 | *
|
|---|
| 1386 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1387 | *****************************************************************************/
|
|---|
| 1388 |
|
|---|
| 1389 | BOOL HMLockFile (HFILE hFile,
|
|---|
| 1390 | DWORD arg2,
|
|---|
| 1391 | DWORD arg3,
|
|---|
| 1392 | DWORD arg4,
|
|---|
| 1393 | DWORD arg5)
|
|---|
| 1394 | {
|
|---|
| 1395 | int iIndex; /* index into the handle table */
|
|---|
| 1396 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1397 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1398 |
|
|---|
| 1399 | /* validate handle */
|
|---|
| 1400 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1401 | if (-1 == iIndex) /* error ? */
|
|---|
| 1402 | {
|
|---|
| 1403 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1404 | return FALSE; /* signal failure */
|
|---|
| 1405 | }
|
|---|
| 1406 |
|
|---|
| 1407 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1408 | dwResult = pHMHandle->pDeviceHandler->LockFile(&pHMHandle->hmHandleData,
|
|---|
| 1409 | arg2,
|
|---|
| 1410 | arg3,
|
|---|
| 1411 | arg4,
|
|---|
| 1412 | arg5);
|
|---|
| 1413 |
|
|---|
| 1414 | return (dwResult); /* deliver return code */
|
|---|
| 1415 | }
|
|---|
| 1416 |
|
|---|
| 1417 |
|
|---|
| 1418 | /*****************************************************************************
|
|---|
| 1419 | * Name : HMDeviceHandler::LockFileEx
|
|---|
| 1420 | * Purpose : router function for LockFileEx
|
|---|
| 1421 | * Parameters:
|
|---|
| 1422 | * Variables :
|
|---|
| 1423 | * Result :
|
|---|
| 1424 | * Remark :
|
|---|
| 1425 | * Status :
|
|---|
| 1426 | *
|
|---|
| 1427 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1428 | *****************************************************************************/
|
|---|
| 1429 |
|
|---|
| 1430 | BOOL HMLockFileEx(HANDLE hFile,
|
|---|
| 1431 | DWORD dwFlags,
|
|---|
| 1432 | DWORD dwReserved,
|
|---|
| 1433 | DWORD nNumberOfBytesToLockLow,
|
|---|
| 1434 | DWORD nNumberOfBytesToLockHigh,
|
|---|
| 1435 | LPOVERLAPPED lpOverlapped)
|
|---|
| 1436 | {
|
|---|
| 1437 | int iIndex; /* index into the handle table */
|
|---|
| 1438 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1439 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1440 |
|
|---|
| 1441 | /* validate handle */
|
|---|
| 1442 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1443 | if (-1 == iIndex) /* error ? */
|
|---|
| 1444 | {
|
|---|
| 1445 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1446 | return FALSE; /* signal failure */
|
|---|
| 1447 | }
|
|---|
| 1448 |
|
|---|
| 1449 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1450 | dwResult = pHMHandle->pDeviceHandler->LockFileEx(&pHMHandle->hmHandleData,
|
|---|
| 1451 | dwFlags,
|
|---|
| 1452 | dwReserved,
|
|---|
| 1453 | nNumberOfBytesToLockLow,
|
|---|
| 1454 | nNumberOfBytesToLockHigh,
|
|---|
| 1455 | lpOverlapped);
|
|---|
| 1456 |
|
|---|
| 1457 | return (dwResult); /* deliver return code */
|
|---|
| 1458 | }
|
|---|
| 1459 |
|
|---|
| 1460 |
|
|---|
| 1461 |
|
|---|
| 1462 | /*****************************************************************************
|
|---|
| 1463 | * Name : HMDeviceHandler::UnlockFile
|
|---|
| 1464 | * Purpose : router function for UnlockFile
|
|---|
| 1465 | * Parameters:
|
|---|
| 1466 | * Variables :
|
|---|
| 1467 | * Result :
|
|---|
| 1468 | * Remark :
|
|---|
| 1469 | * Status :
|
|---|
| 1470 | *
|
|---|
| 1471 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1472 | *****************************************************************************/
|
|---|
| 1473 |
|
|---|
| 1474 | BOOL HMUnlockFile (HFILE hFile,
|
|---|
| 1475 | DWORD arg2,
|
|---|
| 1476 | DWORD arg3,
|
|---|
| 1477 | DWORD arg4,
|
|---|
| 1478 | DWORD arg5)
|
|---|
| 1479 | {
|
|---|
| 1480 | int iIndex; /* index into the handle table */
|
|---|
| 1481 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1482 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1483 |
|
|---|
| 1484 | /* validate handle */
|
|---|
| 1485 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1486 | if (-1 == iIndex) /* error ? */
|
|---|
| 1487 | {
|
|---|
| 1488 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1489 | return FALSE; /* signal failure */
|
|---|
| 1490 | }
|
|---|
| 1491 |
|
|---|
| 1492 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1493 | dwResult = pHMHandle->pDeviceHandler->UnlockFile(&pHMHandle->hmHandleData,
|
|---|
| 1494 | arg2,
|
|---|
| 1495 | arg3,
|
|---|
| 1496 | arg4,
|
|---|
| 1497 | arg5);
|
|---|
| 1498 |
|
|---|
| 1499 | return (dwResult); /* deliver return code */
|
|---|
| 1500 | }
|
|---|
| 1501 |
|
|---|
| 1502 |
|
|---|
| 1503 | /*****************************************************************************
|
|---|
| 1504 | * Name : HMDeviceHandler::UnlockFileEx
|
|---|
| 1505 | * Purpose : router function for UnlockFileEx
|
|---|
| 1506 | * Parameters:
|
|---|
| 1507 | * Variables :
|
|---|
| 1508 | * Result :
|
|---|
| 1509 | * Remark :
|
|---|
| 1510 | * Status :
|
|---|
| 1511 | *
|
|---|
| 1512 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1513 | *****************************************************************************/
|
|---|
| 1514 |
|
|---|
| 1515 | BOOL HMUnlockFileEx(HANDLE hFile,
|
|---|
| 1516 | DWORD dwFlags,
|
|---|
| 1517 | DWORD dwReserved,
|
|---|
| 1518 | DWORD nNumberOfBytesToLockLow,
|
|---|
| 1519 | DWORD nNumberOfBytesToLockHigh,
|
|---|
| 1520 | LPOVERLAPPED lpOverlapped)
|
|---|
| 1521 | {
|
|---|
| 1522 | int iIndex; /* index into the handle table */
|
|---|
| 1523 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1524 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1525 |
|
|---|
| 1526 | /* validate handle */
|
|---|
| 1527 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1528 | if (-1 == iIndex) /* error ? */
|
|---|
| 1529 | {
|
|---|
| 1530 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1531 | return FALSE; /* signal failure */
|
|---|
| 1532 | }
|
|---|
| 1533 |
|
|---|
| 1534 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1535 | dwResult = pHMHandle->pDeviceHandler->UnlockFileEx(&pHMHandle->hmHandleData,
|
|---|
| 1536 | dwFlags,
|
|---|
| 1537 | dwReserved,
|
|---|
| 1538 | nNumberOfBytesToLockLow,
|
|---|
| 1539 | nNumberOfBytesToLockHigh,
|
|---|
| 1540 | lpOverlapped);
|
|---|
| 1541 |
|
|---|
| 1542 | return (dwResult); /* deliver return code */
|
|---|
| 1543 | }
|
|---|
| 1544 |
|
|---|
| 1545 |
|
|---|
| 1546 | /*****************************************************************************
|
|---|
| 1547 | * Name : HMDeviceHandler::WaitForSingleObject
|
|---|
| 1548 | * Purpose : router function for WaitForSingleObject
|
|---|
| 1549 | * Parameters:
|
|---|
| 1550 | * Variables :
|
|---|
| 1551 | * Result :
|
|---|
| 1552 | * Remark :
|
|---|
| 1553 | * Status :
|
|---|
| 1554 | *
|
|---|
| 1555 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1556 | *****************************************************************************/
|
|---|
| 1557 |
|
|---|
| 1558 | DWORD HMWaitForSingleObject(HANDLE hObject,
|
|---|
| 1559 | DWORD dwTimeout)
|
|---|
| 1560 | {
|
|---|
| 1561 | int iIndex; /* index into the handle table */
|
|---|
| 1562 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1563 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1564 |
|
|---|
| 1565 | /* validate handle */
|
|---|
| 1566 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1567 | if (-1 == iIndex) /* error ? */
|
|---|
| 1568 | {
|
|---|
| 1569 | dprintf(("KERNEL32: HandleManager:HMWaitForSingleObject(%08xh) passed on to Open32.\n",
|
|---|
| 1570 | hObject));
|
|---|
| 1571 |
|
|---|
| 1572 | // maybe handles from CreateProcess() ...
|
|---|
| 1573 | dwResult = O32_WaitForSingleObject(hObject, dwTimeout);
|
|---|
| 1574 | return (dwResult);
|
|---|
| 1575 | }
|
|---|
| 1576 |
|
|---|
| 1577 | // @@@PH Problem: wrong class (base class) is called instead of
|
|---|
| 1578 | // open32 class ?! Why ?!
|
|---|
| 1579 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1580 | dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData,
|
|---|
| 1581 | dwTimeout);
|
|---|
| 1582 |
|
|---|
| 1583 | return (dwResult); /* deliver return code */
|
|---|
| 1584 | }
|
|---|
| 1585 |
|
|---|
| 1586 |
|
|---|
| 1587 | /*****************************************************************************
|
|---|
| 1588 | * Name : HMDeviceHandler::WaitForSingleObjectEx
|
|---|
| 1589 | * Purpose : router function for WaitForSingleObjectEx
|
|---|
| 1590 | * Parameters:
|
|---|
| 1591 | * Variables :
|
|---|
| 1592 | * Result :
|
|---|
| 1593 | * Remark :
|
|---|
| 1594 | * Status :
|
|---|
| 1595 | *
|
|---|
| 1596 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1597 | *****************************************************************************/
|
|---|
| 1598 |
|
|---|
| 1599 | DWORD HMWaitForSingleObjectEx(HANDLE hObject,
|
|---|
| 1600 | DWORD dwTimeout,
|
|---|
| 1601 | BOOL fAlertable)
|
|---|
| 1602 | {
|
|---|
| 1603 | int iIndex; /* index into the handle table */
|
|---|
| 1604 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1605 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1606 |
|
|---|
| 1607 | /* validate handle */
|
|---|
| 1608 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1609 | if (-1 == iIndex) /* error ? */
|
|---|
| 1610 | {
|
|---|
| 1611 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1612 | return WAIT_FAILED; /* signal failure */
|
|---|
| 1613 | }
|
|---|
| 1614 |
|
|---|
| 1615 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1616 | dwResult = pHMHandle->pDeviceHandler->WaitForSingleObjectEx(&pHMHandle->hmHandleData,
|
|---|
| 1617 | dwTimeout,
|
|---|
| 1618 | fAlertable);
|
|---|
| 1619 |
|
|---|
| 1620 | return (dwResult); /* deliver return code */
|
|---|
| 1621 | }
|
|---|
| 1622 |
|
|---|
| 1623 |
|
|---|
| 1624 | /*****************************************************************************
|
|---|
| 1625 | * Name : HMDeviceHandler::FlushFileBuffers
|
|---|
| 1626 | * Purpose : router function for FlushFileBuffers
|
|---|
| 1627 | * Parameters:
|
|---|
| 1628 | * Variables :
|
|---|
| 1629 | * Result :
|
|---|
| 1630 | * Remark :
|
|---|
| 1631 | * Status :
|
|---|
| 1632 | *
|
|---|
| 1633 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1634 | *****************************************************************************/
|
|---|
| 1635 |
|
|---|
| 1636 | BOOL HMFlushFileBuffers(HANDLE hFile)
|
|---|
| 1637 | {
|
|---|
| 1638 | int iIndex; /* index into the handle table */
|
|---|
| 1639 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1640 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1641 |
|
|---|
| 1642 | /* validate handle */
|
|---|
| 1643 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 1644 | if (-1 == iIndex) /* error ? */
|
|---|
| 1645 | {
|
|---|
| 1646 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1647 | return FALSE; /* signal failure */
|
|---|
| 1648 | }
|
|---|
| 1649 |
|
|---|
| 1650 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1651 | dwResult = pHMHandle->pDeviceHandler->FlushFileBuffers(&pHMHandle->hmHandleData);
|
|---|
| 1652 |
|
|---|
| 1653 | return (dwResult); /* deliver return code */
|
|---|
| 1654 | }
|
|---|
| 1655 |
|
|---|
| 1656 |
|
|---|
| 1657 | /*****************************************************************************
|
|---|
| 1658 | * Name : HMDeviceHandler::GetOverlappedResult
|
|---|
| 1659 | * Purpose : router function for GetOverlappedResult
|
|---|
| 1660 | * Parameters:
|
|---|
| 1661 | * Variables :
|
|---|
| 1662 | * Result :
|
|---|
| 1663 | * Remark :
|
|---|
| 1664 | * Status :
|
|---|
| 1665 | *
|
|---|
| 1666 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1667 | *****************************************************************************/
|
|---|
| 1668 |
|
|---|
| 1669 | BOOL HMGetOverlappedResult(HANDLE hObject,
|
|---|
| 1670 | LPOVERLAPPED lpOverlapped,
|
|---|
| 1671 | LPDWORD arg3,
|
|---|
| 1672 | BOOL arg4)
|
|---|
| 1673 | {
|
|---|
| 1674 | int iIndex; /* index into the handle table */
|
|---|
| 1675 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1676 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1677 |
|
|---|
| 1678 | /* validate handle */
|
|---|
| 1679 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1680 | if (-1 == iIndex) /* error ? */
|
|---|
| 1681 | {
|
|---|
| 1682 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1683 | return FALSE; /* signal failure */
|
|---|
| 1684 | }
|
|---|
| 1685 |
|
|---|
| 1686 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1687 | dwResult = pHMHandle->pDeviceHandler->GetOverlappedResult(&pHMHandle->hmHandleData,
|
|---|
| 1688 | lpOverlapped,
|
|---|
| 1689 | arg3,
|
|---|
| 1690 | arg4);
|
|---|
| 1691 |
|
|---|
| 1692 | return (dwResult); /* deliver return code */
|
|---|
| 1693 | }
|
|---|
| 1694 |
|
|---|
| 1695 |
|
|---|
| 1696 | /*****************************************************************************
|
|---|
| 1697 | * Name : HMReleaseMutex
|
|---|
| 1698 | * Purpose : router function for ReleaseMutex
|
|---|
| 1699 | * Parameters:
|
|---|
| 1700 | * Variables :
|
|---|
| 1701 | * Result :
|
|---|
| 1702 | * Remark :
|
|---|
| 1703 | * Status :
|
|---|
| 1704 | *
|
|---|
| 1705 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1706 | *****************************************************************************/
|
|---|
| 1707 |
|
|---|
| 1708 | BOOL HMReleaseMutex(HANDLE hObject)
|
|---|
| 1709 | {
|
|---|
| 1710 | int iIndex; /* index into the handle table */
|
|---|
| 1711 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1712 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1713 |
|
|---|
| 1714 | /* validate handle */
|
|---|
| 1715 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
|---|
| 1716 | if (-1 == iIndex) /* error ? */
|
|---|
| 1717 | {
|
|---|
| 1718 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1719 | return FALSE; /* signal failure */
|
|---|
| 1720 | }
|
|---|
| 1721 |
|
|---|
| 1722 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1723 | dwResult = pHMHandle->pDeviceHandler->ReleaseMutex(&pHMHandle->hmHandleData);
|
|---|
| 1724 |
|
|---|
| 1725 | return (dwResult); /* deliver return code */
|
|---|
| 1726 | }
|
|---|
| 1727 |
|
|---|
| 1728 |
|
|---|
| 1729 | /*****************************************************************************
|
|---|
| 1730 | * Name : HMSetEvent
|
|---|
| 1731 | * Purpose : router function for SetEvent
|
|---|
| 1732 | * Parameters:
|
|---|
| 1733 | * Variables :
|
|---|
| 1734 | * Result :
|
|---|
| 1735 | * Remark :
|
|---|
| 1736 | * Status :
|
|---|
| 1737 | *
|
|---|
| 1738 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1739 | *****************************************************************************/
|
|---|
| 1740 |
|
|---|
| 1741 | BOOL HMSetEvent(HANDLE hEvent)
|
|---|
| 1742 | {
|
|---|
| 1743 | int iIndex; /* index into the handle table */
|
|---|
| 1744 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1745 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1746 |
|
|---|
| 1747 | /* validate handle */
|
|---|
| 1748 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 1749 | if (-1 == iIndex) /* error ? */
|
|---|
| 1750 | {
|
|---|
| 1751 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1752 | return FALSE; /* signal failure */
|
|---|
| 1753 | }
|
|---|
| 1754 |
|
|---|
| 1755 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1756 | dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData);
|
|---|
| 1757 |
|
|---|
| 1758 | return (dwResult); /* deliver return code */
|
|---|
| 1759 | }
|
|---|
| 1760 |
|
|---|
| 1761 |
|
|---|
| 1762 | /*****************************************************************************
|
|---|
| 1763 | * Name : HMPulseEvent
|
|---|
| 1764 | * Purpose : router function for PulseEvent
|
|---|
| 1765 | * Parameters:
|
|---|
| 1766 | * Variables :
|
|---|
| 1767 | * Result :
|
|---|
| 1768 | * Remark :
|
|---|
| 1769 | * Status :
|
|---|
| 1770 | *
|
|---|
| 1771 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1772 | *****************************************************************************/
|
|---|
| 1773 |
|
|---|
| 1774 | BOOL HMPulseEvent(HANDLE hEvent)
|
|---|
| 1775 | {
|
|---|
| 1776 | int iIndex; /* index into the handle table */
|
|---|
| 1777 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1778 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1779 |
|
|---|
| 1780 | /* validate handle */
|
|---|
| 1781 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 1782 | if (-1 == iIndex) /* error ? */
|
|---|
| 1783 | {
|
|---|
| 1784 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1785 | return FALSE; /* signal failure */
|
|---|
| 1786 | }
|
|---|
| 1787 |
|
|---|
| 1788 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1789 | dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData);
|
|---|
| 1790 |
|
|---|
| 1791 | return (dwResult); /* deliver return code */
|
|---|
| 1792 | }
|
|---|
| 1793 |
|
|---|
| 1794 |
|
|---|
| 1795 | /*****************************************************************************
|
|---|
| 1796 | * Name : HMResetEvent
|
|---|
| 1797 | * Purpose : router function for ResetEvent
|
|---|
| 1798 | * Parameters:
|
|---|
| 1799 | * Variables :
|
|---|
| 1800 | * Result :
|
|---|
| 1801 | * Remark :
|
|---|
| 1802 | * Status :
|
|---|
| 1803 | *
|
|---|
| 1804 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 1805 | *****************************************************************************/
|
|---|
| 1806 |
|
|---|
| 1807 | BOOL HMResetEvent(HANDLE hEvent)
|
|---|
| 1808 | {
|
|---|
| 1809 | int iIndex; /* index into the handle table */
|
|---|
| 1810 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 1811 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 1812 |
|
|---|
| 1813 | /* validate handle */
|
|---|
| 1814 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 1815 | if (-1 == iIndex) /* error ? */
|
|---|
| 1816 | {
|
|---|
| 1817 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 1818 | return FALSE; /* signal failure */
|
|---|
| 1819 | }
|
|---|
| 1820 |
|
|---|
| 1821 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 1822 | dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData);
|
|---|
| 1823 |
|
|---|
| 1824 | return (dwResult); /* deliver return code */
|
|---|
| 1825 | }
|
|---|
| 1826 |
|
|---|
| 1827 |
|
|---|
| 1828 | /*****************************************************************************
|
|---|
| 1829 | * Name : HANDLE HMCreateEvent
|
|---|
| 1830 | * Purpose : Wrapper for the CreateEvent() API
|
|---|
| 1831 | * Parameters:
|
|---|
| 1832 | * Variables :
|
|---|
| 1833 | * Result :
|
|---|
| 1834 | * Remark :
|
|---|
| 1835 | * Status :
|
|---|
| 1836 | *
|
|---|
| 1837 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1838 | *****************************************************************************/
|
|---|
| 1839 |
|
|---|
| 1840 | HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 1841 | BOOL bManualReset,
|
|---|
| 1842 | BOOL bInitialState,
|
|---|
| 1843 | LPCTSTR lpName)
|
|---|
| 1844 | {
|
|---|
| 1845 | int iIndex; /* index into the handle table */
|
|---|
| 1846 | int iIndexNew; /* index into the handle table */
|
|---|
| 1847 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 1848 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 1849 | DWORD rc; /* API return code */
|
|---|
| 1850 |
|
|---|
| 1851 |
|
|---|
| 1852 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
|---|
| 1853 |
|
|---|
| 1854 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 1855 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 1856 | {
|
|---|
| 1857 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 1858 | return 0; /* signal error */
|
|---|
| 1859 | }
|
|---|
| 1860 |
|
|---|
| 1861 |
|
|---|
| 1862 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 1863 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 1864 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 1865 | pHMHandleData->dwAccess = 0;
|
|---|
| 1866 | pHMHandleData->dwShare = 0;
|
|---|
| 1867 | pHMHandleData->dwCreation = 0;
|
|---|
| 1868 | pHMHandleData->dwFlags = 0;
|
|---|
| 1869 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 1870 |
|
|---|
| 1871 |
|
|---|
| 1872 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 1873 | /* could be created within the device handler -> deadlock */
|
|---|
| 1874 |
|
|---|
| 1875 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 1876 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 1877 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 1878 |
|
|---|
| 1879 | /* call the device handler */
|
|---|
| 1880 | rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 1881 | lpsa,
|
|---|
| 1882 | bManualReset,
|
|---|
| 1883 | bInitialState,
|
|---|
| 1884 | lpName);
|
|---|
| 1885 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 1886 | {
|
|---|
| 1887 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1888 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 1889 | return 0; /* signal error */
|
|---|
| 1890 | }
|
|---|
| 1891 | else
|
|---|
| 1892 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 1893 |
|
|---|
| 1894 | return iIndexNew; /* return valid handle */
|
|---|
| 1895 | }
|
|---|
| 1896 |
|
|---|
| 1897 |
|
|---|
| 1898 | /*****************************************************************************
|
|---|
| 1899 | * Name : HANDLE HMCreateMutex
|
|---|
| 1900 | * Purpose : Wrapper for the CreateMutex() API
|
|---|
| 1901 | * Parameters:
|
|---|
| 1902 | * Variables :
|
|---|
| 1903 | * Result :
|
|---|
| 1904 | * Remark :
|
|---|
| 1905 | * Status :
|
|---|
| 1906 | *
|
|---|
| 1907 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1908 | *****************************************************************************/
|
|---|
| 1909 |
|
|---|
| 1910 | HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 1911 | BOOL bInitialOwner,
|
|---|
| 1912 | LPCTSTR lpName)
|
|---|
| 1913 | {
|
|---|
| 1914 | int iIndex; /* index into the handle table */
|
|---|
| 1915 | int iIndexNew; /* index into the handle table */
|
|---|
| 1916 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 1917 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 1918 | DWORD rc; /* API return code */
|
|---|
| 1919 |
|
|---|
| 1920 |
|
|---|
| 1921 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
|---|
| 1922 |
|
|---|
| 1923 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 1924 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 1925 | {
|
|---|
| 1926 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 1927 | return 0; /* signal error */
|
|---|
| 1928 | }
|
|---|
| 1929 |
|
|---|
| 1930 |
|
|---|
| 1931 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 1932 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 1933 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 1934 | pHMHandleData->dwAccess = 0;
|
|---|
| 1935 | pHMHandleData->dwShare = 0;
|
|---|
| 1936 | pHMHandleData->dwCreation = 0;
|
|---|
| 1937 | pHMHandleData->dwFlags = 0;
|
|---|
| 1938 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 1939 |
|
|---|
| 1940 |
|
|---|
| 1941 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 1942 | /* could be created within the device handler -> deadlock */
|
|---|
| 1943 |
|
|---|
| 1944 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 1945 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 1946 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 1947 |
|
|---|
| 1948 | /* call the device handler */
|
|---|
| 1949 | rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 1950 | lpsa,
|
|---|
| 1951 | bInitialOwner,
|
|---|
| 1952 | lpName);
|
|---|
| 1953 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 1954 | {
|
|---|
| 1955 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 1956 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 1957 | return 0; /* signal error */
|
|---|
| 1958 | }
|
|---|
| 1959 | else
|
|---|
| 1960 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 1961 |
|
|---|
| 1962 | return iIndexNew; /* return valid handle */
|
|---|
| 1963 | }
|
|---|
| 1964 |
|
|---|
| 1965 |
|
|---|
| 1966 | /*****************************************************************************
|
|---|
| 1967 | * Name : HANDLE HMOpenEvent
|
|---|
| 1968 | * Purpose : Wrapper for the OpenEvent() API
|
|---|
| 1969 | * Parameters:
|
|---|
| 1970 | * Variables :
|
|---|
| 1971 | * Result :
|
|---|
| 1972 | * Remark :
|
|---|
| 1973 | * Status :
|
|---|
| 1974 | *
|
|---|
| 1975 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 1976 | *****************************************************************************/
|
|---|
| 1977 |
|
|---|
| 1978 | HANDLE HMOpenEvent(DWORD fdwAccess,
|
|---|
| 1979 | BOOL fInherit,
|
|---|
| 1980 | LPCTSTR lpName)
|
|---|
| 1981 | {
|
|---|
| 1982 | int iIndex; /* index into the handle table */
|
|---|
| 1983 | int iIndexNew; /* index into the handle table */
|
|---|
| 1984 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 1985 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 1986 | DWORD rc; /* API return code */
|
|---|
| 1987 |
|
|---|
| 1988 |
|
|---|
| 1989 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
|---|
| 1990 |
|
|---|
| 1991 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 1992 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 1993 | {
|
|---|
| 1994 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 1995 | return 0; /* signal error */
|
|---|
| 1996 | }
|
|---|
| 1997 |
|
|---|
| 1998 |
|
|---|
| 1999 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2000 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2001 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 2002 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2003 | pHMHandleData->dwShare = 0;
|
|---|
| 2004 | pHMHandleData->dwCreation = 0;
|
|---|
| 2005 | pHMHandleData->dwFlags = 0;
|
|---|
| 2006 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2007 |
|
|---|
| 2008 |
|
|---|
| 2009 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2010 | /* could be created within the device handler -> deadlock */
|
|---|
| 2011 |
|
|---|
| 2012 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2013 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2014 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2015 |
|
|---|
| 2016 | /* call the device handler */
|
|---|
| 2017 | rc = pDeviceHandler->OpenEvent(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2018 | fInherit,
|
|---|
| 2019 | lpName);
|
|---|
| 2020 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2021 | {
|
|---|
| 2022 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2023 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2024 | return 0; /* signal error */
|
|---|
| 2025 | }
|
|---|
| 2026 | else
|
|---|
| 2027 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2028 |
|
|---|
| 2029 | return iIndexNew; /* return valid handle */
|
|---|
| 2030 | }
|
|---|
| 2031 |
|
|---|
| 2032 |
|
|---|
| 2033 | /*****************************************************************************
|
|---|
| 2034 | * Name : HANDLE HMOpenMutex
|
|---|
| 2035 | * Purpose : Wrapper for the OpenMutex() API
|
|---|
| 2036 | * Parameters:
|
|---|
| 2037 | * Variables :
|
|---|
| 2038 | * Result :
|
|---|
| 2039 | * Remark :
|
|---|
| 2040 | * Status :
|
|---|
| 2041 | *
|
|---|
| 2042 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2043 | *****************************************************************************/
|
|---|
| 2044 |
|
|---|
| 2045 | HANDLE HMOpenMutex(DWORD fdwAccess,
|
|---|
| 2046 | BOOL fInherit,
|
|---|
| 2047 | LPCTSTR lpName)
|
|---|
| 2048 | {
|
|---|
| 2049 | int iIndex; /* index into the handle table */
|
|---|
| 2050 | int iIndexNew; /* index into the handle table */
|
|---|
| 2051 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2052 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2053 | DWORD rc; /* API return code */
|
|---|
| 2054 |
|
|---|
| 2055 |
|
|---|
| 2056 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
|---|
| 2057 |
|
|---|
| 2058 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2059 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2060 | {
|
|---|
| 2061 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2062 | return 0; /* signal error */
|
|---|
| 2063 | }
|
|---|
| 2064 |
|
|---|
| 2065 |
|
|---|
| 2066 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2067 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2068 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 2069 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2070 | pHMHandleData->dwShare = 0;
|
|---|
| 2071 | pHMHandleData->dwCreation = 0;
|
|---|
| 2072 | pHMHandleData->dwFlags = 0;
|
|---|
| 2073 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2074 |
|
|---|
| 2075 |
|
|---|
| 2076 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2077 | /* could be created within the device handler -> deadlock */
|
|---|
| 2078 |
|
|---|
| 2079 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2080 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2081 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2082 |
|
|---|
| 2083 | /* call the device handler */
|
|---|
| 2084 | rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2085 | fInherit,
|
|---|
| 2086 | lpName);
|
|---|
| 2087 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2088 | {
|
|---|
| 2089 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2090 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2091 | return 0; /* signal error */
|
|---|
| 2092 | }
|
|---|
| 2093 | else
|
|---|
| 2094 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2095 |
|
|---|
| 2096 | return iIndexNew; /* return valid handle */
|
|---|
| 2097 | }
|
|---|
| 2098 |
|
|---|
| 2099 |
|
|---|
| 2100 | /*****************************************************************************
|
|---|
| 2101 | * Name : HANDLE HMCreateSemaphore
|
|---|
| 2102 | * Purpose : Wrapper for the CreateSemaphore() API
|
|---|
| 2103 | * Parameters:
|
|---|
| 2104 | * Variables :
|
|---|
| 2105 | * Result :
|
|---|
| 2106 | * Remark :
|
|---|
| 2107 | * Status :
|
|---|
| 2108 | *
|
|---|
| 2109 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2110 | *****************************************************************************/
|
|---|
| 2111 |
|
|---|
| 2112 | HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa,
|
|---|
| 2113 | LONG lInitialCount,
|
|---|
| 2114 | LONG lMaximumCount,
|
|---|
| 2115 | LPCTSTR lpName)
|
|---|
| 2116 | {
|
|---|
| 2117 | int iIndex; /* index into the handle table */
|
|---|
| 2118 | int iIndexNew; /* index into the handle table */
|
|---|
| 2119 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2120 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2121 | DWORD rc; /* API return code */
|
|---|
| 2122 |
|
|---|
| 2123 |
|
|---|
| 2124 | pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */
|
|---|
| 2125 |
|
|---|
| 2126 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2127 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2128 | {
|
|---|
| 2129 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2130 | return 0; /* signal error */
|
|---|
| 2131 | }
|
|---|
| 2132 |
|
|---|
| 2133 |
|
|---|
| 2134 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2135 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2136 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 2137 | pHMHandleData->dwAccess = 0;
|
|---|
| 2138 | pHMHandleData->dwShare = 0;
|
|---|
| 2139 | pHMHandleData->dwCreation = 0;
|
|---|
| 2140 | pHMHandleData->dwFlags = 0;
|
|---|
| 2141 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2142 |
|
|---|
| 2143 |
|
|---|
| 2144 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2145 | /* could be created within the device handler -> deadlock */
|
|---|
| 2146 |
|
|---|
| 2147 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2148 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2149 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2150 |
|
|---|
| 2151 | /* call the device handler */
|
|---|
| 2152 | rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2153 | lpsa,
|
|---|
| 2154 | lInitialCount,
|
|---|
| 2155 | lMaximumCount,
|
|---|
| 2156 | lpName);
|
|---|
| 2157 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2158 | {
|
|---|
| 2159 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2160 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2161 | return 0; /* signal failure */
|
|---|
| 2162 | }
|
|---|
| 2163 | else
|
|---|
| 2164 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2165 |
|
|---|
| 2166 | return iIndexNew; /* return valid handle */
|
|---|
| 2167 | }
|
|---|
| 2168 |
|
|---|
| 2169 |
|
|---|
| 2170 | /*****************************************************************************
|
|---|
| 2171 | * Name : HANDLE HMOpenSemaphore
|
|---|
| 2172 | * Purpose : Wrapper for the OpenSemaphore() API
|
|---|
| 2173 | * Parameters:
|
|---|
| 2174 | * Variables :
|
|---|
| 2175 | * Result :
|
|---|
| 2176 | * Remark :
|
|---|
| 2177 | * Status :
|
|---|
| 2178 | *
|
|---|
| 2179 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2180 | *****************************************************************************/
|
|---|
| 2181 |
|
|---|
| 2182 | HANDLE HMOpenSemaphore(DWORD fdwAccess,
|
|---|
| 2183 | BOOL fInherit,
|
|---|
| 2184 | LPCTSTR lpName)
|
|---|
| 2185 | {
|
|---|
| 2186 | int iIndex; /* index into the handle table */
|
|---|
| 2187 | int iIndexNew; /* index into the handle table */
|
|---|
| 2188 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2189 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2190 | DWORD rc; /* API return code */
|
|---|
| 2191 |
|
|---|
| 2192 |
|
|---|
| 2193 | pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */
|
|---|
| 2194 |
|
|---|
| 2195 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2196 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2197 | {
|
|---|
| 2198 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2199 | return 0; /* signal error */
|
|---|
| 2200 | }
|
|---|
| 2201 |
|
|---|
| 2202 |
|
|---|
| 2203 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2204 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2205 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 2206 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2207 | pHMHandleData->dwShare = 0;
|
|---|
| 2208 | pHMHandleData->dwCreation = 0;
|
|---|
| 2209 | pHMHandleData->dwFlags = 0;
|
|---|
| 2210 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2211 |
|
|---|
| 2212 |
|
|---|
| 2213 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2214 | /* could be created within the device handler -> deadlock */
|
|---|
| 2215 |
|
|---|
| 2216 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2217 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2218 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2219 |
|
|---|
| 2220 | /* call the device handler */
|
|---|
| 2221 | rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2222 | fInherit,
|
|---|
| 2223 | lpName);
|
|---|
| 2224 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2225 | {
|
|---|
| 2226 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2227 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2228 | return 0; /* signal failure */
|
|---|
| 2229 | }
|
|---|
| 2230 | else
|
|---|
| 2231 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2232 |
|
|---|
| 2233 | return iIndexNew; /* return valid handle */
|
|---|
| 2234 | }
|
|---|
| 2235 |
|
|---|
| 2236 |
|
|---|
| 2237 | /*****************************************************************************
|
|---|
| 2238 | * Name : HMReleaseSemaphore
|
|---|
| 2239 | * Purpose : router function for ReleaseSemaphore
|
|---|
| 2240 | * Parameters:
|
|---|
| 2241 | * Variables :
|
|---|
| 2242 | * Result :
|
|---|
| 2243 | * Remark :
|
|---|
| 2244 | * Status :
|
|---|
| 2245 | *
|
|---|
| 2246 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2247 | *****************************************************************************/
|
|---|
| 2248 |
|
|---|
| 2249 | BOOL HMReleaseSemaphore(HANDLE hEvent,
|
|---|
| 2250 | LONG cReleaseCount,
|
|---|
| 2251 | LPLONG lpPreviousCount)
|
|---|
| 2252 | {
|
|---|
| 2253 | int iIndex; /* index into the handle table */
|
|---|
| 2254 | DWORD dwResult; /* result from the device handler's API */
|
|---|
| 2255 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2256 |
|
|---|
| 2257 | /* validate handle */
|
|---|
| 2258 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
|---|
| 2259 | if (-1 == iIndex) /* error ? */
|
|---|
| 2260 | {
|
|---|
| 2261 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2262 | return 0; /* signal failure */
|
|---|
| 2263 | }
|
|---|
| 2264 | else
|
|---|
| 2265 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2266 |
|
|---|
| 2267 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2268 | dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData,
|
|---|
| 2269 | cReleaseCount,
|
|---|
| 2270 | lpPreviousCount);
|
|---|
| 2271 |
|
|---|
| 2272 | return (dwResult); /* deliver return code */
|
|---|
| 2273 | }
|
|---|
| 2274 |
|
|---|
| 2275 |
|
|---|
| 2276 | /*****************************************************************************
|
|---|
| 2277 | * Name : HANDLE HMCreateFileMapping
|
|---|
| 2278 | * Purpose : Wrapper for the CreateFileMapping() API
|
|---|
| 2279 | * Parameters:
|
|---|
| 2280 | * Variables :
|
|---|
| 2281 | * Result :
|
|---|
| 2282 | * Remark :
|
|---|
| 2283 | * Status :
|
|---|
| 2284 | *
|
|---|
| 2285 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2286 | *****************************************************************************/
|
|---|
| 2287 |
|
|---|
| 2288 | HANDLE HMCreateFileMapping(HANDLE hFile,
|
|---|
| 2289 | LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
|
|---|
| 2290 | DWORD flProtect,
|
|---|
| 2291 | DWORD dwMaximumSizeHigh,
|
|---|
| 2292 | DWORD dwMaximumSizeLow,
|
|---|
| 2293 | LPCTSTR lpName)
|
|---|
| 2294 | {
|
|---|
| 2295 | int iIndex; /* index into the handle table */
|
|---|
| 2296 | int iIndexNew; /* index into the handle table */
|
|---|
| 2297 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2298 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2299 | DWORD rc; /* API return code */
|
|---|
| 2300 |
|
|---|
| 2301 |
|
|---|
| 2302 | pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */
|
|---|
| 2303 |
|
|---|
| 2304 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2305 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2306 | {
|
|---|
| 2307 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2308 | return 0; /* signal error */
|
|---|
| 2309 | }
|
|---|
| 2310 |
|
|---|
| 2311 |
|
|---|
| 2312 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2313 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2314 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 2315 | pHMHandleData->dwAccess = 0;
|
|---|
| 2316 | pHMHandleData->dwShare = 0;
|
|---|
| 2317 | pHMHandleData->dwCreation = 0;
|
|---|
| 2318 | pHMHandleData->dwFlags = 0;
|
|---|
| 2319 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2320 |
|
|---|
| 2321 |
|
|---|
| 2322 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2323 | /* could be created within the device handler -> deadlock */
|
|---|
| 2324 |
|
|---|
| 2325 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2326 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2327 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2328 |
|
|---|
| 2329 | /* call the device handler */
|
|---|
| 2330 |
|
|---|
| 2331 | // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
|
|---|
| 2332 | // a valid HandleManager-internal handle!
|
|---|
| 2333 | rc = pDeviceHandler->CreateFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2334 | hFile,
|
|---|
| 2335 | lpFileMappingAttributes,
|
|---|
| 2336 | flProtect,
|
|---|
| 2337 | dwMaximumSizeHigh,
|
|---|
| 2338 | dwMaximumSizeLow,
|
|---|
| 2339 | lpName);
|
|---|
| 2340 |
|
|---|
| 2341 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2342 | {
|
|---|
| 2343 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2344 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2345 | return (NULL); /* signal error */
|
|---|
| 2346 | }
|
|---|
| 2347 | else
|
|---|
| 2348 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2349 |
|
|---|
| 2350 | return iIndexNew; /* return valid handle */
|
|---|
| 2351 | }
|
|---|
| 2352 |
|
|---|
| 2353 |
|
|---|
| 2354 | /*****************************************************************************
|
|---|
| 2355 | * Name : HANDLE HMOpenFileMapping
|
|---|
| 2356 | * Purpose : Wrapper for the OpenFileMapping() API
|
|---|
| 2357 | * Parameters:
|
|---|
| 2358 | * Variables :
|
|---|
| 2359 | * Result : HANDLE if succeeded,
|
|---|
| 2360 | * NULL if failed.
|
|---|
| 2361 | * Remark :
|
|---|
| 2362 | * Status :
|
|---|
| 2363 | *
|
|---|
| 2364 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 2365 | *****************************************************************************/
|
|---|
| 2366 |
|
|---|
| 2367 | HANDLE HMOpenFileMapping(DWORD fdwAccess,
|
|---|
| 2368 | BOOL fInherit,
|
|---|
| 2369 | LPCTSTR lpName)
|
|---|
| 2370 | {
|
|---|
| 2371 | int iIndex; /* index into the handle table */
|
|---|
| 2372 | int iIndexNew; /* index into the handle table */
|
|---|
| 2373 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
|---|
| 2374 | PHMHANDLEDATA pHMHandleData;
|
|---|
| 2375 | DWORD rc; /* API return code */
|
|---|
| 2376 |
|
|---|
| 2377 |
|
|---|
| 2378 | pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */
|
|---|
| 2379 |
|
|---|
| 2380 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
|---|
| 2381 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
|---|
| 2382 | {
|
|---|
| 2383 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
|---|
| 2384 | return (NULL); /* signal error */
|
|---|
| 2385 | }
|
|---|
| 2386 |
|
|---|
| 2387 | /* initialize the complete HMHANDLEDATA structure */
|
|---|
| 2388 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
|---|
| 2389 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
|---|
| 2390 | pHMHandleData->dwAccess = fdwAccess;
|
|---|
| 2391 | pHMHandleData->dwShare = 0;
|
|---|
| 2392 | pHMHandleData->dwCreation = 0;
|
|---|
| 2393 | pHMHandleData->dwFlags = 0;
|
|---|
| 2394 | pHMHandleData->lpHandlerData = NULL;
|
|---|
| 2395 |
|
|---|
| 2396 |
|
|---|
| 2397 | /* we've got to mark the handle as occupied here, since another device */
|
|---|
| 2398 | /* could be created within the device handler -> deadlock */
|
|---|
| 2399 |
|
|---|
| 2400 | /* write appropriate entry into the handle table if open succeeded */
|
|---|
| 2401 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
|---|
| 2402 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
|---|
| 2403 |
|
|---|
| 2404 | /* call the device handler */
|
|---|
| 2405 | rc = pDeviceHandler->OpenFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
|
|---|
| 2406 | fdwAccess,
|
|---|
| 2407 | fInherit,
|
|---|
| 2408 | lpName);
|
|---|
| 2409 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
|---|
| 2410 | {
|
|---|
| 2411 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
|---|
| 2412 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
|---|
| 2413 | return (NULL); /* signal error */
|
|---|
| 2414 | }
|
|---|
| 2415 | else
|
|---|
| 2416 | SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
|
|---|
| 2417 |
|
|---|
| 2418 | return iIndexNew; /* return valid handle */
|
|---|
| 2419 | }
|
|---|
| 2420 |
|
|---|
| 2421 |
|
|---|
| 2422 | /*****************************************************************************
|
|---|
| 2423 | * Name : HMMapViewOfFileEx
|
|---|
| 2424 | * Purpose : router function for MapViewOfFileEx
|
|---|
| 2425 | * Parameters:
|
|---|
| 2426 | * Variables :
|
|---|
| 2427 | * Result :
|
|---|
| 2428 | * Remark :
|
|---|
| 2429 | * Status :
|
|---|
| 2430 | *
|
|---|
| 2431 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2432 | *****************************************************************************/
|
|---|
| 2433 |
|
|---|
| 2434 | LPVOID HMMapViewOfFileEx(HANDLE hFileMappingObject,
|
|---|
| 2435 | DWORD dwDesiredAccess,
|
|---|
| 2436 | DWORD dwFileOffsetHigh,
|
|---|
| 2437 | DWORD dwFileOffsetLow,
|
|---|
| 2438 | DWORD dwNumberOfBytesToMap,
|
|---|
| 2439 | LPVOID lpBaseAddress)
|
|---|
| 2440 | {
|
|---|
| 2441 | int iIndex; /* index into the handle table */
|
|---|
| 2442 | LPVOID lpResult; /* result from the device handler's API */
|
|---|
| 2443 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2444 |
|
|---|
| 2445 | /* validate handle */
|
|---|
| 2446 | iIndex = _HMHandleQuery(hFileMappingObject); /* get the index */
|
|---|
| 2447 | if (-1 == iIndex) /* error ? */
|
|---|
| 2448 | {
|
|---|
| 2449 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2450 | return (NULL); /* signal failure */
|
|---|
| 2451 | }
|
|---|
| 2452 |
|
|---|
| 2453 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2454 | lpResult = pHMHandle->pDeviceHandler->MapViewOfFileEx(&pHMHandle->hmHandleData,
|
|---|
| 2455 | dwDesiredAccess,
|
|---|
| 2456 | dwFileOffsetHigh,
|
|---|
| 2457 | dwFileOffsetLow,
|
|---|
| 2458 | dwNumberOfBytesToMap,
|
|---|
| 2459 | lpBaseAddress);
|
|---|
| 2460 |
|
|---|
| 2461 | return (lpResult); /* deliver return code */
|
|---|
| 2462 | }
|
|---|
| 2463 |
|
|---|
| 2464 | /*****************************************************************************
|
|---|
| 2465 | * Name : HMWaitForMultipleObjects
|
|---|
| 2466 | * Purpose : router function for WaitForMultipleObjects
|
|---|
| 2467 | * Parameters:
|
|---|
| 2468 | * Variables :
|
|---|
| 2469 | * Result :
|
|---|
| 2470 | * Remark :
|
|---|
| 2471 | * Status :
|
|---|
| 2472 | *
|
|---|
| 2473 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2474 | *****************************************************************************/
|
|---|
| 2475 |
|
|---|
| 2476 | DWORD HMWaitForMultipleObjects (DWORD cObjects,
|
|---|
| 2477 | PHANDLE lphObjects,
|
|---|
| 2478 | BOOL fWaitAll,
|
|---|
| 2479 | DWORD dwTimeout)
|
|---|
| 2480 | {
|
|---|
| 2481 | ULONG ulIndex;
|
|---|
| 2482 | PHANDLE pArrayOfHandles;
|
|---|
| 2483 | PHANDLE pLoop1 = lphObjects;
|
|---|
| 2484 | PHANDLE pLoop2;
|
|---|
| 2485 | DWORD rc;
|
|---|
| 2486 |
|
|---|
| 2487 | // allocate array for handle table
|
|---|
| 2488 | pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE));
|
|---|
| 2489 | if (pArrayOfHandles == NULL)
|
|---|
| 2490 | {
|
|---|
| 2491 | O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|---|
| 2492 | return WAIT_FAILED;
|
|---|
| 2493 | }
|
|---|
| 2494 | else
|
|---|
| 2495 | pLoop2 = pArrayOfHandles;
|
|---|
| 2496 |
|
|---|
| 2497 | // convert array to odin handles
|
|---|
| 2498 | for (ulIndex = 0;
|
|---|
| 2499 |
|
|---|
| 2500 | ulIndex < cObjects;
|
|---|
| 2501 |
|
|---|
| 2502 | ulIndex++,
|
|---|
| 2503 | pLoop1++,
|
|---|
| 2504 | pLoop2++)
|
|---|
| 2505 | {
|
|---|
| 2506 | rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
|
|---|
| 2507 | pLoop2);
|
|---|
| 2508 |
|
|---|
| 2509 | if (rc != NO_ERROR)
|
|---|
| 2510 | {
|
|---|
| 2511 | free (pArrayOfHandles); // free memory
|
|---|
| 2512 | O32_SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 2513 | return (WAIT_FAILED);
|
|---|
| 2514 | }
|
|---|
| 2515 | }
|
|---|
| 2516 |
|
|---|
| 2517 | // OK, now forward to Open32.
|
|---|
| 2518 | // @@@PH: Note this will fail on handles that do NOT belong to Open32
|
|---|
| 2519 | // but to i.e. the console subsystem!
|
|---|
| 2520 | rc = O32_WaitForMultipleObjects(cObjects,
|
|---|
| 2521 | pArrayOfHandles,
|
|---|
| 2522 | fWaitAll,
|
|---|
| 2523 | dwTimeout);
|
|---|
| 2524 |
|
|---|
| 2525 | free(pArrayOfHandles); // free memory
|
|---|
| 2526 | return (rc); // OK, done
|
|---|
| 2527 | }
|
|---|
| 2528 |
|
|---|
| 2529 |
|
|---|
| 2530 | /*****************************************************************************
|
|---|
| 2531 | * Name : HMWaitForMultipleObjectsEx
|
|---|
| 2532 | * Purpose : router function for WaitForMultipleObjectsEx
|
|---|
| 2533 | * Parameters:
|
|---|
| 2534 | * Variables :
|
|---|
| 2535 | * Result :
|
|---|
| 2536 | * Remark :
|
|---|
| 2537 | * Status :
|
|---|
| 2538 | *
|
|---|
| 2539 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
|---|
| 2540 | *****************************************************************************/
|
|---|
| 2541 |
|
|---|
| 2542 | DWORD HMWaitForMultipleObjectsEx (DWORD cObjects,
|
|---|
| 2543 | PHANDLE lphObjects,
|
|---|
| 2544 | BOOL fWaitAll,
|
|---|
| 2545 | DWORD dwTimeout,
|
|---|
| 2546 | BOOL fAlertable)
|
|---|
| 2547 | {
|
|---|
| 2548 | // @@@PH: Note: fAlertable is ignored !
|
|---|
| 2549 | return (HMWaitForMultipleObjects(cObjects,
|
|---|
| 2550 | lphObjects,
|
|---|
| 2551 | fWaitAll,
|
|---|
| 2552 | dwTimeout));
|
|---|
| 2553 | }
|
|---|
| 2554 |
|
|---|
| 2555 | /*****************************************************************************
|
|---|
| 2556 | * Name : HMDeviceIoControl
|
|---|
| 2557 | * Purpose : router function for DeviceIoControl
|
|---|
| 2558 | * Parameters:
|
|---|
| 2559 | * Variables :
|
|---|
| 2560 | * Result :
|
|---|
| 2561 | * Remark :
|
|---|
| 2562 | * Status :
|
|---|
| 2563 | *
|
|---|
| 2564 | * Author : Sander van Leeuwen
|
|---|
| 2565 | *****************************************************************************/
|
|---|
| 2566 |
|
|---|
| 2567 | BOOL WIN32API DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
|
|---|
| 2568 | LPVOID lpInBuffer, DWORD nInBufferSize,
|
|---|
| 2569 | LPVOID lpOutBuffer, DWORD nOutBufferSize,
|
|---|
| 2570 | LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
|
|---|
| 2571 | {
|
|---|
| 2572 | int iIndex; /* index into the handle table */
|
|---|
| 2573 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
|---|
| 2574 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2575 |
|
|---|
| 2576 | /* validate handle */
|
|---|
| 2577 | iIndex = _HMHandleQuery(hDevice); /* get the index */
|
|---|
| 2578 | if (-1 == iIndex) /* error ? */
|
|---|
| 2579 | {
|
|---|
| 2580 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2581 | return (FALSE); /* signal failure */
|
|---|
| 2582 | }
|
|---|
| 2583 |
|
|---|
| 2584 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2585 | fResult = pHMHandle->pDeviceHandler->DeviceIoControl(&pHMHandle->hmHandleData,
|
|---|
| 2586 | dwIoControlCode,
|
|---|
| 2587 | lpInBuffer, nInBufferSize,
|
|---|
| 2588 | lpOutBuffer, nOutBufferSize,
|
|---|
| 2589 | lpBytesReturned, lpOverlapped);
|
|---|
| 2590 |
|
|---|
| 2591 | return (fResult); /* deliver return code */
|
|---|
| 2592 | }
|
|---|
| 2593 |
|
|---|
| 2594 |
|
|---|
| 2595 | /*****************************************************************************
|
|---|
| 2596 | * Name : HMSetupComm
|
|---|
| 2597 | * Purpose : router function for SetupComm
|
|---|
| 2598 | * Parameters:
|
|---|
| 2599 | * Variables :
|
|---|
| 2600 | * Result :
|
|---|
| 2601 | * Remark :
|
|---|
| 2602 | * Status :
|
|---|
| 2603 | *
|
|---|
| 2604 | * Author : Achim Hasenmueller [Sat, 1999/11/27 13:13]
|
|---|
| 2605 | *****************************************************************************/
|
|---|
| 2606 |
|
|---|
| 2607 | BOOL HMSetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
|
|---|
| 2608 | {
|
|---|
| 2609 | int iIndex; /* index into the handle table */
|
|---|
| 2610 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 2611 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2612 |
|
|---|
| 2613 | /* validate handle */
|
|---|
| 2614 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
|---|
| 2615 | if (-1 == iIndex) /* error ? */
|
|---|
| 2616 | {
|
|---|
| 2617 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2618 | return (NULL); /* signal failure */
|
|---|
| 2619 | }
|
|---|
| 2620 |
|
|---|
| 2621 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2622 | bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,
|
|---|
| 2623 | dwInQueue, dwOutQueue);
|
|---|
| 2624 |
|
|---|
| 2625 | return (bResult); /* deliver return code */
|
|---|
| 2626 | }
|
|---|
| 2627 |
|
|---|
| 2628 |
|
|---|
| 2629 | /*****************************************************************************
|
|---|
| 2630 | * Name : HMGetCommState
|
|---|
| 2631 | * Purpose : router function for GetCommState
|
|---|
| 2632 | * Parameters:
|
|---|
| 2633 | * Variables :
|
|---|
| 2634 | * Result :
|
|---|
| 2635 | * Remark :
|
|---|
| 2636 | * Status :
|
|---|
| 2637 | *
|
|---|
| 2638 | * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40]
|
|---|
| 2639 | *****************************************************************************/
|
|---|
| 2640 |
|
|---|
| 2641 | BOOL HMGetCommState(INT hCommDev, LPDCB lpdcb)
|
|---|
| 2642 | {
|
|---|
| 2643 | int iIndex; /* index into the handle table */
|
|---|
| 2644 | BOOL bResult; /* result from the device handler's API */
|
|---|
| 2645 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
|---|
| 2646 |
|
|---|
| 2647 | /* validate handle */
|
|---|
| 2648 | iIndex = _HMHandleQuery(hCommDev); /* get the index */
|
|---|
| 2649 | if (-1 == iIndex) /* error ? */
|
|---|
| 2650 | {
|
|---|
| 2651 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
|---|
| 2652 | return (NULL); /* signal failure */
|
|---|
| 2653 | }
|
|---|
| 2654 |
|
|---|
| 2655 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
|---|
| 2656 | bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData,
|
|---|
| 2657 | lpdcb);
|
|---|
| 2658 |
|
|---|
| 2659 | return (bResult); /* deliver return code */
|
|---|
| 2660 | }
|
|---|