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

Last change on this file since 9653 was 9653, checked in by sandervl, 23 years ago

implemented Get/SetHandleInformation; CloseHandle change for HANDLE_FLAG_PROTECT_FROM_CLOSE; inheritance support added to DuplicateHandle

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