source: trunk/src/kernel32/HandleManager.cpp@ 7151

Last change on this file since 7151 was 7151, checked in by phaller, 24 years ago

inlined HMHandleQuery

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