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

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

parport support

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