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