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