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