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

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

fixed wrong error translation for WaitForSingleObject

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