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

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

WaitForSingleObject fix

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