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