1 | /* $Id: HandleManager.cpp,v 1.6 1999-07-06 15:48:45 phaller Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | *
|
---|
5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
6 | *
|
---|
7 | */
|
---|
8 | /*
|
---|
9 | * Win32 Unified Handle Manager for OS/2
|
---|
10 | *
|
---|
11 | * 1998/02/11 PH Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
12 | *
|
---|
13 | * @(#) HandleManager.Cpp 1.0.0 1998/02/11 PH start
|
---|
14 | */
|
---|
15 |
|
---|
16 | #undef DEBUG_LOCAL
|
---|
17 | //#define DEBUG_LOCAL
|
---|
18 |
|
---|
19 |
|
---|
20 | /*****************************************************************************
|
---|
21 | * Remark *
|
---|
22 | *****************************************************************************
|
---|
23 |
|
---|
24 | 1998/02/11 PH Even overlapped I/O could be simulated by another subsystem
|
---|
25 | thread with a request queue. We'll see if required ...
|
---|
26 |
|
---|
27 |
|
---|
28 | Flush (flush handle buffer)
|
---|
29 | WaitForSingleObject
|
---|
30 | WaitForMultipleObjects (?)
|
---|
31 |
|
---|
32 | 1998/02/12 PH IBM and Microsoft disagree about the definition of FILE_TYPE_xxx
|
---|
33 | Interesting, Open32 returns Microsoft's values ...
|
---|
34 |
|
---|
35 | 1998/02/12 PH Handles should be equipped with a locking mechanism, in particular
|
---|
36 | as we publish a pointer into the handle table via HMHandleQueryHandleData
|
---|
37 |
|
---|
38 | */
|
---|
39 |
|
---|
40 |
|
---|
41 | /*****************************************************************************
|
---|
42 | * Includes *
|
---|
43 | *****************************************************************************/
|
---|
44 |
|
---|
45 | #include <os2win.h>
|
---|
46 | #include <stdlib.h>
|
---|
47 | #include <string.h>
|
---|
48 | #include "unicode.h"
|
---|
49 | #include "misc.h"
|
---|
50 |
|
---|
51 | #include "HandleManager.H"
|
---|
52 | #include "HMDevice.h"
|
---|
53 | #include "HMOpen32.h"
|
---|
54 | #include "HMEvent.h"
|
---|
55 | #include "HMMutex.h"
|
---|
56 | #include "HMSemaphore.h"
|
---|
57 |
|
---|
58 |
|
---|
59 | /*****************************************************************************
|
---|
60 | * Defines *
|
---|
61 | *****************************************************************************/
|
---|
62 |
|
---|
63 | /* this is the size of our currently static handle table */
|
---|
64 | #define MAX_OS2_HMHANDLES 2048
|
---|
65 |
|
---|
66 |
|
---|
67 | /*****************************************************************************
|
---|
68 | * Structures *
|
---|
69 | *****************************************************************************/
|
---|
70 |
|
---|
71 |
|
---|
72 | typedef struct _HMHANDLE
|
---|
73 | {
|
---|
74 | HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */
|
---|
75 | HMHANDLEDATA hmHandleData; /* attributes of the handle */
|
---|
76 | } HMHANDLE, *PHMHANDLE;
|
---|
77 |
|
---|
78 |
|
---|
79 | typedef struct _HMDEVICE
|
---|
80 | {
|
---|
81 | struct _HMDEVICE *pNext; /* pointer to next device in chain */
|
---|
82 |
|
---|
83 | PSZ pszDeviceName; /* name or alias of the pseudo-device */
|
---|
84 | HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */
|
---|
85 | } HMDEVICE, *PHMDEVICE;
|
---|
86 |
|
---|
87 |
|
---|
88 | /*****************************************************************************
|
---|
89 | * This pseudo-device logs all device requests to the logfile and returns *
|
---|
90 | * ERROR_INVALID_FUNCTION to virtually all requests -> debugging *
|
---|
91 | *****************************************************************************/
|
---|
92 | class HMDeviceDebugClass : public HMDeviceHandler
|
---|
93 | {
|
---|
94 | public:
|
---|
95 | HMDeviceDebugClass(LPCSTR lpDeviceName) : HMDeviceHandler(lpDeviceName) {}
|
---|
96 | };
|
---|
97 |
|
---|
98 |
|
---|
99 | /*****************************************************************************
|
---|
100 | * Process Global Structures *
|
---|
101 | *****************************************************************************/
|
---|
102 |
|
---|
103 |
|
---|
104 | /* the device name is repeated here to enable device alias names */
|
---|
105 | static PHMDEVICE TabWin32Devices = NULL;
|
---|
106 | static HMHANDLE TabWin32Handles[MAX_OS2_HMHANDLES]; /* static handle table */
|
---|
107 |
|
---|
108 |
|
---|
109 | struct _HMGlobals
|
---|
110 | {
|
---|
111 | HANDLE hStandardIn; /* stdin handle to CONIN$ */
|
---|
112 | HANDLE hStandardOut; /* stdout handle to CONOUT$ */
|
---|
113 | HANDLE hStandardError; /* stderr handle to CONOUT$ */
|
---|
114 |
|
---|
115 | BOOL fIsInitialized; /* if HM is initialized already ? */
|
---|
116 | /* this MUST !!! be false initially */
|
---|
117 |
|
---|
118 | HMDeviceHandler *pHMOpen32; /* default handle manager instance */
|
---|
119 | HMDeviceHandler *pHMEvent; /* static instances of subsystems */
|
---|
120 | HMDeviceHandler *pHMMutex;
|
---|
121 | HMDeviceHandler *pHMSemaphore;
|
---|
122 |
|
---|
123 | ULONG ulHandleLast; /* index of last used handle */
|
---|
124 | } HMGlobals;
|
---|
125 |
|
---|
126 |
|
---|
127 | /*****************************************************************************
|
---|
128 | * Local Prototypes *
|
---|
129 | *****************************************************************************/
|
---|
130 |
|
---|
131 | /* get appropriate device handler by the device name */
|
---|
132 | static HMDeviceHandler *_HMDeviceFind(PSZ pszDeviceName);
|
---|
133 |
|
---|
134 | /* get next free handle from the handle table */
|
---|
135 | static ULONG _HMHandleGetFree(void);
|
---|
136 |
|
---|
137 | /* get handle table entry from handle */
|
---|
138 | static ULONG _HMHandleQuery(HANDLE hHandle);
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 | /*****************************************************************************
|
---|
143 | * Name : static HMDeviceHandler * _HMDeviceFind
|
---|
144 | * Purpose : obtain appropriate device handler from the table by searching
|
---|
145 | * for a device name or alias
|
---|
146 | * Parameters: PSZ pszDeviceName
|
---|
147 | * Variables :
|
---|
148 | * Result : HMDeviceHandler * - pointer to the handler object
|
---|
149 | * Remark :
|
---|
150 | * Status :
|
---|
151 | *
|
---|
152 | * Author : Patrick Haller [Wed, 1998/02/11 20:42]
|
---|
153 | *****************************************************************************/
|
---|
154 |
|
---|
155 | static HMDeviceHandler *_HMDeviceFind (PSZ pszDeviceName)
|
---|
156 | {
|
---|
157 | PHMDEVICE pHMDevice; /* iterator over the device table */
|
---|
158 |
|
---|
159 | if (pszDeviceName != NULL)
|
---|
160 | for (pHMDevice = TabWin32Devices; /* loop over all devices in the table */
|
---|
161 | pHMDevice != NULL;
|
---|
162 | pHMDevice = pHMDevice->pNext)
|
---|
163 | {
|
---|
164 | if (stricmp(pHMDevice->pszDeviceName, /* case-insensitive search */
|
---|
165 | pszDeviceName) == 0)
|
---|
166 | return (pHMDevice->pDeviceHandler); /* OK, we've found our device */
|
---|
167 | }
|
---|
168 |
|
---|
169 | return (HMGlobals.pHMOpen32); /* haven't found anything, return default */
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | /*****************************************************************************
|
---|
174 | * Name : static int _HMHandleGetFree
|
---|
175 | * Purpose : get index to first free handle in the handle table
|
---|
176 | * Parameters:
|
---|
177 | * Variables :
|
---|
178 | * Result : int iIndex - index to the table or -1 in case of error
|
---|
179 | * Remark :
|
---|
180 | * Status :
|
---|
181 | *
|
---|
182 | * Author : Patrick Haller [Wed, 1998/02/11 20:43]
|
---|
183 | *****************************************************************************/
|
---|
184 |
|
---|
185 | static ULONG _HMHandleGetFree(void)
|
---|
186 | {
|
---|
187 | register ULONG ulLoop;
|
---|
188 |
|
---|
189 | for (ulLoop = 0;
|
---|
190 | ulLoop < MAX_OS2_HMHANDLES;
|
---|
191 | ulLoop++)
|
---|
192 | {
|
---|
193 | /* free handle found ? */
|
---|
194 | if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle)
|
---|
195 | return (ulLoop); /* OK, then return it to the caller */
|
---|
196 | }
|
---|
197 |
|
---|
198 | return (INVALID_HANDLE_VALUE); /* haven't found any free handle */
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | /*****************************************************************************
|
---|
203 | * Name : static int _HMHandleQuery
|
---|
204 | * Purpose : gets the index of handle table entry as fast as possible from
|
---|
205 | * the specified handle
|
---|
206 | * Parameters: HANDLE hHandle
|
---|
207 | * Variables :
|
---|
208 | * Result : index or -1 in case of error
|
---|
209 | * Remark :
|
---|
210 | * Status :
|
---|
211 | *
|
---|
212 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
213 | *****************************************************************************/
|
---|
214 |
|
---|
215 | static ULONG _HMHandleQuery(HANDLE hHandle)
|
---|
216 | {
|
---|
217 | if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */
|
---|
218 | return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */
|
---|
219 |
|
---|
220 | /* Oops, invalid handle ! */
|
---|
221 | if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
|
---|
222 | return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */
|
---|
223 |
|
---|
224 | return ( hHandle); /* OK, we've got our handle index */
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | /*****************************************************************************
|
---|
229 | * Name : DWORD HMDeviceRegister
|
---|
230 | * Purpose : register a device with the handle manager
|
---|
231 | * Parameters: PSZ pszDeviceName
|
---|
232 | * HMDeviceHandler *pDeviceHandler
|
---|
233 | * Variables :
|
---|
234 | * Result : API returncode
|
---|
235 | * Remark :
|
---|
236 | * Status :
|
---|
237 | *
|
---|
238 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
---|
239 | *****************************************************************************/
|
---|
240 |
|
---|
241 | DWORD HMDeviceRegister(PSZ pszDeviceName,
|
---|
242 | HMDeviceHandler *pDeviceHandler)
|
---|
243 | {
|
---|
244 | PHMDEVICE pHMDevice; /* our new device to be allocated */
|
---|
245 |
|
---|
246 | if ( (pszDeviceName == NULL) || /* check parameters */
|
---|
247 | (pDeviceHandler == NULL) )
|
---|
248 | return (ERROR_INVALID_PARAMETER); /* raise error conditon */
|
---|
249 |
|
---|
250 |
|
---|
251 | pHMDevice = (PHMDEVICE) malloc (sizeof (HMDEVICE) ); /* allocate memory */
|
---|
252 | if (pHMDevice == NULL) /* check proper allocation */
|
---|
253 | return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */
|
---|
254 |
|
---|
255 | pHMDevice->pszDeviceName = strdup(pszDeviceName); /* copy name */
|
---|
256 | if (pHMDevice->pszDeviceName == NULL) /* check proper allocation */
|
---|
257 | {
|
---|
258 | free (pHMDevice); /* free previously allocated memory */
|
---|
259 | return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */
|
---|
260 | }
|
---|
261 |
|
---|
262 | pHMDevice->pDeviceHandler = pDeviceHandler; /* store pointer to device */
|
---|
263 | pHMDevice->pNext = TabWin32Devices; /* establish linkage */
|
---|
264 |
|
---|
265 | TabWin32Devices = pHMDevice; /* insert new node as root in the list */
|
---|
266 |
|
---|
267 | return (NO_ERROR);
|
---|
268 | }
|
---|
269 |
|
---|
270 |
|
---|
271 | /*****************************************************************************
|
---|
272 | * Name : DWORD HMInitialize
|
---|
273 | * Purpose : Initialize the handlemanager
|
---|
274 | * Parameters: -
|
---|
275 | * Variables : -
|
---|
276 | * Result : always NO_ERROR
|
---|
277 | * Remark : this routine just stores the standard handles in the
|
---|
278 | * internal table within the HandleManager
|
---|
279 | * Status :
|
---|
280 | *
|
---|
281 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
---|
282 | *****************************************************************************/
|
---|
283 |
|
---|
284 | DWORD HMInitialize(void)
|
---|
285 | {
|
---|
286 | ULONG ulIndex;
|
---|
287 |
|
---|
288 | if (HMGlobals.fIsInitialized != TRUE)
|
---|
289 | {
|
---|
290 | HMGlobals.fIsInitialized = TRUE; /* OK, done */
|
---|
291 |
|
---|
292 | // fill handle table
|
---|
293 | for (ulIndex = 0;
|
---|
294 | ulIndex < MAX_OS2_HMHANDLES;
|
---|
295 | ulIndex++)
|
---|
296 | TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
297 |
|
---|
298 | dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n"));
|
---|
299 |
|
---|
300 | memset(&HMGlobals, /* zero out the structure first */
|
---|
301 | 0,
|
---|
302 | sizeof(HMGlobals));
|
---|
303 |
|
---|
304 | /* copy standard handles from OS/2's Open32 Subsystem */
|
---|
305 | HMSetStdHandle(STD_INPUT_HANDLE, GetStdHandle(STD_INPUT_HANDLE));
|
---|
306 | HMSetStdHandle(STD_OUTPUT_HANDLE, GetStdHandle(STD_OUTPUT_HANDLE));
|
---|
307 | HMSetStdHandle(STD_ERROR_HANDLE, GetStdHandle(STD_ERROR_HANDLE));
|
---|
308 |
|
---|
309 | /* create handle manager instance for Open32 handles */
|
---|
310 | HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\");
|
---|
311 | HMGlobals.pHMEvent = new HMDeviceEventClass("\\\\EVENT\\");
|
---|
312 | HMGlobals.pHMMutex = new HMDeviceMutexClass("\\\\MUTEX\\");
|
---|
313 | HMGlobals.pHMSemaphore = new HMDeviceSemaphoreClass("\\\\SEM\\");
|
---|
314 | }
|
---|
315 | return (NO_ERROR);
|
---|
316 | }
|
---|
317 |
|
---|
318 |
|
---|
319 | /*****************************************************************************
|
---|
320 | * Name : DWORD HMTerminate
|
---|
321 | * Purpose : Terminate the handlemanager
|
---|
322 | * Parameters:
|
---|
323 | * Variables :
|
---|
324 | * Result :
|
---|
325 | * Remark :
|
---|
326 | * Status :
|
---|
327 | *
|
---|
328 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
---|
329 | *****************************************************************************/
|
---|
330 |
|
---|
331 | DWORD HMTerminate(void)
|
---|
332 | {
|
---|
333 | /* @@@PH we could deallocate the device list here */
|
---|
334 |
|
---|
335 | delete HMGlobals.pHMOpen32;
|
---|
336 | delete HMGlobals.pHMEvent;
|
---|
337 | delete HMGlobals.pHMMutex;
|
---|
338 | delete HMGlobals.pHMSemaphore;
|
---|
339 |
|
---|
340 | return (NO_ERROR);
|
---|
341 | }
|
---|
342 |
|
---|
343 |
|
---|
344 | /*****************************************************************************/
|
---|
345 | /* handle translation buffer management */
|
---|
346 | /* */
|
---|
347 | /* Since some Win32 applications rely (!) on 16-bit handles, we've got to do */
|
---|
348 | /* 32-bit to 16-bit and vs vsa translation here. */
|
---|
349 | /* Filehandle-based functions should be routed via the handlemanager instead */
|
---|
350 | /* of going to Open32 directly. */
|
---|
351 | /*****************************************************************************/
|
---|
352 |
|
---|
353 |
|
---|
354 | /*****************************************************************************
|
---|
355 | * Name : DWORD HMHandleAllocate
|
---|
356 | * Purpose : allocate a handle in the translation table
|
---|
357 | * Parameters: PULONG pHandle16 - to return the allocated handle
|
---|
358 | * ULONG hHandle32 - the associated OS/2 handle
|
---|
359 | * Variables :
|
---|
360 | * Result : API returncode
|
---|
361 | * Remark : no parameter checking is done, phHandle may not be invalid
|
---|
362 | * hHandle32 shouldn't be 0
|
---|
363 | * Should be protected with a HM-Mutex !
|
---|
364 | * Status :
|
---|
365 | *
|
---|
366 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
367 | *****************************************************************************/
|
---|
368 |
|
---|
369 | DWORD HMHandleAllocate (PULONG phHandle16,
|
---|
370 | ULONG hHandleOS2)
|
---|
371 | {
|
---|
372 | register ULONG ulHandle;
|
---|
373 |
|
---|
374 | #ifdef DEBUG_LOCAL
|
---|
375 | dprintf(("KERNEL32: HMHandleAllocate (%08xh,%08xh)\n",
|
---|
376 | phHandle16,
|
---|
377 | hHandleOS2));
|
---|
378 | #endif
|
---|
379 |
|
---|
380 | ulHandle = HMGlobals.ulHandleLast; /* get free handle */
|
---|
381 |
|
---|
382 | do
|
---|
383 | {
|
---|
384 | /* check if handle is free */
|
---|
385 | if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
|
---|
386 | {
|
---|
387 | *phHandle16 = ulHandle;
|
---|
388 | TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2;
|
---|
389 | HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */
|
---|
390 |
|
---|
391 | return (NO_ERROR); /* OK */
|
---|
392 | }
|
---|
393 |
|
---|
394 | ulHandle++; /* skip to next entry */
|
---|
395 |
|
---|
396 | if (ulHandle >= MAX_OS2_HMHANDLES) /* check boundary */
|
---|
397 | ulHandle = 0;
|
---|
398 | }
|
---|
399 | while (ulHandle != HMGlobals.ulHandleLast);
|
---|
400 |
|
---|
401 | return (ERROR_TOO_MANY_OPEN_FILES); /* OK, we're done */
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | /*****************************************************************************
|
---|
406 | * Name : DWORD HMHandleFree
|
---|
407 | * Purpose : free a handle from the translation table
|
---|
408 | * Parameters: ULONG hHandle16 - the handle to be freed
|
---|
409 | * Variables :
|
---|
410 | * Result : API returncode
|
---|
411 | * Remark : no parameter checking is done, hHandle16 MAY NEVER exceed
|
---|
412 | * the MAX_TRANSLATION_HANDLES boundary
|
---|
413 | * Status :
|
---|
414 | *
|
---|
415 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
416 | *****************************************************************************/
|
---|
417 |
|
---|
418 | DWORD HMHandleFree (ULONG hHandle16)
|
---|
419 | {
|
---|
420 | ULONG rc; /* API returncode */
|
---|
421 |
|
---|
422 | #ifdef DEBUG_LOCAL
|
---|
423 | dprintf(("KERNEL32: HMHandleFree (%08xh)\n",
|
---|
424 | hHandle16));
|
---|
425 | #endif
|
---|
426 |
|
---|
427 | rc = HMHandleValidate(hHandle16); /* verify handle */
|
---|
428 | if (rc != NO_ERROR) /* check errors */
|
---|
429 | return (rc); /* raise error condition */
|
---|
430 |
|
---|
431 | TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
432 | /* OK, done */
|
---|
433 |
|
---|
434 | return (NO_ERROR);
|
---|
435 | }
|
---|
436 |
|
---|
437 |
|
---|
438 | /*****************************************************************************
|
---|
439 | * Name : DWORD HMHandleValidate
|
---|
440 | * Purpose : validate a handle through the translation table
|
---|
441 | * Parameters: ULONG hHandle16 - the handle to be verified
|
---|
442 | * Variables :
|
---|
443 | * Result : API returncode
|
---|
444 | * Remark :
|
---|
445 | * Status :
|
---|
446 | *
|
---|
447 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
448 | *****************************************************************************/
|
---|
449 |
|
---|
450 | DWORD HMHandleValidate (ULONG hHandle16)
|
---|
451 | {
|
---|
452 | #ifdef DEBUG_LOCAL
|
---|
453 | dprintf(("KERNEL32: HMHandleValidate (%08xh)\n",
|
---|
454 | hHandle16));
|
---|
455 | #endif
|
---|
456 |
|
---|
457 | if (hHandle16 >= MAX_OS2_HMHANDLES) /* check boundary */
|
---|
458 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
---|
459 |
|
---|
460 | if (TabWin32Handles[hHandle16].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
|
---|
461 | /* valid ? */
|
---|
462 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
---|
463 |
|
---|
464 | return (NO_ERROR);
|
---|
465 | }
|
---|
466 |
|
---|
467 |
|
---|
468 | /*****************************************************************************
|
---|
469 | * Name : DWORD HMHandleTranslateToWin
|
---|
470 | * Purpose : translate a 32-bit OS/2 handle to the associated windows handle
|
---|
471 | * Parameters: ULONG hHandle32 - the OS/2 handle
|
---|
472 | * PULONG phHandle16 - the associated windows handle
|
---|
473 | * Variables :
|
---|
474 | * Result : API returncode
|
---|
475 | * Remark :
|
---|
476 | * Status :
|
---|
477 | *
|
---|
478 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
479 | *****************************************************************************/
|
---|
480 |
|
---|
481 | DWORD HMHandleTranslateToWin (ULONG hHandleOS2,
|
---|
482 | PULONG phHandle16)
|
---|
483 | {
|
---|
484 | ULONG rc; /* API returncode */
|
---|
485 | register ULONG ulIndex; /* index counter over the table */
|
---|
486 |
|
---|
487 | #ifdef DEBUG_LOCAL
|
---|
488 | dprintf(("KERNEL32: HMHandleTranslateToWin (%08xh, %08xh)\n",
|
---|
489 | hHandleOS2,
|
---|
490 | phHandle16));
|
---|
491 | #endif
|
---|
492 |
|
---|
493 | for (ulIndex = 0;
|
---|
494 | ulIndex < MAX_OS2_HMHANDLES;
|
---|
495 | ulIndex++)
|
---|
496 | {
|
---|
497 | /* look for the handle */
|
---|
498 | if (TabWin32Handles[ulIndex].hmHandleData.hHMHandle == hHandleOS2)
|
---|
499 | {
|
---|
500 | *phHandle16 = ulIndex; /* deliver result */
|
---|
501 | return (NO_ERROR); /* OK */
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
---|
506 | }
|
---|
507 |
|
---|
508 |
|
---|
509 | /*****************************************************************************
|
---|
510 | * Name : DWORD HMHandleTranslateToOS2
|
---|
511 | * Purpose : translate a 16-bit Win32 handle to the associated OS/2 handle
|
---|
512 | * Parameters: ULONG hHandle16 - the windows handle
|
---|
513 | * PULONG phHandle32 - the associated OS/2 handle
|
---|
514 | * Variables :
|
---|
515 | * Result : API returncode
|
---|
516 | * Remark :
|
---|
517 | * Status :
|
---|
518 | *
|
---|
519 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
520 | *****************************************************************************/
|
---|
521 |
|
---|
522 | DWORD HMHandleTranslateToOS2 (ULONG hHandle16,
|
---|
523 | PULONG phHandleOS2)
|
---|
524 | {
|
---|
525 | #ifdef DEBUG_LOCAL
|
---|
526 | dprintf(("KERNEL32: HMHandleTranslateToOS2 (%08xh, %08xh)\n",
|
---|
527 | hHandle16,
|
---|
528 | phHandleOS2));
|
---|
529 | #endif
|
---|
530 |
|
---|
531 | if (HMHandleValidate(hHandle16) == NO_ERROR) /* verify handle */
|
---|
532 | {
|
---|
533 | *phHandleOS2 = TabWin32Handles[hHandle16].hmHandleData.hHMHandle;
|
---|
534 | return (NO_ERROR);
|
---|
535 | }
|
---|
536 |
|
---|
537 | return (ERROR_INVALID_HANDLE); /* raise error condition */
|
---|
538 | }
|
---|
539 |
|
---|
540 |
|
---|
541 | /*****************************************************************************
|
---|
542 | * Name : DWORD HMHandleTranslateToOS2i
|
---|
543 | * Purpose : translate a 16-bit Win32 handle to the associated OS/2 handle
|
---|
544 | * Parameters: ULONG hHandle16 - the windows handle
|
---|
545 | * Variables :
|
---|
546 | * Result : OS/2 handle
|
---|
547 | * Remark : no checkinf
|
---|
548 | * Status :
|
---|
549 | *
|
---|
550 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
551 | *****************************************************************************/
|
---|
552 |
|
---|
553 | DWORD HMHandleTranslateToOS2i (ULONG hHandle16)
|
---|
554 | {
|
---|
555 | #ifdef DEBUG_LOCAL
|
---|
556 | dprintf(("KERNEL32: HMHandleTranslateToOS2i (%08xh)\n",
|
---|
557 | hHandle16));
|
---|
558 | #endif
|
---|
559 |
|
---|
560 | return(TabWin32Handles[hHandle16].hmHandleData.hHMHandle);
|
---|
561 | }
|
---|
562 |
|
---|
563 |
|
---|
564 |
|
---|
565 | /*****************************************************************************
|
---|
566 | * Name : HANDLE _HMGetStdHandle
|
---|
567 | * Purpose : replacement for Open32's GetStdHandle function
|
---|
568 | * Parameters: DWORD nStdHandle
|
---|
569 | * Variables :
|
---|
570 | * Result : HANDLE to standard device
|
---|
571 | * Remark :
|
---|
572 | * Status :
|
---|
573 | *
|
---|
574 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
---|
575 | *****************************************************************************/
|
---|
576 |
|
---|
577 | HANDLE HMGetStdHandle(DWORD nStdHandle)
|
---|
578 | {
|
---|
579 | switch (nStdHandle)
|
---|
580 | {
|
---|
581 | case STD_INPUT_HANDLE: return (HMGlobals.hStandardIn);
|
---|
582 | case STD_OUTPUT_HANDLE: return (HMGlobals.hStandardOut);
|
---|
583 | case STD_ERROR_HANDLE: return (HMGlobals.hStandardError);
|
---|
584 |
|
---|
585 | default:
|
---|
586 | {
|
---|
587 | SetLastError(ERROR_INVALID_PARAMETER); /* set error information */
|
---|
588 | return (INVALID_HANDLE_VALUE); /* raise error condition */
|
---|
589 | }
|
---|
590 | }
|
---|
591 | }
|
---|
592 |
|
---|
593 |
|
---|
594 | /*****************************************************************************
|
---|
595 | * Name : HANDLE _HMSetStdHandle
|
---|
596 | * Purpose : replacement for Open32's SetStdHandle function
|
---|
597 | * Parameters: DWORD nStdHandle
|
---|
598 | * HANDLE hHandle
|
---|
599 | * Variables :
|
---|
600 | * Result : BOOL fSuccess
|
---|
601 | * Remark :
|
---|
602 | * Status :
|
---|
603 | *
|
---|
604 | * Author : Patrick Haller [Wed, 1998/02/12 20:44]
|
---|
605 | *****************************************************************************/
|
---|
606 |
|
---|
607 | BOOL HMSetStdHandle(DWORD nStdHandle,
|
---|
608 | HANDLE hHandle)
|
---|
609 | {
|
---|
610 | switch (nStdHandle)
|
---|
611 | {
|
---|
612 | case STD_INPUT_HANDLE: HMGlobals.hStandardIn = hHandle; return TRUE;
|
---|
613 | case STD_OUTPUT_HANDLE: HMGlobals.hStandardOut = hHandle; return TRUE;
|
---|
614 | case STD_ERROR_HANDLE: HMGlobals.hStandardError = hHandle; return TRUE;
|
---|
615 |
|
---|
616 | default:
|
---|
617 | {
|
---|
618 | SetLastError(ERROR_INVALID_PARAMETER); /* set error information */
|
---|
619 | return (FALSE); /* raise error condition */
|
---|
620 | }
|
---|
621 | }
|
---|
622 | }
|
---|
623 |
|
---|
624 |
|
---|
625 | /*****************************************************************************
|
---|
626 | * Name : HANDLE HMCreateFile
|
---|
627 | * Purpose : Wrapper for the CreateFile() API
|
---|
628 | * Parameters:
|
---|
629 | * Variables :
|
---|
630 | * Result :
|
---|
631 | * Remark : Fix parameters passed to the HMDeviceManager::CreateFile
|
---|
632 | * Supply access mode and share mode validation routines
|
---|
633 | * Status :
|
---|
634 | *
|
---|
635 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
636 | *****************************************************************************/
|
---|
637 |
|
---|
638 | HFILE HMCreateFile(LPCSTR lpFileName,
|
---|
639 | DWORD dwDesiredAccess,
|
---|
640 | DWORD dwShareMode,
|
---|
641 | LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
---|
642 | DWORD dwCreationDisposition,
|
---|
643 | DWORD dwFlagsAndAttributes,
|
---|
644 | HANDLE hTemplateFile)
|
---|
645 | {
|
---|
646 | int iIndex; /* index into the handle table */
|
---|
647 | int iIndexNew; /* index into the handle table */
|
---|
648 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
649 | HANDLE hResult;
|
---|
650 | DWORD rc; /* API return code */
|
---|
651 | PHMHANDLEDATA pHMHandleData;
|
---|
652 | HMHANDLEDATA HMHandleTemp; /* temporary buffer for handle data */
|
---|
653 |
|
---|
654 | /* create new handle by either lpFileName or hTemplateFile */
|
---|
655 | if (lpFileName == NULL) /* this indicates creation from template */
|
---|
656 | {
|
---|
657 | iIndex = _HMHandleQuery(hTemplateFile); /* query table for template */
|
---|
658 | if (-1 == iIndex) /* this device is unknown to us */
|
---|
659 | {
|
---|
660 | SetLastError (ERROR_INVALID_HANDLE);
|
---|
661 | return INVALID_HANDLE_VALUE;
|
---|
662 | }
|
---|
663 | else
|
---|
664 | {
|
---|
665 | /* to pass to handler */
|
---|
666 | pHMHandleData = &TabWin32Handles[iIndex].hmHandleData;
|
---|
667 | pDeviceHandler = TabWin32Handles[iIndex].pDeviceHandler;
|
---|
668 | }
|
---|
669 | }
|
---|
670 | else
|
---|
671 | {
|
---|
672 | pDeviceHandler = _HMDeviceFind((PSZ)lpFileName); /* find device */
|
---|
673 |
|
---|
674 | if (NULL == pDeviceHandler) /* this name is unknown to us */
|
---|
675 | {
|
---|
676 | SetLastError(ERROR_FILE_NOT_FOUND);
|
---|
677 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
678 | }
|
---|
679 | else
|
---|
680 | pHMHandleData = NULL;
|
---|
681 | }
|
---|
682 |
|
---|
683 |
|
---|
684 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
685 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
686 | {
|
---|
687 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
688 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
689 | }
|
---|
690 |
|
---|
691 |
|
---|
692 | /* initialize the complete HMHANDLEDATA structure */
|
---|
693 | if (lpFileName == NULL) /* create from template */
|
---|
694 | memcpy (&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
695 | &TabWin32Handles[iIndex].hmHandleData,
|
---|
696 | sizeof(HMHANDLEDATA));
|
---|
697 | else
|
---|
698 | {
|
---|
699 | HMHandleTemp.dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
700 | HMHandleTemp.dwAccess = dwDesiredAccess;
|
---|
701 | HMHandleTemp.dwShare = dwShareMode;
|
---|
702 | HMHandleTemp.dwCreation = dwCreationDisposition;
|
---|
703 | HMHandleTemp.dwFlags = dwFlagsAndAttributes;
|
---|
704 | HMHandleTemp.lpHandlerData = NULL;
|
---|
705 | }
|
---|
706 |
|
---|
707 | /* we've got to mark the handle as occupied here, since another device */
|
---|
708 | /* could be created within the device handler -> deadlock */
|
---|
709 |
|
---|
710 | /* write appropriate entry into the handle table if open succeeded */
|
---|
711 | HMHandleTemp.hHMHandle = iIndexNew;
|
---|
712 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
713 |
|
---|
714 | /* now copy back our temporary handle data */
|
---|
715 | memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
716 | &HMHandleTemp,
|
---|
717 | sizeof(HMHANDLEDATA));
|
---|
718 |
|
---|
719 | rc = pDeviceHandler->CreateFile(lpFileName, /* call the device handler */
|
---|
720 | &HMHandleTemp,
|
---|
721 | lpSecurityAttributes,
|
---|
722 | pHMHandleData);
|
---|
723 |
|
---|
724 | #ifdef DEBUG_LOCAL
|
---|
725 | dprintf(("KERNEL32/HandleManager:CheckPoint2: %s lpHandlerData=%08xh\n",
|
---|
726 | lpFileName,
|
---|
727 | HMHandleTemp.lpHandlerData));
|
---|
728 | #endif
|
---|
729 |
|
---|
730 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
731 | {
|
---|
732 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
733 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
734 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
735 | }
|
---|
736 | else
|
---|
737 | {
|
---|
738 | /* copy data fields that might have been modified by CreateFile */
|
---|
739 | memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
740 | &HMHandleTemp,
|
---|
741 | sizeof(HMHANDLEDATA));
|
---|
742 | }
|
---|
743 |
|
---|
744 |
|
---|
745 | #ifdef DEBUG_LOCAL
|
---|
746 | dprintf(("KERNEL32/HandleManager: CreateFile(%s)=%08xh\n",
|
---|
747 | lpFileName,
|
---|
748 | iIndexNew));
|
---|
749 | #endif
|
---|
750 |
|
---|
751 | return (HFILE)iIndexNew; /* return valid handle */
|
---|
752 | }
|
---|
753 |
|
---|
754 |
|
---|
755 | /*****************************************************************************
|
---|
756 | * Name : HANDLE HMOpenFile
|
---|
757 | * Purpose : Wrapper for the OpenFile() API
|
---|
758 | * Parameters:
|
---|
759 | * Variables :
|
---|
760 | * Result :
|
---|
761 | * Remark : Fix parameters passed to the HMDeviceManager::OpenFile
|
---|
762 | * Supply access mode and share mode validation routines
|
---|
763 | * Status :
|
---|
764 | *
|
---|
765 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
766 | *****************************************************************************/
|
---|
767 |
|
---|
768 |
|
---|
769 | /***********************************************************************
|
---|
770 | * FILE_ConvertOFMode
|
---|
771 | *
|
---|
772 | * Convert OF_* mode into flags for CreateFile.
|
---|
773 | */
|
---|
774 | static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing )
|
---|
775 | {
|
---|
776 | switch(mode & 0x03)
|
---|
777 | {
|
---|
778 | case OF_READ: *access = GENERIC_READ; break;
|
---|
779 | case OF_WRITE: *access = GENERIC_WRITE; break;
|
---|
780 | case OF_READWRITE: *access = GENERIC_READ | GENERIC_WRITE; break;
|
---|
781 | default: *access = 0; break;
|
---|
782 | }
|
---|
783 | switch(mode & 0x70)
|
---|
784 | {
|
---|
785 | case OF_SHARE_EXCLUSIVE: *sharing = 0; break;
|
---|
786 | case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break;
|
---|
787 | case OF_SHARE_DENY_READ: *sharing = FILE_SHARE_WRITE; break;
|
---|
788 | case OF_SHARE_DENY_NONE:
|
---|
789 | case OF_SHARE_COMPAT:
|
---|
790 | default: *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break;
|
---|
791 | }
|
---|
792 | }
|
---|
793 |
|
---|
794 | HANDLE HMOpenFile(LPCSTR lpFileName,
|
---|
795 | OFSTRUCT* pOFStruct,
|
---|
796 | UINT fuMode)
|
---|
797 | {
|
---|
798 | int iIndex; /* index into the handle table */
|
---|
799 | int iIndexNew; /* index into the handle table */
|
---|
800 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
801 | PHMHANDLEDATA pHMHandleData;
|
---|
802 | DWORD rc; /* API return code */
|
---|
803 |
|
---|
804 |
|
---|
805 | pDeviceHandler = _HMDeviceFind((PSZ)lpFileName); /* find device */
|
---|
806 | if (NULL == pDeviceHandler) /* this name is unknown to us */
|
---|
807 | {
|
---|
808 | SetLastError(ERROR_FILE_NOT_FOUND);
|
---|
809 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
810 | }
|
---|
811 | else
|
---|
812 | pHMHandleData = NULL;
|
---|
813 |
|
---|
814 |
|
---|
815 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
816 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
817 | {
|
---|
818 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
819 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
820 | }
|
---|
821 |
|
---|
822 |
|
---|
823 | /* initialize the complete HMHANDLEDATA structure */
|
---|
824 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
825 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
826 |
|
---|
827 | FILE_ConvertOFMode(fuMode, /* map OF_flags */
|
---|
828 | &pHMHandleData->dwAccess,
|
---|
829 | &pHMHandleData->dwShare);
|
---|
830 |
|
---|
831 | pHMHandleData->dwCreation = 0;
|
---|
832 | pHMHandleData->dwFlags = 0;
|
---|
833 | pHMHandleData->lpHandlerData = NULL;
|
---|
834 |
|
---|
835 |
|
---|
836 | /* we've got to mark the handle as occupied here, since another device */
|
---|
837 | /* could be created within the device handler -> deadlock */
|
---|
838 |
|
---|
839 | /* write appropriate entry into the handle table if open succeeded */
|
---|
840 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
841 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
842 |
|
---|
843 | rc = pDeviceHandler->OpenFile (lpFileName, /* call the device handler */
|
---|
844 | &TabWin32Handles[iIndexNew].hmHandleData,
|
---|
845 | pOFStruct,
|
---|
846 | fuMode);
|
---|
847 |
|
---|
848 | #ifdef DEBUG_LOCAL
|
---|
849 | dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh rc=%08xh\n",
|
---|
850 | lpFileName,
|
---|
851 | &TabWin32Handles[iIndexNew].hmHandleData.lpHandlerData,
|
---|
852 | rc));
|
---|
853 | #endif
|
---|
854 |
|
---|
855 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
856 | {
|
---|
857 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
858 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
859 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
860 | }
|
---|
861 |
|
---|
862 | #ifdef DEBUG_LOCAL
|
---|
863 | dprintf(("KERNEL32/HandleManager: OpenFile(%s)=%08xh\n",
|
---|
864 | lpFileName,
|
---|
865 | hResult));
|
---|
866 | #endif
|
---|
867 |
|
---|
868 | return iIndexNew; /* return valid handle */
|
---|
869 | }
|
---|
870 |
|
---|
871 |
|
---|
872 |
|
---|
873 | /*****************************************************************************
|
---|
874 | * Name : HANDLE HMCloseFile
|
---|
875 | * Purpose : Wrapper for the CloseHandle() API
|
---|
876 | * Parameters:
|
---|
877 | * Variables :
|
---|
878 | * Result :
|
---|
879 | * Remark :
|
---|
880 | * Status :
|
---|
881 | *
|
---|
882 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
883 | *****************************************************************************/
|
---|
884 |
|
---|
885 | BOOL HMCloseHandle(HANDLE hObject)
|
---|
886 | {
|
---|
887 | int iIndex; /* index into the handle table */
|
---|
888 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
---|
889 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
890 |
|
---|
891 | /* validate handle */
|
---|
892 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
---|
893 | if (-1 == iIndex) /* error ? */
|
---|
894 | {
|
---|
895 | //@@@PH it may occur someone closes e.g. a semaphore handle
|
---|
896 | // which is not registered through the HandleManager yet.
|
---|
897 | // so we try to pass on to Open32 instead.
|
---|
898 | dprintf(("KERNEL32: HandleManager:HMCloseHandle(%08xh) passed on to Open32.\n",
|
---|
899 | hObject));
|
---|
900 |
|
---|
901 | fResult = O32_CloseHandle(hObject);
|
---|
902 | return (fResult);
|
---|
903 |
|
---|
904 | //SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
905 | //return (FALSE); /* signal failure */
|
---|
906 | }
|
---|
907 |
|
---|
908 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
909 | fResult = pHMHandle->pDeviceHandler->CloseHandle(&pHMHandle->hmHandleData);
|
---|
910 |
|
---|
911 | if (fResult == TRUE) /* remove handle if close succeeded */
|
---|
912 | pHMHandle->hmHandleData.hHMHandle = 0; /* mark handle as free */
|
---|
913 |
|
---|
914 | return (fResult); /* deliver return code */
|
---|
915 | }
|
---|
916 |
|
---|
917 |
|
---|
918 | /*****************************************************************************
|
---|
919 | * Name : HANDLE HMReadFile
|
---|
920 | * Purpose : Wrapper for the ReadHandle() API
|
---|
921 | * Parameters:
|
---|
922 | * Variables :
|
---|
923 | * Result :
|
---|
924 | * Remark :
|
---|
925 | * Status :
|
---|
926 | *
|
---|
927 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
928 | *****************************************************************************/
|
---|
929 |
|
---|
930 | BOOL HMReadFile(HANDLE hFile,
|
---|
931 | LPVOID lpBuffer,
|
---|
932 | DWORD nNumberOfBytesToRead,
|
---|
933 | LPDWORD lpNumberOfBytesRead,
|
---|
934 | LPOVERLAPPED lpOverlapped)
|
---|
935 | {
|
---|
936 | int iIndex; /* index into the handle table */
|
---|
937 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
---|
938 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
939 |
|
---|
940 | /* validate handle */
|
---|
941 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
942 | if (-1 == iIndex) /* error ? */
|
---|
943 | {
|
---|
944 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
945 | return (FALSE); /* signal failure */
|
---|
946 | }
|
---|
947 |
|
---|
948 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
949 | fResult = pHMHandle->pDeviceHandler->ReadFile(&pHMHandle->hmHandleData,
|
---|
950 | lpBuffer,
|
---|
951 | nNumberOfBytesToRead,
|
---|
952 | lpNumberOfBytesRead,
|
---|
953 | lpOverlapped);
|
---|
954 |
|
---|
955 | return (fResult); /* deliver return code */
|
---|
956 | }
|
---|
957 |
|
---|
958 |
|
---|
959 | /*****************************************************************************
|
---|
960 | * Name : HANDLE HMWriteFile
|
---|
961 | * Purpose : Wrapper for the WriteHandle() API
|
---|
962 | * Parameters:
|
---|
963 | * Variables :
|
---|
964 | * Result :
|
---|
965 | * Remark :
|
---|
966 | * Status :
|
---|
967 | *
|
---|
968 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
969 | *****************************************************************************/
|
---|
970 |
|
---|
971 | BOOL HMWriteFile(HANDLE hFile,
|
---|
972 | LPCVOID lpBuffer,
|
---|
973 | DWORD nNumberOfBytesToWrite,
|
---|
974 | LPDWORD lpNumberOfBytesWritten,
|
---|
975 | LPOVERLAPPED lpOverlapped)
|
---|
976 | {
|
---|
977 | int iIndex; /* index into the handle table */
|
---|
978 | BOOL fResult; /* result from the device handler's CloseHandle() */
|
---|
979 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
980 |
|
---|
981 | /* validate handle */
|
---|
982 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
983 | if (-1 == iIndex) /* error ? */
|
---|
984 | {
|
---|
985 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
986 | return (FALSE); /* signal failure */
|
---|
987 | }
|
---|
988 |
|
---|
989 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
990 | fResult = pHMHandle->pDeviceHandler->WriteFile(&pHMHandle->hmHandleData,
|
---|
991 | lpBuffer,
|
---|
992 | nNumberOfBytesToWrite,
|
---|
993 | lpNumberOfBytesWritten,
|
---|
994 | lpOverlapped);
|
---|
995 |
|
---|
996 | return (fResult); /* deliver return code */
|
---|
997 | }
|
---|
998 |
|
---|
999 |
|
---|
1000 | /*****************************************************************************
|
---|
1001 | * Name : HANDLE HMGetFileType
|
---|
1002 | * Purpose : Wrapper for the GetFileType() API
|
---|
1003 | * Parameters:
|
---|
1004 | * Variables :
|
---|
1005 | * Result :
|
---|
1006 | * Remark :
|
---|
1007 | * Status :
|
---|
1008 | *
|
---|
1009 | * Author : Patrick Haller [Wed, 1998/02/12 13:37]
|
---|
1010 | *****************************************************************************/
|
---|
1011 |
|
---|
1012 | DWORD HMGetFileType(HANDLE hFile)
|
---|
1013 | {
|
---|
1014 | int iIndex; /* index into the handle table */
|
---|
1015 | DWORD dwResult; /* result from the device handler's API */
|
---|
1016 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1017 |
|
---|
1018 | /* validate handle */
|
---|
1019 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1020 | if (-1 == iIndex) /* error ? */
|
---|
1021 | {
|
---|
1022 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1023 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1027 | dwResult = pHMHandle->pDeviceHandler->GetFileType(&pHMHandle->hmHandleData);
|
---|
1028 |
|
---|
1029 | return (dwResult); /* deliver return code */
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 |
|
---|
1033 | /*****************************************************************************
|
---|
1034 | * Name : HMDeviceHandler::_DeviceReuqest
|
---|
1035 | * Purpose : entry method for special request functions
|
---|
1036 | * Parameters: ULONG ulRequestCode
|
---|
1037 | * various parameters as required
|
---|
1038 | * Variables :
|
---|
1039 | * Result :
|
---|
1040 | * Remark : the standard behaviour is to return an error code for non-
|
---|
1041 | * existant request codes
|
---|
1042 | * Status :
|
---|
1043 | *
|
---|
1044 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
1045 | *****************************************************************************/
|
---|
1046 |
|
---|
1047 | DWORD HMDeviceRequest (HANDLE hFile,
|
---|
1048 | ULONG ulRequestCode,
|
---|
1049 | ULONG arg1,
|
---|
1050 | ULONG arg2,
|
---|
1051 | ULONG arg3,
|
---|
1052 | ULONG arg4)
|
---|
1053 | {
|
---|
1054 | int iIndex; /* index into the handle table */
|
---|
1055 | DWORD dwResult; /* result from the device handler's API */
|
---|
1056 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1057 |
|
---|
1058 | /* validate handle */
|
---|
1059 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1060 | if (-1 == iIndex) /* error ? */
|
---|
1061 | {
|
---|
1062 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1063 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1067 | dwResult = pHMHandle->pDeviceHandler->_DeviceRequest(&pHMHandle->hmHandleData,
|
---|
1068 | ulRequestCode,
|
---|
1069 | arg1,
|
---|
1070 | arg2,
|
---|
1071 | arg3,
|
---|
1072 | arg4);
|
---|
1073 |
|
---|
1074 | return (dwResult); /* deliver return code */
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 |
|
---|
1078 | /*****************************************************************************
|
---|
1079 | * Name : HMDeviceHandler::GetFileInformationByHandle
|
---|
1080 | * Purpose : router function for GetFileInformationByHandle
|
---|
1081 | * Parameters:
|
---|
1082 | * Variables :
|
---|
1083 | * Result :
|
---|
1084 | * Remark :
|
---|
1085 | * Status :
|
---|
1086 | *
|
---|
1087 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1088 | *****************************************************************************/
|
---|
1089 |
|
---|
1090 | BOOL HMGetFileInformationByHandle (HANDLE hFile,
|
---|
1091 | BY_HANDLE_FILE_INFORMATION *pHFI)
|
---|
1092 | {
|
---|
1093 | int iIndex; /* index into the handle table */
|
---|
1094 | DWORD dwResult; /* result from the device handler's API */
|
---|
1095 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1096 |
|
---|
1097 | /* validate handle */
|
---|
1098 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1099 | if (-1 == iIndex) /* error ? */
|
---|
1100 | {
|
---|
1101 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1102 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1106 | dwResult = pHMHandle->pDeviceHandler->GetFileInformationByHandle(&pHMHandle->hmHandleData,
|
---|
1107 | pHFI);
|
---|
1108 |
|
---|
1109 | return (dwResult); /* deliver return code */
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 |
|
---|
1113 | /*****************************************************************************
|
---|
1114 | * Name : HMDeviceHandler::SetEndOfFile
|
---|
1115 | * Purpose : router function for SetEndOfFile
|
---|
1116 | * Parameters:
|
---|
1117 | * Variables :
|
---|
1118 | * Result :
|
---|
1119 | * Remark :
|
---|
1120 | * Status :
|
---|
1121 | *
|
---|
1122 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1123 | *****************************************************************************/
|
---|
1124 |
|
---|
1125 | BOOL HMSetEndOfFile (HANDLE hFile)
|
---|
1126 | {
|
---|
1127 | int iIndex; /* index into the handle table */
|
---|
1128 | BOOL bResult; /* result from the device handler's API */
|
---|
1129 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1130 |
|
---|
1131 | /* validate handle */
|
---|
1132 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1133 | if (-1 == iIndex) /* error ? */
|
---|
1134 | {
|
---|
1135 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1136 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1140 | bResult = pHMHandle->pDeviceHandler->SetEndOfFile(&pHMHandle->hmHandleData);
|
---|
1141 |
|
---|
1142 | return (bResult); /* deliver return code */
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 |
|
---|
1146 | /*****************************************************************************
|
---|
1147 | * Name : HMDeviceHandler::SetFileTime
|
---|
1148 | * Purpose : router function for SetFileTime
|
---|
1149 | * Parameters:
|
---|
1150 | * Variables :
|
---|
1151 | * Result :
|
---|
1152 | * Remark :
|
---|
1153 | * Status :
|
---|
1154 | *
|
---|
1155 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1156 | *****************************************************************************/
|
---|
1157 |
|
---|
1158 | BOOL HMSetFileTime (HANDLE hFile,
|
---|
1159 | const FILETIME *pFT1,
|
---|
1160 | const FILETIME *pFT2,
|
---|
1161 | const FILETIME *pFT3)
|
---|
1162 | {
|
---|
1163 | int iIndex; /* index into the handle table */
|
---|
1164 | BOOL bResult; /* result from the device handler's API */
|
---|
1165 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1166 |
|
---|
1167 | /* validate handle */
|
---|
1168 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1169 | if (-1 == iIndex) /* error ? */
|
---|
1170 | {
|
---|
1171 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1172 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1176 | bResult = pHMHandle->pDeviceHandler->SetFileTime(&pHMHandle->hmHandleData,
|
---|
1177 | (LPFILETIME)pFT1,
|
---|
1178 | (LPFILETIME)pFT2,
|
---|
1179 | (LPFILETIME)pFT3);
|
---|
1180 |
|
---|
1181 | return (bResult); /* deliver return code */
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 |
|
---|
1185 | /*****************************************************************************
|
---|
1186 | * Name : HMDeviceHandler::GetFileSize
|
---|
1187 | * Purpose : router function for GetFileSize
|
---|
1188 | * Parameters:
|
---|
1189 | * Variables :
|
---|
1190 | * Result :
|
---|
1191 | * Remark :
|
---|
1192 | * Status :
|
---|
1193 | *
|
---|
1194 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1195 | *****************************************************************************/
|
---|
1196 |
|
---|
1197 | DWORD HMGetFileSize (HANDLE hFile,
|
---|
1198 | PDWORD pSize)
|
---|
1199 | {
|
---|
1200 | int iIndex; /* index into the handle table */
|
---|
1201 | DWORD dwResult; /* result from the device handler's API */
|
---|
1202 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1203 |
|
---|
1204 | /* validate handle */
|
---|
1205 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1206 | if (-1 == iIndex) /* error ? */
|
---|
1207 | {
|
---|
1208 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1209 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1213 | dwResult = pHMHandle->pDeviceHandler->GetFileSize(&pHMHandle->hmHandleData,
|
---|
1214 | pSize);
|
---|
1215 |
|
---|
1216 | return (dwResult); /* deliver return code */
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 |
|
---|
1220 | /*****************************************************************************
|
---|
1221 | * Name : HMDeviceHandler::SetFilePointer
|
---|
1222 | * Purpose : router function for SetFilePointer
|
---|
1223 | * Parameters:
|
---|
1224 | * Variables :
|
---|
1225 | * Result :
|
---|
1226 | * Remark :
|
---|
1227 | * Status :
|
---|
1228 | *
|
---|
1229 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1230 | *****************************************************************************/
|
---|
1231 |
|
---|
1232 | DWORD HMSetFilePointer (HANDLE hFile,
|
---|
1233 | LONG lDistanceToMove,
|
---|
1234 | PLONG lpDistanceToMoveHigh,
|
---|
1235 | DWORD dwMoveMethod)
|
---|
1236 | {
|
---|
1237 | int iIndex; /* index into the handle table */
|
---|
1238 | DWORD dwResult; /* result from the device handler's API */
|
---|
1239 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1240 |
|
---|
1241 | /* validate handle */
|
---|
1242 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1243 | if (-1 == iIndex) /* error ? */
|
---|
1244 | {
|
---|
1245 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1246 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1250 | dwResult = pHMHandle->pDeviceHandler->SetFilePointer(&pHMHandle->hmHandleData,
|
---|
1251 | lDistanceToMove,
|
---|
1252 | lpDistanceToMoveHigh,
|
---|
1253 | dwMoveMethod);
|
---|
1254 |
|
---|
1255 | return (dwResult); /* deliver return code */
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | /*****************************************************************************
|
---|
1260 | * Name : HMDeviceHandler::LockFile
|
---|
1261 | * Purpose : router function for LockFile
|
---|
1262 | * Parameters:
|
---|
1263 | * Variables :
|
---|
1264 | * Result :
|
---|
1265 | * Remark :
|
---|
1266 | * Status :
|
---|
1267 | *
|
---|
1268 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1269 | *****************************************************************************/
|
---|
1270 |
|
---|
1271 | BOOL HMLockFile (HFILE hFile,
|
---|
1272 | DWORD arg2,
|
---|
1273 | DWORD arg3,
|
---|
1274 | DWORD arg4,
|
---|
1275 | DWORD arg5)
|
---|
1276 | {
|
---|
1277 | int iIndex; /* index into the handle table */
|
---|
1278 | DWORD dwResult; /* result from the device handler's API */
|
---|
1279 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1280 |
|
---|
1281 | /* validate handle */
|
---|
1282 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1283 | if (-1 == iIndex) /* error ? */
|
---|
1284 | {
|
---|
1285 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1286 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1290 | dwResult = pHMHandle->pDeviceHandler->LockFile(&pHMHandle->hmHandleData,
|
---|
1291 | arg2,
|
---|
1292 | arg3,
|
---|
1293 | arg4,
|
---|
1294 | arg5);
|
---|
1295 |
|
---|
1296 | return (dwResult); /* deliver return code */
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 |
|
---|
1300 | /*****************************************************************************
|
---|
1301 | * Name : HMDeviceHandler::LockFileEx
|
---|
1302 | * Purpose : router function for LockFileEx
|
---|
1303 | * Parameters:
|
---|
1304 | * Variables :
|
---|
1305 | * Result :
|
---|
1306 | * Remark :
|
---|
1307 | * Status :
|
---|
1308 | *
|
---|
1309 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1310 | *****************************************************************************/
|
---|
1311 |
|
---|
1312 | BOOL HMLockFileEx(HANDLE hFile,
|
---|
1313 | DWORD dwFlags,
|
---|
1314 | DWORD dwReserved,
|
---|
1315 | DWORD nNumberOfBytesToLockLow,
|
---|
1316 | DWORD nNumberOfBytesToLockHigh,
|
---|
1317 | LPOVERLAPPED lpOverlapped)
|
---|
1318 | {
|
---|
1319 | int iIndex; /* index into the handle table */
|
---|
1320 | DWORD dwResult; /* result from the device handler's API */
|
---|
1321 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1322 |
|
---|
1323 | /* validate handle */
|
---|
1324 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1325 | if (-1 == iIndex) /* error ? */
|
---|
1326 | {
|
---|
1327 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1328 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1332 | dwResult = pHMHandle->pDeviceHandler->LockFileEx(&pHMHandle->hmHandleData,
|
---|
1333 | dwFlags,
|
---|
1334 | dwReserved,
|
---|
1335 | nNumberOfBytesToLockLow,
|
---|
1336 | nNumberOfBytesToLockHigh,
|
---|
1337 | lpOverlapped);
|
---|
1338 |
|
---|
1339 | return (dwResult); /* deliver return code */
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 |
|
---|
1343 |
|
---|
1344 | /*****************************************************************************
|
---|
1345 | * Name : HMDeviceHandler::UnlockFile
|
---|
1346 | * Purpose : router function for UnlockFile
|
---|
1347 | * Parameters:
|
---|
1348 | * Variables :
|
---|
1349 | * Result :
|
---|
1350 | * Remark :
|
---|
1351 | * Status :
|
---|
1352 | *
|
---|
1353 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1354 | *****************************************************************************/
|
---|
1355 |
|
---|
1356 | BOOL HMUnlockFile (HFILE hFile,
|
---|
1357 | DWORD arg2,
|
---|
1358 | DWORD arg3,
|
---|
1359 | DWORD arg4,
|
---|
1360 | DWORD arg5)
|
---|
1361 | {
|
---|
1362 | int iIndex; /* index into the handle table */
|
---|
1363 | DWORD dwResult; /* result from the device handler's API */
|
---|
1364 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1365 |
|
---|
1366 | /* validate handle */
|
---|
1367 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1368 | if (-1 == iIndex) /* error ? */
|
---|
1369 | {
|
---|
1370 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1371 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1375 | dwResult = pHMHandle->pDeviceHandler->UnlockFile(&pHMHandle->hmHandleData,
|
---|
1376 | arg2,
|
---|
1377 | arg3,
|
---|
1378 | arg4,
|
---|
1379 | arg5);
|
---|
1380 |
|
---|
1381 | return (dwResult); /* deliver return code */
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 |
|
---|
1385 | /*****************************************************************************
|
---|
1386 | * Name : HMDeviceHandler::UnlockFileEx
|
---|
1387 | * Purpose : router function for UnlockFileEx
|
---|
1388 | * Parameters:
|
---|
1389 | * Variables :
|
---|
1390 | * Result :
|
---|
1391 | * Remark :
|
---|
1392 | * Status :
|
---|
1393 | *
|
---|
1394 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1395 | *****************************************************************************/
|
---|
1396 |
|
---|
1397 | BOOL HMUnlockFileEx(HANDLE hFile,
|
---|
1398 | DWORD dwFlags,
|
---|
1399 | DWORD dwReserved,
|
---|
1400 | DWORD nNumberOfBytesToLockLow,
|
---|
1401 | DWORD nNumberOfBytesToLockHigh,
|
---|
1402 | LPOVERLAPPED lpOverlapped)
|
---|
1403 | {
|
---|
1404 | int iIndex; /* index into the handle table */
|
---|
1405 | DWORD dwResult; /* result from the device handler's API */
|
---|
1406 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1407 |
|
---|
1408 | /* validate handle */
|
---|
1409 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1410 | if (-1 == iIndex) /* error ? */
|
---|
1411 | {
|
---|
1412 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1413 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1417 | dwResult = pHMHandle->pDeviceHandler->UnlockFileEx(&pHMHandle->hmHandleData,
|
---|
1418 | dwFlags,
|
---|
1419 | dwReserved,
|
---|
1420 | nNumberOfBytesToLockLow,
|
---|
1421 | nNumberOfBytesToLockHigh,
|
---|
1422 | lpOverlapped);
|
---|
1423 |
|
---|
1424 | return (dwResult); /* deliver return code */
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 |
|
---|
1428 | /*****************************************************************************
|
---|
1429 | * Name : HMDeviceHandler::WaitForSingleObject
|
---|
1430 | * Purpose : router function for WaitForSingleObject
|
---|
1431 | * Parameters:
|
---|
1432 | * Variables :
|
---|
1433 | * Result :
|
---|
1434 | * Remark :
|
---|
1435 | * Status :
|
---|
1436 | *
|
---|
1437 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1438 | *****************************************************************************/
|
---|
1439 |
|
---|
1440 | DWORD HMWaitForSingleObject(HANDLE hObject,
|
---|
1441 | DWORD dwTimeout)
|
---|
1442 | {
|
---|
1443 | int iIndex; /* index into the handle table */
|
---|
1444 | DWORD dwResult; /* result from the device handler's API */
|
---|
1445 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1446 |
|
---|
1447 | /* validate handle */
|
---|
1448 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
---|
1449 | if (-1 == iIndex) /* error ? */
|
---|
1450 | {
|
---|
1451 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1452 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1456 | dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData,
|
---|
1457 | dwTimeout);
|
---|
1458 |
|
---|
1459 | return (dwResult); /* deliver return code */
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 |
|
---|
1463 | /*****************************************************************************
|
---|
1464 | * Name : HMDeviceHandler::WaitForSingleObjectEx
|
---|
1465 | * Purpose : router function for WaitForSingleObjectEx
|
---|
1466 | * Parameters:
|
---|
1467 | * Variables :
|
---|
1468 | * Result :
|
---|
1469 | * Remark :
|
---|
1470 | * Status :
|
---|
1471 | *
|
---|
1472 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1473 | *****************************************************************************/
|
---|
1474 |
|
---|
1475 | DWORD HMWaitForSingleObjectEx(HANDLE hObject,
|
---|
1476 | DWORD dwTimeout,
|
---|
1477 | BOOL fAlertable)
|
---|
1478 | {
|
---|
1479 | int iIndex; /* index into the handle table */
|
---|
1480 | DWORD dwResult; /* result from the device handler's API */
|
---|
1481 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1482 |
|
---|
1483 | /* validate handle */
|
---|
1484 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
---|
1485 | if (-1 == iIndex) /* error ? */
|
---|
1486 | {
|
---|
1487 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1488 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1492 | dwResult = pHMHandle->pDeviceHandler->WaitForSingleObjectEx(&pHMHandle->hmHandleData,
|
---|
1493 | dwTimeout,
|
---|
1494 | fAlertable);
|
---|
1495 |
|
---|
1496 | return (dwResult); /* deliver return code */
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 |
|
---|
1500 | /*****************************************************************************
|
---|
1501 | * Name : HMDeviceHandler::FlushFileBuffers
|
---|
1502 | * Purpose : router function for FlushFileBuffers
|
---|
1503 | * Parameters:
|
---|
1504 | * Variables :
|
---|
1505 | * Result :
|
---|
1506 | * Remark :
|
---|
1507 | * Status :
|
---|
1508 | *
|
---|
1509 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1510 | *****************************************************************************/
|
---|
1511 |
|
---|
1512 | BOOL HMFlushFileBuffers(HANDLE hFile)
|
---|
1513 | {
|
---|
1514 | int iIndex; /* index into the handle table */
|
---|
1515 | DWORD dwResult; /* result from the device handler's API */
|
---|
1516 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1517 |
|
---|
1518 | /* validate handle */
|
---|
1519 | iIndex = _HMHandleQuery(hFile); /* get the index */
|
---|
1520 | if (-1 == iIndex) /* error ? */
|
---|
1521 | {
|
---|
1522 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1523 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1527 | dwResult = pHMHandle->pDeviceHandler->FlushFileBuffers(&pHMHandle->hmHandleData);
|
---|
1528 |
|
---|
1529 | return (dwResult); /* deliver return code */
|
---|
1530 | }
|
---|
1531 |
|
---|
1532 |
|
---|
1533 | /*****************************************************************************
|
---|
1534 | * Name : HMDeviceHandler::GetOverlappedResult
|
---|
1535 | * Purpose : router function for GetOverlappedResult
|
---|
1536 | * Parameters:
|
---|
1537 | * Variables :
|
---|
1538 | * Result :
|
---|
1539 | * Remark :
|
---|
1540 | * Status :
|
---|
1541 | *
|
---|
1542 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1543 | *****************************************************************************/
|
---|
1544 |
|
---|
1545 | BOOL HMGetOverlappedResult(HANDLE hObject,
|
---|
1546 | LPOVERLAPPED lpOverlapped,
|
---|
1547 | LPDWORD arg3,
|
---|
1548 | BOOL arg4)
|
---|
1549 | {
|
---|
1550 | int iIndex; /* index into the handle table */
|
---|
1551 | DWORD dwResult; /* result from the device handler's API */
|
---|
1552 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1553 |
|
---|
1554 | /* validate handle */
|
---|
1555 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
---|
1556 | if (-1 == iIndex) /* error ? */
|
---|
1557 | {
|
---|
1558 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1559 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1563 | dwResult = pHMHandle->pDeviceHandler->GetOverlappedResult(&pHMHandle->hmHandleData,
|
---|
1564 | lpOverlapped,
|
---|
1565 | arg3,
|
---|
1566 | arg4);
|
---|
1567 |
|
---|
1568 | return (dwResult); /* deliver return code */
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 |
|
---|
1572 | /*****************************************************************************
|
---|
1573 | * Name : HMReleaseMutex
|
---|
1574 | * Purpose : router function for ReleaseMutex
|
---|
1575 | * Parameters:
|
---|
1576 | * Variables :
|
---|
1577 | * Result :
|
---|
1578 | * Remark :
|
---|
1579 | * Status :
|
---|
1580 | *
|
---|
1581 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1582 | *****************************************************************************/
|
---|
1583 |
|
---|
1584 | BOOL HMReleaseMutex(HANDLE hObject)
|
---|
1585 | {
|
---|
1586 | int iIndex; /* index into the handle table */
|
---|
1587 | DWORD dwResult; /* result from the device handler's API */
|
---|
1588 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1589 |
|
---|
1590 | /* validate handle */
|
---|
1591 | iIndex = _HMHandleQuery(hObject); /* get the index */
|
---|
1592 | if (-1 == iIndex) /* error ? */
|
---|
1593 | {
|
---|
1594 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1595 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1596 | }
|
---|
1597 |
|
---|
1598 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1599 | dwResult = pHMHandle->pDeviceHandler->ReleaseMutex(&pHMHandle->hmHandleData);
|
---|
1600 |
|
---|
1601 | return (dwResult); /* deliver return code */
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 |
|
---|
1605 | /*****************************************************************************
|
---|
1606 | * Name : HMSetEvent
|
---|
1607 | * Purpose : router function for SetEvent
|
---|
1608 | * Parameters:
|
---|
1609 | * Variables :
|
---|
1610 | * Result :
|
---|
1611 | * Remark :
|
---|
1612 | * Status :
|
---|
1613 | *
|
---|
1614 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1615 | *****************************************************************************/
|
---|
1616 |
|
---|
1617 | BOOL HMSetEvent(HANDLE hEvent)
|
---|
1618 | {
|
---|
1619 | int iIndex; /* index into the handle table */
|
---|
1620 | DWORD dwResult; /* result from the device handler's API */
|
---|
1621 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1622 |
|
---|
1623 | /* validate handle */
|
---|
1624 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
---|
1625 | if (-1 == iIndex) /* error ? */
|
---|
1626 | {
|
---|
1627 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1628 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1632 | dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData);
|
---|
1633 |
|
---|
1634 | return (dwResult); /* deliver return code */
|
---|
1635 | }
|
---|
1636 |
|
---|
1637 |
|
---|
1638 | /*****************************************************************************
|
---|
1639 | * Name : HMPulseEvent
|
---|
1640 | * Purpose : router function for PulseEvent
|
---|
1641 | * Parameters:
|
---|
1642 | * Variables :
|
---|
1643 | * Result :
|
---|
1644 | * Remark :
|
---|
1645 | * Status :
|
---|
1646 | *
|
---|
1647 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1648 | *****************************************************************************/
|
---|
1649 |
|
---|
1650 | BOOL HMPulseEvent(HANDLE hEvent)
|
---|
1651 | {
|
---|
1652 | int iIndex; /* index into the handle table */
|
---|
1653 | DWORD dwResult; /* result from the device handler's API */
|
---|
1654 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1655 |
|
---|
1656 | /* validate handle */
|
---|
1657 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
---|
1658 | if (-1 == iIndex) /* error ? */
|
---|
1659 | {
|
---|
1660 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1661 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1665 | dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData);
|
---|
1666 |
|
---|
1667 | return (dwResult); /* deliver return code */
|
---|
1668 | }
|
---|
1669 |
|
---|
1670 |
|
---|
1671 | /*****************************************************************************
|
---|
1672 | * Name : HMResetEvent
|
---|
1673 | * Purpose : router function for ResetEvent
|
---|
1674 | * Parameters:
|
---|
1675 | * Variables :
|
---|
1676 | * Result :
|
---|
1677 | * Remark :
|
---|
1678 | * Status :
|
---|
1679 | *
|
---|
1680 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
1681 | *****************************************************************************/
|
---|
1682 |
|
---|
1683 | BOOL HMResetEvent(HANDLE hEvent)
|
---|
1684 | {
|
---|
1685 | int iIndex; /* index into the handle table */
|
---|
1686 | DWORD dwResult; /* result from the device handler's API */
|
---|
1687 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
1688 |
|
---|
1689 | /* validate handle */
|
---|
1690 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
---|
1691 | if (-1 == iIndex) /* error ? */
|
---|
1692 | {
|
---|
1693 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
1694 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
1695 | }
|
---|
1696 |
|
---|
1697 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
1698 | dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData);
|
---|
1699 |
|
---|
1700 | return (dwResult); /* deliver return code */
|
---|
1701 | }
|
---|
1702 |
|
---|
1703 |
|
---|
1704 | /*****************************************************************************
|
---|
1705 | * Name : HANDLE HMCreateEvent
|
---|
1706 | * Purpose : Wrapper for the CreateEvent() API
|
---|
1707 | * Parameters:
|
---|
1708 | * Variables :
|
---|
1709 | * Result :
|
---|
1710 | * Remark :
|
---|
1711 | * Status :
|
---|
1712 | *
|
---|
1713 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
1714 | *****************************************************************************/
|
---|
1715 |
|
---|
1716 | HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa,
|
---|
1717 | BOOL bManualReset,
|
---|
1718 | BOOL bInitialState,
|
---|
1719 | LPCTSTR lpName)
|
---|
1720 | {
|
---|
1721 | int iIndex; /* index into the handle table */
|
---|
1722 | int iIndexNew; /* index into the handle table */
|
---|
1723 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
1724 | PHMHANDLEDATA pHMHandleData;
|
---|
1725 | DWORD rc; /* API return code */
|
---|
1726 |
|
---|
1727 |
|
---|
1728 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
---|
1729 |
|
---|
1730 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
1731 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
1732 | {
|
---|
1733 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
1734 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 |
|
---|
1738 | /* initialize the complete HMHANDLEDATA structure */
|
---|
1739 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
1740 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
1741 | pHMHandleData->dwAccess = 0;
|
---|
1742 | pHMHandleData->dwShare = 0;
|
---|
1743 | pHMHandleData->dwCreation = 0;
|
---|
1744 | pHMHandleData->dwFlags = 0;
|
---|
1745 | pHMHandleData->lpHandlerData = NULL;
|
---|
1746 |
|
---|
1747 |
|
---|
1748 | /* we've got to mark the handle as occupied here, since another device */
|
---|
1749 | /* could be created within the device handler -> deadlock */
|
---|
1750 |
|
---|
1751 | /* write appropriate entry into the handle table if open succeeded */
|
---|
1752 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
1753 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
1754 |
|
---|
1755 | /* call the device handler */
|
---|
1756 | rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
1757 | lpsa,
|
---|
1758 | bManualReset,
|
---|
1759 | bInitialState,
|
---|
1760 | lpName);
|
---|
1761 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
1762 | {
|
---|
1763 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
1764 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
1765 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | return iIndexNew; /* return valid handle */
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 |
|
---|
1772 | /*****************************************************************************
|
---|
1773 | * Name : HANDLE HMCreateMutex
|
---|
1774 | * Purpose : Wrapper for the CreateMutex() API
|
---|
1775 | * Parameters:
|
---|
1776 | * Variables :
|
---|
1777 | * Result :
|
---|
1778 | * Remark :
|
---|
1779 | * Status :
|
---|
1780 | *
|
---|
1781 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
1782 | *****************************************************************************/
|
---|
1783 |
|
---|
1784 | HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa,
|
---|
1785 | BOOL bInitialOwner,
|
---|
1786 | LPCTSTR lpName)
|
---|
1787 | {
|
---|
1788 | int iIndex; /* index into the handle table */
|
---|
1789 | int iIndexNew; /* index into the handle table */
|
---|
1790 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
1791 | PHMHANDLEDATA pHMHandleData;
|
---|
1792 | DWORD rc; /* API return code */
|
---|
1793 |
|
---|
1794 |
|
---|
1795 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
---|
1796 |
|
---|
1797 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
1798 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
1799 | {
|
---|
1800 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
1801 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1802 | }
|
---|
1803 |
|
---|
1804 |
|
---|
1805 | /* initialize the complete HMHANDLEDATA structure */
|
---|
1806 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
1807 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
1808 | pHMHandleData->dwAccess = 0;
|
---|
1809 | pHMHandleData->dwShare = 0;
|
---|
1810 | pHMHandleData->dwCreation = 0;
|
---|
1811 | pHMHandleData->dwFlags = 0;
|
---|
1812 | pHMHandleData->lpHandlerData = NULL;
|
---|
1813 |
|
---|
1814 |
|
---|
1815 | /* we've got to mark the handle as occupied here, since another device */
|
---|
1816 | /* could be created within the device handler -> deadlock */
|
---|
1817 |
|
---|
1818 | /* write appropriate entry into the handle table if open succeeded */
|
---|
1819 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
1820 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
1821 |
|
---|
1822 | /* call the device handler */
|
---|
1823 | rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
1824 | lpsa,
|
---|
1825 | bInitialOwner,
|
---|
1826 | lpName);
|
---|
1827 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
1828 | {
|
---|
1829 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
1830 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
1831 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1832 | }
|
---|
1833 |
|
---|
1834 | return iIndexNew; /* return valid handle */
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 |
|
---|
1838 | /*****************************************************************************
|
---|
1839 | * Name : HANDLE HMOpenEvent
|
---|
1840 | * Purpose : Wrapper for the OpenEvent() API
|
---|
1841 | * Parameters:
|
---|
1842 | * Variables :
|
---|
1843 | * Result :
|
---|
1844 | * Remark :
|
---|
1845 | * Status :
|
---|
1846 | *
|
---|
1847 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
1848 | *****************************************************************************/
|
---|
1849 |
|
---|
1850 | HANDLE HMOpenEvent(DWORD fdwAccess,
|
---|
1851 | BOOL fInherit,
|
---|
1852 | LPCTSTR lpName)
|
---|
1853 | {
|
---|
1854 | int iIndex; /* index into the handle table */
|
---|
1855 | int iIndexNew; /* index into the handle table */
|
---|
1856 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
1857 | PHMHANDLEDATA pHMHandleData;
|
---|
1858 | DWORD rc; /* API return code */
|
---|
1859 |
|
---|
1860 |
|
---|
1861 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
---|
1862 |
|
---|
1863 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
1864 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
1865 | {
|
---|
1866 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
1867 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 |
|
---|
1871 | /* initialize the complete HMHANDLEDATA structure */
|
---|
1872 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
1873 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
1874 | pHMHandleData->dwAccess = fdwAccess;
|
---|
1875 | pHMHandleData->dwShare = 0;
|
---|
1876 | pHMHandleData->dwCreation = 0;
|
---|
1877 | pHMHandleData->dwFlags = 0;
|
---|
1878 | pHMHandleData->lpHandlerData = NULL;
|
---|
1879 |
|
---|
1880 |
|
---|
1881 | /* we've got to mark the handle as occupied here, since another device */
|
---|
1882 | /* could be created within the device handler -> deadlock */
|
---|
1883 |
|
---|
1884 | /* write appropriate entry into the handle table if open succeeded */
|
---|
1885 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
1886 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
1887 |
|
---|
1888 | /* call the device handler */
|
---|
1889 | rc = pDeviceHandler->OpenEvent(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
1890 | fInherit,
|
---|
1891 | lpName);
|
---|
1892 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
1893 | {
|
---|
1894 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
1895 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
1896 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1897 | }
|
---|
1898 |
|
---|
1899 | return iIndexNew; /* return valid handle */
|
---|
1900 | }
|
---|
1901 |
|
---|
1902 |
|
---|
1903 | /*****************************************************************************
|
---|
1904 | * Name : HANDLE HMOpenMutex
|
---|
1905 | * Purpose : Wrapper for the OpenMutex() API
|
---|
1906 | * Parameters:
|
---|
1907 | * Variables :
|
---|
1908 | * Result :
|
---|
1909 | * Remark :
|
---|
1910 | * Status :
|
---|
1911 | *
|
---|
1912 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
1913 | *****************************************************************************/
|
---|
1914 |
|
---|
1915 | HANDLE HMOpenMutex(DWORD fdwAccess,
|
---|
1916 | BOOL fInherit,
|
---|
1917 | LPCTSTR lpName)
|
---|
1918 | {
|
---|
1919 | int iIndex; /* index into the handle table */
|
---|
1920 | int iIndexNew; /* index into the handle table */
|
---|
1921 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
1922 | PHMHANDLEDATA pHMHandleData;
|
---|
1923 | DWORD rc; /* API return code */
|
---|
1924 |
|
---|
1925 |
|
---|
1926 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
---|
1927 |
|
---|
1928 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
1929 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
1930 | {
|
---|
1931 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
1932 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1933 | }
|
---|
1934 |
|
---|
1935 |
|
---|
1936 | /* initialize the complete HMHANDLEDATA structure */
|
---|
1937 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
1938 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
1939 | pHMHandleData->dwAccess = fdwAccess;
|
---|
1940 | pHMHandleData->dwShare = 0;
|
---|
1941 | pHMHandleData->dwCreation = 0;
|
---|
1942 | pHMHandleData->dwFlags = 0;
|
---|
1943 | pHMHandleData->lpHandlerData = NULL;
|
---|
1944 |
|
---|
1945 |
|
---|
1946 | /* we've got to mark the handle as occupied here, since another device */
|
---|
1947 | /* could be created within the device handler -> deadlock */
|
---|
1948 |
|
---|
1949 | /* write appropriate entry into the handle table if open succeeded */
|
---|
1950 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
1951 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
1952 |
|
---|
1953 | /* call the device handler */
|
---|
1954 | rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
1955 | fInherit,
|
---|
1956 | lpName);
|
---|
1957 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
1958 | {
|
---|
1959 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
1960 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
1961 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1962 | }
|
---|
1963 |
|
---|
1964 | return iIndexNew; /* return valid handle */
|
---|
1965 | }
|
---|
1966 |
|
---|
1967 |
|
---|
1968 | /*****************************************************************************
|
---|
1969 | * Name : HANDLE HMCreateSemaphore
|
---|
1970 | * Purpose : Wrapper for the CreateSemaphore() API
|
---|
1971 | * Parameters:
|
---|
1972 | * Variables :
|
---|
1973 | * Result :
|
---|
1974 | * Remark :
|
---|
1975 | * Status :
|
---|
1976 | *
|
---|
1977 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
1978 | *****************************************************************************/
|
---|
1979 |
|
---|
1980 | HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa,
|
---|
1981 | LONG lInitialCount,
|
---|
1982 | LONG lMaximumCount,
|
---|
1983 | LPCTSTR lpName)
|
---|
1984 | {
|
---|
1985 | int iIndex; /* index into the handle table */
|
---|
1986 | int iIndexNew; /* index into the handle table */
|
---|
1987 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
1988 | PHMHANDLEDATA pHMHandleData;
|
---|
1989 | DWORD rc; /* API return code */
|
---|
1990 |
|
---|
1991 |
|
---|
1992 | pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */
|
---|
1993 |
|
---|
1994 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
1995 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
1996 | {
|
---|
1997 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
1998 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 |
|
---|
2002 | /* initialize the complete HMHANDLEDATA structure */
|
---|
2003 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
2004 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
2005 | pHMHandleData->dwAccess = 0;
|
---|
2006 | pHMHandleData->dwShare = 0;
|
---|
2007 | pHMHandleData->dwCreation = 0;
|
---|
2008 | pHMHandleData->dwFlags = 0;
|
---|
2009 | pHMHandleData->lpHandlerData = NULL;
|
---|
2010 |
|
---|
2011 |
|
---|
2012 | /* we've got to mark the handle as occupied here, since another device */
|
---|
2013 | /* could be created within the device handler -> deadlock */
|
---|
2014 |
|
---|
2015 | /* write appropriate entry into the handle table if open succeeded */
|
---|
2016 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
2017 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
2018 |
|
---|
2019 | /* call the device handler */
|
---|
2020 | rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
2021 | lpsa,
|
---|
2022 | lInitialCount,
|
---|
2023 | lMaximumCount,
|
---|
2024 | lpName);
|
---|
2025 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
2026 | {
|
---|
2027 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
2028 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
2029 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
2030 | }
|
---|
2031 |
|
---|
2032 | return iIndexNew; /* return valid handle */
|
---|
2033 | }
|
---|
2034 |
|
---|
2035 |
|
---|
2036 | /*****************************************************************************
|
---|
2037 | * Name : HANDLE HMOpenSemaphore
|
---|
2038 | * Purpose : Wrapper for the OpenSemaphore() API
|
---|
2039 | * Parameters:
|
---|
2040 | * Variables :
|
---|
2041 | * Result :
|
---|
2042 | * Remark :
|
---|
2043 | * Status :
|
---|
2044 | *
|
---|
2045 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
2046 | *****************************************************************************/
|
---|
2047 |
|
---|
2048 | HANDLE HMOpenSemaphore(DWORD fdwAccess,
|
---|
2049 | BOOL fInherit,
|
---|
2050 | LPCTSTR lpName)
|
---|
2051 | {
|
---|
2052 | int iIndex; /* index into the handle table */
|
---|
2053 | int iIndexNew; /* index into the handle table */
|
---|
2054 | HMDeviceHandler *pDeviceHandler; /* device handler for this handle */
|
---|
2055 | PHMHANDLEDATA pHMHandleData;
|
---|
2056 | DWORD rc; /* API return code */
|
---|
2057 |
|
---|
2058 |
|
---|
2059 | pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */
|
---|
2060 |
|
---|
2061 | iIndexNew = _HMHandleGetFree(); /* get free handle */
|
---|
2062 | if (-1 == iIndexNew) /* oops, no free handles ! */
|
---|
2063 | {
|
---|
2064 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
2065 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 |
|
---|
2069 | /* initialize the complete HMHANDLEDATA structure */
|
---|
2070 | pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
|
---|
2071 | pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */
|
---|
2072 | pHMHandleData->dwAccess = fdwAccess;
|
---|
2073 | pHMHandleData->dwShare = 0;
|
---|
2074 | pHMHandleData->dwCreation = 0;
|
---|
2075 | pHMHandleData->dwFlags = 0;
|
---|
2076 | pHMHandleData->lpHandlerData = NULL;
|
---|
2077 |
|
---|
2078 |
|
---|
2079 | /* we've got to mark the handle as occupied here, since another device */
|
---|
2080 | /* could be created within the device handler -> deadlock */
|
---|
2081 |
|
---|
2082 | /* write appropriate entry into the handle table if open succeeded */
|
---|
2083 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
|
---|
2084 | TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
|
---|
2085 |
|
---|
2086 | /* call the device handler */
|
---|
2087 | rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
|
---|
2088 | fInherit,
|
---|
2089 | lpName);
|
---|
2090 | if (rc != NO_ERROR) /* oops, creation failed within the device handler */
|
---|
2091 | {
|
---|
2092 | TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
|
---|
2093 | SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */
|
---|
2094 | return (INVALID_HANDLE_VALUE); /* signal error */
|
---|
2095 | }
|
---|
2096 |
|
---|
2097 | return iIndexNew; /* return valid handle */
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 |
|
---|
2101 | /*****************************************************************************
|
---|
2102 | * Name : HMReleaseSemaphore
|
---|
2103 | * Purpose : router function for ReleaseSemaphore
|
---|
2104 | * Parameters:
|
---|
2105 | * Variables :
|
---|
2106 | * Result :
|
---|
2107 | * Remark :
|
---|
2108 | * Status :
|
---|
2109 | *
|
---|
2110 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
2111 | *****************************************************************************/
|
---|
2112 |
|
---|
2113 | BOOL HMReleaseSemaphore(HANDLE hEvent,
|
---|
2114 | LONG cReleaseCount,
|
---|
2115 | LPLONG lpPreviousCount)
|
---|
2116 | {
|
---|
2117 | int iIndex; /* index into the handle table */
|
---|
2118 | DWORD dwResult; /* result from the device handler's API */
|
---|
2119 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
2120 |
|
---|
2121 | /* validate handle */
|
---|
2122 | iIndex = _HMHandleQuery(hEvent); /* get the index */
|
---|
2123 | if (-1 == iIndex) /* error ? */
|
---|
2124 | {
|
---|
2125 | SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */
|
---|
2126 | return (INVALID_HANDLE_ERROR); /* signal failure */
|
---|
2127 | }
|
---|
2128 |
|
---|
2129 | pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */
|
---|
2130 | dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData,
|
---|
2131 | cReleaseCount,
|
---|
2132 | lpPreviousCount);
|
---|
2133 |
|
---|
2134 | return (dwResult); /* deliver return code */
|
---|
2135 | }
|
---|
2136 |
|
---|
2137 |
|
---|
2138 | /*****************************************************************************
|
---|
2139 | * Name : HMWaitForMultipleObjects
|
---|
2140 | * Purpose : router function for WaitForMultipleObjects
|
---|
2141 | * Parameters:
|
---|
2142 | * Variables :
|
---|
2143 | * Result :
|
---|
2144 | * Remark :
|
---|
2145 | * Status :
|
---|
2146 | *
|
---|
2147 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
2148 | *****************************************************************************/
|
---|
2149 |
|
---|
2150 | DWORD HMWaitForMultipleObjects (DWORD cObjects,
|
---|
2151 | PHANDLE lphObjects,
|
---|
2152 | BOOL fWaitAll,
|
---|
2153 | DWORD dwTimeout)
|
---|
2154 | {
|
---|
2155 | ULONG ulIndex;
|
---|
2156 | PHANDLE pArrayOfHandles;
|
---|
2157 | PHANDLE pLoop1 = lphObjects;
|
---|
2158 | PHANDLE pLoop2;
|
---|
2159 | DWORD rc;
|
---|
2160 |
|
---|
2161 | // allocate array for handle table
|
---|
2162 | pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE));
|
---|
2163 | if (pArrayOfHandles == NULL)
|
---|
2164 | {
|
---|
2165 | O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
2166 | return WAIT_FAILED;
|
---|
2167 | }
|
---|
2168 | else
|
---|
2169 | pLoop2 = pArrayOfHandles;
|
---|
2170 |
|
---|
2171 | // convert array to odin handles
|
---|
2172 | for (ulIndex = 0;
|
---|
2173 |
|
---|
2174 | ulIndex < cObjects;
|
---|
2175 |
|
---|
2176 | ulIndex++,
|
---|
2177 | pLoop1++,
|
---|
2178 | pLoop2++)
|
---|
2179 | {
|
---|
2180 | rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle
|
---|
2181 | pLoop2);
|
---|
2182 |
|
---|
2183 | if (rc != NO_ERROR)
|
---|
2184 | {
|
---|
2185 | free (pArrayOfHandles); // free memory
|
---|
2186 | O32_SetLastError(ERROR_INVALID_HANDLE);
|
---|
2187 | return (WAIT_FAILED);
|
---|
2188 | }
|
---|
2189 | }
|
---|
2190 |
|
---|
2191 | // OK, now forward to Open32.
|
---|
2192 | // @@@PH: Note this will fail on handles that do NOT belong to Open32
|
---|
2193 | // but to i.e. the console subsystem!
|
---|
2194 | rc = O32_WaitForMultipleObjects(cObjects,
|
---|
2195 | pArrayOfHandles,
|
---|
2196 | fWaitAll,
|
---|
2197 | dwTimeout);
|
---|
2198 |
|
---|
2199 | free(pArrayOfHandles); // free memory
|
---|
2200 | return (rc); // OK, done
|
---|
2201 | }
|
---|
2202 |
|
---|
2203 |
|
---|
2204 | /*****************************************************************************
|
---|
2205 | * Name : HMWaitForMultipleObjectsEx
|
---|
2206 | * Purpose : router function for WaitForMultipleObjectsEx
|
---|
2207 | * Parameters:
|
---|
2208 | * Variables :
|
---|
2209 | * Result :
|
---|
2210 | * Remark :
|
---|
2211 | * Status :
|
---|
2212 | *
|
---|
2213 | * Author : Patrick Haller [Wed, 1999/06/17 20:44]
|
---|
2214 | *****************************************************************************/
|
---|
2215 |
|
---|
2216 | DWORD HMWaitForMultipleObjectsEx (DWORD cObjects,
|
---|
2217 | PHANDLE lphObjects,
|
---|
2218 | BOOL fWaitAll,
|
---|
2219 | DWORD dwTimeout,
|
---|
2220 | BOOL fAlertable)
|
---|
2221 | {
|
---|
2222 | // @@@PH: Note: fAlertable is ignored !
|
---|
2223 | return (HMWaitForMultipleObjects(cObjects,
|
---|
2224 | lphObjects,
|
---|
2225 | fWaitAll,
|
---|
2226 | dwTimeout));
|
---|
2227 | }
|
---|
2228 |
|
---|