Do not use the PEB lock as loader lock, use a separate critical
[wine] / scheduler / handle.c
1 /*
2  * Win32 process handles
3  *
4  * Copyright 1998 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include "winbase.h"
11 #include "wine/server.h"
12 #include "winerror.h"
13 #include "debugtools.h"
14
15 DEFAULT_DEBUG_CHANNEL(win32);
16
17 /*********************************************************************
18  *           CloseW32Handle (KERNEL.474)
19  *           CloseHandle    (KERNEL32.@)
20  */
21 BOOL WINAPI CloseHandle( HANDLE handle )
22 {
23     NTSTATUS status;
24
25     /* stdio handles need special treatment */
26     if ((handle == STD_INPUT_HANDLE) ||
27         (handle == STD_OUTPUT_HANDLE) ||
28         (handle == STD_ERROR_HANDLE))
29         handle = GetStdHandle( handle );
30
31     status = NtClose( handle );
32     if (status) SetLastError( RtlNtStatusToDosError(status) );
33     return !status;
34 }
35
36
37 /*********************************************************************
38  *           GetHandleInformation   (KERNEL32.@)
39  */
40 BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
41 {
42     BOOL ret;
43     SERVER_START_REQ( set_handle_info )
44     {
45         req->handle = handle;
46         req->flags  = 0;
47         req->mask   = 0;
48         req->fd     = -1;
49         ret = !wine_server_call_err( req );
50         if (ret && flags) *flags = reply->old_flags;
51     }
52     SERVER_END_REQ;
53     return ret;
54 }
55
56
57 /*********************************************************************
58  *           SetHandleInformation   (KERNEL32.@)
59  */
60 BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
61 {
62     BOOL ret;
63     SERVER_START_REQ( set_handle_info )
64     {
65         req->handle = handle;
66         req->flags  = flags;
67         req->mask   = mask;
68         req->fd     = -1;
69         ret = !wine_server_call_err( req );
70     }
71     SERVER_END_REQ;
72     return ret;
73 }
74
75
76 /*********************************************************************
77  *           DuplicateHandle   (KERNEL32.@)
78  */
79 BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
80                                HANDLE dest_process, HANDLE *dest,
81                                DWORD access, BOOL inherit, DWORD options )
82 {
83     BOOL ret;
84     SERVER_START_REQ( dup_handle )
85     {
86         req->src_process = source_process;
87         req->src_handle  = source;
88         req->dst_process = dest_process;
89         req->access      = access;
90         req->inherit     = inherit;
91         req->options     = options;
92
93         ret = !wine_server_call_err( req );
94         if (ret)
95         {
96             if (dest) *dest = reply->handle;
97             if (reply->fd != -1) close( reply->fd );
98         }
99     }
100     SERVER_END_REQ;
101     return ret;
102 }
103
104
105 /***********************************************************************
106  *           ConvertToGlobalHandle              (KERNEL.476)
107  *           ConvertToGlobalHandle              (KERNEL32.@)
108  */
109 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
110 {
111     HANDLE ret = INVALID_HANDLE_VALUE;
112     DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
113                      DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
114     return ret;
115 }
116
117 /***********************************************************************
118  *           SetHandleContext                   (KERNEL32.@)
119  */
120 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) {
121     FIXME("(%d,%ld), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context);
122     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
123     return FALSE;
124 }
125
126 /***********************************************************************
127  *           GetHandleContext                   (KERNEL32.@)
128  */
129 DWORD WINAPI GetHandleContext(HANDLE hnd) {
130     FIXME("(%d), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd);
131     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
132     return 0;
133 }
134
135 /***********************************************************************
136  *           CreateSocketHandle                 (KERNEL32.@)
137  */
138 HANDLE WINAPI CreateSocketHandle(void) {
139     FIXME("(), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n");
140     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
141     return INVALID_HANDLE_VALUE;
142 }