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

Last change on this file since 10073 was 10073, checked in by sandervl, 22 years ago

Fixed closing of parent file handle by duplicate memory map; Compare file names instead of handles when checking for duplicate file maps

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