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

Last change on this file since 6049 was 6049, checked in by sandervl, 24 years ago

semaphore rewrite (not activated)

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