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

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

removed symbolic name change

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