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