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

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

heap corruption fix (initcommandline) + handlemanager class for disks

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