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

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

memory map + handle manager fixes

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