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