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