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