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

Last change on this file since 7854 was 7854, checked in by sandervl, 24 years ago

logging updates

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