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

Last change on this file since 7443 was 7443, checked in by phaller, 24 years ago

.

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