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