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