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

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

semaphore updates

File size: 188.4 KB
Line 
1/* $Id: HandleManager.cpp,v 1.68 2001-06-23 16:59:26 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 return (rc); // OK, done
3101#endif
3102}
3103/*****************************************************************************
3104 * Name : HMDeviceIoControl
3105 * Purpose : router function for DeviceIoControl
3106 * Parameters:
3107 * Variables :
3108 * Result :
3109 * Remark :
3110 * Status :
3111 *
3112 * Author : Sander van Leeuwen
3113 *****************************************************************************/
3114
3115BOOL HMDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
3116 LPVOID lpInBuffer, DWORD nInBufferSize,
3117 LPVOID lpOutBuffer, DWORD nOutBufferSize,
3118 LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
3119{
3120 int iIndex; /* index into the handle table */
3121 BOOL fResult; /* result from the device handler's CloseHandle() */
3122 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3123
3124 /* validate handle */
3125 iIndex = _HMHandleQuery(hDevice); /* get the index */
3126 if (-1 == iIndex) /* error ? */
3127 {
3128 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3129 return (FALSE); /* signal failure */
3130 }
3131
3132 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3133 fResult = pHMHandle->pDeviceHandler->DeviceIoControl(&pHMHandle->hmHandleData,
3134 dwIoControlCode,
3135 lpInBuffer, nInBufferSize,
3136 lpOutBuffer, nOutBufferSize,
3137 lpBytesReturned, lpOverlapped);
3138
3139 return (fResult); /* deliver return code */
3140}
3141
3142
3143
3144/*****************************************************************************
3145 * Name : HMCOMGetCommState
3146 * Purpose : router function for GetCommState
3147 * Parameters:
3148 * Variables :
3149 * Result :
3150 * Remark :
3151 * Status :
3152 *
3153 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40]
3154 *****************************************************************************/
3155
3156BOOL HMCommGetCommState(HANDLE hCommDev, LPDCB lpdcb)
3157{
3158 int iIndex; /* index into the handle table */
3159 BOOL bResult; /* result from the device handler's API */
3160 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3161
3162 /* validate handle */
3163 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3164 if (-1 == iIndex) /* error ? */
3165 {
3166 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3167 return (NULL); /* signal failure */
3168 }
3169
3170 if(IsBadWritePtr(lpdcb,sizeof(DCB)))
3171 {
3172 SetLastError(ERROR_INVALID_PARAMETER);
3173 return FALSE;
3174 }
3175
3176 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3177 bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData,
3178 lpdcb);
3179
3180 return (bResult); /* deliver return code */
3181}
3182
3183BOOL HMCommWaitCommEvent( HANDLE hCommDev,
3184 LPDWORD lpfdwEvtMask,
3185 LPOVERLAPPED lpo)
3186{
3187 int iIndex; /* index into the handle table */
3188 BOOL bResult; /* result from the device handler's API */
3189 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3190
3191 /* validate handle */
3192 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3193 if (-1 == iIndex) /* error ? */
3194 {
3195 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3196 return FALSE; /* signal failure */
3197 }
3198
3199 if(NULL!=lpo && IsBadReadPtr(lpo,sizeof(OVERLAPPED)) )
3200 {
3201 SetLastError(ERROR_INVALID_PARAMETER);
3202 return FALSE;
3203 }
3204
3205 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3206 bResult = pHMHandle->pDeviceHandler->WaitCommEvent( &pHMHandle->hmHandleData,
3207 lpfdwEvtMask,
3208 lpo);
3209
3210 return (bResult); /* deliver return code */
3211}
3212
3213BOOL HMCommGetCommProperties( HANDLE hCommDev,
3214 LPCOMMPROP lpcmmp)
3215{
3216 int iIndex; /* index into the handle table */
3217 BOOL bResult; /* result from the device handler's API */
3218 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3219
3220 /* validate handle */
3221 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3222 if (-1 == iIndex) /* error ? */
3223 {
3224 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3225 return (NULL); /* signal failure */
3226 }
3227
3228 if(IsBadWritePtr(lpcmmp,sizeof(COMMPROP)) )
3229 {
3230 SetLastError(ERROR_INVALID_PARAMETER);
3231 return FALSE;
3232 }
3233
3234 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3235 bResult = pHMHandle->pDeviceHandler->GetCommProperties( &pHMHandle->hmHandleData,
3236 lpcmmp);
3237
3238 return (bResult); /* deliver return code */
3239}
3240
3241BOOL HMCommGetCommMask( HANDLE hCommDev,
3242 LPDWORD lpfdwEvtMask)
3243{
3244 int iIndex; /* index into the handle table */
3245 BOOL bResult; /* result from the device handler's API */
3246 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3247
3248 /* validate handle */
3249 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3250 if (-1 == iIndex) /* error ? */
3251 {
3252 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3253 return (NULL); /* signal failure */
3254 }
3255
3256 if(IsBadWritePtr(lpfdwEvtMask,sizeof(DWORD)) )
3257 {
3258 SetLastError(ERROR_INVALID_PARAMETER);
3259 return FALSE;
3260 }
3261
3262 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3263 bResult = pHMHandle->pDeviceHandler->GetCommMask( &pHMHandle->hmHandleData,
3264 lpfdwEvtMask);
3265
3266 return (bResult); /* deliver return code */
3267}
3268
3269BOOL HMCommSetCommMask( HANDLE hCommDev,
3270 DWORD fdwEvtMask)
3271{
3272 int iIndex; /* index into the handle table */
3273 BOOL bResult; /* result from the device handler's API */
3274 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3275
3276 /* validate handle */
3277 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3278 if (-1 == iIndex) /* error ? */
3279 {
3280 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3281 return (NULL); /* signal failure */
3282 }
3283
3284 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3285 bResult = pHMHandle->pDeviceHandler->SetCommMask( &pHMHandle->hmHandleData,
3286 fdwEvtMask);
3287
3288 return (bResult); /* deliver return code */
3289}
3290
3291BOOL HMCommPurgeComm( HANDLE hCommDev,
3292 DWORD fdwAction)
3293{
3294 int iIndex; /* index into the handle table */
3295 BOOL bResult; /* result from the device handler's API */
3296 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3297
3298 /* validate handle */
3299 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3300 if (-1 == iIndex) /* error ? */
3301 {
3302 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3303 return (NULL); /* signal failure */
3304 }
3305
3306
3307 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3308 bResult = pHMHandle->pDeviceHandler->PurgeComm( &pHMHandle->hmHandleData,
3309 fdwAction);
3310
3311 return (bResult); /* deliver return code */
3312}
3313
3314BOOL HMCommClearCommError( HANDLE hCommDev,
3315 LPDWORD lpdwErrors,
3316 LPCOMSTAT lpcst)
3317{
3318 int iIndex; /* index into the handle table */
3319 BOOL bResult; /* result from the device handler's API */
3320 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3321
3322 /* validate handle */
3323 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3324 if (-1 == iIndex) /* error ? */
3325 {
3326 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3327 return (NULL); /* signal failure */
3328 }
3329
3330 if(IsBadWritePtr(lpdwErrors,sizeof(DWORD)) ||
3331 (NULL!=lpcst && IsBadWritePtr(lpcst,sizeof(COMSTAT)) ) )
3332 {
3333 SetLastError(ERROR_INVALID_PARAMETER);
3334 return FALSE;
3335 }
3336
3337 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3338 bResult = pHMHandle->pDeviceHandler->ClearCommError(&pHMHandle->hmHandleData,
3339 lpdwErrors,
3340 lpcst);
3341
3342 return (bResult); /* deliver return code */
3343}
3344
3345BOOL HMCommSetCommState( HANDLE hCommDev,
3346 LPDCB lpdcb)
3347{
3348 int iIndex; /* index into the handle table */
3349 BOOL bResult; /* result from the device handler's API */
3350 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3351
3352 /* validate handle */
3353 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3354 if (-1 == iIndex) /* error ? */
3355 {
3356 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3357 return (NULL); /* signal failure */
3358 }
3359
3360 if(IsBadReadPtr(lpdcb,sizeof(DCB)) )
3361 {
3362 SetLastError(ERROR_INVALID_PARAMETER);
3363 return FALSE;
3364 }
3365
3366
3367 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3368 bResult = pHMHandle->pDeviceHandler->SetCommState(&pHMHandle->hmHandleData,
3369 lpdcb);
3370
3371 return (bResult); /* deliver return code */
3372}
3373
3374
3375BOOL HMCommGetCommTimeouts( HANDLE hCommDev,
3376 LPCOMMTIMEOUTS lpctmo)
3377{
3378 int iIndex; /* index into the handle table */
3379 BOOL bResult; /* result from the device handler's API */
3380 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3381
3382 /* validate handle */
3383 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3384 if (-1 == iIndex) /* error ? */
3385 {
3386 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3387 return (NULL); /* signal failure */
3388 }
3389
3390 if(IsBadWritePtr(lpctmo,sizeof(COMMTIMEOUTS)) )
3391 {
3392 SetLastError(ERROR_INVALID_PARAMETER);
3393 return FALSE;
3394 }
3395
3396 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3397 bResult = pHMHandle->pDeviceHandler->GetCommTimeouts( &pHMHandle->hmHandleData,
3398 lpctmo);
3399
3400 return (bResult); /* deliver return code */
3401}
3402BOOL HMCommGetCommModemStatus( HANDLE hCommDev,
3403 LPDWORD lpModemStat )
3404{
3405 int iIndex; /* index into the handle table */
3406 BOOL bResult; /* result from the device handler's API */
3407 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3408
3409 /* validate handle */
3410 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3411 if (-1 == iIndex) /* error ? */
3412 {
3413 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3414 return (NULL); /* signal failure */
3415 }
3416
3417 if(IsBadWritePtr(lpModemStat,sizeof(DWORD)) )
3418 {
3419 SetLastError(ERROR_INVALID_PARAMETER);
3420 return FALSE;
3421 }
3422
3423 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3424 bResult = pHMHandle->pDeviceHandler->GetCommModemStatus( &pHMHandle->hmHandleData,
3425 lpModemStat);
3426
3427 return (bResult); /* deliver return code */
3428}
3429
3430BOOL HMCommSetCommTimeouts( HANDLE hCommDev,
3431 LPCOMMTIMEOUTS lpctmo)
3432{
3433 int iIndex; /* index into the handle table */
3434 BOOL bResult; /* result from the device handler's API */
3435 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3436
3437 /* validate handle */
3438 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3439 if (-1 == iIndex) /* error ? */
3440 {
3441 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3442 return (NULL); /* signal failure */
3443 }
3444
3445 if(IsBadReadPtr(lpctmo,sizeof(COMMTIMEOUTS)) )
3446 {
3447 SetLastError(ERROR_INVALID_PARAMETER);
3448 return FALSE;
3449 }
3450
3451 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3452 bResult = pHMHandle->pDeviceHandler->SetCommTimeouts( &pHMHandle->hmHandleData,
3453 lpctmo);
3454
3455 return (bResult); /* deliver return code */
3456}
3457
3458BOOL HMCommTransmitCommChar( HANDLE hCommDev,
3459 CHAR cChar )
3460{
3461 int iIndex; /* index into the handle table */
3462 BOOL bResult; /* result from the device handler's API */
3463 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3464
3465 /* validate handle */
3466 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3467 if (-1 == iIndex) /* error ? */
3468 {
3469 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3470 return (NULL); /* signal failure */
3471 }
3472
3473 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3474 bResult = pHMHandle->pDeviceHandler->TransmitCommChar( &pHMHandle->hmHandleData,
3475 cChar);
3476
3477 return (bResult); /* deliver return code */
3478}
3479
3480BOOL HMCommSetCommConfig( HANDLE hCommDev,
3481 LPCOMMCONFIG lpCC,
3482 DWORD dwSize )
3483{
3484 int iIndex; /* index into the handle table */
3485 BOOL bResult; /* result from the device handler's API */
3486 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3487
3488 /* validate handle */
3489 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3490 if (-1 == iIndex) /* error ? */
3491 {
3492 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3493 return (NULL); /* signal failure */
3494 }
3495
3496 if( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||
3497 dwSize < sizeof(COMMCONFIG) )
3498 {
3499 SetLastError(ERROR_INVALID_PARAMETER);
3500 return FALSE;
3501 }
3502
3503 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3504 bResult = pHMHandle->pDeviceHandler->SetCommConfig( &pHMHandle->hmHandleData,
3505 lpCC,
3506 dwSize);
3507
3508 return (bResult); /* deliver return code */
3509}
3510
3511BOOL HMCommSetCommBreak( HANDLE hCommDev )
3512{
3513 int iIndex; /* index into the handle table */
3514 BOOL bResult; /* result from the device handler's API */
3515 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3516
3517 /* validate handle */
3518 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3519 if (-1 == iIndex) /* error ? */
3520 {
3521 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3522 return (NULL); /* signal failure */
3523 }
3524
3525 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3526 bResult = pHMHandle->pDeviceHandler->SetCommBreak( &pHMHandle->hmHandleData);
3527
3528 return (bResult); /* deliver return code */
3529}
3530
3531BOOL HMCommGetCommConfig( HANDLE hCommDev,
3532 LPCOMMCONFIG lpCC,
3533 LPDWORD lpdwSize )
3534{
3535 int iIndex; /* index into the handle table */
3536 BOOL bResult; /* result from the device handler's API */
3537 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3538
3539 /* validate handle */
3540 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3541 if (-1 == iIndex) /* error ? */
3542 {
3543 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3544 return (NULL); /* signal failure */
3545 }
3546
3547 if(IsBadWritePtr(lpdwSize,sizeof(DWORD)) )
3548 {
3549 SetLastError(ERROR_INVALID_PARAMETER);
3550 return FALSE;
3551 }
3552
3553 if( IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
3554 *lpdwSize< sizeof(COMMCONFIG) )
3555 {
3556 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3557 *lpdwSize= sizeof(COMMCONFIG);
3558 return FALSE;
3559 }
3560
3561 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3562 bResult = pHMHandle->pDeviceHandler->GetCommConfig( &pHMHandle->hmHandleData,
3563 lpCC,
3564 lpdwSize);
3565
3566 return (bResult); /* deliver return code */
3567}
3568
3569BOOL HMCommEscapeCommFunction( HANDLE hCommDev,
3570 UINT dwFunc )
3571{
3572 int iIndex; /* index into the handle table */
3573 BOOL bResult; /* result from the device handler's API */
3574 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3575
3576 /* validate handle */
3577 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3578 if (-1 == iIndex) /* error ? */
3579 {
3580 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3581 return (NULL); /* signal failure */
3582 }
3583
3584 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3585
3586 switch(dwFunc)
3587 {
3588 case CLRDTR:
3589 case CLRRTS:
3590 case SETDTR:
3591 case SETRTS:
3592 case SETXOFF:
3593 case SETXON:
3594 bResult = pHMHandle->pDeviceHandler->EscapeCommFunction( &pHMHandle->hmHandleData,
3595 dwFunc);
3596 break;
3597 case SETBREAK:
3598 bResult = pHMHandle->pDeviceHandler->SetCommBreak(&pHMHandle->hmHandleData);
3599 break;
3600 case CLRBREAK:
3601 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);
3602 break;
3603 default:
3604 SetLastError(ERROR_INVALID_PARAMETER);
3605 bResult = FALSE;
3606 }
3607
3608
3609 return (bResult); /* deliver return code */
3610}
3611
3612BOOL HMCommSetupComm( HANDLE hCommDev,
3613 DWORD dwInQueue,
3614 DWORD dwOutQueue)
3615{
3616 int iIndex; /* index into the handle table */
3617 BOOL bResult; /* result from the device handler's API */
3618 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3619
3620 /* validate handle */
3621 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3622 if (-1 == iIndex) /* error ? */
3623 {
3624 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3625 return (NULL); /* signal failure */
3626 }
3627
3628 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3629 bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,
3630 dwInQueue,
3631 dwOutQueue);
3632
3633 return (bResult); /* deliver return code */
3634}
3635
3636BOOL HMCommClearCommBreak(HANDLE hCommDev)
3637{
3638 int iIndex; /* index into the handle table */
3639 BOOL bResult; /* result from the device handler's API */
3640 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3641
3642 /* validate handle */
3643 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3644 if (-1 == iIndex) /* error ? */
3645 {
3646 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3647 return (NULL); /* signal failure */
3648 }
3649
3650 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3651 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);
3652
3653 return (bResult); /* deliver return code */
3654}
3655
3656BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev,
3657 LPCOMMCONFIG lpCC,
3658 DWORD dwSize)
3659{
3660 int iIndex; /* index into the handle table */
3661 BOOL bResult; /* result from the device handler's API */
3662 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3663
3664 /* validate handle */
3665 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3666 if (-1 == iIndex) /* error ? */
3667 {
3668 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3669 return (NULL); /* signal failure */
3670 }
3671
3672 if( (lpCC!=NULL) &&
3673 ( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||
3674 dwSize != sizeof(COMMCONFIG) ) )
3675 {
3676 SetLastError(ERROR_INVALID_PARAMETER);
3677 return FALSE;
3678 }
3679
3680 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3681 bResult = pHMHandle->pDeviceHandler->SetDefaultCommConfig(&pHMHandle->hmHandleData,
3682 lpCC,
3683 dwSize);
3684
3685 return (bResult); /* deliver return code */
3686}
3687
3688BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev,
3689 LPCOMMCONFIG lpCC,
3690 LPDWORD lpdwSize)
3691{
3692 int iIndex; /* index into the handle table */
3693 BOOL bResult; /* result from the device handler's API */
3694 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3695
3696 /* validate handle */
3697 iIndex = _HMHandleQuery(hCommDev); /* get the index */
3698 if (-1 == iIndex) /* error ? */
3699 {
3700 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3701 return (NULL); /* signal failure */
3702 }
3703
3704 if(IsBadWritePtr(lpdwSize,sizeof(DWORD)))
3705 {
3706 SetLastError(ERROR_INVALID_PARAMETER);
3707 return FALSE;
3708 }
3709
3710 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3711 bResult = pHMHandle->pDeviceHandler->GetDefaultCommConfig( &pHMHandle->hmHandleData,
3712 lpCC,
3713 lpdwSize);
3714
3715 return (bResult); /* deliver return code */
3716}
3717
3718/*****************************************************************************
3719 * Name : HMOpenThreadToken
3720 * Purpose : router function for NtOpenThreadToken
3721 * Parameters:
3722 * Variables :
3723 * Result :
3724 * Remark :
3725 * Status :
3726 *
3727 * Author : SvL
3728 *****************************************************************************/
3729
3730DWORD HMOpenThreadToken(HANDLE ThreadHandle,
3731 DWORD DesiredAccess,
3732 DWORD OpenAsSelf,
3733 HANDLE *TokenHandle)
3734{
3735 int iIndex; /* index into the handle table */
3736 int iIndexNew; /* index into the handle table */
3737 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3738 PHMHANDLEDATA pHMHandleData;
3739 DWORD rc; /* API return code */
3740
3741 pDeviceHandler = HMGlobals.pHMToken; /* device is predefined */
3742
3743 iIndexNew = _HMHandleGetFree(); /* get free handle */
3744 if (-1 == iIndexNew) /* oops, no free handles ! */
3745 {
3746 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3747 return ERROR_NOT_ENOUGH_MEMORY;
3748 }
3749
3750 /* initialize the complete HMHANDLEDATA structure */
3751 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
3752 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
3753 pHMHandleData->dwAccess = DesiredAccess;
3754 pHMHandleData->dwShare = 0;
3755 pHMHandleData->dwCreation = 0;
3756 pHMHandleData->dwFlags = 0;
3757 pHMHandleData->lpHandlerData = NULL;
3758
3759
3760 /* we've got to mark the handle as occupied here, since another device */
3761 /* could be created within the device handler -> deadlock */
3762
3763 /* write appropriate entry into the handle table if open succeeded */
3764 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3765 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3766
3767 /* call the device handler */
3768
3769 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
3770 // a valid HandleManager-internal handle!
3771 rc = pDeviceHandler->OpenThreadToken(&TabWin32Handles[iIndexNew].hmHandleData,
3772 ThreadHandle,
3773 OpenAsSelf);
3774
3775 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
3776 {
3777 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3778 return (rc); /* signal error */
3779 }
3780 else
3781 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
3782
3783 *TokenHandle = iIndexNew; /* return valid handle */
3784 return STATUS_SUCCESS;
3785}
3786
3787/*****************************************************************************
3788 * Name : HMOpenProcessToken
3789 * Purpose : router function for NtOpenProcessToken
3790 * Parameters:
3791 * Variables :
3792 * Result :
3793 * Remark :
3794 * Status :
3795 *
3796 * Author : SvL
3797 *****************************************************************************/
3798DWORD HMOpenProcessToken(HANDLE ProcessHandle,
3799 DWORD DesiredAccess,
3800 DWORD dwUserData,
3801 HANDLE *TokenHandle)
3802{
3803 int iIndex; /* index into the handle table */
3804 int iIndexNew; /* index into the handle table */
3805 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3806 PHMHANDLEDATA pHMHandleData;
3807 DWORD rc; /* API return code */
3808
3809 pDeviceHandler = HMGlobals.pHMToken; /* device is predefined */
3810
3811 iIndexNew = _HMHandleGetFree(); /* get free handle */
3812 if (-1 == iIndexNew) /* oops, no free handles ! */
3813 {
3814 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3815 return ERROR_NOT_ENOUGH_MEMORY;
3816 }
3817
3818 /* initialize the complete HMHANDLEDATA structure */
3819 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
3820 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
3821 pHMHandleData->dwAccess = DesiredAccess;
3822 pHMHandleData->dwShare = 0;
3823 pHMHandleData->dwCreation = 0;
3824 pHMHandleData->dwFlags = 0;
3825 pHMHandleData->lpHandlerData = NULL;
3826
3827
3828 /* we've got to mark the handle as occupied here, since another device */
3829 /* could be created within the device handler -> deadlock */
3830
3831 /* write appropriate entry into the handle table if open succeeded */
3832 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3833 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3834
3835 /* call the device handler */
3836
3837 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
3838 // a valid HandleManager-internal handle!
3839 rc = pDeviceHandler->OpenProcessToken(&TabWin32Handles[iIndexNew].hmHandleData,
3840 dwUserData,
3841 ProcessHandle);
3842
3843 if (rc != NO_ERROR) /* oops, creation failed within the device handler */
3844 {
3845 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3846 return (rc); /* signal error */
3847 }
3848 else
3849 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
3850
3851 *TokenHandle = iIndexNew; /* return valid handle */
3852 return STATUS_SUCCESS;
3853}
3854/*****************************************************************************
3855 * Name : HMCreateThread
3856 * Purpose : router function for CreateThread
3857 * Parameters:
3858 * Variables :
3859 * Result :
3860 * Remark :
3861 * Status :
3862 *
3863 * Author : SvL
3864 *****************************************************************************/
3865HANDLE HMCreateThread(LPSECURITY_ATTRIBUTES lpsa,
3866 DWORD cbStack,
3867 LPTHREAD_START_ROUTINE lpStartAddr,
3868 LPVOID lpvThreadParm,
3869 DWORD fdwCreate,
3870 LPDWORD lpIDThread,
3871 BOOL fFirstThread)
3872{
3873 int iIndex; /* index into the handle table */
3874 int iIndexNew; /* index into the handle table */
3875 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
3876 PHMHANDLEDATA pHMHandleData;
3877 HANDLE rc; /* API return code */
3878
3879 SetLastError(ERROR_SUCCESS);
3880
3881 pDeviceHandler = HMGlobals.pHMThread; /* device is predefined */
3882
3883 iIndexNew = _HMHandleGetFree(); /* get free handle */
3884 if (-1 == iIndexNew) /* oops, no free handles ! */
3885 {
3886 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
3887 return 0;
3888 }
3889
3890 /* initialize the complete HMHANDLEDATA structure */
3891 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
3892 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
3893 pHMHandleData->dwAccess = 0;
3894 pHMHandleData->dwShare = 0;
3895 pHMHandleData->dwCreation = 0;
3896 pHMHandleData->dwFlags = 0;
3897 pHMHandleData->lpHandlerData = NULL;
3898
3899
3900 /* we've got to mark the handle as occupied here, since another device */
3901 /* could be created within the device handler -> deadlock */
3902
3903 /* write appropriate entry into the handle table if open succeeded */
3904 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
3905 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
3906
3907 /* call the device handler */
3908
3909 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
3910 // a valid HandleManager-internal handle!
3911 rc = pDeviceHandler->CreateThread(&TabWin32Handles[iIndexNew].hmHandleData,
3912 lpsa, cbStack, lpStartAddr,
3913 lpvThreadParm, fdwCreate, lpIDThread, fFirstThread);
3914
3915 if (rc == 0) /* oops, creation failed within the device handler */
3916 {
3917 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
3918 return 0; /* signal error */
3919 }
3920
3921 return iIndexNew;
3922}
3923/*****************************************************************************
3924 * Name : HMGetThreadPriority
3925 * Purpose : router function for GetThreadPriority
3926 * Parameters:
3927 * Variables :
3928 * Result :
3929 * Remark :
3930 * Status :
3931 *
3932 * Author : SvL
3933 *****************************************************************************/
3934INT HMGetThreadPriority(HANDLE hThread)
3935{
3936 int iIndex; /* index into the handle table */
3937 INT lpResult; /* result from the device handler's API */
3938 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3939
3940 SetLastError(ERROR_SUCCESS);
3941 /* validate handle */
3942 iIndex = _HMHandleQuery(hThread); /* get the index */
3943 if (-1 == iIndex) /* error ? */
3944 {
3945 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3946 return (-1); /* signal failure */
3947 }
3948
3949 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3950 lpResult = pHMHandle->pDeviceHandler->GetThreadPriority(&TabWin32Handles[iIndex].hmHandleData);
3951
3952 return (lpResult); /* deliver return code */
3953}
3954/*****************************************************************************
3955 * Name : HMSuspendThread
3956 * Purpose : router function for SuspendThread
3957 * Parameters:
3958 * Variables :
3959 * Result :
3960 * Remark :
3961 * Status :
3962 *
3963 * Author : SvL
3964 *****************************************************************************/
3965DWORD HMSuspendThread(HANDLE hThread)
3966{
3967 int iIndex; /* index into the handle table */
3968 HANDLE lpResult; /* result from the device handler's API */
3969 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
3970
3971 SetLastError(ERROR_SUCCESS);
3972 /* validate handle */
3973 iIndex = _HMHandleQuery(hThread); /* get the index */
3974 if (-1 == iIndex) /* error ? */
3975 {
3976 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
3977 return -1; /* signal failure */
3978 }
3979
3980 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
3981 lpResult = pHMHandle->pDeviceHandler->SuspendThread(&TabWin32Handles[iIndex].hmHandleData);
3982
3983 return (lpResult); /* deliver return code */
3984}
3985/*****************************************************************************
3986 * Name : HMSetThreadPriority
3987 * Purpose : router function for SetThreadPriority
3988 * Parameters:
3989 * Variables :
3990 * Result :
3991 * Remark :
3992 * Status :
3993 *
3994 * Author : SvL
3995 *****************************************************************************/
3996BOOL HMSetThreadPriority(HANDLE hThread, int priority)
3997{
3998 int iIndex; /* index into the handle table */
3999 BOOL lpResult; /* result from the device handler's API */
4000 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4001
4002 SetLastError(ERROR_SUCCESS);
4003 /* validate handle */
4004 iIndex = _HMHandleQuery(hThread); /* get the index */
4005 if (-1 == iIndex) /* error ? */
4006 {
4007 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4008 return FALSE; /* signal failure */
4009 }
4010
4011 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4012 lpResult = pHMHandle->pDeviceHandler->SetThreadPriority(&TabWin32Handles[iIndex].hmHandleData, priority);
4013
4014 return (lpResult); /* deliver return code */
4015}
4016/*****************************************************************************
4017 * Name : HMGetThreadContext
4018 * Purpose : router function for GetThreadContext
4019 * Parameters:
4020 * Variables :
4021 * Result :
4022 * Remark :
4023 * Status :
4024 *
4025 * Author : SvL
4026 *****************************************************************************/
4027BOOL HMGetThreadContext(HANDLE hThread, CONTEXT *lpContext)
4028{
4029 int iIndex; /* index into the handle table */
4030 BOOL lpResult; /* result from the device handler's API */
4031 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4032
4033 SetLastError(ERROR_SUCCESS);
4034 /* validate handle */
4035 iIndex = _HMHandleQuery(hThread); /* get the index */
4036 if (-1 == iIndex) /* error ? */
4037 {
4038 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4039 return FALSE; /* signal failure */
4040 }
4041
4042 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4043 lpResult = pHMHandle->pDeviceHandler->GetThreadContext(&TabWin32Handles[iIndex].hmHandleData, lpContext);
4044
4045 return (lpResult); /* deliver return code */
4046}
4047/*****************************************************************************
4048 * Name : HMSetThreadContext
4049 * Purpose : router function for SetThreadContext
4050 * Parameters:
4051 * Variables :
4052 * Result :
4053 * Remark :
4054 * Status :
4055 *
4056 * Author : SvL
4057 *****************************************************************************/
4058BOOL HMSetThreadContext(HANDLE hThread, const CONTEXT *lpContext)
4059{
4060 int iIndex; /* index into the handle table */
4061 BOOL lpResult; /* result from the device handler's API */
4062 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4063
4064 SetLastError(ERROR_SUCCESS);
4065 /* validate handle */
4066 iIndex = _HMHandleQuery(hThread); /* get the index */
4067 if (-1 == iIndex) /* error ? */
4068 {
4069 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4070 return FALSE; /* signal failure */
4071 }
4072
4073 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4074 lpResult = pHMHandle->pDeviceHandler->SetThreadContext(&TabWin32Handles[iIndex].hmHandleData, lpContext);
4075
4076 return (lpResult); /* deliver return code */
4077}
4078/*****************************************************************************
4079 * Name : HMTerminateThread
4080 * Purpose : router function for TerminateThread
4081 * Parameters:
4082 * Variables :
4083 * Result :
4084 * Remark :
4085 * Status :
4086 *
4087 * Author : SvL
4088 *****************************************************************************/
4089BOOL HMTerminateThread(HANDLE hThread, DWORD exitcode)
4090{
4091 int iIndex; /* index into the handle table */
4092 BOOL lpResult; /* result from the device handler's API */
4093 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4094
4095 SetLastError(ERROR_SUCCESS);
4096 /* validate handle */
4097 iIndex = _HMHandleQuery(hThread); /* get the index */
4098 if (-1 == iIndex) /* error ? */
4099 {
4100 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4101 return FALSE; /* signal failure */
4102 }
4103
4104 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4105 lpResult = pHMHandle->pDeviceHandler->TerminateThread(&TabWin32Handles[iIndex].hmHandleData, exitcode);
4106
4107 return (lpResult); /* deliver return code */
4108}
4109/*****************************************************************************
4110 * Name : HMResumeThread
4111 * Purpose : router function for ResumeThread
4112 * Parameters:
4113 * Variables :
4114 * Result :
4115 * Remark :
4116 * Status :
4117 *
4118 * Author : SvL
4119 *****************************************************************************/
4120DWORD HMResumeThread(HANDLE hThread)
4121{
4122 int iIndex; /* index into the handle table */
4123 DWORD lpResult; /* result from the device handler's API */
4124 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4125
4126 SetLastError(ERROR_SUCCESS);
4127 /* validate handle */
4128 iIndex = _HMHandleQuery(hThread); /* get the index */
4129 if (-1 == iIndex) /* error ? */
4130 {
4131 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4132 return -1; /* signal failure */
4133 }
4134
4135 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4136 lpResult = pHMHandle->pDeviceHandler->ResumeThread(&TabWin32Handles[iIndex].hmHandleData);
4137
4138 return (lpResult); /* deliver return code */
4139}
4140
4141/*****************************************************************************
4142 * Name : HMGetExitCodeThread
4143 * Purpose : router function for GetExitCodeThread
4144 * Parameters:
4145 * Variables :
4146 * Result :
4147 * Remark :
4148 * Status :
4149 *
4150 * Author : SvL
4151 *****************************************************************************/
4152BOOL HMGetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode)
4153{
4154 int iIndex; /* index into the handle table */
4155 BOOL lpResult; /* result from the device handler's API */
4156 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4157
4158 SetLastError(ERROR_SUCCESS);
4159 /* validate handle */
4160 iIndex = _HMHandleQuery(hThread); /* get the index */
4161 if (-1 == iIndex) /* error ? */
4162 {
4163 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4164 return FALSE; /* signal failure */
4165 }
4166
4167 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4168 lpResult = pHMHandle->pDeviceHandler->GetExitCodeThread(&TabWin32Handles[iIndex].hmHandleData, lpExitCode);
4169
4170 return (lpResult); /* deliver return code */
4171}
4172/*****************************************************************************
4173 * Name : HMSetThreadTerminated
4174 * Purpose :
4175 * Parameters:
4176 * Variables :
4177 * Result :
4178 * Remark :
4179 * Status :
4180 *
4181 * Author : SvL
4182 *****************************************************************************/
4183BOOL HMSetThreadTerminated(HANDLE hThread)
4184{
4185 int iIndex; /* index into the handle table */
4186 BOOL lpResult; /* result from the device handler's API */
4187 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4188
4189 SetLastError(ERROR_SUCCESS);
4190 /* validate handle */
4191 iIndex = _HMHandleQuery(hThread); /* get the index */
4192 if (-1 == iIndex) /* error ? */
4193 {
4194 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4195 return FALSE; /* signal failure */
4196 }
4197
4198 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4199 lpResult = pHMHandle->pDeviceHandler->SetThreadTerminated(&TabWin32Handles[iIndex].hmHandleData);
4200
4201 return (lpResult); /* deliver return code */
4202}
4203
4204/*****************************************************************************
4205 * Name : HMPeekNamedPipe
4206 * Purpose :
4207 * Parameters:
4208 * Variables :
4209 * Result :
4210 * Remark :
4211 * Status :
4212 *
4213 * Author : Przemyslaw Dobrowolski
4214 *****************************************************************************/
4215BOOL HMPeekNamedPipe(HANDLE hPipe,
4216 LPVOID lpvBuffer,
4217 DWORD cbBuffer,
4218 LPDWORD lpcbRead,
4219 LPDWORD lpcbAvail,
4220 LPDWORD lpcbMessage)
4221{
4222 int iIndex; /* index into the handle table */
4223 BOOL lpResult; /* result from the device handler's API */
4224 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4225
4226 SetLastError(ERROR_SUCCESS);
4227 /* validate handle */
4228 iIndex = _HMHandleQuery(hPipe); /* get the index */
4229 if (-1 == iIndex) /* error ? */
4230 {
4231 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4232 return FALSE; /* signal failure */
4233 }
4234
4235 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4236 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
4237 lpvBuffer,
4238 cbBuffer,
4239 lpcbRead,
4240 lpcbAvail,
4241 lpcbMessage);
4242
4243 return (lpResult); /* deliver return code */
4244}
4245
4246/*****************************************************************************
4247 * Name : HMCreateNamedPipe
4248 * Purpose :
4249 * Parameters:
4250 * Variables :
4251 * Result :
4252 * Remark :
4253 * Status :
4254 *
4255 * Author : Przemyslaw Dobrowolski
4256 *****************************************************************************/
4257DWORD HMCreateNamedPipe(LPCTSTR lpName,
4258 DWORD dwOpenMode,
4259 DWORD dwPipeMode,
4260 DWORD nMaxInstances,
4261 DWORD nOutBufferSize,
4262 DWORD nInBufferSize,
4263 DWORD nDefaultTimeOut,
4264 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
4265{
4266 int iIndex; /* index into the handle table */
4267 int iIndexNew; /* index into the handle table */
4268 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
4269 PHMHANDLEDATA pHMHandleData;
4270 HANDLE rc; /* API return code */
4271
4272 SetLastError(ERROR_SUCCESS);
4273
4274 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */
4275
4276 iIndexNew = _HMHandleGetFree(); /* get free handle */
4277 if (-1 == iIndexNew) /* oops, no free handles ! */
4278 {
4279 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
4280 return 0;
4281 }
4282
4283 /* initialize the complete HMHANDLEDATA structure */
4284 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
4285 pHMHandleData->dwType = FILE_TYPE_PIPE;
4286 pHMHandleData->dwAccess = 0;
4287 pHMHandleData->dwShare = 0;
4288 pHMHandleData->dwCreation = 0;
4289 pHMHandleData->dwFlags = 0;
4290 pHMHandleData->lpHandlerData = NULL;
4291
4292 /* we've got to mark the handle as occupied here, since another device */
4293 /* could be created within the device handler -> deadlock */
4294
4295 /* write appropriate entry into the handle table if open succeeded */
4296 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
4297 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
4298
4299 /* call the device handler */
4300
4301 rc = pDeviceHandler->CreateNamedPipe(&TabWin32Handles[iIndexNew].hmHandleData,
4302 lpName,dwOpenMode,
4303 dwPipeMode,nMaxInstances,
4304 nOutBufferSize,nInBufferSize,
4305 nDefaultTimeOut,lpSecurityAttributes);
4306
4307 if (rc == -1) /* oops, creation failed within the device handler */
4308 {
4309 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
4310 return 0; /* signal error */
4311 }
4312
4313 dprintf(("Win32 Handle -> %08x",iIndexNew));
4314
4315 return iIndexNew;
4316}
4317
4318/*****************************************************************************
4319 * Name : HMConnectNamedPipe
4320 * Purpose :
4321 * Parameters:
4322 * Variables :
4323 * Result :
4324 * Remark :
4325 * Status :
4326 *
4327 * Author : Przemyslaw Dobrowolski
4328 *****************************************************************************/
4329BOOL HMConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED lpOverlapped)
4330{
4331 int iIndex; /* index into the handle table */
4332 BOOL lpResult; /* result from the device handler's API */
4333 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4334
4335 SetLastError(ERROR_SUCCESS);
4336 /* validate handle */
4337 iIndex = _HMHandleQuery(hPipe); /* get the index */
4338 if (-1 == iIndex) /* error ? */
4339 {
4340 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4341 return FALSE; /* signal failure */
4342 }
4343
4344 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4345 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
4346 lpOverlapped);
4347
4348 return (lpResult); /* deliver return code */
4349}
4350
4351/*****************************************************************************
4352 * Name : HMDisconnectNamedPipe
4353 * Purpose :
4354 * Parameters:
4355 * Variables :
4356 * Result :
4357 * Remark :
4358 * Status :
4359 *
4360 * Author : Przemyslaw Dobrowolski
4361 *****************************************************************************/
4362BOOL HMDisconnectNamedPipe(HANDLE hPipe)
4363{
4364 int iIndex; /* index into the handle table */
4365 BOOL lpResult; /* result from the device handler's API */
4366 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4367
4368 SetLastError(ERROR_SUCCESS);
4369 /* validate handle */
4370 iIndex = _HMHandleQuery(hPipe); /* get the index */
4371 if (-1 == iIndex) /* error ? */
4372 {
4373 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4374 return FALSE; /* signal failure */
4375 }
4376
4377 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4378 lpResult = pHMHandle->pDeviceHandler->DisconnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData);
4379
4380 return (lpResult); /* deliver return code */
4381}
4382
4383/*****************************************************************************
4384 * Name : HMGetNamedPipeHandleState
4385 * Purpose :
4386 * Parameters:
4387 * Variables :
4388 * Result :
4389 * Remark :
4390 * Status :
4391 *
4392 * Author : Przemyslaw Dobrowolski
4393 *****************************************************************************/
4394BOOL HMGetNamedPipeHandleState(HANDLE hPipe,
4395 LPDWORD lpState,
4396 LPDWORD lpCurInstances,
4397 LPDWORD lpMaxCollectionCount,
4398 LPDWORD lpCollectDataTimeout,
4399 LPTSTR lpUserName,
4400 DWORD nMaxUserNameSize)
4401{
4402 int iIndex; /* index into the handle table */
4403 BOOL lpResult; /* result from the device handler's API */
4404 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4405
4406 SetLastError(ERROR_SUCCESS);
4407 /* validate handle */
4408 iIndex = _HMHandleQuery(hPipe); /* get the index */
4409 if (-1 == iIndex) /* error ? */
4410 {
4411 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4412 return FALSE; /* signal failure */
4413 }
4414
4415 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4416 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData,
4417 lpState,
4418 lpCurInstances,
4419 lpMaxCollectionCount,
4420 lpCollectDataTimeout,
4421 lpUserName,
4422 nMaxUserNameSize);
4423
4424
4425 return (lpResult); /* deliver return code */
4426}
4427
4428/*****************************************************************************
4429 * Name : HMGetNamedPipeInfo
4430 * Purpose :
4431 * Parameters:
4432 * Variables :
4433 * Result :
4434 * Remark :
4435 * Status :
4436 *
4437 * Author : Przemyslaw Dobrowolski
4438 *****************************************************************************/
4439BOOL HMGetNamedPipeInfo(HANDLE hPipe,
4440 LPDWORD lpFlags,
4441 LPDWORD lpOutBufferSize,
4442 LPDWORD lpInBufferSize,
4443 LPDWORD lpMaxInstances)
4444{
4445 int iIndex; /* index into the handle table */
4446 BOOL lpResult; /* result from the device handler's API */
4447 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4448
4449 SetLastError(ERROR_SUCCESS);
4450 /* validate handle */
4451 iIndex = _HMHandleQuery(hPipe); /* get the index */
4452 if (-1 == iIndex) /* error ? */
4453 {
4454 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4455 return FALSE; /* signal failure */
4456 }
4457
4458 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4459 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeInfo(&TabWin32Handles[iIndex].hmHandleData,
4460 lpFlags,
4461 lpOutBufferSize,
4462 lpInBufferSize,
4463 lpMaxInstances);
4464
4465 return (lpResult); /* deliver return code */
4466}
4467
4468/*****************************************************************************
4469 * Name : HMTransactNamedPipe
4470 * Purpose :
4471 * Parameters:
4472 * Variables :
4473 * Result :
4474 * Remark :
4475 * Status :
4476 *
4477 * Author : Przemyslaw Dobrowolski
4478 *****************************************************************************/
4479DWORD HMTransactNamedPipe(HANDLE hPipe,
4480 LPVOID lpvWriteBuf,
4481 DWORD cbWriteBuf,
4482 LPVOID lpvReadBuf,
4483 DWORD cbReadBuf,
4484 LPDWORD lpcbRead,
4485 LPOVERLAPPED lpo)
4486{
4487 int iIndex; /* index into the handle table */
4488 DWORD lpResult; /* result from the device handler's API */
4489 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4490
4491 SetLastError(ERROR_SUCCESS);
4492 /* validate handle */
4493 iIndex = _HMHandleQuery(hPipe); /* get the index */
4494 if (-1 == iIndex) /* error ? */
4495 {
4496 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4497 return FALSE; /* signal failure */
4498 }
4499
4500 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4501 lpResult = pHMHandle->pDeviceHandler->TransactNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
4502 lpvWriteBuf,
4503 cbWriteBuf,
4504 lpvReadBuf,
4505 cbReadBuf,
4506 lpcbRead,
4507 lpo);
4508
4509 return (lpResult); /* deliver return code */
4510}
4511
4512/*****************************************************************************
4513 * Name : HMSetNamedPipeHandleState
4514 * Purpose :
4515 * Parameters:
4516 * Variables :
4517 * Result :
4518 * Remark :
4519 * Status :
4520 *
4521 * Author : Przemyslaw Dobrowolski
4522 *****************************************************************************/
4523BOOL HMSetNamedPipeHandleState(HANDLE hPipe,
4524 LPDWORD lpdwMode,
4525 LPDWORD lpcbMaxCollect,
4526 LPDWORD lpdwCollectDataTimeout)
4527{
4528 int iIndex; /* index into the handle table */
4529 BOOL lpResult; /* result from the device handler's API */
4530 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4531
4532 SetLastError(ERROR_SUCCESS);
4533 /* validate handle */
4534 iIndex = _HMHandleQuery(hPipe); /* get the index */
4535 if (-1 == iIndex) /* error ? */
4536 {
4537 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4538 return FALSE; /* signal failure */
4539 }
4540
4541 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4542 lpResult = pHMHandle->pDeviceHandler->SetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData,
4543 lpdwMode,
4544 lpcbMaxCollect,
4545 lpdwCollectDataTimeout);
4546
4547 return (lpResult); /* deliver return code */
4548}
4549
4550/*****************************************************************************
4551 * Name : HMCreatePipe
4552 * Purpose :
4553 * Parameters:
4554 * Variables :
4555 * Result :
4556 * Remark :
4557 * Status : NOT TESTED!
4558 *
4559 * Author : Przemyslaw Dobrowolski
4560 *****************************************************************************/
4561BOOL HMCreatePipe(PHANDLE phRead,
4562 PHANDLE phWrite,
4563 LPSECURITY_ATTRIBUTES lpsa,
4564 DWORD cbPipe)
4565{
4566 int iIndex; /* index into the handle table */
4567 int iIndexNewRead; /* index into the handle table */
4568 int iIndexNewWrite; /* index into the handle table */
4569 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
4570 PHMHANDLEDATA pHMHandleData;
4571 HANDLE rc; /* API return code */
4572
4573 SetLastError(ERROR_SUCCESS);
4574
4575 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */
4576
4577 iIndexNewRead = _HMHandleGetFree(); /* get free handle */
4578 if (-1 == iIndexNewRead) /* oops, no free handles ! */
4579 {
4580 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
4581 return 0;
4582 }
4583
4584 iIndexNewWrite = _HMHandleGetFree(); /* get free handle */
4585 if (-1 == iIndexNewWrite) /* oops, no free handles ! */
4586 {
4587 HMHandleFree(iIndexNewRead);
4588 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
4589 return 0;
4590 }
4591
4592
4593 /* initialize the complete HMHANDLEDATA structure */
4594 pHMHandleData = &TabWin32Handles[iIndexNewRead].hmHandleData;
4595 pHMHandleData->dwType = FILE_TYPE_PIPE;
4596 pHMHandleData->dwAccess = 0;
4597 pHMHandleData->dwShare = 0;
4598 pHMHandleData->dwCreation = 0;
4599 pHMHandleData->dwFlags = 0;
4600 pHMHandleData->lpHandlerData = NULL;
4601
4602 /* we've got to mark the handle as occupied here, since another device */
4603 /* could be created within the device handler -> deadlock */
4604
4605 /* write appropriate entry into the handle table if open succeeded */
4606 TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = iIndexNewRead;
4607 TabWin32Handles[iIndexNewRead].pDeviceHandler = pDeviceHandler;
4608
4609 /* initialize the complete HMHANDLEDATA structure */
4610 pHMHandleData = &TabWin32Handles[iIndexNewWrite].hmHandleData;
4611 pHMHandleData->dwType = FILE_TYPE_PIPE;
4612 pHMHandleData->dwAccess = 0;
4613 pHMHandleData->dwShare = 0;
4614 pHMHandleData->dwCreation = 0;
4615 pHMHandleData->dwFlags = 0;
4616 pHMHandleData->lpHandlerData = NULL;
4617
4618 /* we've got to mark the handle as occupied here, since another device */
4619 /* could be created within the device handler -> deadlock */
4620
4621 /* write appropriate entry into the handle table if open succeeded */
4622 TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = iIndexNewWrite;
4623 TabWin32Handles[iIndexNewWrite].pDeviceHandler = pDeviceHandler;
4624 /* call the device handler */
4625
4626 rc = pDeviceHandler->CreatePipe(&TabWin32Handles[iIndexNewRead].hmHandleData,
4627 &TabWin32Handles[iIndexNewWrite].hmHandleData,
4628 lpsa,
4629 cbPipe);
4630
4631 if (rc == 0) /* oops, creation failed within the device handler */
4632 {
4633 HMHandleFree(iIndexNewRead);
4634 HMHandleFree(iIndexNewWrite);
4635 return FALSE; /* signal error */
4636 }
4637
4638 *phRead = iIndexNewRead;
4639 *phWrite = iIndexNewWrite;
4640
4641 return TRUE;
4642}
4643
4644/*****************************************************************************
4645 * Name : HMCreateMailslotA
4646 * Purpose :
4647 * Parameters:
4648 * Variables :
4649 * Result :
4650 * Remark :
4651 * Status :
4652 *
4653 * Author : SvL
4654 *****************************************************************************/
4655HANDLE HMCreateMailslotA(LPCSTR lpName, DWORD nMaxMessageSize,
4656 DWORD lReadTimeout,
4657 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
4658{
4659 int iIndex; /* index into the handle table */
4660 int iIndexNew; /* index into the handle table */
4661 HMMailslotClass *pDeviceHandler; /* device handler for this handle */
4662 PHMHANDLEDATA pHMHandleData;
4663 BOOL rc; /* API return code */
4664
4665 SetLastError(ERROR_SUCCESS);
4666
4667 pDeviceHandler = (HMMailslotClass *)HMGlobals.pHMMailslot; /* device is predefined */
4668
4669 iIndexNew = _HMHandleGetFree(); /* get free handle */
4670 if (-1 == iIndexNew) /* oops, no free handles ! */
4671 {
4672 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
4673 return 0;
4674 }
4675
4676 /* initialize the complete HMHANDLEDATA structure */
4677 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
4678 pHMHandleData->dwType = FILE_TYPE_UNKNOWN;
4679 pHMHandleData->dwAccess = 0;
4680 pHMHandleData->dwShare = 0;
4681 pHMHandleData->dwCreation = 0;
4682 pHMHandleData->dwFlags = 0;
4683 pHMHandleData->lpHandlerData = NULL;
4684
4685 /* we've got to mark the handle as occupied here, since another device */
4686 /* could be created within the device handler -> deadlock */
4687
4688 /* write appropriate entry into the handle table if open succeeded */
4689 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
4690 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
4691
4692 /* call the device handler */
4693
4694 rc = pDeviceHandler->CreateMailslotA(&TabWin32Handles[iIndexNew].hmHandleData,
4695 lpName, nMaxMessageSize,
4696 lReadTimeout, lpSecurityAttributes);
4697
4698 if (rc == FALSE) /* oops, creation failed within the device handler */
4699 {
4700 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
4701 return 0; /* signal error */
4702 }
4703
4704 return iIndexNew;
4705}
4706/*****************************************************************************
4707 * Name : HMGetMailslotInfo
4708 * Purpose :
4709 * Parameters:
4710 * Variables :
4711 * Result :
4712 * Remark :
4713 * Status :
4714 *
4715 * Author : SvL
4716 *****************************************************************************/
4717BOOL HMGetMailslotInfo(HANDLE hMailslot,
4718 LPDWORD lpMaxMessageSize,
4719 LPDWORD lpNextSize,
4720 LPDWORD lpMessageCount,
4721 LPDWORD lpReadTimeout)
4722{
4723 int iIndex; /* index into the handle table */
4724 BOOL lpResult; /* result from the device handler's API */
4725 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4726
4727 SetLastError(ERROR_SUCCESS);
4728 /* validate handle */
4729 iIndex = _HMHandleQuery(hMailslot); /* get the index */
4730 if (-1 == iIndex) /* error ? */
4731 {
4732 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4733 return FALSE; /* signal failure */
4734 }
4735
4736 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4737 lpResult = pHMHandle->pDeviceHandler->GetMailslotInfo(&TabWin32Handles[iIndex].hmHandleData,
4738 lpMaxMessageSize,
4739 lpNextSize,
4740 lpMessageCount,
4741 lpReadTimeout);
4742 return (lpResult); /* deliver return code */
4743}
4744/*****************************************************************************
4745 * Name : HMSetMailslotInfo
4746 * Purpose :
4747 * Parameters:
4748 * Variables :
4749 * Result :
4750 * Remark :
4751 * Status :
4752 *
4753 * Author : SvL
4754 *****************************************************************************/
4755BOOL HMSetMailslotInfo(HANDLE hMailslot,
4756 DWORD dwReadTimeout)
4757{
4758 int iIndex; /* index into the handle table */
4759 BOOL lpResult; /* result from the device handler's API */
4760 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
4761
4762 SetLastError(ERROR_SUCCESS);
4763 /* validate handle */
4764 iIndex = _HMHandleQuery(hMailslot); /* get the index */
4765 if (-1 == iIndex) /* error ? */
4766 {
4767 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
4768 return FALSE; /* signal failure */
4769 }
4770
4771 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
4772 lpResult = pHMHandle->pDeviceHandler->SetMailslotInfo(&TabWin32Handles[iIndex].hmHandleData,
4773 dwReadTimeout);
4774
4775 return (lpResult); /* deliver return code */
4776}
Note: See TracBrowser for help on using the repository browser.