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