Commit | Line | Data |
---|---|---|
026d9db8 JS |
1 | /* |
2 | * Process synchronisation | |
0799c1a7 AJ |
3 | * |
4 | * Copyright 1999, 2000 Juergen Schmied | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
026d9db8 JS |
19 | */ |
20 | ||
fdcfdb9a | 21 | #include <stdio.h> |
026d9db8 JS |
22 | #include <stdlib.h> |
23 | #include <string.h> | |
24 | #include <time.h> | |
0799c1a7 | 25 | #include "wine/debug.h" |
026d9db8 | 26 | |
02d45e52 | 27 | #include "winerror.h" |
0aa6cc29 | 28 | #include "wine/unicode.h" |
37e9503a | 29 | #include "wine/server.h" |
9c1de6de | 30 | #include "winternl.h" |
02d45e52 | 31 | #include "ntdll_misc.h" |
026d9db8 | 32 | |
0799c1a7 | 33 | WINE_DEFAULT_DEBUG_CHANNEL(ntdll); |
02d45e52 | 34 | |
02d45e52 | 35 | |
026d9db8 | 36 | /* |
02d45e52 | 37 | * Semaphores |
026d9db8 JS |
38 | */ |
39 | ||
40 | /****************************************************************************** | |
8b216b3d | 41 | * NtCreateSemaphore (NTDLL.@) |
026d9db8 | 42 | */ |
9c2370bd AJ |
43 | NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle, |
44 | IN ACCESS_MASK access, | |
45 | IN const OBJECT_ATTRIBUTES *attr OPTIONAL, | |
46 | IN ULONG InitialCount, | |
47 | IN ULONG MaximumCount ) | |
026d9db8 | 48 | { |
9c2370bd | 49 | DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; |
fee65e46 AJ |
50 | NTSTATUS ret; |
51 | ||
e5b5af9d | 52 | if ((MaximumCount <= 0) || (InitialCount > MaximumCount)) |
fee65e46 AJ |
53 | return STATUS_INVALID_PARAMETER; |
54 | ||
9caa71ee | 55 | SERVER_START_REQ( create_semaphore ) |
9c2370bd | 56 | { |
9c2370bd AJ |
57 | req->initial = InitialCount; |
58 | req->max = MaximumCount; | |
59 | req->inherit = attr && (attr->Attributes & OBJ_INHERIT); | |
9caa71ee AJ |
60 | if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len ); |
61 | ret = wine_server_call( req ); | |
62 | *SemaphoreHandle = reply->handle; | |
9c2370bd | 63 | } |
9caa71ee | 64 | SERVER_END_REQ; |
fee65e46 | 65 | return ret; |
026d9db8 JS |
66 | } |
67 | ||
68 | /****************************************************************************** | |
8b216b3d | 69 | * NtOpenSemaphore (NTDLL.@) |
026d9db8 | 70 | */ |
9c2370bd AJ |
71 | NTSTATUS WINAPI NtOpenSemaphore( OUT PHANDLE SemaphoreHandle, |
72 | IN ACCESS_MASK access, | |
73 | IN const OBJECT_ATTRIBUTES *attr ) | |
026d9db8 | 74 | { |
9c2370bd | 75 | DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; |
fee65e46 AJ |
76 | NTSTATUS ret; |
77 | ||
9caa71ee | 78 | SERVER_START_REQ( open_semaphore ) |
9c2370bd | 79 | { |
9c2370bd AJ |
80 | req->access = access; |
81 | req->inherit = attr && (attr->Attributes & OBJ_INHERIT); | |
9caa71ee AJ |
82 | if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len ); |
83 | ret = wine_server_call( req ); | |
84 | *SemaphoreHandle = reply->handle; | |
9c2370bd | 85 | } |
9caa71ee | 86 | SERVER_END_REQ; |
fee65e46 | 87 | return ret; |
026d9db8 JS |
88 | } |
89 | ||
90 | /****************************************************************************** | |
8b216b3d | 91 | * NtQuerySemaphore (NTDLL.@) |
026d9db8 JS |
92 | */ |
93 | NTSTATUS WINAPI NtQuerySemaphore( | |
94 | HANDLE SemaphoreHandle, | |
95 | PVOID SemaphoreInformationClass, | |
96 | OUT PVOID SemaphoreInformation, | |
97 | ULONG Length, | |
9a624916 | 98 | PULONG ReturnLength) |
026d9db8 | 99 | { |
ed800c69 | 100 | FIXME("(0x%p,%p,%p,0x%08lx,%p) stub!\n", |
026d9db8 | 101 | SemaphoreHandle, SemaphoreInformationClass, SemaphoreInformation, Length, ReturnLength); |
02d45e52 | 102 | return STATUS_SUCCESS; |
026d9db8 | 103 | } |
9c2370bd | 104 | |
026d9db8 | 105 | /****************************************************************************** |
8b216b3d | 106 | * NtReleaseSemaphore (NTDLL.@) |
026d9db8 | 107 | */ |
9c2370bd | 108 | NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous ) |
026d9db8 | 109 | { |
fee65e46 | 110 | NTSTATUS ret; |
67a74999 | 111 | SERVER_START_REQ( release_semaphore ) |
fee65e46 | 112 | { |
9c2370bd AJ |
113 | req->handle = handle; |
114 | req->count = count; | |
9caa71ee | 115 | if (!(ret = wine_server_call( req ))) |
9c2370bd | 116 | { |
9caa71ee | 117 | if (previous) *previous = reply->prev_count; |
9c2370bd | 118 | } |
fee65e46 | 119 | } |
9c2370bd | 120 | SERVER_END_REQ; |
fee65e46 | 121 | return ret; |
026d9db8 JS |
122 | } |
123 | ||
124 | /* | |
02d45e52 | 125 | * Events |
026d9db8 | 126 | */ |
9a624916 | 127 | |
026d9db8 | 128 | /************************************************************************** |
8b216b3d | 129 | * NtCreateEvent (NTDLL.@) |
044855c6 | 130 | * ZwCreateEvent (NTDLL.@) |
026d9db8 JS |
131 | */ |
132 | NTSTATUS WINAPI NtCreateEvent( | |
133 | OUT PHANDLE EventHandle, | |
134 | IN ACCESS_MASK DesiredAccess, | |
9c2370bd | 135 | IN const OBJECT_ATTRIBUTES *attr, |
026d9db8 JS |
136 | IN BOOLEAN ManualReset, |
137 | IN BOOLEAN InitialState) | |
138 | { | |
9c2370bd | 139 | DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; |
fee65e46 AJ |
140 | NTSTATUS ret; |
141 | ||
9caa71ee | 142 | SERVER_START_REQ( create_event ) |
9c2370bd | 143 | { |
9c2370bd AJ |
144 | req->manual_reset = ManualReset; |
145 | req->initial_state = InitialState; | |
146 | req->inherit = attr && (attr->Attributes & OBJ_INHERIT); | |
9caa71ee AJ |
147 | if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len ); |
148 | ret = wine_server_call( req ); | |
149 | *EventHandle = reply->handle; | |
9c2370bd | 150 | } |
9caa71ee | 151 | SERVER_END_REQ; |
fee65e46 | 152 | return ret; |
026d9db8 JS |
153 | } |
154 | ||
155 | /****************************************************************************** | |
8b216b3d | 156 | * NtOpenEvent (NTDLL.@) |
044855c6 | 157 | * ZwOpenEvent (NTDLL.@) |
026d9db8 JS |
158 | */ |
159 | NTSTATUS WINAPI NtOpenEvent( | |
160 | OUT PHANDLE EventHandle, | |
161 | IN ACCESS_MASK DesiredAccess, | |
9c2370bd | 162 | IN const OBJECT_ATTRIBUTES *attr ) |
026d9db8 | 163 | { |
9c2370bd | 164 | DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; |
fee65e46 AJ |
165 | NTSTATUS ret; |
166 | ||
9caa71ee | 167 | SERVER_START_REQ( open_event ) |
9c2370bd | 168 | { |
9c2370bd AJ |
169 | req->access = DesiredAccess; |
170 | req->inherit = attr && (attr->Attributes & OBJ_INHERIT); | |
9caa71ee AJ |
171 | if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len ); |
172 | ret = wine_server_call( req ); | |
173 | *EventHandle = reply->handle; | |
9c2370bd | 174 | } |
9caa71ee | 175 | SERVER_END_REQ; |
fee65e46 | 176 | return ret; |
02d45e52 JS |
177 | } |
178 | ||
026d9db8 JS |
179 | |
180 | /****************************************************************************** | |
8b216b3d | 181 | * NtSetEvent (NTDLL.@) |
044855c6 | 182 | * ZwSetEvent (NTDLL.@) |
026d9db8 | 183 | */ |
9c2370bd | 184 | NTSTATUS WINAPI NtSetEvent( HANDLE handle, PULONG NumberOfThreadsReleased ) |
026d9db8 | 185 | { |
9c2370bd | 186 | NTSTATUS ret; |
afb49ead AJ |
187 | |
188 | /* FIXME: set NumberOfThreadsReleased */ | |
189 | ||
67a74999 | 190 | SERVER_START_REQ( event_op ) |
9c2370bd | 191 | { |
9c2370bd AJ |
192 | req->handle = handle; |
193 | req->op = SET_EVENT; | |
9caa71ee | 194 | ret = wine_server_call( req ); |
9c2370bd AJ |
195 | } |
196 | SERVER_END_REQ; | |
197 | return ret; | |
026d9db8 JS |
198 | } |
199 | ||
02d45e52 | 200 | /****************************************************************************** |
8b216b3d | 201 | * NtResetEvent (NTDLL.@) |
02d45e52 | 202 | */ |
9c2370bd | 203 | NTSTATUS WINAPI NtResetEvent( HANDLE handle, PULONG NumberOfThreadsReleased ) |
02d45e52 | 204 | { |
9c2370bd AJ |
205 | NTSTATUS ret; |
206 | ||
207 | /* resetting an event can't release any thread... */ | |
208 | if (NumberOfThreadsReleased) *NumberOfThreadsReleased = 0; | |
209 | ||
67a74999 | 210 | SERVER_START_REQ( event_op ) |
9c2370bd | 211 | { |
9c2370bd AJ |
212 | req->handle = handle; |
213 | req->op = RESET_EVENT; | |
9caa71ee | 214 | ret = wine_server_call( req ); |
9c2370bd AJ |
215 | } |
216 | SERVER_END_REQ; | |
217 | return ret; | |
02d45e52 JS |
218 | } |
219 | ||
220 | /****************************************************************************** | |
8b216b3d | 221 | * NtClearEvent (NTDLL.@) |
02d45e52 JS |
222 | * |
223 | * FIXME | |
224 | * same as NtResetEvent ??? | |
225 | */ | |
9c2370bd | 226 | NTSTATUS WINAPI NtClearEvent ( HANDLE handle ) |
02d45e52 | 227 | { |
9c2370bd | 228 | return NtResetEvent( handle, NULL ); |
02d45e52 JS |
229 | } |
230 | ||
231 | /****************************************************************************** | |
8b216b3d | 232 | * NtPulseEvent (NTDLL.@) |
02d45e52 JS |
233 | * |
234 | * FIXME | |
235 | * PulseCount | |
236 | */ | |
9c2370bd | 237 | NTSTATUS WINAPI NtPulseEvent( HANDLE handle, PULONG PulseCount ) |
02d45e52 | 238 | { |
9c2370bd | 239 | NTSTATUS ret; |
ed800c69 | 240 | FIXME("(0x%p,%p)\n", handle, PulseCount); |
67a74999 | 241 | SERVER_START_REQ( event_op ) |
9c2370bd | 242 | { |
9c2370bd AJ |
243 | req->handle = handle; |
244 | req->op = PULSE_EVENT; | |
9caa71ee | 245 | ret = wine_server_call( req ); |
9c2370bd AJ |
246 | } |
247 | SERVER_END_REQ; | |
248 | return ret; | |
02d45e52 JS |
249 | } |
250 | ||
251 | /****************************************************************************** | |
8b216b3d | 252 | * NtQueryEvent (NTDLL.@) |
02d45e52 JS |
253 | */ |
254 | NTSTATUS WINAPI NtQueryEvent ( | |
255 | IN HANDLE EventHandle, | |
256 | IN UINT EventInformationClass, | |
257 | OUT PVOID EventInformation, | |
258 | IN ULONG EventInformationLength, | |
259 | OUT PULONG ReturnLength) | |
260 | { | |
ed800c69 | 261 | FIXME("(0x%p)\n", EventHandle); |
02d45e52 JS |
262 | return STATUS_SUCCESS; |
263 | } |