source: trunk/src/kernel32/kobjects.cpp@ 1601

Last change on this file since 1601 was 1601, checked in by phaller, 26 years ago

Fix: CreateEventW fixed

File size: 22.5 KB
Line 
1/* $Id: kobjects.cpp,v 1.6 1999-11-04 19:49:13 phaller Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 * Win32 compatibility file functions for OS/2
6 * Copyright 1998 Sander van Leeuven
7 * Copyright 1998 Patrick Haller
8 * Copyright 1998 Peter Fitzsimmons
9 * Copyright 1998 Knut St. Osmundsen
10 */
11
12
13/*****************************************************************************
14 * Includes *
15 *****************************************************************************/
16
17#include <odin.h>
18#include <odinwrap.h>
19#include <os2sel.h>
20
21#include <os2win.h>
22#include "misc.h"
23#include "handlemanager.h"
24
25
26ODINDEBUGCHANNEL(KERNEL32-KOBJECTS)
27
28
29// REMARK: THIS IS IN PREPARATION FOR HANDLEMANAGER SUPPORT (PH) !!
30//#define HMCreateEvent O32_CreateEvent
31//#define HMCreateMutex O32_CreateMutex
32//#define HMCreateSemaphore O32_CreateSemaphore
33//#define HMSetEvent O32_SetEvent
34//#define HMReleaseMutex O32_ReleaseMutex
35//#define HMWaitForSingleObject O32_WaitForSingleObject
36//#define HMWaitForSingleObjectEx O32_WaitForSingleObjectEx
37//#define HMGetOverlappedResult O32_GetOverlappedResult
38//#define HMOpenEvent O32_OpenEvent
39//#define HMOpenMutex O32_OpenMutex
40//#define HMOpenSemaphore O32_OpenSemaphore
41//#define HMPulseEvent O32_PulseEvent
42//#define HMReleaseSemaphore O32_ReleaseSemaphore
43//#define HMResetEvent O32_ResetEvent
44//#define HMWaitForMultipleObjects O32_WaitForMultipleObjects
45//#define HMWaitForMultipleObjectsEx O32_WaitForMultipleObjectsEx
46//#define HMFlushFileBuffers O32_FlushFileBuffers
47#define HMSetHandleCount O32_SetHandleCount
48#define HMGetHandleCount O32_GetHandleCount
49//#define HMDuplicateHandle O32_DuplicateHandle
50
51
52
53/*****************************************************************************
54 * Defines *
55 *****************************************************************************/
56
57 /* this define enables certain less important debug messages */
58//#define DEBUG_LOCAL 1
59
60
61
62/*****************************************************************************
63 * Name : BOOL CreateEventA
64 * Purpose : forward call to Open32
65 * Parameters:
66 * Variables :
67 * Result :
68 * Remark :
69 * Status :
70 *
71 * Author : Patrick Haller [Fri, 1998/06/12 03:44]
72 *****************************************************************************/
73
74ODINFUNCTION4(HANDLE, CreateEventA,
75 LPSECURITY_ATTRIBUTES, lpsa,
76 BOOL, fManualReset,
77 BOOL, fInitialState,
78 LPCTSTR, lpszEventName)
79{
80 return(HMCreateEvent(lpsa, /* create event semaphore */
81 fManualReset,
82 fInitialState,
83 lpszEventName));
84}
85
86
87/*****************************************************************************
88 * Name : BOOL CreateEventW
89 * Purpose : forward call to Open32
90 * Parameters:
91 * Variables :
92 * Result :
93 * Remark : handle translation is done in CreateEventA
94 * Status :
95 *
96 * Author : Patrick Haller [Fri, 1998/06/12 03:44]
97 *****************************************************************************/
98
99ODINFUNCTION4(HANDLE, CreateEventW,
100 LPSECURITY_ATTRIBUTES, arg1,
101 BOOL, arg2,
102 BOOL, arg3,
103 LPCWSTR, arg4)
104{
105 HANDLE rc;
106 char *astring;
107
108 if (arg4 != NULL) // support for unnamed semaphores
109 astring = UnicodeToAsciiString((LPWSTR)arg4);
110 else
111 arg4 = NULL;
112
113 dprintf(("KERNEL32: CreateEventW(%s)\n",
114 astring));
115
116 rc = HMCreateEvent(arg1,
117 arg2,
118 arg3,
119 astring);
120
121 if (astring != NULL)
122 FreeAsciiString(astring);
123
124 return(rc);
125}
126
127
128/*****************************************************************************
129 * Name : BOOL CreateMutexA
130 * Purpose : forward call to Open32
131 * Parameters:
132 * Variables :
133 * Result :
134 * Remark : handle translation is done in CreateMutexA
135 * Status :
136 *
137 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
138 *****************************************************************************/
139
140ODINFUNCTION3(HANDLE, CreateMutexA,
141 LPSECURITY_ATTRIBUTES, lpsa,
142 BOOL, fInitialOwner,
143 LPCTSTR, lpszMutexName)
144{
145 dprintf(("KERNEL32: CreateMutexA(%s)\n",
146 lpszMutexName));
147
148 return(HMCreateMutex(lpsa,
149 fInitialOwner,
150 lpszMutexName));
151}
152
153
154/*****************************************************************************
155 * Name : BOOL CreateMutexW
156 * Purpose : forward call to Open32
157 * Parameters:
158 * Variables :
159 * Result :
160 * Remark : handle translation is done in CreateMutexW
161 * Status :
162 *
163 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
164 *****************************************************************************/
165
166ODINFUNCTION3(HANDLE, CreateMutexW,
167 PSECURITY_ATTRIBUTES, arg1,
168 BOOL, arg2,
169 LPCWSTR, arg3)
170{
171 HANDLE rc;
172 char *astring;
173
174 astring = UnicodeToAsciiString((LPWSTR)arg3);
175
176 dprintf(("KERNEL32: CreateMutexW(%s)\n",
177 astring));
178
179 rc = HMCreateMutex(arg1,
180 arg2,
181 astring);
182 FreeAsciiString(astring);
183
184 return(rc);
185}
186
187
188/*****************************************************************************
189 * Name : BOOL ReleaseMutex
190 * Purpose : forward call to Open32
191 * Parameters:
192 * Variables :
193 * Result :
194 * Remark : handle translation is done in ReleaseMutex
195 * Status :
196 *
197 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
198 *****************************************************************************/
199
200ODINFUNCTION1(BOOL, ReleaseMutex,
201 HANDLE, mutex)
202{
203 return(HMReleaseMutex(mutex));
204}
205
206
207/*****************************************************************************
208 * Name : BOOL SetEvent
209 * Purpose : forward call to Open32
210 * Parameters:
211 * Variables :
212 * Result :
213 * Remark : handle translation is done in SetEvent
214 * Status :
215 *
216 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
217 *****************************************************************************/
218
219ODINFUNCTION1(BOOL, SetEvent,
220 HANDLE, hEvent)
221{
222 return(HMSetEvent(hEvent));
223}
224
225
226/*****************************************************************************
227 * Name : BOOL WaitForSingleObject
228 * Purpose : forward call to Open32
229 * Parameters:
230 * Variables :
231 * Result :
232 * Remark : handle translation is done in WaitForSingleObject
233 * Status :
234 *
235 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
236 *****************************************************************************/
237
238ODINFUNCTION2(DWORD, WaitForSingleObject,
239 HANDLE, hObject,
240 DWORD, timeout)
241{
242 return(HMWaitForSingleObject(hObject,
243 timeout));
244}
245
246
247/*****************************************************************************
248 * Name : DWORD OS2WaitForSingleObjectEx
249 * Purpose : The WaitForSingleObjectEx function is an extended wait function
250 * that can be used to perform an alertable wait. This enables the
251 * function to return when the system queues an I/O completion
252 * routine to be executed by the calling thread. The function also
253 * returns when the specified object is in the signaled state or
254 * when the time-out interval elapses.
255 * Parameters: HANDLE hObject handle of object to wait for
256 * DWORD dwTimeout time-out interval in milliseconds
257 * BOOL fAlertable alertable wait flag
258 * Variables :
259 * Result : 0xFFFFFFFF in case of error
260 * Remark : only really required for async I/O
261 * Status : UNTESTED STUB
262 *
263 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
264 *****************************************************************************/
265
266ODINFUNCTION3(DWORD, WaitForSingleObjectEx,
267 HANDLE, hObject,
268 DWORD, dwTimeout,
269 BOOL, fAlertable)
270{
271 dprintf(("Kernel32: WaitForSingleObjectEx(%08xh,%08xh,%08xh) not implemented correctly.\n",
272 hObject,
273 dwTimeout,
274 fAlertable));
275
276 return(HMWaitForSingleObjectEx(hObject,
277 dwTimeout,
278 fAlertable));
279}
280
281
282/*****************************************************************************
283 * Name : BOOL FlushFileBuffers
284 * Purpose : forward call to Open32
285 * Parameters:
286 * Variables :
287 * Result :
288 * Remark : handle translation is done in FlushFileBuffers
289 * Status :
290 *
291 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
292 *****************************************************************************/
293
294ODINFUNCTION1(BOOL, FlushFileBuffers,
295 HANDLE, hFile)
296{
297 return(HMFlushFileBuffers(hFile));
298}
299
300
301/*****************************************************************************
302 * Name : UINT SetHandleCount
303 * Purpose : forward call to Open32
304 * Parameters:
305 * Variables :
306 * Result :
307 * Remark : handle translation is done in SetHandleCount
308 * Status :
309 *
310 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
311 *****************************************************************************/
312
313ODINFUNCTION1(UINT, SetHandleCount,
314 UINT, cHandles)
315{
316 return(HMSetHandleCount(cHandles));
317}
318
319
320/*****************************************************************************
321 * Name : BOOL DuplicateHandle
322 * Purpose : forward call to Open32
323 * Parameters:
324 * Variables :
325 * Result :
326 * Remark : handle translation is done in DuplicateHandle
327 * Status :
328 *
329 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
330 *****************************************************************************/
331
332//******************************************************************************
333//SvL: 24-6-'97 - Added
334//SvL: 28-6-'97: Fix for timeSetEvent in Red Alert Map Editor
335//******************************************************************************
336ODINFUNCTION7(BOOL, DuplicateHandle,
337 HANDLE, srcprocess,
338 HANDLE, srchandle,
339 HANDLE, destprocess,
340 PHANDLE, desthandle,
341 DWORD, arg5,
342 BOOL, arg6,
343 DWORD, arg7)
344{
345 BOOL rc;
346
347 rc = HMDuplicateHandle(srcprocess,
348 srchandle,
349 destprocess,
350 desthandle,
351 arg5,
352 arg6,
353 arg7);
354 //@@@PH: (temporary) fix for non-HandleManager handles
355 if (rc == FALSE)
356 rc = O32_DuplicateHandle(srcprocess,
357 srchandle,
358 destprocess,
359 desthandle,
360 arg5,
361 arg6,
362 arg7);
363
364 return(rc);
365}
366
367
368/*****************************************************************************
369 * Name : BOOL CreateSemaphoreA
370 * Purpose : forward call to Open32
371 * Parameters:
372 * Variables :
373 * Result :
374 * Remark : handle translation is done in CreateSemaphoreA
375 * Status :
376 *
377 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
378 *****************************************************************************/
379
380ODINFUNCTION4(HANDLE, CreateSemaphoreA,
381 LPSECURITY_ATTRIBUTES, arg1,
382 LONG, arg2,
383 LONG, arg3,
384 LPCSTR, arg4)
385{
386 dprintf(("KERNEL32: CreateSemaphoreA(%s)\n",
387 arg4));
388
389 return HMCreateSemaphore(arg1,
390 arg2,
391 arg3,
392 (LPSTR)arg4);
393}
394
395
396/*****************************************************************************
397 * Name : BOOL CreateSemaphoreW
398 * Purpose : forward call to Open32
399 * Parameters:
400 * Variables :
401 * Result :
402 * Remark : handle translation is done in CreateSemaphoreW
403 * Status :
404 *
405 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
406 *****************************************************************************/
407
408ODINFUNCTION4(HANDLE, CreateSemaphoreW,
409 PSECURITY_ATTRIBUTES, arg1,
410 LONG, arg2,
411 LONG, arg3,
412 LPCWSTR, arg4)
413{
414 HANDLE rc;
415 char *astring;
416
417 astring = UnicodeToAsciiString((LPWSTR)arg4);
418
419 dprintf(("KERNEL32: CreateSemaphoreW(%s)\n",
420 astring));
421
422 rc = HMCreateSemaphore(arg1,
423 arg2,
424 arg3,
425 astring);
426 FreeAsciiString(astring);
427 return(rc);
428}
429
430
431/*****************************************************************************
432 * Name : BOOL GetOverlappedResult
433 * Purpose : forward call to Open32
434 * Parameters:
435 * Variables :
436 * Result :
437 * Remark : handle translation is done in GetOverlappedResult
438 * Status :
439 *
440 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
441 *****************************************************************************/
442
443ODINFUNCTION4(BOOL, GetOverlappedResult,
444 HANDLE, arg1,
445 LPOVERLAPPED, arg2,
446 LPDWORD, arg3,
447 BOOL, arg4)
448{
449 return HMGetOverlappedResult(arg1,
450 arg2,
451 arg3,
452 arg4);
453}
454
455
456/*****************************************************************************
457 * Name : BOOL OpenEventA
458 * Purpose : forward call to Open32
459 * Parameters:
460 * Variables :
461 * Result :
462 * Remark : handle translation is done in OpenEventA
463 * Status :
464 *
465 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
466 *****************************************************************************/
467
468ODINFUNCTION3(HANDLE, OpenEventA,
469 DWORD, arg1,
470 BOOL, arg2,
471 LPCSTR, arg3)
472{
473 dprintf(("KERNEL32: OpenEventA(%s)\n",
474 arg3));
475
476 return HMOpenEvent(arg1,
477 arg2,
478 arg3);
479}
480
481
482/*****************************************************************************
483 * Name : BOOL OpenEventW
484 * Purpose : forward call to Open32
485 * Parameters:
486 * Variables :
487 * Result :
488 * Remark : handle translation is done in OpenEventW
489 * Status :
490 *
491 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
492 *****************************************************************************/
493
494ODINFUNCTION3(HANDLE, OpenEventW,
495 DWORD, dwDesiredAccess,
496 BOOL, bInheritHandle,
497 LPCWSTR, lpName)
498{
499 char *asciiname;
500 HANDLE rc;
501
502 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
503
504 dprintf(("KERNEL32: OpenEventW(%s)\n",
505 asciiname));
506
507 rc = HMOpenEvent(dwDesiredAccess,
508 bInheritHandle,
509 asciiname);
510 FreeAsciiString(asciiname);
511 return(rc);
512}
513
514
515/*****************************************************************************
516 * Name : BOOL OpenMutexA
517 * Purpose : forward call to Open32
518 * Parameters:
519 * Variables :
520 * Result :
521 * Remark : handle translation is done in OpenMutexA
522 * Status :
523 *
524 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
525 *****************************************************************************/
526
527ODINFUNCTION3(HANDLE, OpenMutexA,
528 DWORD, arg1,
529 BOOL, arg2,
530 LPCSTR, arg3)
531{
532 dprintf(("KERNEL32: OpenMutexA(%s)\n",
533 arg3));
534
535 return HMOpenMutex(arg1,
536 arg2,
537 arg3);
538}
539
540
541/*****************************************************************************
542 * Name : BOOL OpenMutexW
543 * Purpose : forward call to Open32
544 * Parameters:
545 * Variables :
546 * Result :
547 * Remark : handle translation is done in OpenMutexW
548 * Status :
549 *
550 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
551 *****************************************************************************/
552
553ODINFUNCTION3(HANDLE, OpenMutexW,
554 DWORD, dwDesiredAccess,
555 BOOL, bInheritHandle,
556 LPCWSTR, lpName)
557{
558 char *asciiname;
559 HANDLE rc;
560
561 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
562
563 dprintf(("KERNEL32: OpenMutexW(%s)\n",
564 asciiname));
565
566 rc = HMOpenMutex(dwDesiredAccess,
567 bInheritHandle,
568 asciiname);
569 FreeAsciiString(asciiname);
570 return(rc);
571}
572
573
574/*****************************************************************************
575 * Name : BOOL OpenSemaphoreA
576 * Purpose : forward call to Open32
577 * Parameters:
578 * Variables :
579 * Result :
580 * Remark : handle translation is done in OpenSemaphoreA
581 * Status :
582 *
583 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
584 *****************************************************************************/
585
586ODINFUNCTION3(HANDLE, OpenSemaphoreA,
587 DWORD, arg1,
588 BOOL, arg2,
589 LPCSTR, arg3)
590{
591 dprintf(("KERNEL32: OpenSemaphoreA(%s)\n",
592 arg3));
593
594 return HMOpenSemaphore(arg1,
595 arg2,
596 arg3);
597}
598
599
600/*****************************************************************************
601 * Name : BOOL OpenSemaphoreW
602 * Purpose : forward call to Open32
603 * Parameters:
604 * Variables :
605 * Result :
606 * Remark : handle translation is done in OpenSemaphoreW
607 * Status :
608 *
609 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
610 *****************************************************************************/
611
612ODINFUNCTION3(HANDLE, OpenSemaphoreW,
613 DWORD, dwDesiredAccess,
614 BOOL, bInheritHandle,
615 LPCWSTR, lpName)
616{
617 char *asciiname;
618 HANDLE rc;
619
620 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
621
622 dprintf(("KERNEL32: OpenSemaphoreW(%s)\n",
623 asciiname));
624
625 rc = HMOpenSemaphore(dwDesiredAccess,
626 bInheritHandle,
627 asciiname);
628 FreeAsciiString(asciiname);
629 return(rc);
630}
631
632
633/*****************************************************************************
634 * Name : BOOL PulseEvent
635 * Purpose : forward call to Open32
636 * Parameters:
637 * Variables :
638 * Result :
639 * Remark : handle translation is done in PulseEvent
640 * Status :
641 *
642 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
643 *****************************************************************************/
644
645ODINFUNCTION1(BOOL, PulseEvent,
646 HANDLE, arg1)
647{
648 return HMPulseEvent(arg1);
649}
650
651
652/*****************************************************************************
653 * Name : BOOL ReleaseSemaphore
654 * Purpose : forward call to Open32
655 * Parameters:
656 * Variables :
657 * Result :
658 * Remark : handle translation is done in ReleaseSemaphore
659 * Status :
660 *
661 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
662 *****************************************************************************/
663
664ODINFUNCTION3(BOOL, ReleaseSemaphore,
665 HANDLE, arg1,
666 LONG, arg2,
667 PLONG, arg3)
668{
669 return HMReleaseSemaphore(arg1,
670 arg2,
671 arg3);
672}
673
674
675/*****************************************************************************
676 * Name : BOOL ResetEvent
677 * Purpose : forward call to Open32
678 * Parameters:
679 * Variables :
680 * Result :
681 * Remark : handle translation is done in ResetEvent
682 * Status :
683 *
684 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
685 *****************************************************************************/
686
687ODINFUNCTION1(BOOL, ResetEvent,
688 HANDLE, arg1)
689{
690 return HMResetEvent(arg1);
691}
692
693
694/*****************************************************************************
695 * Name : BOOL WaitForMultipleObjects
696 * Purpose : forward call to Open32
697 * Parameters:
698 * Variables :
699 * Result :
700 * Remark : handle translation is done in WaitForMultipleObjects
701 * Status :
702 *
703 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
704 *****************************************************************************/
705
706ODINFUNCTION4(DWORD, WaitForMultipleObjects,
707 DWORD, arg1,
708 const HANDLE *, arg2,
709 BOOL, arg3,
710 DWORD, arg4)
711{
712 return HMWaitForMultipleObjects(arg1,
713 (PHANDLE)arg2,
714 arg3,
715 arg4);
716}
717
718
719/*****************************************************************************
720 * Name : DWORD OS2WaitForMultipleObjectsEx
721 * Purpose : The WaitForMultipleObjectsEx function is an extended wait
722 * function that can be used to perform an alertable wait. This
723 * enables the function to return when the system queues an I/O
724 * completion routine to be executed by the calling thread. The
725 * function also returns either when any one or when all of the
726 * specified objects are in the signaled state, or when the
727 * time-out interval elapses.
728 * Parameters: DWORD cObjects number of handles in handle array
729 * HANDLE *lphObjects address of object-handle array
730 * BOOL fWaitAll wait flag
731 * DWORD dwTimeout time-out interval in milliseconds
732 * BOOL fAlertable alertable wait flag
733 * Variables :
734 * Result : 0xFFFFFFFF in case of error
735 * Remark : only really required for async I/O
736 * Status : UNTESTED STUB
737 *
738 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
739 *****************************************************************************/
740
741ODINFUNCTION5(DWORD, WaitForMultipleObjectsEx,
742 DWORD, cObjects,
743 CONST HANDLE *, lphObjects,
744 BOOL, fWaitAll,
745 DWORD, dwTimeout,
746 BOOL, fAlertable)
747{
748 return(HMWaitForMultipleObjectsEx(cObjects,
749 (PHANDLE)lphObjects,
750 fWaitAll,
751 dwTimeout,
752 fAlertable));
753}
754
755
756/*****************************************************************************
757 * Name : HANDLE ConvertToGlobalHandle
758 * Purpose : forward call to Open32
759 * Parameters:
760 * Variables :
761 * Result :
762 * Remark : handle translation is done in ConvertToGlobalHandle
763 * Status :
764 *
765 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
766 *****************************************************************************/
767
768ODINFUNCTION1(HANDLE, ConvertToGlobalHandle,
769 HANDLE, hHandle)
770
771//ODINFUNCTION2(HANDLE, ConvertToGlobalHandle,
772// HANDLE, hHandle,
773// BOOL, fInherit)
774{
775 return (hHandle);
776}
777
778
Note: See TracBrowser for help on using the repository browser.