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