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

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

Fix: creation of unnamed objects

File size: 22.7 KB
Line 
1/* $Id: kobjects.cpp,v 1.7 1999-11-04 20:03:08 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 astring = 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 if (arg3 != NULL) // support for unnamed mutexes
175 astring = UnicodeToAsciiString((LPWSTR)arg3);
176 else
177 astring = NULL;
178
179 dprintf(("KERNEL32: CreateMutexW(%s)\n",
180 astring));
181
182 rc = HMCreateMutex(arg1,
183 arg2,
184 astring);
185
186 if (astring != NULL)
187 FreeAsciiString(astring);
188
189 return(rc);
190}
191
192
193/*****************************************************************************
194 * Name : BOOL ReleaseMutex
195 * Purpose : forward call to Open32
196 * Parameters:
197 * Variables :
198 * Result :
199 * Remark : handle translation is done in ReleaseMutex
200 * Status :
201 *
202 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
203 *****************************************************************************/
204
205ODINFUNCTION1(BOOL, ReleaseMutex,
206 HANDLE, mutex)
207{
208 return(HMReleaseMutex(mutex));
209}
210
211
212/*****************************************************************************
213 * Name : BOOL SetEvent
214 * Purpose : forward call to Open32
215 * Parameters:
216 * Variables :
217 * Result :
218 * Remark : handle translation is done in SetEvent
219 * Status :
220 *
221 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
222 *****************************************************************************/
223
224ODINFUNCTION1(BOOL, SetEvent,
225 HANDLE, hEvent)
226{
227 return(HMSetEvent(hEvent));
228}
229
230
231/*****************************************************************************
232 * Name : BOOL WaitForSingleObject
233 * Purpose : forward call to Open32
234 * Parameters:
235 * Variables :
236 * Result :
237 * Remark : handle translation is done in WaitForSingleObject
238 * Status :
239 *
240 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
241 *****************************************************************************/
242
243ODINFUNCTION2(DWORD, WaitForSingleObject,
244 HANDLE, hObject,
245 DWORD, timeout)
246{
247 return(HMWaitForSingleObject(hObject,
248 timeout));
249}
250
251
252/*****************************************************************************
253 * Name : DWORD OS2WaitForSingleObjectEx
254 * Purpose : The WaitForSingleObjectEx function is an extended wait function
255 * that can be used to perform an alertable wait. This enables the
256 * function to return when the system queues an I/O completion
257 * routine to be executed by the calling thread. The function also
258 * returns when the specified object is in the signaled state or
259 * when the time-out interval elapses.
260 * Parameters: HANDLE hObject handle of object to wait for
261 * DWORD dwTimeout time-out interval in milliseconds
262 * BOOL fAlertable alertable wait flag
263 * Variables :
264 * Result : 0xFFFFFFFF in case of error
265 * Remark : only really required for async I/O
266 * Status : UNTESTED STUB
267 *
268 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
269 *****************************************************************************/
270
271ODINFUNCTION3(DWORD, WaitForSingleObjectEx,
272 HANDLE, hObject,
273 DWORD, dwTimeout,
274 BOOL, fAlertable)
275{
276 dprintf(("Kernel32: WaitForSingleObjectEx(%08xh,%08xh,%08xh) not implemented correctly.\n",
277 hObject,
278 dwTimeout,
279 fAlertable));
280
281 return(HMWaitForSingleObjectEx(hObject,
282 dwTimeout,
283 fAlertable));
284}
285
286
287/*****************************************************************************
288 * Name : BOOL FlushFileBuffers
289 * Purpose : forward call to Open32
290 * Parameters:
291 * Variables :
292 * Result :
293 * Remark : handle translation is done in FlushFileBuffers
294 * Status :
295 *
296 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
297 *****************************************************************************/
298
299ODINFUNCTION1(BOOL, FlushFileBuffers,
300 HANDLE, hFile)
301{
302 return(HMFlushFileBuffers(hFile));
303}
304
305
306/*****************************************************************************
307 * Name : UINT SetHandleCount
308 * Purpose : forward call to Open32
309 * Parameters:
310 * Variables :
311 * Result :
312 * Remark : handle translation is done in SetHandleCount
313 * Status :
314 *
315 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
316 *****************************************************************************/
317
318ODINFUNCTION1(UINT, SetHandleCount,
319 UINT, cHandles)
320{
321 return(HMSetHandleCount(cHandles));
322}
323
324
325/*****************************************************************************
326 * Name : BOOL DuplicateHandle
327 * Purpose : forward call to Open32
328 * Parameters:
329 * Variables :
330 * Result :
331 * Remark : handle translation is done in DuplicateHandle
332 * Status :
333 *
334 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
335 *****************************************************************************/
336
337//******************************************************************************
338//SvL: 24-6-'97 - Added
339//SvL: 28-6-'97: Fix for timeSetEvent in Red Alert Map Editor
340//******************************************************************************
341ODINFUNCTION7(BOOL, DuplicateHandle,
342 HANDLE, srcprocess,
343 HANDLE, srchandle,
344 HANDLE, destprocess,
345 PHANDLE, desthandle,
346 DWORD, arg5,
347 BOOL, arg6,
348 DWORD, arg7)
349{
350 BOOL rc;
351
352 rc = HMDuplicateHandle(srcprocess,
353 srchandle,
354 destprocess,
355 desthandle,
356 arg5,
357 arg6,
358 arg7);
359 //@@@PH: (temporary) fix for non-HandleManager handles
360 if (rc == FALSE)
361 rc = O32_DuplicateHandle(srcprocess,
362 srchandle,
363 destprocess,
364 desthandle,
365 arg5,
366 arg6,
367 arg7);
368
369 return(rc);
370}
371
372
373/*****************************************************************************
374 * Name : BOOL CreateSemaphoreA
375 * Purpose : forward call to Open32
376 * Parameters:
377 * Variables :
378 * Result :
379 * Remark : handle translation is done in CreateSemaphoreA
380 * Status :
381 *
382 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
383 *****************************************************************************/
384
385ODINFUNCTION4(HANDLE, CreateSemaphoreA,
386 LPSECURITY_ATTRIBUTES, arg1,
387 LONG, arg2,
388 LONG, arg3,
389 LPCSTR, arg4)
390{
391 dprintf(("KERNEL32: CreateSemaphoreA(%s)\n",
392 arg4));
393
394 return HMCreateSemaphore(arg1,
395 arg2,
396 arg3,
397 (LPSTR)arg4);
398}
399
400
401/*****************************************************************************
402 * Name : BOOL CreateSemaphoreW
403 * Purpose : forward call to Open32
404 * Parameters:
405 * Variables :
406 * Result :
407 * Remark : handle translation is done in CreateSemaphoreW
408 * Status :
409 *
410 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
411 *****************************************************************************/
412
413ODINFUNCTION4(HANDLE, CreateSemaphoreW,
414 PSECURITY_ATTRIBUTES, arg1,
415 LONG, arg2,
416 LONG, arg3,
417 LPCWSTR, arg4)
418{
419 HANDLE rc;
420 char *astring;
421
422 if (arg4 != NULL) // support for unnamed semaphores
423 astring = UnicodeToAsciiString((LPWSTR)arg4);
424 else
425 astring = NULL;
426
427 dprintf(("KERNEL32: CreateSemaphoreW(%s)\n",
428 astring));
429
430 rc = HMCreateSemaphore(arg1,
431 arg2,
432 arg3,
433 astring);
434
435 if (astring != NULL)
436 FreeAsciiString(astring);
437 return(rc);
438}
439
440
441/*****************************************************************************
442 * Name : BOOL GetOverlappedResult
443 * Purpose : forward call to Open32
444 * Parameters:
445 * Variables :
446 * Result :
447 * Remark : handle translation is done in GetOverlappedResult
448 * Status :
449 *
450 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
451 *****************************************************************************/
452
453ODINFUNCTION4(BOOL, GetOverlappedResult,
454 HANDLE, arg1,
455 LPOVERLAPPED, arg2,
456 LPDWORD, arg3,
457 BOOL, arg4)
458{
459 return HMGetOverlappedResult(arg1,
460 arg2,
461 arg3,
462 arg4);
463}
464
465
466/*****************************************************************************
467 * Name : BOOL OpenEventA
468 * Purpose : forward call to Open32
469 * Parameters:
470 * Variables :
471 * Result :
472 * Remark : handle translation is done in OpenEventA
473 * Status :
474 *
475 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
476 *****************************************************************************/
477
478ODINFUNCTION3(HANDLE, OpenEventA,
479 DWORD, arg1,
480 BOOL, arg2,
481 LPCSTR, arg3)
482{
483 dprintf(("KERNEL32: OpenEventA(%s)\n",
484 arg3));
485
486 return HMOpenEvent(arg1,
487 arg2,
488 arg3);
489}
490
491
492/*****************************************************************************
493 * Name : BOOL
494 * Purpose : forward call to Open32
495 * Parameters:
496 * Variables :
497 * Result :
498 * Remark : handle translation is done in OpenEventW
499 * Status :
500 *
501 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
502 *****************************************************************************/
503
504ODINFUNCTION3(HANDLE, OpenEventW,
505 DWORD, dwDesiredAccess,
506 BOOL, bInheritHandle,
507 LPCWSTR, lpName)
508{
509 char *asciiname;
510 HANDLE rc;
511
512 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
513
514 dprintf(("KERNEL32: OpenEventW(%s)\n",
515 asciiname));
516
517 rc = HMOpenEvent(dwDesiredAccess,
518 bInheritHandle,
519 asciiname);
520 FreeAsciiString(asciiname);
521 return(rc);
522}
523
524
525/*****************************************************************************
526 * Name : BOOL OpenMutexA
527 * Purpose : forward call to Open32
528 * Parameters:
529 * Variables :
530 * Result :
531 * Remark : handle translation is done in OpenMutexA
532 * Status :
533 *
534 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
535 *****************************************************************************/
536
537ODINFUNCTION3(HANDLE, OpenMutexA,
538 DWORD, arg1,
539 BOOL, arg2,
540 LPCSTR, arg3)
541{
542 dprintf(("KERNEL32: OpenMutexA(%s)\n",
543 arg3));
544
545 return HMOpenMutex(arg1,
546 arg2,
547 arg3);
548}
549
550
551/*****************************************************************************
552 * Name : BOOL OpenMutexW
553 * Purpose : forward call to Open32
554 * Parameters:
555 * Variables :
556 * Result :
557 * Remark : handle translation is done in OpenMutexW
558 * Status :
559 *
560 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
561 *****************************************************************************/
562
563ODINFUNCTION3(HANDLE, OpenMutexW,
564 DWORD, dwDesiredAccess,
565 BOOL, bInheritHandle,
566 LPCWSTR, lpName)
567{
568 char *asciiname;
569 HANDLE rc;
570
571 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
572
573 dprintf(("KERNEL32: OpenMutexW(%s)\n",
574 asciiname));
575
576 rc = HMOpenMutex(dwDesiredAccess,
577 bInheritHandle,
578 asciiname);
579 FreeAsciiString(asciiname);
580 return(rc);
581}
582
583
584/*****************************************************************************
585 * Name : BOOL OpenSemaphoreA
586 * Purpose : forward call to Open32
587 * Parameters:
588 * Variables :
589 * Result :
590 * Remark : handle translation is done in OpenSemaphoreA
591 * Status :
592 *
593 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
594 *****************************************************************************/
595
596ODINFUNCTION3(HANDLE, OpenSemaphoreA,
597 DWORD, arg1,
598 BOOL, arg2,
599 LPCSTR, arg3)
600{
601 dprintf(("KERNEL32: OpenSemaphoreA(%s)\n",
602 arg3));
603
604 return HMOpenSemaphore(arg1,
605 arg2,
606 arg3);
607}
608
609
610/*****************************************************************************
611 * Name : BOOL OpenSemaphoreW
612 * Purpose : forward call to Open32
613 * Parameters:
614 * Variables :
615 * Result :
616 * Remark : handle translation is done in OpenSemaphoreW
617 * Status :
618 *
619 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
620 *****************************************************************************/
621
622ODINFUNCTION3(HANDLE, OpenSemaphoreW,
623 DWORD, dwDesiredAccess,
624 BOOL, bInheritHandle,
625 LPCWSTR, lpName)
626{
627 char *asciiname;
628 HANDLE rc;
629
630 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
631
632 dprintf(("KERNEL32: OpenSemaphoreW(%s)\n",
633 asciiname));
634
635 rc = HMOpenSemaphore(dwDesiredAccess,
636 bInheritHandle,
637 asciiname);
638 FreeAsciiString(asciiname);
639 return(rc);
640}
641
642
643/*****************************************************************************
644 * Name : BOOL PulseEvent
645 * Purpose : forward call to Open32
646 * Parameters:
647 * Variables :
648 * Result :
649 * Remark : handle translation is done in PulseEvent
650 * Status :
651 *
652 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
653 *****************************************************************************/
654
655ODINFUNCTION1(BOOL, PulseEvent,
656 HANDLE, arg1)
657{
658 return HMPulseEvent(arg1);
659}
660
661
662/*****************************************************************************
663 * Name : BOOL ReleaseSemaphore
664 * Purpose : forward call to Open32
665 * Parameters:
666 * Variables :
667 * Result :
668 * Remark : handle translation is done in ReleaseSemaphore
669 * Status :
670 *
671 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
672 *****************************************************************************/
673
674ODINFUNCTION3(BOOL, ReleaseSemaphore,
675 HANDLE, arg1,
676 LONG, arg2,
677 PLONG, arg3)
678{
679 return HMReleaseSemaphore(arg1,
680 arg2,
681 arg3);
682}
683
684
685/*****************************************************************************
686 * Name : BOOL ResetEvent
687 * Purpose : forward call to Open32
688 * Parameters:
689 * Variables :
690 * Result :
691 * Remark : handle translation is done in ResetEvent
692 * Status :
693 *
694 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
695 *****************************************************************************/
696
697ODINFUNCTION1(BOOL, ResetEvent,
698 HANDLE, arg1)
699{
700 return HMResetEvent(arg1);
701}
702
703
704/*****************************************************************************
705 * Name : BOOL WaitForMultipleObjects
706 * Purpose : forward call to Open32
707 * Parameters:
708 * Variables :
709 * Result :
710 * Remark : handle translation is done in WaitForMultipleObjects
711 * Status :
712 *
713 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
714 *****************************************************************************/
715
716ODINFUNCTION4(DWORD, WaitForMultipleObjects,
717 DWORD, arg1,
718 const HANDLE *, arg2,
719 BOOL, arg3,
720 DWORD, arg4)
721{
722 return HMWaitForMultipleObjects(arg1,
723 (PHANDLE)arg2,
724 arg3,
725 arg4);
726}
727
728
729/*****************************************************************************
730 * Name : DWORD OS2WaitForMultipleObjectsEx
731 * Purpose : The WaitForMultipleObjectsEx function is an extended wait
732 * function that can be used to perform an alertable wait. This
733 * enables the function to return when the system queues an I/O
734 * completion routine to be executed by the calling thread. The
735 * function also returns either when any one or when all of the
736 * specified objects are in the signaled state, or when the
737 * time-out interval elapses.
738 * Parameters: DWORD cObjects number of handles in handle array
739 * HANDLE *lphObjects address of object-handle array
740 * BOOL fWaitAll wait flag
741 * DWORD dwTimeout time-out interval in milliseconds
742 * BOOL fAlertable alertable wait flag
743 * Variables :
744 * Result : 0xFFFFFFFF in case of error
745 * Remark : only really required for async I/O
746 * Status : UNTESTED STUB
747 *
748 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
749 *****************************************************************************/
750
751ODINFUNCTION5(DWORD, WaitForMultipleObjectsEx,
752 DWORD, cObjects,
753 CONST HANDLE *, lphObjects,
754 BOOL, fWaitAll,
755 DWORD, dwTimeout,
756 BOOL, fAlertable)
757{
758 return(HMWaitForMultipleObjectsEx(cObjects,
759 (PHANDLE)lphObjects,
760 fWaitAll,
761 dwTimeout,
762 fAlertable));
763}
764
765
766/*****************************************************************************
767 * Name : HANDLE ConvertToGlobalHandle
768 * Purpose : forward call to Open32
769 * Parameters:
770 * Variables :
771 * Result :
772 * Remark : handle translation is done in ConvertToGlobalHandle
773 * Status :
774 *
775 * Author : Patrick Haller [Fri, 1999/06/18 03:44]
776 *****************************************************************************/
777
778ODINFUNCTION1(HANDLE, ConvertToGlobalHandle,
779 HANDLE, hHandle)
780
781//ODINFUNCTION2(HANDLE, ConvertToGlobalHandle,
782// HANDLE, hHandle,
783// BOOL, fInherit)
784{
785 return (hHandle);
786}
787
788
Note: See TracBrowser for help on using the repository browser.