Implementation of IOCTL_SCSI_PASS_THROUGH and
[wine] / dlls / ntdll / sync.c
1 /*
2  *      Process synchronisation
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
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25 #include "wine/debug.h"
26
27 #include "winerror.h"
28 #include "wine/unicode.h"
29 #include "wine/server.h"
30 #include "ntddk.h"
31 #include "ntdll_misc.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
34
35
36 /*
37  *      Semaphores
38  */
39
40 /******************************************************************************
41  *  NtCreateSemaphore (NTDLL.@)
42  */
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 )
48 {
49     DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
50     NTSTATUS ret;
51
52     if ((MaximumCount <= 0) || (InitialCount > MaximumCount))
53         return STATUS_INVALID_PARAMETER;
54
55     SERVER_START_REQ( create_semaphore )
56     {
57         req->initial = InitialCount;
58         req->max     = MaximumCount;
59         req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
60         if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
61         ret = wine_server_call( req );
62         *SemaphoreHandle = reply->handle;
63     }
64     SERVER_END_REQ;
65     return ret;
66 }
67
68 /******************************************************************************
69  *  NtOpenSemaphore (NTDLL.@)
70  */
71 NTSTATUS WINAPI NtOpenSemaphore( OUT PHANDLE SemaphoreHandle,
72                                  IN ACCESS_MASK access,
73                                  IN const OBJECT_ATTRIBUTES *attr )
74 {
75     DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
76     NTSTATUS ret;
77
78     SERVER_START_REQ( open_semaphore )
79     {
80         req->access  = access;
81         req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
82         if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
83         ret = wine_server_call( req );
84         *SemaphoreHandle = reply->handle;
85     }
86     SERVER_END_REQ;
87     return ret;
88 }
89
90 /******************************************************************************
91  *  NtQuerySemaphore (NTDLL.@)
92  */
93 NTSTATUS WINAPI NtQuerySemaphore(
94         HANDLE SemaphoreHandle,
95         PVOID SemaphoreInformationClass,
96         OUT PVOID SemaphoreInformation,
97         ULONG Length,
98         PULONG ReturnLength) 
99 {
100         FIXME("(0x%08x,%p,%p,0x%08lx,%p) stub!\n",
101         SemaphoreHandle, SemaphoreInformationClass, SemaphoreInformation, Length, ReturnLength);
102         return STATUS_SUCCESS;
103 }
104
105 /******************************************************************************
106  *  NtReleaseSemaphore (NTDLL.@)
107  */
108 NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous )
109 {
110     NTSTATUS ret;
111     SERVER_START_REQ( release_semaphore )
112     {
113         req->handle = handle;
114         req->count  = count;
115         if (!(ret = wine_server_call( req )))
116         {
117             if (previous) *previous = reply->prev_count;
118         }
119     }
120     SERVER_END_REQ;
121     return ret;
122 }
123
124 /*
125  *      Events
126  */
127  
128 /**************************************************************************
129  * NtCreateEvent (NTDLL.@)
130  * ZwCreateEvent (NTDLL.@)
131  */
132 NTSTATUS WINAPI NtCreateEvent(
133         OUT PHANDLE EventHandle,
134         IN ACCESS_MASK DesiredAccess,
135         IN const OBJECT_ATTRIBUTES *attr,
136         IN BOOLEAN ManualReset,
137         IN BOOLEAN InitialState)
138 {
139     DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
140     NTSTATUS ret;
141
142     SERVER_START_REQ( create_event )
143     {
144         req->manual_reset = ManualReset;
145         req->initial_state = InitialState;
146         req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
147         if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
148         ret = wine_server_call( req );
149         *EventHandle = reply->handle;
150     }
151     SERVER_END_REQ;
152     return ret;
153 }
154
155 /******************************************************************************
156  *  NtOpenEvent (NTDLL.@)
157  *  ZwOpenEvent (NTDLL.@)
158  */
159 NTSTATUS WINAPI NtOpenEvent(
160         OUT PHANDLE EventHandle,
161         IN ACCESS_MASK DesiredAccess,
162         IN const OBJECT_ATTRIBUTES *attr )
163 {
164     DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
165     NTSTATUS ret;
166
167     SERVER_START_REQ( open_event )
168     {
169         req->access  = DesiredAccess;
170         req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
171         if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
172         ret = wine_server_call( req );
173         *EventHandle = reply->handle;
174     }
175     SERVER_END_REQ;
176     return ret;
177 }
178
179
180 /******************************************************************************
181  *  NtSetEvent (NTDLL.@)
182  *  ZwSetEvent (NTDLL.@)
183  */
184 NTSTATUS WINAPI NtSetEvent( HANDLE handle, PULONG NumberOfThreadsReleased )
185 {
186     NTSTATUS ret;
187
188     /* FIXME: set NumberOfThreadsReleased */
189
190     SERVER_START_REQ( event_op )
191     {
192         req->handle = handle;
193         req->op     = SET_EVENT;
194         ret = wine_server_call( req );
195     }
196     SERVER_END_REQ;
197     return ret;
198 }
199
200 /******************************************************************************
201  *  NtResetEvent (NTDLL.@)
202  */
203 NTSTATUS WINAPI NtResetEvent( HANDLE handle, PULONG NumberOfThreadsReleased )
204 {
205     NTSTATUS ret;
206
207     /* resetting an event can't release any thread... */
208     if (NumberOfThreadsReleased) *NumberOfThreadsReleased = 0;
209
210     SERVER_START_REQ( event_op )
211     {
212         req->handle = handle;
213         req->op     = RESET_EVENT;
214         ret = wine_server_call( req );
215     }
216     SERVER_END_REQ;
217     return ret;
218 }
219
220 /******************************************************************************
221  *  NtClearEvent (NTDLL.@)
222  *
223  * FIXME
224  *   same as NtResetEvent ???
225  */
226 NTSTATUS WINAPI NtClearEvent ( HANDLE handle )
227 {
228     return NtResetEvent( handle, NULL );
229 }
230
231 /******************************************************************************
232  *  NtPulseEvent (NTDLL.@)
233  *
234  * FIXME
235  *   PulseCount
236  */
237 NTSTATUS WINAPI NtPulseEvent( HANDLE handle, PULONG PulseCount )
238 {
239     NTSTATUS ret;
240     FIXME("(0x%08x,%p)\n", handle, PulseCount);
241     SERVER_START_REQ( event_op )
242     {
243         req->handle = handle;
244         req->op     = PULSE_EVENT;
245         ret = wine_server_call( req );
246     }
247     SERVER_END_REQ;
248     return ret;
249 }
250
251 /******************************************************************************
252  *  NtQueryEvent (NTDLL.@)
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 {
261         FIXME("(0x%08x)\n", EventHandle);
262         return STATUS_SUCCESS;
263 }