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