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

Last change on this file since 4739 was 4739, checked in by sandervl, 25 years ago

Added renaming for mcicda

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