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