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

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

added ./ as standard symbolic link to the local namespace

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