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