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

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

added cdrom get/setvolume ioctls

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