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

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

misc updates + fixes

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