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

Last change on this file since 3837 was 3837, checked in by phaller, 25 years ago

Fix: HMWaitForSingleObject

File size: 151.3 KB
Line 
1/* $Id: HandleManager.cpp,v 1.43 2000-07-17 00:40:17 phaller Exp $ */
2
3/*
4 * Win32 Unified Handle Manager for OS/2
5 *
6 * 1998/02/11 PH Patrick Haller (haller@zebra.fh-weingarten.de)
7 *
8 * @(#) HandleManager.Cpp 1.0.0 1998/02/11 PH start
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13
14#undef DEBUG_LOCAL
15//#define DEBUG_LOCAL
16
17
18/*****************************************************************************
19 * Remark *
20 *****************************************************************************
21
22 1998/02/11 PH Even overlapped I/O could be simulated by another subsystem
23 thread with a request queue. We'll see if required ...
24
25
26 Flush (flush handle buffer)
27 WaitForSingleObject
28 WaitForMultipleObjects (?)
29
30 1998/02/12 PH IBM and Microsoft disagree about the definition of FILE_TYPE_xxx
31 Interesting, Open32 returns Microsoft's values ...
32
33 1998/02/12 PH Handles should be equipped with a locking mechanism, in particular
34 as we publish a pointer into the handle table via HMHandleQueryHandleData
35
36 */
37
38
39/*****************************************************************************
40 * Includes *
41 *****************************************************************************/
42
43#include <os2win.h>
44#include <stdlib.h>
45#include <string.h>
46
47#include "unicode.h"
48#include "misc.h"
49
50#include "HandleManager.H"
51#include "HMDevice.h"
52#include "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 // @@@PH Note: return code is wrong!
1767 switch (dwResult)
1768 {
1769 case 1: // OS/2: ERROR_INVALID_FUNCTION
1770 dprintf(("KERNEL32: HandleManager:HMWaitForSingleObject(%08xh) %s needs implementation\n",
1771 pHMHandle->pDeviceHandler->lpHMDeviceName));
1772 dwResult = WAIT_ABANDONED;
1773 break;
1774
1775 case 640: // OS/2: ERROR_TIMEOUT
1776 dwResult = WAIT_TIMEOUT;
1777 break;
1778
1779 case 105: // ERROR_SEM_OWNER_DIED:
1780 case 95: // ERROR_INTERRUPT
1781 dwResult = WAIT_ABANDONED;
1782 break;
1783
1784 case NO_ERROR:
1785 dwResult = WAIT_OBJECT_0;
1786 break;
1787
1788 default:
1789 SetLastError(dwResult);
1790 dwResult = WAIT_FAILED;
1791 break;
1792 }
1793
1794 return (dwResult); /* deliver return code */
1795}
1796
1797
1798/*****************************************************************************
1799 * Name : HMDeviceHandler::WaitForSingleObjectEx
1800 * Purpose : router function for WaitForSingleObjectEx
1801 * Parameters:
1802 * Variables :
1803 * Result :
1804 * Remark :
1805 * Status :
1806 *
1807 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1808 *****************************************************************************/
1809
1810DWORD HMWaitForSingleObjectEx(HANDLE hObject,
1811 DWORD dwTimeout,
1812 BOOL fAlertable)
1813{
1814 int iIndex; /* index into the handle table */
1815 DWORD dwResult; /* result from the device handler's API */
1816 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
1817
1818 /* validate handle */
1819 iIndex = _HMHandleQuery(hObject); /* get the index */
1820 if (-1 == iIndex) /* error ? */
1821 {
1822 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
1823 return WAIT_FAILED; /* signal failure */
1824 }
1825
1826 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
1827 dwResult = pHMHandle->pDeviceHandler->WaitForSingleObjectEx(&pHMHandle->hmHandleData,
1828 dwTimeout,
1829 fAlertable);
1830
1831 return (dwResult); /* deliver return code */
1832}
1833
1834
1835/*****************************************************************************
1836 * Name : HMDeviceHandler::FlushFileBuffers
1837 * Purpose : router function for FlushFileBuffers
1838 * Parameters:
1839 * Variables :
1840 * Result :
1841 * Remark :
1842 * Status :
1843 *
1844 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1845 *****************************************************************************/
1846
1847BOOL HMFlushFileBuffers(HANDLE hFile)
1848{
1849 int iIndex; /* index into the handle table */
1850 DWORD dwResult; /* result from the device handler's API */
1851 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
1852
1853 /* validate handle */
1854 iIndex = _HMHandleQuery(hFile); /* get the index */
1855 if (-1 == iIndex) /* error ? */
1856 {
1857 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
1858 return FALSE; /* signal failure */
1859 }
1860
1861 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
1862 dwResult = pHMHandle->pDeviceHandler->FlushFileBuffers(&pHMHandle->hmHandleData);
1863
1864 return (dwResult); /* deliver return code */
1865}
1866
1867
1868/*****************************************************************************
1869 * Name : HMDeviceHandler::GetOverlappedResult
1870 * Purpose : router function for GetOverlappedResult
1871 * Parameters:
1872 * Variables :
1873 * Result :
1874 * Remark :
1875 * Status :
1876 *
1877 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1878 *****************************************************************************/
1879
1880BOOL HMGetOverlappedResult(HANDLE hObject,
1881 LPOVERLAPPED lpOverlapped,
1882 LPDWORD arg3,
1883 BOOL arg4)
1884{
1885 int iIndex; /* index into the handle table */
1886 DWORD dwResult; /* result from the device handler's API */
1887 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
1888
1889 /* validate handle */
1890 iIndex = _HMHandleQuery(hObject); /* get the index */
1891 if (-1 == iIndex) /* error ? */
1892 {
1893 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
1894 return FALSE; /* signal failure */
1895 }
1896
1897 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
1898 dwResult = pHMHandle->pDeviceHandler->GetOverlappedResult(&pHMHandle->hmHandleData,
1899 lpOverlapped,
1900 arg3,
1901 arg4);
1902
1903 return (dwResult); /* deliver return code */
1904}
1905
1906
1907/*****************************************************************************
1908 * Name : HMReleaseMutex
1909 * Purpose : router function for ReleaseMutex
1910 * Parameters:
1911 * Variables :
1912 * Result :
1913 * Remark :
1914 * Status :
1915 *
1916 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1917 *****************************************************************************/
1918
1919BOOL HMReleaseMutex(HANDLE hObject)
1920{
1921 int iIndex; /* index into the handle table */
1922 DWORD dwResult; /* result from the device handler's API */
1923 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
1924
1925 /* validate handle */
1926 iIndex = _HMHandleQuery(hObject); /* get the index */
1927 if (-1 == iIndex) /* error ? */
1928 {
1929 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
1930 return FALSE; /* signal failure */
1931 }
1932
1933 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
1934 dwResult = pHMHandle->pDeviceHandler->ReleaseMutex(&pHMHandle->hmHandleData);
1935
1936 return (dwResult); /* deliver return code */
1937}
1938
1939
1940/*****************************************************************************
1941 * Name : HMSetEvent
1942 * Purpose : router function for SetEvent
1943 * Parameters:
1944 * Variables :
1945 * Result :
1946 * Remark :
1947 * Status :
1948 *
1949 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1950 *****************************************************************************/
1951
1952BOOL HMSetEvent(HANDLE hEvent)
1953{
1954 int iIndex; /* index into the handle table */
1955 DWORD dwResult; /* result from the device handler's API */
1956 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
1957
1958 /* validate handle */
1959 iIndex = _HMHandleQuery(hEvent); /* get the index */
1960 if (-1 == iIndex) /* error ? */
1961 {
1962 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
1963 return FALSE; /* signal failure */
1964 }
1965
1966 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
1967 dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData);
1968
1969 return (dwResult); /* deliver return code */
1970}
1971
1972
1973/*****************************************************************************
1974 * Name : HMPulseEvent
1975 * Purpose : router function for PulseEvent
1976 * Parameters:
1977 * Variables :
1978 * Result :
1979 * Remark :
1980 * Status :
1981 *
1982 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1983 *****************************************************************************/
1984
1985BOOL HMPulseEvent(HANDLE hEvent)
1986{
1987 int iIndex; /* index into the handle table */
1988 DWORD dwResult; /* result from the device handler's API */
1989 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
1990
1991 /* validate handle */
1992 iIndex = _HMHandleQuery(hEvent); /* get the index */
1993 if (-1 == iIndex) /* error ? */
1994 {
1995 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
1996 return FALSE; /* signal failure */
1997 }
1998
1999 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2000 dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData);
2001
2002 return (dwResult); /* deliver return code */
2003}
2004
2005
2006/*****************************************************************************
2007 * Name : HMResetEvent
2008 * Purpose : router function for ResetEvent
2009 * Parameters:
2010 * Variables :
2011 * Result :
2012 * Remark :
2013 * Status :
2014 *
2015 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
2016 *****************************************************************************/
2017
2018BOOL HMResetEvent(HANDLE hEvent)
2019{
2020 int iIndex; /* index into the handle table */
2021 DWORD dwResult; /* result from the device handler's API */
2022 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
2023
2024 /* validate handle */
2025 iIndex = _HMHandleQuery(hEvent); /* get the index */
2026 if (-1 == iIndex) /* error ? */
2027 {
2028 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
2029 return FALSE; /* signal failure */
2030 }
2031
2032 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2033 dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData);
2034
2035 return (dwResult); /* deliver return code */
2036}
2037
2038
2039/*****************************************************************************
2040 * Name : HANDLE HMCreateEvent
2041 * Purpose : Wrapper for the CreateEvent() API
2042 * Parameters:
2043 * Variables :
2044 * Result :
2045 * Remark :
2046 * Status :
2047 *
2048 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2049 *****************************************************************************/
2050
2051HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa,
2052 BOOL bManualReset,
2053 BOOL bInitialState,
2054 LPCTSTR lpName)
2055{
2056 int iIndex; /* index into the handle table */
2057 int iIndexNew; /* index into the handle table */
2058 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2059 PHMHANDLEDATA pHMHandleData;
2060 DWORD rc; /* API return code */
2061
2062
2063 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
2064
2065 iIndexNew = _HMHandleGetFree(); /* get free handle */
2066 if (-1 == iIndexNew) /* oops, no free handles ! */
2067 {
2068 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2069 return 0; /* signal error */
2070 }
2071
2072
2073 /* initialize the complete HMHANDLEDATA structure */
2074 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2075 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2076 pHMHandleData->dwAccess = 0;
2077 pHMHandleData->dwShare = 0;
2078 pHMHandleData->dwCreation = 0;
2079 pHMHandleData->dwFlags = 0;
2080 pHMHandleData->lpHandlerData = NULL;
2081
2082
2083 /* we've got to mark the handle as occupied here, since another device */
2084 /* could be created within the device handler -> deadlock */
2085
2086 /* write appropriate entry into the handle table if open succeeded */
2087 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2088 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2089
2090 /* call the device handler */
2091 rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData,
2092 lpsa,
2093 bManualReset,
2094 bInitialState,
2095 lpName);
2096 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2097 {
2098 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2099 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2100 return 0; /* signal error */
2101 }
2102 else
2103 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2104
2105 return iIndexNew; /* return valid handle */
2106}
2107
2108
2109/*****************************************************************************
2110 * Name : HANDLE HMCreateMutex
2111 * Purpose : Wrapper for the CreateMutex() API
2112 * Parameters:
2113 * Variables :
2114 * Result :
2115 * Remark :
2116 * Status :
2117 *
2118 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2119 *****************************************************************************/
2120
2121HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa,
2122 BOOL bInitialOwner,
2123 LPCTSTR lpName)
2124{
2125 int iIndex; /* index into the handle table */
2126 int iIndexNew; /* index into the handle table */
2127 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2128 PHMHANDLEDATA pHMHandleData;
2129 DWORD rc; /* API return code */
2130
2131
2132 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
2133
2134 iIndexNew = _HMHandleGetFree(); /* get free handle */
2135 if (-1 == iIndexNew) /* oops, no free handles ! */
2136 {
2137 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2138 return 0; /* signal error */
2139 }
2140
2141
2142 /* initialize the complete HMHANDLEDATA structure */
2143 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2144 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2145 pHMHandleData->dwAccess = 0;
2146 pHMHandleData->dwShare = 0;
2147 pHMHandleData->dwCreation = 0;
2148 pHMHandleData->dwFlags = 0;
2149 pHMHandleData->lpHandlerData = NULL;
2150
2151
2152 /* we've got to mark the handle as occupied here, since another device */
2153 /* could be created within the device handler -> deadlock */
2154
2155 /* write appropriate entry into the handle table if open succeeded */
2156 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2157 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2158
2159 /* call the device handler */
2160 rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData,
2161 lpsa,
2162 bInitialOwner,
2163 lpName);
2164 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2165 {
2166 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2167 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2168 return 0; /* signal error */
2169 }
2170 else
2171 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2172
2173 return iIndexNew; /* return valid handle */
2174}
2175
2176
2177/*****************************************************************************
2178 * Name : HANDLE HMOpenEvent
2179 * Purpose : Wrapper for the OpenEvent() API
2180 * Parameters:
2181 * Variables :
2182 * Result :
2183 * Remark :
2184 * Status :
2185 *
2186 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2187 *****************************************************************************/
2188
2189HANDLE HMOpenEvent(DWORD fdwAccess,
2190 BOOL fInherit,
2191 LPCTSTR lpName)
2192{
2193 int iIndex; /* index into the handle table */
2194 int iIndexNew; /* index into the handle table */
2195 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2196 PHMHANDLEDATA pHMHandleData;
2197 DWORD rc; /* API return code */
2198
2199
2200 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
2201
2202 iIndexNew = _HMHandleGetFree(); /* get free handle */
2203 if (-1 == iIndexNew) /* oops, no free handles ! */
2204 {
2205 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2206 return 0; /* signal error */
2207 }
2208
2209
2210 /* initialize the complete HMHANDLEDATA structure */
2211 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2212 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2213 pHMHandleData->dwAccess = fdwAccess;
2214 pHMHandleData->dwShare = 0;
2215 pHMHandleData->dwCreation = 0;
2216 pHMHandleData->dwFlags = 0;
2217 pHMHandleData->lpHandlerData = NULL;
2218
2219
2220 /* we've got to mark the handle as occupied here, since another device */
2221 /* could be created within the device handler -> deadlock */
2222
2223 /* write appropriate entry into the handle table if open succeeded */
2224 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2225 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2226
2227 /* call the device handler */
2228 rc = pDeviceHandler->OpenEvent(&TabWin32Handles[iIndexNew].hmHandleData,
2229 fInherit,
2230 lpName);
2231 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2232 {
2233 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2234 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2235 return 0; /* signal error */
2236 }
2237 else
2238 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2239
2240 return iIndexNew; /* return valid handle */
2241}
2242
2243
2244/*****************************************************************************
2245 * Name : HANDLE HMOpenMutex
2246 * Purpose : Wrapper for the OpenMutex() API
2247 * Parameters:
2248 * Variables :
2249 * Result :
2250 * Remark :
2251 * Status :
2252 *
2253 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2254 *****************************************************************************/
2255
2256HANDLE HMOpenMutex(DWORD fdwAccess,
2257 BOOL fInherit,
2258 LPCTSTR lpName)
2259{
2260 int iIndex; /* index into the handle table */
2261 int iIndexNew; /* index into the handle table */
2262 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2263 PHMHANDLEDATA pHMHandleData;
2264 DWORD rc; /* API return code */
2265
2266
2267 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
2268
2269 iIndexNew = _HMHandleGetFree(); /* get free handle */
2270 if (-1 == iIndexNew) /* oops, no free handles ! */
2271 {
2272 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2273 return 0; /* signal error */
2274 }
2275
2276
2277 /* initialize the complete HMHANDLEDATA structure */
2278 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2279 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2280 pHMHandleData->dwAccess = fdwAccess;
2281 pHMHandleData->dwShare = 0;
2282 pHMHandleData->dwCreation = 0;
2283 pHMHandleData->dwFlags = 0;
2284 pHMHandleData->lpHandlerData = NULL;
2285
2286
2287 /* we've got to mark the handle as occupied here, since another device */
2288 /* could be created within the device handler -> deadlock */
2289
2290 /* write appropriate entry into the handle table if open succeeded */
2291 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2292 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2293
2294 /* call the device handler */
2295 rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData,
2296 fInherit,
2297 lpName);
2298 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2299 {
2300 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2301 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2302 return 0; /* signal error */
2303 }
2304 else
2305 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2306
2307 return iIndexNew; /* return valid handle */
2308}
2309
2310
2311/*****************************************************************************
2312 * Name : HANDLE HMCreateSemaphore
2313 * Purpose : Wrapper for the CreateSemaphore() API
2314 * Parameters:
2315 * Variables :
2316 * Result :
2317 * Remark :
2318 * Status :
2319 *
2320 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2321 *****************************************************************************/
2322
2323HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa,
2324 LONG lInitialCount,
2325 LONG lMaximumCount,
2326 LPCTSTR lpName)
2327{
2328 int iIndex; /* index into the handle table */
2329 int iIndexNew; /* index into the handle table */
2330 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2331 PHMHANDLEDATA pHMHandleData;
2332 DWORD rc; /* API return code */
2333
2334
2335 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */
2336
2337 iIndexNew = _HMHandleGetFree(); /* get free handle */
2338 if (-1 == iIndexNew) /* oops, no free handles ! */
2339 {
2340 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2341 return 0; /* signal error */
2342 }
2343
2344
2345 /* initialize the complete HMHANDLEDATA structure */
2346 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2347 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2348 pHMHandleData->dwAccess = 0;
2349 pHMHandleData->dwShare = 0;
2350 pHMHandleData->dwCreation = 0;
2351 pHMHandleData->dwFlags = 0;
2352 pHMHandleData->lpHandlerData = NULL;
2353
2354
2355 /* we've got to mark the handle as occupied here, since another device */
2356 /* could be created within the device handler -> deadlock */
2357
2358 /* write appropriate entry into the handle table if open succeeded */
2359 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2360 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2361
2362 /* call the device handler */
2363 rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
2364 lpsa,
2365 lInitialCount,
2366 lMaximumCount,
2367 lpName);
2368 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2369 {
2370 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2371 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2372 return 0; /* signal failure */
2373 }
2374 else
2375 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2376
2377 return iIndexNew; /* return valid handle */
2378}
2379
2380
2381/*****************************************************************************
2382 * Name : HANDLE HMOpenSemaphore
2383 * Purpose : Wrapper for the OpenSemaphore() API
2384 * Parameters:
2385 * Variables :
2386 * Result :
2387 * Remark :
2388 * Status :
2389 *
2390 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2391 *****************************************************************************/
2392
2393HANDLE HMOpenSemaphore(DWORD fdwAccess,
2394 BOOL fInherit,
2395 LPCTSTR lpName)
2396{
2397 int iIndex; /* index into the handle table */
2398 int iIndexNew; /* index into the handle table */
2399 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2400 PHMHANDLEDATA pHMHandleData;
2401 DWORD rc; /* API return code */
2402
2403
2404 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */
2405
2406 iIndexNew = _HMHandleGetFree(); /* get free handle */
2407 if (-1 == iIndexNew) /* oops, no free handles ! */
2408 {
2409 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2410 return 0; /* signal error */
2411 }
2412
2413
2414 /* initialize the complete HMHANDLEDATA structure */
2415 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2416 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2417 pHMHandleData->dwAccess = fdwAccess;
2418 pHMHandleData->dwShare = 0;
2419 pHMHandleData->dwCreation = 0;
2420 pHMHandleData->dwFlags = 0;
2421 pHMHandleData->lpHandlerData = NULL;
2422
2423
2424 /* we've got to mark the handle as occupied here, since another device */
2425 /* could be created within the device handler -> deadlock */
2426
2427 /* write appropriate entry into the handle table if open succeeded */
2428 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2429 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2430
2431 /* call the device handler */
2432 rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
2433 fInherit,
2434 lpName);
2435 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2436 {
2437 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2438 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2439 return 0; /* signal failure */
2440 }
2441 else
2442 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2443
2444 return iIndexNew; /* return valid handle */
2445}
2446
2447
2448/*****************************************************************************
2449 * Name : HMReleaseSemaphore
2450 * Purpose : router function for ReleaseSemaphore
2451 * Parameters:
2452 * Variables :
2453 * Result :
2454 * Remark :
2455 * Status :
2456 *
2457 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
2458 *****************************************************************************/
2459
2460BOOL HMReleaseSemaphore(HANDLE hEvent,
2461 LONG cReleaseCount,
2462 LPLONG lpPreviousCount)
2463{
2464 int iIndex; /* index into the handle table */
2465 DWORD dwResult; /* result from the device handler's API */
2466 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
2467
2468 /* validate handle */
2469 iIndex = _HMHandleQuery(hEvent); /* get the index */
2470 if (-1 == iIndex) /* error ? */
2471 {
2472 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
2473 return 0; /* signal failure */
2474 }
2475 else
2476 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2477
2478 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2479 dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData,
2480 cReleaseCount,
2481 lpPreviousCount);
2482
2483 return (dwResult); /* deliver return code */
2484}
2485
2486
2487/*****************************************************************************
2488 * Name : HANDLE HMCreateFileMapping
2489 * Purpose : Wrapper for the CreateFileMapping() API
2490 * Parameters:
2491 * Variables :
2492 * Result :
2493 * Remark :
2494 * Status :
2495 *
2496 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2497 *****************************************************************************/
2498
2499HANDLE HMCreateFileMapping(HANDLE hFile,
2500 LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
2501 DWORD flProtect,
2502 DWORD dwMaximumSizeHigh,
2503 DWORD dwMaximumSizeLow,
2504 LPCTSTR lpName)
2505{
2506 int iIndex; /* index into the handle table */
2507 int iIndexNew; /* index into the handle table */
2508 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2509 PHMHANDLEDATA pHMHandleData;
2510 DWORD rc; /* API return code */
2511 HANDLE hOldMemMap = -1;
2512
2513 pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */
2514
2515 iIndexNew = _HMHandleGetFree(); /* get free handle */
2516 if (-1 == iIndexNew) /* oops, no free handles ! */
2517 {
2518 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2519 return 0; /* signal error */
2520 }
2521
2522
2523 /* initialize the complete HMHANDLEDATA structure */
2524 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2525 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2526 pHMHandleData->dwAccess = 0;
2527 pHMHandleData->dwShare = 0;
2528 pHMHandleData->dwCreation = 0;
2529 pHMHandleData->dwFlags = 0;
2530 pHMHandleData->lpHandlerData = NULL;
2531
2532
2533 /* we've got to mark the handle as occupied here, since another device */
2534 /* could be created within the device handler -> deadlock */
2535
2536 /* write appropriate entry into the handle table if open succeeded */
2537 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2538 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2539
2540 /* call the device handler */
2541
2542 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
2543 // a valid HandleManager-internal handle!
2544 rc = pDeviceHandler->CreateFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
2545 hFile,
2546 lpFileMappingAttributes,
2547 flProtect,
2548 dwMaximumSizeHigh,
2549 dwMaximumSizeLow,
2550 lpName, &hOldMemMap);
2551
2552 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2553 {
2554 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2555 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2556 if(rc == ERROR_ALREADY_EXISTS) {
2557 return hOldMemMap; //return handle of existing file mapping
2558 }
2559 else return (NULL); /* signal error */
2560 }
2561 else
2562 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2563
2564 return iIndexNew; /* return valid handle */
2565}
2566
2567
2568/*****************************************************************************
2569 * Name : HANDLE HMOpenFileMapping
2570 * Purpose : Wrapper for the OpenFileMapping() API
2571 * Parameters:
2572 * Variables :
2573 * Result : HANDLE if succeeded,
2574 * NULL if failed.
2575 * Remark :
2576 * Status :
2577 *
2578 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
2579 *****************************************************************************/
2580
2581HANDLE HMOpenFileMapping(DWORD fdwAccess,
2582 BOOL fInherit,
2583 LPCTSTR lpName)
2584{
2585 int iIndex; /* index into the handle table */
2586 int iIndexNew; /* index into the handle table */
2587 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2588 PHMHANDLEDATA pHMHandleData;
2589 DWORD rc; /* API return code */
2590
2591
2592 pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */
2593
2594 iIndexNew = _HMHandleGetFree(); /* get free handle */
2595 if (-1 == iIndexNew) /* oops, no free handles ! */
2596 {
2597 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2598 return (NULL); /* signal error */
2599 }
2600
2601 /* initialize the complete HMHANDLEDATA structure */
2602 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2603 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2604 pHMHandleData->dwAccess = fdwAccess;
2605 pHMHandleData->dwShare = 0;
2606 pHMHandleData->dwCreation = 0;
2607 pHMHandleData->dwFlags = 0;
2608 pHMHandleData->lpHandlerData = NULL;
2609
2610
2611 /* we've got to mark the handle as occupied here, since another device */
2612 /* could be created within the device handler -> deadlock */
2613
2614 /* write appropriate entry into the handle table if open succeeded */
2615 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
2616 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
2617
2618 /* call the device handler */
2619 rc = pDeviceHandler->OpenFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
2620 fdwAccess,
2621 fInherit,
2622 lpName);
2623 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
2624 {
2625 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
2626 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
2627 return (NULL); /* signal error */
2628 }
2629 else
2630 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
2631
2632 return iIndexNew; /* return valid handle */
2633}
2634
2635
2636/*****************************************************************************
2637 * Name : HMMapViewOfFileEx
2638 * Purpose : router function for MapViewOfFileEx
2639 * Parameters:
2640 * Variables :
2641 * Result :
2642 * Remark :
2643 * Status :
2644 *
2645 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
2646 *****************************************************************************/
2647
2648LPVOID HMMapViewOfFileEx(HANDLE hFileMappingObject,
2649 DWORD dwDesiredAccess,
2650 DWORD dwFileOffsetHigh,
2651 DWORD dwFileOffsetLow,
2652 DWORD dwNumberOfBytesToMap,
2653 LPVOID lpBaseAddress)
2654{
2655 int iIndex; /* index into the handle table */
2656 LPVOID lpResult; /* result from the device handler's API */
2657 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
2658
2659 /* validate handle */
2660 iIndex = _HMHandleQuery(hFileMappingObject); /* get the index */
2661 if (-1 == iIndex) /* error ? */
2662 {
2663 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
2664 return (NULL); /* signal failure */
2665 }
2666
2667 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2668 lpResult = pHMHandle->pDeviceHandler->MapViewOfFileEx(&pHMHandle->hmHandleData,
2669 dwDesiredAccess,
2670 dwFileOffsetHigh,
2671 dwFileOffsetLow,
2672 dwNumberOfBytesToMap,
2673 lpBaseAddress);
2674
2675 return (lpResult); /* deliver return code */
2676}
2677
2678/*****************************************************************************
2679 * Name : HMWaitForMultipleObjects
2680 * Purpose : router function for WaitForMultipleObjects
2681 * Parameters:
2682 * Variables :
2683 * Result :
2684 * Remark :
2685 * Status :
2686 *
2687 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
2688 *****************************************************************************/
2689
2690DWORD HMWaitForMultipleObjects (DWORD cObjects,
2691 PHANDLE lphObjects,
2692 BOOL fWaitAll,
2693 DWORD dwTimeout)
2694{
2695 ULONG ulIndex;
2696 PHANDLE pArrayOfHandles;
2697 PHANDLE pLoop1 = lphObjects;
2698 PHANDLE pLoop2;
2699 DWORD rc;
2700
2701 // allocate array for handle table
2702 pArrayOfHandles = (PHANDLE)alloca(cObjects * sizeof(HANDLE));
2703 if (pArrayOfHandles == NULL)
2704 {
2705 dprintf(("ERROR: HMWaitForMultipleObjects: alloca failed to allocate %d handles", cObjects));
2706 O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2707 return WAIT_FAILED;
2708 }
2709 else
2710 pLoop2 = pArrayOfHandles;
2711
2712 // convert array to odin handles
2713 for (ulIndex = 0;
2714
2715 ulIndex < cObjects;
2716
2717 ulIndex++,
2718 pLoop1++,
2719 pLoop2++)
2720 {
2721 rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
2722 pLoop2);
2723
2724 dprintf(("KERNEL32: HMWaitForMultipleObjects: handle %3i: ODIN-%08xh, Open32-%08xh\n",
2725 ulIndex,
2726 *pLoop1,
2727 *pLoop2));
2728
2729 // @@@PH to imlpement: check handle type!
2730 // SvL: We still use Open32 handles for threads & processes -> don't fail here!
2731 if (rc != NO_ERROR)
2732 {
2733 dprintf(("KERNEL32: HMWaitForMultipleObjects - WARNING: handle %08xh is NOT an Odin handle (probably Open32 thread or process)\n",
2734 *pLoop1));
2735
2736 *pLoop2 = *pLoop1;
2737//// O32_SetLastError(ERROR_INVALID_HANDLE);
2738//// return (WAIT_FAILED);
2739 }
2740 }
2741
2742 // OK, now forward to Open32.
2743 // @@@PH: Note this will fail on handles that do NOT belong to Open32
2744 // but to i.e. the console subsystem!
2745 rc = O32_WaitForMultipleObjects(cObjects,
2746 pArrayOfHandles,
2747 fWaitAll,
2748 dwTimeout);
2749
2750 return (rc); // OK, done
2751}
2752
2753
2754/*****************************************************************************
2755 * Name : HMWaitForMultipleObjectsEx
2756 * Purpose : router function for WaitForMultipleObjectsEx
2757 * Parameters:
2758 * Variables :
2759 * Result :
2760 * Remark :
2761 * Status :
2762 *
2763 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
2764 *****************************************************************************/
2765
2766DWORD HMWaitForMultipleObjectsEx (DWORD cObjects,
2767 PHANDLE lphObjects,
2768 BOOL fWaitAll,
2769 DWORD dwTimeout,
2770 BOOL fAlertable)
2771{
2772 // @@@PH: Note: fAlertable is ignored !
2773 return (HMWaitForMultipleObjects(cObjects,
2774 lphObjects,
2775 fWaitAll,
2776 dwTimeout));
2777}
2778
2779/*****************************************************************************
2780 * Name : HMMsgWaitForMultipleObjects
2781 * Purpose : router function for MsgWaitForMultipleObjects
2782 * Parameters:
2783 * Variables :
2784 * Result :
2785 * Remark : Open32 doesn't implement this properly! (doesn't check dwWakeMask)
2786 * Status :
2787 *
2788 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
2789 *****************************************************************************/
2790
2791DWORD HMMsgWaitForMultipleObjects (DWORD nCount,
2792 LPHANDLE pHandles,
2793 BOOL fWaitAll,
2794 DWORD dwMilliseconds,
2795 DWORD dwWakeMask)
2796{
2797 ULONG ulIndex;
2798 PHANDLE pArrayOfHandles;
2799 PHANDLE pLoop1 = pHandles;
2800 PHANDLE pLoop2;
2801 DWORD rc;
2802
2803 // allocate array for handle table
2804 pArrayOfHandles = (PHANDLE)alloca(nCount * sizeof(HANDLE));
2805 if (pArrayOfHandles == NULL)
2806 {
2807 dprintf(("ERROR: HMMsgWaitForMultipleObjects: alloca failed to allocate %d handles", nCount));
2808 O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2809 return WAIT_FAILED;
2810 }
2811 else
2812 pLoop2 = pArrayOfHandles;
2813
2814 // convert array to odin handles
2815 for (ulIndex = 0;
2816
2817 ulIndex < nCount;
2818
2819 ulIndex++,
2820 pLoop1++,
2821 pLoop2++)
2822 {
2823 rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
2824 pLoop2);
2825
2826 // SvL: We still use Open32 handles for threads & processes -> don't fail here!
2827 if (rc != NO_ERROR)
2828 {
2829 dprintf(("KERNEL32: HMMsgWaitForMultipleObjects - WARNING: handle %08xh is NOT an Odin handle (probably Open32 thread or process)\n",
2830 *pLoop1));
2831
2832 *pLoop2 = *pLoop1;
2833//// O32_SetLastError(ERROR_INVALID_HANDLE);
2834//// return (WAIT_FAILED);
2835 }
2836 }
2837
2838 // OK, now forward to Open32.
2839 // @@@PH: Note this will fail on handles that do NOT belong to Open32
2840 // but to i.e. the console subsystem!
2841 rc = O32_MsgWaitForMultipleObjects(nCount,
2842 pArrayOfHandles,
2843 fWaitAll, dwMilliseconds,
2844 dwWakeMask);
2845
2846 return (rc); // OK, done
2847}
2848/*****************************************************************************
2849 * Name : HMDeviceIoControl
2850 * Purpose : router function for DeviceIoControl
2851 * Parameters:
2852 * Variables :
2853 * Result :
2854 * Remark :
2855 * Status :
2856 *
2857 * Author : Sander van Leeuwen
2858 *****************************************************************************/
2859
2860BOOL WIN32API DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
2861 LPVOID lpInBuffer, DWORD nInBufferSize,
2862 LPVOID lpOutBuffer, DWORD nOutBufferSize,
2863 LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
2864{
2865 int iIndex; /* index into the handle table */
2866 BOOL fResult; /* result from the device handler's CloseHandle() */
2867 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
2868
2869 /* validate handle */
2870 iIndex = _HMHandleQuery(hDevice); /* get the index */
2871 if (-1 == iIndex) /* error ? */
2872 {
2873 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
2874 return (FALSE); /* signal failure */
2875 }
2876
2877 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2878 fResult = pHMHandle->pDeviceHandler->DeviceIoControl(&pHMHandle->hmHandleData,
2879 dwIoControlCode,
2880 lpInBuffer, nInBufferSize,
2881 lpOutBuffer, nOutBufferSize,
2882 lpBytesReturned, lpOverlapped);
2883
2884 return (fResult); /* deliver return code */
2885}
2886
2887
2888/*****************************************************************************
2889 * Name : HMSetupComm
2890 * Purpose : router function for SetupComm
2891 * Parameters:
2892 * Variables :
2893 * Result :
2894 * Remark :
2895 * Status :
2896 *
2897 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:13]
2898 *****************************************************************************/
2899
2900BOOL HMSetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
2901{
2902 int iIndex; /* index into the handle table */
2903 BOOL bResult; /* result from the device handler's API */
2904 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
2905
2906 /* validate handle */
2907 iIndex = _HMHandleQuery(hFile); /* get the index */
2908 if (-1 == iIndex) /* error ? */
2909 {
2910 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
2911 return (NULL); /* signal failure */
2912 }
2913
2914 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2915 bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,
2916 dwInQueue, dwOutQueue);
2917
2918 return (bResult); /* deliver return code */
2919}
2920
2921
2922/*****************************************************************************
2923 * Name : HMGetCommState
2924 * Purpose : router function for GetCommState
2925 * Parameters:
2926 * Variables :
2927 * Result :
2928 * Remark :
2929 * Status :
2930 *
2931 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40]
2932 *****************************************************************************/
2933
2934BOOL HMGetCommState(INT hCommDev, LPDCB lpdcb)
2935{
2936 int iIndex; /* index into the handle table */
2937 BOOL bResult; /* result from the device handler's API */
2938 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
2939
2940 /* validate handle */
2941 iIndex = _HMHandleQuery(hCommDev); /* get the index */
2942 if (-1 == iIndex) /* error ? */
2943 {
2944 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
2945 return (NULL); /* signal failure */
2946 }
2947
2948 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
2949 bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData,
2950 lpdcb);
2951
2952 return (bResult); /* deliver return code */
2953}
2954
2955/*****************************************************************************
2956 * Name : HMOpenThreadToken
2957 * Purpose : router function for NtOpenThreadToken
2958 * Parameters:
2959 * Variables :
2960 * Result :
2961 * Remark :
2962 * Status :
2963 *
2964 * Author : SvL
2965 *****************************************************************************/
2966
2967DWORD HMOpenThreadToken(HANDLE ThreadHandle,
2968 DWORD DesiredAccess,
2969 DWORD OpenAsSelf,
2970 HANDLE *TokenHandle)
2971{
2972 int iIndex; /* index into the handle table */
2973 int iIndexNew; /* index into the handle table */
2974 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
2975 PHMHANDLEDATA pHMHandleData;
2976 DWORD rc; /* API return code */
2977
2978 pDeviceHandler = HMGlobals.pHMToken; /* device is predefined */
2979
2980 iIndexNew = _HMHandleGetFree(); /* get free handle */
2981 if (-1 == iIndexNew) /* oops, no free handles ! */
2982 {
2983 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
2984 return ERROR_NOT_ENOUGH_MEMORY;
2985 }
2986
2987 /* initialize the complete HMHANDLEDATA structure */
2988 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
2989 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
2990 pHMHandleData->dwAccess = DesiredAccess;
2991 pHMHandleData->dwShare = 0;
2992 pHMHandleData->dwCreation = 0;
2993 pHMHandleData->dwFlags = 0;
2994 pHMHandleData->lpHandlerData = NULL;
2995
2996
2997 /* we've got to mark the handle as occupied here, since another device */
2998 /* could be created within the device handler -> deadlock */
2999
3000 /* write appropriate entry into the handle table if open succeeded */
3001 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3002 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3003
3004 /* call the device handler */
3005
3006 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
3007 // a valid HandleManager-internal handle!
3008 rc = pDeviceHandler->OpenThreadToken(&TabWin32Handles[iIndexNew].hmHandleData,
3009 ThreadHandle,
3010 OpenAsSelf);
3011
3012 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
3013 {
3014 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3015 return (rc); /* signal error */
3016 }
3017 else
3018 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
3019
3020 *TokenHandle = iIndexNew; /* return valid handle */
3021 return STATUS_SUCCESS;
3022}
3023
3024/*****************************************************************************
3025 * Name : HMOpenProcessToken
3026 * Purpose : router function for NtOpenProcessToken
3027 * Parameters:
3028 * Variables :
3029 * Result :
3030 * Remark :
3031 * Status :
3032 *
3033 * Author : SvL
3034 *****************************************************************************/
3035DWORD HMOpenProcessToken(HANDLE ProcessHandle,
3036 DWORD DesiredAccess,
3037 DWORD dwUserData,
3038 HANDLE *TokenHandle)
3039{
3040 int iIndex; /* index into the handle table */
3041 int iIndexNew; /* index into the handle table */
3042 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3043 PHMHANDLEDATA pHMHandleData;
3044 DWORD rc; /* API return code */
3045
3046 pDeviceHandler = HMGlobals.pHMToken; /* device is predefined */
3047
3048 iIndexNew = _HMHandleGetFree(); /* get free handle */
3049 if (-1 == iIndexNew) /* oops, no free handles ! */
3050 {
3051 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3052 return ERROR_NOT_ENOUGH_MEMORY;
3053 }
3054
3055 /* initialize the complete HMHANDLEDATA structure */
3056 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
3057 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
3058 pHMHandleData->dwAccess = DesiredAccess;
3059 pHMHandleData->dwShare = 0;
3060 pHMHandleData->dwCreation = 0;
3061 pHMHandleData->dwFlags = 0;
3062 pHMHandleData->lpHandlerData = NULL;
3063
3064
3065 /* we've got to mark the handle as occupied here, since another device */
3066 /* could be created within the device handler -> deadlock */
3067
3068 /* write appropriate entry into the handle table if open succeeded */
3069 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3070 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3071
3072 /* call the device handler */
3073
3074 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
3075 // a valid HandleManager-internal handle!
3076 rc = pDeviceHandler->OpenProcessToken(&TabWin32Handles[iIndexNew].hmHandleData,
3077 dwUserData,
3078 ProcessHandle);
3079
3080 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
3081 {
3082 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3083 return (rc); /* signal error */
3084 }
3085 else
3086 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
3087
3088 *TokenHandle = iIndexNew; /* return valid handle */
3089 return STATUS_SUCCESS;
3090}
3091/*****************************************************************************
3092 * Name : HMCreateThread
3093 * Purpose : router function for CreateThread
3094 * Parameters:
3095 * Variables :
3096 * Result :
3097 * Remark :
3098 * Status :
3099 *
3100 * Author : SvL
3101 *****************************************************************************/
3102HANDLE HMCreateThread(LPSECURITY_ATTRIBUTES lpsa,
3103 DWORD cbStack,
3104 LPTHREAD_START_ROUTINE lpStartAddr,
3105 LPVOID lpvThreadParm,
3106 DWORD fdwCreate,
3107 LPDWORD lpIDThread,
3108 BOOL fFirstThread)
3109{
3110 int iIndex; /* index into the handle table */
3111 int iIndexNew; /* index into the handle table */
3112 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3113 PHMHANDLEDATA pHMHandleData;
3114 HANDLE rc; /* API return code */
3115
3116 SetLastError(ERROR_SUCCESS);
3117
3118 pDeviceHandler = HMGlobals.pHMThread; /* device is predefined */
3119
3120 iIndexNew = _HMHandleGetFree(); /* get free handle */
3121 if (-1 == iIndexNew) /* oops, no free handles ! */
3122 {
3123 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3124 return 0;
3125 }
3126
3127 /* initialize the complete HMHANDLEDATA structure */
3128 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
3129 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
3130 pHMHandleData->dwAccess = 0;
3131 pHMHandleData->dwShare = 0;
3132 pHMHandleData->dwCreation = 0;
3133 pHMHandleData->dwFlags = 0;
3134 pHMHandleData->lpHandlerData = NULL;
3135
3136
3137 /* we've got to mark the handle as occupied here, since another device */
3138 /* could be created within the device handler -> deadlock */
3139
3140 /* write appropriate entry into the handle table if open succeeded */
3141 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3142 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3143
3144 /* call the device handler */
3145
3146 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
3147 // a valid HandleManager-internal handle!
3148 rc = pDeviceHandler->CreateThread(&TabWin32Handles[iIndexNew].hmHandleData,
3149 lpsa, cbStack, lpStartAddr,
3150 lpvThreadParm, fdwCreate, lpIDThread, fFirstThread);
3151
3152 if (rc == 0) /* oops, creation failed within the device handler */
3153 {
3154 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3155 return 0; /* signal error */
3156 }
3157
3158 return iIndexNew;
3159}
3160/*****************************************************************************
3161 * Name : HMGetThreadPriority
3162 * Purpose : router function for GetThreadPriority
3163 * Parameters:
3164 * Variables :
3165 * Result :
3166 * Remark :
3167 * Status :
3168 *
3169 * Author : SvL
3170 *****************************************************************************/
3171INT HMGetThreadPriority(HANDLE hThread)
3172{
3173 int iIndex; /* index into the handle table */
3174 INT lpResult; /* result from the device handler's API */
3175 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3176
3177 SetLastError(ERROR_SUCCESS);
3178 /* validate handle */
3179 iIndex = _HMHandleQuery(hThread); /* get the index */
3180 if (-1 == iIndex) /* error ? */
3181 {
3182 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3183 return (-1); /* signal failure */
3184 }
3185
3186 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3187 lpResult = pHMHandle->pDeviceHandler->GetThreadPriority(&TabWin32Handles[iIndex].hmHandleData);
3188
3189 return (lpResult); /* deliver return code */
3190}
3191/*****************************************************************************
3192 * Name : HMSuspendThread
3193 * Purpose : router function for SuspendThread
3194 * Parameters:
3195 * Variables :
3196 * Result :
3197 * Remark :
3198 * Status :
3199 *
3200 * Author : SvL
3201 *****************************************************************************/
3202DWORD HMSuspendThread(HANDLE hThread)
3203{
3204 int iIndex; /* index into the handle table */
3205 HANDLE lpResult; /* result from the device handler's API */
3206 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3207
3208 SetLastError(ERROR_SUCCESS);
3209 /* validate handle */
3210 iIndex = _HMHandleQuery(hThread); /* get the index */
3211 if (-1 == iIndex) /* error ? */
3212 {
3213 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3214 return -1; /* signal failure */
3215 }
3216
3217 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3218 lpResult = pHMHandle->pDeviceHandler->SuspendThread(&TabWin32Handles[iIndex].hmHandleData);
3219
3220 return (lpResult); /* deliver return code */
3221}
3222/*****************************************************************************
3223 * Name : HMSetThreadPriority
3224 * Purpose : router function for SetThreadPriority
3225 * Parameters:
3226 * Variables :
3227 * Result :
3228 * Remark :
3229 * Status :
3230 *
3231 * Author : SvL
3232 *****************************************************************************/
3233BOOL HMSetThreadPriority(HANDLE hThread, int priority)
3234{
3235 int iIndex; /* index into the handle table */
3236 BOOL lpResult; /* result from the device handler's API */
3237 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3238
3239 SetLastError(ERROR_SUCCESS);
3240 /* validate handle */
3241 iIndex = _HMHandleQuery(hThread); /* get the index */
3242 if (-1 == iIndex) /* error ? */
3243 {
3244 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3245 return FALSE; /* signal failure */
3246 }
3247
3248 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3249 lpResult = pHMHandle->pDeviceHandler->SetThreadPriority(&TabWin32Handles[iIndex].hmHandleData, priority);
3250
3251 return (lpResult); /* deliver return code */
3252}
3253/*****************************************************************************
3254 * Name : HMGetThreadContext
3255 * Purpose : router function for GetThreadContext
3256 * Parameters:
3257 * Variables :
3258 * Result :
3259 * Remark :
3260 * Status :
3261 *
3262 * Author : SvL
3263 *****************************************************************************/
3264BOOL HMGetThreadContext(HANDLE hThread, CONTEXT *lpContext)
3265{
3266 int iIndex; /* index into the handle table */
3267 BOOL lpResult; /* result from the device handler's API */
3268 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3269
3270 SetLastError(ERROR_SUCCESS);
3271 /* validate handle */
3272 iIndex = _HMHandleQuery(hThread); /* get the index */
3273 if (-1 == iIndex) /* error ? */
3274 {
3275 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3276 return FALSE; /* signal failure */
3277 }
3278
3279 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3280 lpResult = pHMHandle->pDeviceHandler->GetThreadContext(&TabWin32Handles[iIndex].hmHandleData, lpContext);
3281
3282 return (lpResult); /* deliver return code */
3283}
3284/*****************************************************************************
3285 * Name : HMSetThreadContext
3286 * Purpose : router function for SetThreadContext
3287 * Parameters:
3288 * Variables :
3289 * Result :
3290 * Remark :
3291 * Status :
3292 *
3293 * Author : SvL
3294 *****************************************************************************/
3295BOOL HMSetThreadContext(HANDLE hThread, const CONTEXT *lpContext)
3296{
3297 int iIndex; /* index into the handle table */
3298 BOOL lpResult; /* result from the device handler's API */
3299 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3300
3301 SetLastError(ERROR_SUCCESS);
3302 /* validate handle */
3303 iIndex = _HMHandleQuery(hThread); /* get the index */
3304 if (-1 == iIndex) /* error ? */
3305 {
3306 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3307 return FALSE; /* signal failure */
3308 }
3309
3310 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3311 lpResult = pHMHandle->pDeviceHandler->SetThreadContext(&TabWin32Handles[iIndex].hmHandleData, lpContext);
3312
3313 return (lpResult); /* deliver return code */
3314}
3315/*****************************************************************************
3316 * Name : HMTerminateThread
3317 * Purpose : router function for TerminateThread
3318 * Parameters:
3319 * Variables :
3320 * Result :
3321 * Remark :
3322 * Status :
3323 *
3324 * Author : SvL
3325 *****************************************************************************/
3326BOOL HMTerminateThread(HANDLE hThread, DWORD exitcode)
3327{
3328 int iIndex; /* index into the handle table */
3329 BOOL lpResult; /* result from the device handler's API */
3330 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3331
3332 SetLastError(ERROR_SUCCESS);
3333 /* validate handle */
3334 iIndex = _HMHandleQuery(hThread); /* get the index */
3335 if (-1 == iIndex) /* error ? */
3336 {
3337 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3338 return FALSE; /* signal failure */
3339 }
3340
3341 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3342 lpResult = pHMHandle->pDeviceHandler->TerminateThread(&TabWin32Handles[iIndex].hmHandleData, exitcode);
3343
3344 return (lpResult); /* deliver return code */
3345}
3346/*****************************************************************************
3347 * Name : HMResumeThread
3348 * Purpose : router function for ResumeThread
3349 * Parameters:
3350 * Variables :
3351 * Result :
3352 * Remark :
3353 * Status :
3354 *
3355 * Author : SvL
3356 *****************************************************************************/
3357DWORD HMResumeThread(HANDLE hThread)
3358{
3359 int iIndex; /* index into the handle table */
3360 DWORD lpResult; /* result from the device handler's API */
3361 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3362
3363 SetLastError(ERROR_SUCCESS);
3364 /* validate handle */
3365 iIndex = _HMHandleQuery(hThread); /* get the index */
3366 if (-1 == iIndex) /* error ? */
3367 {
3368 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3369 return -1; /* signal failure */
3370 }
3371
3372 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3373 lpResult = pHMHandle->pDeviceHandler->ResumeThread(&TabWin32Handles[iIndex].hmHandleData);
3374
3375 return (lpResult); /* deliver return code */
3376}
3377
3378/*****************************************************************************
3379 * Name : HMGetExitCodeThread
3380 * Purpose : router function for GetExitCodeThread
3381 * Parameters:
3382 * Variables :
3383 * Result :
3384 * Remark :
3385 * Status :
3386 *
3387 * Author : SvL
3388 *****************************************************************************/
3389BOOL HMGetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode)
3390{
3391 int iIndex; /* index into the handle table */
3392 BOOL lpResult; /* result from the device handler's API */
3393 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3394
3395 SetLastError(ERROR_SUCCESS);
3396 /* validate handle */
3397 iIndex = _HMHandleQuery(hThread); /* get the index */
3398 if (-1 == iIndex) /* error ? */
3399 {
3400 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3401 return FALSE; /* signal failure */
3402 }
3403
3404 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3405 lpResult = pHMHandle->pDeviceHandler->GetExitCodeThread(&TabWin32Handles[iIndex].hmHandleData, lpExitCode);
3406
3407 return (lpResult); /* deliver return code */
3408}
3409/*****************************************************************************
3410 * Name : HMSetThreadTerminated
3411 * Purpose :
3412 * Parameters:
3413 * Variables :
3414 * Result :
3415 * Remark :
3416 * Status :
3417 *
3418 * Author : SvL
3419 *****************************************************************************/
3420BOOL HMSetThreadTerminated(HANDLE hThread)
3421{
3422 int iIndex; /* index into the handle table */
3423 BOOL lpResult; /* result from the device handler's API */
3424 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3425
3426 SetLastError(ERROR_SUCCESS);
3427 /* validate handle */
3428 iIndex = _HMHandleQuery(hThread); /* get the index */
3429 if (-1 == iIndex) /* error ? */
3430 {
3431 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3432 return FALSE; /* signal failure */
3433 }
3434
3435 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3436 lpResult = pHMHandle->pDeviceHandler->SetThreadTerminated(&TabWin32Handles[iIndex].hmHandleData);
3437
3438 return (lpResult); /* deliver return code */
3439}
3440
3441/*****************************************************************************
3442 * Name : HMPeekNamedPipe
3443 * Purpose :
3444 * Parameters:
3445 * Variables :
3446 * Result :
3447 * Remark :
3448 * Status :
3449 *
3450 * Author : Przemyslaw Dobrowolski
3451 *****************************************************************************/
3452BOOL HMPeekNamedPipe(HANDLE hPipe,
3453 LPVOID lpvBuffer,
3454 DWORD cbBuffer,
3455 LPDWORD lpcbRead,
3456 LPDWORD lpcbAvail,
3457 LPDWORD lpcbMessage)
3458{
3459 int iIndex; /* index into the handle table */
3460 BOOL lpResult; /* result from the device handler's API */
3461 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3462
3463 SetLastError(ERROR_SUCCESS);
3464 /* validate handle */
3465 iIndex = _HMHandleQuery(hPipe); /* get the index */
3466 if (-1 == iIndex) /* error ? */
3467 {
3468 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3469 return FALSE; /* signal failure */
3470 }
3471
3472 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3473 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
3474 lpvBuffer,
3475 cbBuffer,
3476 lpcbRead,
3477 lpcbAvail,
3478 lpcbMessage);
3479
3480 return (lpResult); /* deliver return code */
3481}
3482
3483/*****************************************************************************
3484 * Name : HMCreateNamedPipe
3485 * Purpose :
3486 * Parameters:
3487 * Variables :
3488 * Result :
3489 * Remark :
3490 * Status :
3491 *
3492 * Author : Przemyslaw Dobrowolski
3493 *****************************************************************************/
3494DWORD HMCreateNamedPipe(LPCTSTR lpName,
3495 DWORD dwOpenMode,
3496 DWORD dwPipeMode,
3497 DWORD nMaxInstances,
3498 DWORD nOutBufferSize,
3499 DWORD nInBufferSize,
3500 DWORD nDefaultTimeOut,
3501 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
3502{
3503 int iIndex; /* index into the handle table */
3504 int iIndexNew; /* index into the handle table */
3505 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3506 PHMHANDLEDATA pHMHandleData;
3507 HANDLE rc; /* API return code */
3508
3509 SetLastError(ERROR_SUCCESS);
3510
3511 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */
3512
3513 iIndexNew = _HMHandleGetFree(); /* get free handle */
3514 if (-1 == iIndexNew) /* oops, no free handles ! */
3515 {
3516 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3517 return 0;
3518 }
3519
3520 /* initialize the complete HMHANDLEDATA structure */
3521 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
3522 pHMHandleData->dwType = FILE_TYPE_PIPE;
3523 pHMHandleData->dwAccess = 0;
3524 pHMHandleData->dwShare = 0;
3525 pHMHandleData->dwCreation = 0;
3526 pHMHandleData->dwFlags = 0;
3527 pHMHandleData->lpHandlerData = NULL;
3528
3529 /* we've got to mark the handle as occupied here, since another device */
3530 /* could be created within the device handler -> deadlock */
3531
3532 /* write appropriate entry into the handle table if open succeeded */
3533 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3534 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3535
3536 /* call the device handler */
3537
3538 rc = pDeviceHandler->CreateNamedPipe(&TabWin32Handles[iIndexNew].hmHandleData,
3539 lpName,dwOpenMode,
3540 dwPipeMode,nMaxInstances,
3541 nOutBufferSize,nInBufferSize,
3542 nDefaultTimeOut,lpSecurityAttributes);
3543
3544 if (rc == 0) /* oops, creation failed within the device handler */
3545 {
3546 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3547 return 0; /* signal error */
3548 }
3549
3550 dprintf(("Win32 Handle -> %08x",iIndexNew));
3551
3552 return iIndexNew;
3553}
3554
3555/*****************************************************************************
3556 * Name : HMConnectNamedPipe
3557 * Purpose :
3558 * Parameters:
3559 * Variables :
3560 * Result :
3561 * Remark :
3562 * Status :
3563 *
3564 * Author : Przemyslaw Dobrowolski
3565 *****************************************************************************/
3566BOOL HMConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED lpOverlapped)
3567{
3568 int iIndex; /* index into the handle table */
3569 BOOL lpResult; /* result from the device handler's API */
3570 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3571
3572 SetLastError(ERROR_SUCCESS);
3573 /* validate handle */
3574 iIndex = _HMHandleQuery(hPipe); /* get the index */
3575 if (-1 == iIndex) /* error ? */
3576 {
3577 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3578 return FALSE; /* signal failure */
3579 }
3580
3581 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3582 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
3583 lpOverlapped);
3584
3585 return (lpResult); /* deliver return code */
3586}
3587
3588/*****************************************************************************
3589 * Name : HMDisconnectNamedPipe
3590 * Purpose :
3591 * Parameters:
3592 * Variables :
3593 * Result :
3594 * Remark :
3595 * Status :
3596 *
3597 * Author : Przemyslaw Dobrowolski
3598 *****************************************************************************/
3599BOOL HMDisconnectNamedPipe(HANDLE hPipe)
3600{
3601 int iIndex; /* index into the handle table */
3602 BOOL lpResult; /* result from the device handler's API */
3603 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3604
3605 SetLastError(ERROR_SUCCESS);
3606 /* validate handle */
3607 iIndex = _HMHandleQuery(hPipe); /* get the index */
3608 if (-1 == iIndex) /* error ? */
3609 {
3610 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3611 return FALSE; /* signal failure */
3612 }
3613
3614 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3615 lpResult = pHMHandle->pDeviceHandler->DisconnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData);
3616
3617 return (lpResult); /* deliver return code */
3618}
3619
3620/*****************************************************************************
3621 * Name : HMGetNamedPipeHandleState
3622 * Purpose :
3623 * Parameters:
3624 * Variables :
3625 * Result :
3626 * Remark :
3627 * Status :
3628 *
3629 * Author : Przemyslaw Dobrowolski
3630 *****************************************************************************/
3631BOOL HMGetNamedPipeHandleState(HANDLE hPipe,
3632 LPDWORD lpState,
3633 LPDWORD lpCurInstances,
3634 LPDWORD lpMaxCollectionCount,
3635 LPDWORD lpCollectDataTimeout,
3636 LPTSTR lpUserName,
3637 DWORD nMaxUserNameSize)
3638{
3639 int iIndex; /* index into the handle table */
3640 BOOL lpResult; /* result from the device handler's API */
3641 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3642
3643 SetLastError(ERROR_SUCCESS);
3644 /* validate handle */
3645 iIndex = _HMHandleQuery(hPipe); /* get the index */
3646 if (-1 == iIndex) /* error ? */
3647 {
3648 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3649 return FALSE; /* signal failure */
3650 }
3651
3652 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3653 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData,
3654 lpState,
3655 lpCurInstances,
3656 lpMaxCollectionCount,
3657 lpCollectDataTimeout,
3658 lpUserName,
3659 nMaxUserNameSize);
3660
3661
3662 return (lpResult); /* deliver return code */
3663}
3664
3665/*****************************************************************************
3666 * Name : HMGetNamedPipeInfo
3667 * Purpose :
3668 * Parameters:
3669 * Variables :
3670 * Result :
3671 * Remark :
3672 * Status :
3673 *
3674 * Author : Przemyslaw Dobrowolski
3675 *****************************************************************************/
3676BOOL HMGetNamedPipeInfo(HANDLE hPipe,
3677 LPDWORD lpFlags,
3678 LPDWORD lpOutBufferSize,
3679 LPDWORD lpInBufferSize,
3680 LPDWORD lpMaxInstances)
3681{
3682 int iIndex; /* index into the handle table */
3683 BOOL lpResult; /* result from the device handler's API */
3684 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3685
3686 SetLastError(ERROR_SUCCESS);
3687 /* validate handle */
3688 iIndex = _HMHandleQuery(hPipe); /* get the index */
3689 if (-1 == iIndex) /* error ? */
3690 {
3691 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3692 return FALSE; /* signal failure */
3693 }
3694
3695 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3696 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeInfo(&TabWin32Handles[iIndex].hmHandleData,
3697 lpFlags,
3698 lpOutBufferSize,
3699 lpInBufferSize,
3700 lpMaxInstances);
3701
3702 return (lpResult); /* deliver return code */
3703}
3704
3705/*****************************************************************************
3706 * Name : HMTransactNamedPipe
3707 * Purpose :
3708 * Parameters:
3709 * Variables :
3710 * Result :
3711 * Remark :
3712 * Status :
3713 *
3714 * Author : Przemyslaw Dobrowolski
3715 *****************************************************************************/
3716DWORD HMTransactNamedPipe(HANDLE hPipe,
3717 LPVOID lpvWriteBuf,
3718 DWORD cbWriteBuf,
3719 LPVOID lpvReadBuf,
3720 DWORD cbReadBuf,
3721 LPDWORD lpcbRead,
3722 LPOVERLAPPED lpo)
3723{
3724 int iIndex; /* index into the handle table */
3725 DWORD lpResult; /* result from the device handler's API */
3726 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3727
3728 SetLastError(ERROR_SUCCESS);
3729 /* validate handle */
3730 iIndex = _HMHandleQuery(hPipe); /* get the index */
3731 if (-1 == iIndex) /* error ? */
3732 {
3733 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3734 return FALSE; /* signal failure */
3735 }
3736
3737 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3738 lpResult = pHMHandle->pDeviceHandler->TransactNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
3739 lpvWriteBuf,
3740 cbWriteBuf,
3741 lpvReadBuf,
3742 cbReadBuf,
3743 lpcbRead,
3744 lpo);
3745
3746 return (lpResult); /* deliver return code */
3747}
3748
3749/*****************************************************************************
3750 * Name : HMSetNamedPipeHandleState
3751 * Purpose :
3752 * Parameters:
3753 * Variables :
3754 * Result :
3755 * Remark :
3756 * Status :
3757 *
3758 * Author : Przemyslaw Dobrowolski
3759 *****************************************************************************/
3760BOOL HMSetNamedPipeHandleState(HANDLE hPipe,
3761 LPDWORD lpdwMode,
3762 LPDWORD lpcbMaxCollect,
3763 LPDWORD lpdwCollectDataTimeout)
3764{
3765 int iIndex; /* index into the handle table */
3766 BOOL lpResult; /* result from the device handler's API */
3767 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3768
3769 SetLastError(ERROR_SUCCESS);
3770 /* validate handle */
3771 iIndex = _HMHandleQuery(hPipe); /* get the index */
3772 if (-1 == iIndex) /* error ? */
3773 {
3774 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3775 return FALSE; /* signal failure */
3776 }
3777
3778 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3779 lpResult = pHMHandle->pDeviceHandler->SetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData,
3780 lpdwMode,
3781 lpcbMaxCollect,
3782 lpdwCollectDataTimeout);
3783
3784 return (lpResult); /* deliver return code */
3785}
3786
3787/*****************************************************************************
3788 * Name : HMCreatePipe
3789 * Purpose :
3790 * Parameters:
3791 * Variables :
3792 * Result :
3793 * Remark :
3794 * Status : NOT TESTED!
3795 *
3796 * Author : Przemyslaw Dobrowolski
3797 *****************************************************************************/
3798BOOL HMCreatePipe(PHANDLE phRead,
3799 PHANDLE phWrite,
3800 LPSECURITY_ATTRIBUTES lpsa,
3801 DWORD cbPipe)
3802{
3803 int iIndex; /* index into the handle table */
3804 int iIndexNewRead; /* index into the handle table */
3805 int iIndexNewWrite; /* index into the handle table */
3806 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3807 PHMHANDLEDATA pHMHandleData;
3808 HANDLE rc; /* API return code */
3809
3810 SetLastError(ERROR_SUCCESS);
3811
3812 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */
3813
3814 iIndexNewRead = _HMHandleGetFree(); /* get free handle */
3815 if (-1 == iIndexNewRead) /* oops, no free handles ! */
3816 {
3817 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3818 return 0;
3819 }
3820
3821 iIndexNewWrite = _HMHandleGetFree(); /* get free handle */
3822 if (-1 == iIndexNewWrite) /* oops, no free handles ! */
3823 {
3824 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3825 return 0;
3826 }
3827
3828
3829 /* initialize the complete HMHANDLEDATA structure */
3830 pHMHandleData = &TabWin32Handles[iIndexNewRead].hmHandleData;
3831 pHMHandleData->dwType = FILE_TYPE_PIPE;
3832 pHMHandleData->dwAccess = 0;
3833 pHMHandleData->dwShare = 0;
3834 pHMHandleData->dwCreation = 0;
3835 pHMHandleData->dwFlags = 0;
3836 pHMHandleData->lpHandlerData = NULL;
3837
3838 /* we've got to mark the handle as occupied here, since another device */
3839 /* could be created within the device handler -> deadlock */
3840
3841 /* write appropriate entry into the handle table if open succeeded */
3842 TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = iIndexNewRead;
3843 TabWin32Handles[iIndexNewRead].pDeviceHandler = pDeviceHandler;
3844
3845 /* initialize the complete HMHANDLEDATA structure */
3846 pHMHandleData = &TabWin32Handles[iIndexNewWrite].hmHandleData;
3847 pHMHandleData->dwType = FILE_TYPE_PIPE;
3848 pHMHandleData->dwAccess = 0;
3849 pHMHandleData->dwShare = 0;
3850 pHMHandleData->dwCreation = 0;
3851 pHMHandleData->dwFlags = 0;
3852 pHMHandleData->lpHandlerData = NULL;
3853
3854 /* we've got to mark the handle as occupied here, since another device */
3855 /* could be created within the device handler -> deadlock */
3856
3857 /* write appropriate entry into the handle table if open succeeded */
3858 TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = iIndexNewWrite;
3859 TabWin32Handles[iIndexNewWrite].pDeviceHandler = pDeviceHandler;
3860 /* call the device handler */
3861
3862 rc = pDeviceHandler->CreatePipe(&TabWin32Handles[iIndexNewRead].hmHandleData,
3863 &TabWin32Handles[iIndexNewWrite].hmHandleData,
3864 lpsa,
3865 cbPipe);
3866
3867 if (rc == 0) /* oops, creation failed within the device handler */
3868 {
3869 TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3870 TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3871 return FALSE; /* signal error */
3872 }
3873
3874 *phRead = iIndexNewRead;
3875 *phWrite = iIndexNewWrite;
3876
3877 return TRUE;
3878}
Note: See TracBrowser for help on using the repository browser.