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

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

added mailslot implemenation, named pipe fixes + FreeLibraryAndExitThread

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