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

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

Handlemanager fix (MN), changes for device name lookup, com bugfix (error check) + com class now called for COMx: names

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