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