server: Do not dereference symlinks specified as root directory.
[wine/zf.git] / dlls / ntdll / tests / om.c
blobc92b780541fbe13576cde6971baf5619d476ca37
1 /*
2 * Unit test suite for object manager functions
4 * Copyright 2005 Robert Shearman
5 * Copyright 2005 Vitaliy Margolen
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "ntdll_test.h"
23 #include "winternl.h"
24 #include "stdio.h"
25 #include "winnt.h"
26 #include "stdlib.h"
28 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
29 static NTSTATUS (WINAPI *pNtCreateEvent) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, BOOLEAN, BOOLEAN);
30 static NTSTATUS (WINAPI *pNtOpenEvent) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES);
31 static NTSTATUS (WINAPI *pNtPulseEvent) ( HANDLE, PLONG );
32 static NTSTATUS (WINAPI *pNtQueryEvent) ( HANDLE, EVENT_INFORMATION_CLASS, PVOID, ULONG, PULONG );
33 static NTSTATUS (WINAPI *pNtResetEvent) ( HANDLE, LONG* );
34 static NTSTATUS (WINAPI *pNtSetEvent) ( HANDLE, LONG* );
35 static NTSTATUS (WINAPI *pNtCreateJobObject)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES );
36 static NTSTATUS (WINAPI *pNtOpenJobObject)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES );
37 static NTSTATUS (WINAPI *pNtCreateKey)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG,
38 const UNICODE_STRING *, ULONG, PULONG );
39 static NTSTATUS (WINAPI *pNtOpenKey)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES );
40 static NTSTATUS (WINAPI *pNtDeleteKey)( HANDLE );
41 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
42 ULONG, ULONG, ULONG, PLARGE_INTEGER );
43 static NTSTATUS (WINAPI *pNtCreateMutant)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, BOOLEAN );
44 static NTSTATUS (WINAPI *pNtOpenMutant) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES );
45 static NTSTATUS (WINAPI *pNtQueryMutant) ( HANDLE, MUTANT_INFORMATION_CLASS, PVOID, ULONG, PULONG );
46 static NTSTATUS (WINAPI *pNtReleaseMutant)( HANDLE, PLONG );
47 static NTSTATUS (WINAPI *pNtCreateSemaphore)( PHANDLE, ACCESS_MASK,const POBJECT_ATTRIBUTES,LONG,LONG );
48 static NTSTATUS (WINAPI *pNtOpenSemaphore)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES );
49 static NTSTATUS (WINAPI *pNtCreateTimer) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, TIMER_TYPE );
50 static NTSTATUS (WINAPI *pNtOpenTimer)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES );
51 static NTSTATUS (WINAPI *pNtCreateSection)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, const PLARGE_INTEGER,
52 ULONG, ULONG, HANDLE );
53 static NTSTATUS (WINAPI *pNtOpenSection)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES );
54 static NTSTATUS (WINAPI *pNtOpenFile) ( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG );
55 static NTSTATUS (WINAPI *pNtClose) ( HANDLE );
56 static NTSTATUS (WINAPI *pNtCreateNamedPipeFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
57 ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, PLARGE_INTEGER );
58 static NTSTATUS (WINAPI *pNtOpenDirectoryObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
59 static NTSTATUS (WINAPI *pNtCreateDirectoryObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
60 static NTSTATUS (WINAPI *pNtOpenSymbolicLinkObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
61 static NTSTATUS (WINAPI *pNtCreateSymbolicLinkObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PUNICODE_STRING);
62 static NTSTATUS (WINAPI *pNtQuerySymbolicLinkObject)(HANDLE,PUNICODE_STRING,PULONG);
63 static NTSTATUS (WINAPI *pNtQueryObject)(HANDLE,OBJECT_INFORMATION_CLASS,PVOID,ULONG,PULONG);
64 static NTSTATUS (WINAPI *pNtReleaseSemaphore)(HANDLE, ULONG, PULONG);
65 static NTSTATUS (WINAPI *pNtCreateKeyedEvent)( HANDLE *, ACCESS_MASK, const OBJECT_ATTRIBUTES *, ULONG );
66 static NTSTATUS (WINAPI *pNtOpenKeyedEvent)( HANDLE *, ACCESS_MASK, const OBJECT_ATTRIBUTES * );
67 static NTSTATUS (WINAPI *pNtWaitForKeyedEvent)( HANDLE, const void *, BOOLEAN, const LARGE_INTEGER * );
68 static NTSTATUS (WINAPI *pNtReleaseKeyedEvent)( HANDLE, const void *, BOOLEAN, const LARGE_INTEGER * );
69 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
70 static NTSTATUS (WINAPI *pNtOpenIoCompletion)( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES );
71 static NTSTATUS (WINAPI *pNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, void *, ULONG, FILE_INFORMATION_CLASS);
72 static NTSTATUS (WINAPI *pNtQuerySystemTime)( LARGE_INTEGER * );
73 static NTSTATUS (WINAPI *pRtlWaitOnAddress)( const void *, const void *, SIZE_T, const LARGE_INTEGER * );
74 static void (WINAPI *pRtlWakeAddressAll)( const void * );
75 static void (WINAPI *pRtlWakeAddressSingle)( const void * );
76 static NTSTATUS (WINAPI *pNtOpenProcess)( HANDLE *, ACCESS_MASK, const OBJECT_ATTRIBUTES *, const CLIENT_ID * );
78 #define KEYEDEVENT_WAIT 0x0001
79 #define KEYEDEVENT_WAKE 0x0002
80 #define KEYEDEVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x0003)
82 static void test_case_sensitive (void)
84 NTSTATUS status;
85 OBJECT_ATTRIBUTES attr;
86 UNICODE_STRING str;
87 HANDLE Event, Mutant, h;
89 pRtlInitUnicodeString(&str, L"\\BaseNamedObjects\\test");
90 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
91 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
92 ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status);
94 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
95 ok(status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH /* Vista+ */, "got %#x\n", status);
97 pRtlInitUnicodeString(&str, L"\\BaseNamedObjects\\Test");
98 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
99 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
100 ok(status == STATUS_SUCCESS, "Failed to create Event(%08x)\n", status);
102 pRtlInitUnicodeString(&str, L"\\BaseNamedObjects\\TEst");
103 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
104 status = pNtOpenMutant(&h, GENERIC_ALL, &attr);
105 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
106 "NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
108 pNtClose(Mutant);
110 pRtlInitUnicodeString(&str, L"\\BASENamedObjects\\test");
111 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
112 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
113 ok(status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH /* Vista+ */, "got %#x\n", status);
115 status = pNtCreateEvent(&h, GENERIC_ALL, &attr, FALSE, FALSE);
116 ok(status == STATUS_OBJECT_NAME_COLLISION,
117 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08x)\n", status);
119 attr.Attributes = 0;
120 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
121 ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
122 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
124 pNtClose(Event);
127 static void test_namespace_pipe(void)
129 OBJECT_ATTRIBUTES attr;
130 UNICODE_STRING str;
131 IO_STATUS_BLOCK iosb;
132 NTSTATUS status;
133 LARGE_INTEGER timeout;
134 HANDLE pipe, h;
136 timeout.QuadPart = -10000;
138 pRtlInitUnicodeString(&str, L"\\??\\PIPE\\test\\pipe");
139 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
140 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
141 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
142 ok(status == STATUS_SUCCESS, "Failed to create NamedPipe(%08x)\n", status);
144 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
145 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
146 ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
147 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status);
149 pRtlInitUnicodeString(&str, L"\\??\\PIPE\\TEST\\PIPE");
150 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
151 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
152 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
153 ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
154 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status);
156 h = CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
157 OPEN_EXISTING, 0, 0 );
158 ok(h != INVALID_HANDLE_VALUE, "Failed to open NamedPipe (%u)\n", GetLastError());
159 pNtClose(h);
161 pRtlInitUnicodeString(&str, L"\\??\\pipe\\test\\pipe");
162 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
163 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, 0);
164 ok(status == STATUS_OBJECT_PATH_NOT_FOUND ||
165 status == STATUS_PIPE_NOT_AVAILABLE ||
166 status == STATUS_OBJECT_NAME_INVALID || /* vista */
167 status == STATUS_OBJECT_NAME_NOT_FOUND, /* win8 */
168 "NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
170 pRtlInitUnicodeString(&str, L"\\??\\pipe\\test");
171 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
172 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, 0);
173 ok(status == STATUS_OBJECT_NAME_NOT_FOUND ||
174 status == STATUS_OBJECT_NAME_INVALID, /* vista */
175 "NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status);
177 str.Length -= 4 * sizeof(WCHAR);
178 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, 0);
179 ok(status == STATUS_SUCCESS, "NtOpenFile should have succeeded got %08x\n", status);
180 pNtClose( h );
182 str.Length -= sizeof(WCHAR);
183 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, 0);
184 ok(status == STATUS_SUCCESS, "NtOpenFile should have succeeded got %08x\n", status);
185 pNtClose( h );
187 pNtClose(pipe);
190 #define DIRECTORY_QUERY (0x0001)
191 #define SYMBOLIC_LINK_QUERY 0x0001
193 #define check_create_open_dir(parent, name, status) check_create_open_dir_(__LINE__, parent, name, status)
194 static void check_create_open_dir_( int line, HANDLE parent, const WCHAR *name, NTSTATUS expect )
196 OBJECT_ATTRIBUTES attr;
197 UNICODE_STRING str;
198 NTSTATUS status;
199 HANDLE h;
201 RtlInitUnicodeString( &str, name );
202 InitializeObjectAttributes( &attr, &str, 0, parent, NULL );
203 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
204 ok_(__FILE__, line)( status == expect, "NtCreateDirectoryObject(%s) got %08x\n", debugstr_w(name), status );
205 if (!status) pNtClose( h );
207 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
208 ok_(__FILE__, line)( status == expect, "NtOpenDirectoryObject(%s) got %08x\n", debugstr_w(name), status );
209 if (!status) pNtClose( h );
212 static BOOL is_correct_dir( HANDLE dir, const WCHAR *name )
214 NTSTATUS status;
215 UNICODE_STRING str;
216 OBJECT_ATTRIBUTES attr;
217 HANDLE h = 0;
219 RtlInitUnicodeString( &str, name );
220 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
221 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
222 if (h) pNtClose( h );
223 return (status == STATUS_OBJECT_NAME_EXISTS);
226 /* return a handle to the BaseNamedObjects dir where kernel32 objects get created */
227 static HANDLE get_base_dir(void)
229 static const WCHAR objname[] = L"om.c_get_base_dir_obj";
230 NTSTATUS status;
231 UNICODE_STRING str;
232 OBJECT_ATTRIBUTES attr;
233 HANDLE dir, h;
234 WCHAR name[40];
236 h = CreateMutexW( NULL, FALSE, objname );
237 ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
238 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
240 swprintf( name, ARRAY_SIZE(name), L"\\BaseNamedObjects\\Session\\%u", NtCurrentTeb()->Peb->SessionId );
241 RtlInitUnicodeString( &str, name );
242 status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
243 ok(!status, "got %#x\n", status);
244 ok(is_correct_dir( dir, objname ), "wrong dir\n");
246 pNtClose( h );
247 return dir;
250 static void test_name_collisions(void)
252 NTSTATUS status;
253 UNICODE_STRING str;
254 OBJECT_ATTRIBUTES attr;
255 HANDLE dir, h, h1, h2;
256 DWORD winerr;
257 LARGE_INTEGER size;
259 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
260 RtlInitUnicodeString(&str, L"\\");
261 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
262 ok( status == STATUS_OBJECT_NAME_COLLISION, "NtCreateDirectoryObject got %08x\n", status );
263 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
265 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
266 ok( status == STATUS_OBJECT_NAME_EXISTS, "NtCreateDirectoryObject got %08x\n", status );
267 pNtClose(h);
268 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
269 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
270 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
272 RtlInitUnicodeString(&str, L"\\??\\PIPE\\om.c-mutant");
273 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
274 todo_wine ok(status == STATUS_OBJECT_PATH_NOT_FOUND, "got %#x\n", status);
276 dir = get_base_dir();
277 RtlInitUnicodeString(&str, L"om.c-test");
278 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
279 h = CreateMutexA(NULL, FALSE, "om.c-test");
280 ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
281 status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE);
282 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
283 "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
284 h2 = CreateMutexA(NULL, FALSE, "om.c-test");
285 winerr = GetLastError();
286 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
287 "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
288 pNtClose(h);
289 pNtClose(h1);
290 pNtClose(h2);
292 h = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
293 ok(h != 0, "CreateEventA failed got ret=%p (%d)\n", h, GetLastError());
294 status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE);
295 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
296 "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
297 h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
298 winerr = GetLastError();
299 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
300 "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
301 pNtClose(h);
302 pNtClose(h1);
303 pNtClose(h2);
305 h = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
306 ok(h != 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h, GetLastError());
307 status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2);
308 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
309 "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
310 h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
311 winerr = GetLastError();
312 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
313 "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
314 pNtClose(h);
315 pNtClose(h1);
316 pNtClose(h2);
318 h = CreateWaitableTimerA(NULL, TRUE, "om.c-test");
319 ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h, GetLastError());
320 status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer);
321 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
322 "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
323 h2 = CreateWaitableTimerA(NULL, TRUE, "om.c-test");
324 winerr = GetLastError();
325 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
326 "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
327 pNtClose(h);
328 pNtClose(h1);
329 pNtClose(h2);
331 h = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
332 ok(h != 0, "CreateFileMappingA failed got ret=%p (%d)\n", h, GetLastError());
333 size.u.LowPart = 256;
334 size.u.HighPart = 0;
335 status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0);
336 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
337 "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
338 h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
339 winerr = GetLastError();
340 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
341 "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
342 pNtClose(h);
343 pNtClose(h1);
344 pNtClose(h2);
346 pNtClose(dir);
349 static void test_all_kernel_objects( UINT line, OBJECT_ATTRIBUTES *attr,
350 NTSTATUS create_expect, NTSTATUS open_expect )
352 UNICODE_STRING target;
353 LARGE_INTEGER size;
354 NTSTATUS status, status2;
355 HANDLE ret, ret2;
357 RtlInitUnicodeString( &target, L"\\DosDevices" );
358 size.QuadPart = 4096;
360 status = pNtCreateMutant( &ret, GENERIC_ALL, attr, FALSE );
361 ok( status == create_expect, "%u: NtCreateMutant failed %x\n", line, status );
362 status2 = pNtOpenMutant( &ret2, GENERIC_ALL, attr );
363 ok( status2 == open_expect, "%u: NtOpenMutant failed %x\n", line, status2 );
364 if (!status) pNtClose( ret );
365 if (!status2) pNtClose( ret2 );
366 status = pNtCreateSemaphore( &ret, GENERIC_ALL, attr, 1, 2 );
367 ok( status == create_expect, "%u: NtCreateSemaphore failed %x\n", line, status );
368 status2 = pNtOpenSemaphore( &ret2, GENERIC_ALL, attr );
369 ok( status2 == open_expect, "%u: NtOpenSemaphore failed %x\n", line, status2 );
370 if (!status) pNtClose( ret );
371 if (!status2) pNtClose( ret2 );
372 status = pNtCreateEvent( &ret, GENERIC_ALL, attr, 1, 0 );
373 ok( status == create_expect, "%u: NtCreateEvent failed %x\n", line, status );
374 status2 = pNtOpenEvent( &ret2, GENERIC_ALL, attr );
375 ok( status2 == open_expect, "%u: NtOpenEvent failed %x\n", line, status2 );
376 if (!status) pNtClose( ret );
377 if (!status2) pNtClose( ret2 );
378 status = pNtCreateKeyedEvent( &ret, GENERIC_ALL, attr, 0 );
379 ok( status == create_expect, "%u: NtCreateKeyedEvent failed %x\n", line, status );
380 status2 = pNtOpenKeyedEvent( &ret2, GENERIC_ALL, attr );
381 ok( status2 == open_expect, "%u: NtOpenKeyedEvent failed %x\n", line, status2 );
382 if (!status) pNtClose( ret );
383 if (!status2) pNtClose( ret2 );
384 status = pNtCreateTimer( &ret, GENERIC_ALL, attr, NotificationTimer );
385 ok( status == create_expect, "%u: NtCreateTimer failed %x\n", line, status );
386 status2 = pNtOpenTimer( &ret2, GENERIC_ALL, attr );
387 ok( status2 == open_expect, "%u: NtOpenTimer failed %x\n", line, status2 );
388 if (!status) pNtClose( ret );
389 if (!status2) pNtClose( ret2 );
390 status = pNtCreateIoCompletion( &ret, GENERIC_ALL, attr, 0 );
391 ok( status == create_expect, "%u: NtCreateCompletion failed %x\n", line, status );
392 status2 = pNtOpenIoCompletion( &ret2, GENERIC_ALL, attr );
393 ok( status2 == open_expect, "%u: NtOpenCompletion failed %x\n", line, status2 );
394 if (!status) pNtClose( ret );
395 if (!status2) pNtClose( ret2 );
396 status = pNtCreateJobObject( &ret, GENERIC_ALL, attr );
397 ok( status == create_expect, "%u: NtCreateJobObject failed %x\n", line, status );
398 status2 = pNtOpenJobObject( &ret2, GENERIC_ALL, attr );
399 ok( status2 == open_expect, "%u: NtOpenJobObject failed %x\n", line, status2 );
400 if (!status) pNtClose( ret );
401 if (!status2) pNtClose( ret2 );
402 status = pNtCreateDirectoryObject( &ret, GENERIC_ALL, attr );
403 ok( status == create_expect, "%u: NtCreateDirectoryObject failed %x\n", line, status );
404 status2 = pNtOpenDirectoryObject( &ret2, GENERIC_ALL, attr );
405 ok( status2 == open_expect, "%u: NtOpenDirectoryObject failed %x\n", line, status2 );
406 if (!status) pNtClose( ret );
407 if (!status2) pNtClose( ret2 );
408 status = pNtCreateSymbolicLinkObject( &ret, GENERIC_ALL, attr, &target );
409 ok( status == create_expect, "%u: NtCreateSymbolicLinkObject failed %x\n", line, status );
410 status2 = pNtOpenSymbolicLinkObject( &ret2, GENERIC_ALL, attr );
411 ok( status2 == open_expect, "%u: NtOpenSymbolicLinkObject failed %x\n", line, status2 );
412 if (!status) pNtClose( ret );
413 if (!status2) pNtClose( ret2 );
414 status = pNtCreateSection( &ret, SECTION_MAP_WRITE, attr, &size, PAGE_READWRITE, SEC_COMMIT, 0 );
415 ok( status == create_expect, "%u: NtCreateSection failed %x\n", line, status );
416 status2 = pNtOpenSection( &ret2, SECTION_MAP_WRITE, attr );
417 ok( status2 == open_expect, "%u: NtOpenSection failed %x\n", line, status2 );
418 if (!status) pNtClose( ret );
419 if (!status2) pNtClose( ret2 );
422 static void test_name_limits(void)
424 static const WCHAR pipeW[] = L"\\Device\\NamedPipe\\";
425 static const WCHAR mailslotW[] = L"\\Device\\MailSlot\\";
426 static const WCHAR registryW[] = L"\\REGISTRY\\Machine\\SOFTWARE\\Microsoft\\";
427 OBJECT_ATTRIBUTES attr, attr2, attr3;
428 IO_STATUS_BLOCK iosb;
429 LARGE_INTEGER size, timeout;
430 UNICODE_STRING str, str2, target;
431 NTSTATUS status;
432 HANDLE ret, ret2;
433 DWORD i;
435 InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
436 InitializeObjectAttributes( &attr2, &str, 0, (HANDLE)0xdeadbeef, NULL );
437 InitializeObjectAttributes( &attr3, &str, 0, 0, NULL );
438 str.Buffer = HeapAlloc( GetProcessHeap(), 0, 65536 + sizeof(registryW));
439 str.MaximumLength = 65534;
440 for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i] = 'a';
441 size.QuadPart = 4096;
442 RtlInitUnicodeString( &target, L"\\DosDevices" );
444 attr.RootDirectory = get_base_dir();
445 str.Length = 0;
446 status = pNtCreateMutant( &ret, GENERIC_ALL, &attr2, FALSE );
447 ok( status == STATUS_SUCCESS, "%u: NtCreateMutant failed %x\n", str.Length, status );
448 attr3.RootDirectory = ret;
449 status = pNtOpenMutant( &ret2, GENERIC_ALL, &attr );
450 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenMutant failed %x\n", str.Length, status );
451 status = pNtOpenMutant( &ret2, GENERIC_ALL, &attr3 );
452 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
453 "%u: NtOpenMutant failed %x\n", str.Length, status );
454 pNtClose( ret );
455 status = pNtCreateSemaphore( &ret, GENERIC_ALL, &attr2, 1, 2 );
456 ok( status == STATUS_SUCCESS, "%u: NtCreateSemaphore failed %x\n", str.Length, status );
457 attr3.RootDirectory = ret;
458 status = pNtOpenSemaphore( &ret2, GENERIC_ALL, &attr );
459 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenSemaphore failed %x\n", str.Length, status );
460 status = pNtOpenSemaphore( &ret2, GENERIC_ALL, &attr3 );
461 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
462 "%u: NtOpenSemaphore failed %x\n", str.Length, status );
463 pNtClose( ret );
464 status = pNtCreateEvent( &ret, GENERIC_ALL, &attr2, 1, 0 );
465 ok( status == STATUS_SUCCESS, "%u: NtCreateEvent failed %x\n", str.Length, status );
466 attr3.RootDirectory = ret;
467 status = pNtOpenEvent( &ret2, GENERIC_ALL, &attr );
468 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenEvent failed %x\n", str.Length, status );
469 status = pNtOpenEvent( &ret2, GENERIC_ALL, &attr3 );
470 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
471 "%u: NtOpenEvent failed %x\n", str.Length, status );
472 pNtClose( ret );
473 status = pNtCreateKeyedEvent( &ret, GENERIC_ALL, &attr2, 0 );
474 ok( status == STATUS_SUCCESS, "%u: NtCreateKeyedEvent failed %x\n", str.Length, status );
475 attr3.RootDirectory = ret;
476 status = pNtOpenKeyedEvent( &ret2, GENERIC_ALL, &attr );
477 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenKeyedEvent failed %x\n", str.Length, status );
478 status = pNtOpenKeyedEvent( &ret2, GENERIC_ALL, &attr3 );
479 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
480 "%u: NtOpenKeyedEvent failed %x\n", str.Length, status );
481 pNtClose( ret );
482 status = pNtCreateTimer( &ret, GENERIC_ALL, &attr2, NotificationTimer );
483 ok( status == STATUS_SUCCESS, "%u: NtCreateTimer failed %x\n", str.Length, status );
484 attr3.RootDirectory = ret;
485 status = pNtOpenTimer( &ret2, GENERIC_ALL, &attr );
486 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenTimer failed %x\n", str.Length, status );
487 status = pNtOpenTimer( &ret2, GENERIC_ALL, &attr3 );
488 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
489 "%u: NtOpenTimer failed %x\n", str.Length, status );
490 pNtClose( ret );
491 status = pNtCreateIoCompletion( &ret, GENERIC_ALL, &attr2, 0 );
492 ok( status == STATUS_SUCCESS, "%u: NtCreateCompletion failed %x\n", str.Length, status );
493 attr3.RootDirectory = ret;
494 status = pNtOpenIoCompletion( &ret2, GENERIC_ALL, &attr );
495 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenCompletion failed %x\n", str.Length, status );
496 status = pNtOpenIoCompletion( &ret2, GENERIC_ALL, &attr3 );
497 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
498 "%u: NtOpenCompletion failed %x\n", str.Length, status );
499 pNtClose( ret );
500 status = pNtCreateJobObject( &ret, GENERIC_ALL, &attr2 );
501 ok( status == STATUS_SUCCESS, "%u: NtCreateJobObject failed %x\n", str.Length, status );
502 attr3.RootDirectory = ret;
503 status = pNtOpenJobObject( &ret2, GENERIC_ALL, &attr );
504 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenJobObject failed %x\n", str.Length, status );
505 status = pNtOpenJobObject( &ret2, GENERIC_ALL, &attr3 );
506 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
507 "%u: NtOpenJobObject failed %x\n", str.Length, status );
508 pNtClose( ret );
509 status = pNtCreateDirectoryObject( &ret, GENERIC_ALL, &attr2 );
510 ok( status == STATUS_SUCCESS, "%u: NtCreateDirectoryObject failed %x\n", str.Length, status );
511 attr3.RootDirectory = ret;
512 status = pNtOpenDirectoryObject( &ret2, GENERIC_ALL, &attr );
513 ok( status == STATUS_SUCCESS || broken(status == STATUS_ACCESS_DENIED), /* winxp */
514 "%u: NtOpenDirectoryObject failed %x\n", str.Length, status );
515 if (!status) pNtClose( ret2 );
516 status = pNtOpenDirectoryObject( &ret2, GENERIC_ALL, &attr3 );
517 ok( status == STATUS_SUCCESS, "%u: NtOpenDirectoryObject failed %x\n", str.Length, status );
518 pNtClose( ret2 );
519 pNtClose( ret );
520 status = pNtCreateSymbolicLinkObject( &ret, GENERIC_ALL, &attr2, &target );
521 ok( status == STATUS_SUCCESS, "%u: NtCreateSymbolicLinkObject failed %x\n", str.Length, status );
522 attr3.RootDirectory = ret;
523 status = pNtOpenSymbolicLinkObject( &ret2, GENERIC_ALL, &attr );
524 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenSymbolicLinkObject failed %x\n", str.Length, status );
525 status = pNtOpenSymbolicLinkObject( &ret2, GENERIC_ALL, &attr3 );
526 ok( status == STATUS_SUCCESS, "%u: NtOpenSymbolicLinkObject failed %x\n", str.Length, status );
527 pNtClose( ret2 );
528 pNtClose( ret );
529 status = pNtCreateSection( &ret, SECTION_MAP_WRITE, &attr2, &size, PAGE_READWRITE, SEC_COMMIT, 0 );
530 ok( status == STATUS_SUCCESS, "%u: NtCreateSection failed %x\n", str.Length, status );
531 attr3.RootDirectory = ret;
532 status = pNtOpenSection( &ret2, SECTION_MAP_WRITE, &attr );
533 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "%u: NtOpenSection failed %x\n", str.Length, status );
534 status = pNtOpenSection( &ret2, SECTION_MAP_WRITE, &attr3 );
535 ok( status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE /* < 7 */,
536 "%u: NtOpenSection failed %x\n", str.Length, status );
537 pNtClose( ret );
539 str.Length = 67;
540 test_all_kernel_objects( __LINE__, &attr2, STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_NAME_INVALID );
542 str.Length = 65532;
543 test_all_kernel_objects( __LINE__, &attr, STATUS_SUCCESS, STATUS_SUCCESS );
545 str.Length = 65534;
546 test_all_kernel_objects( __LINE__, &attr, STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_NAME_INVALID );
548 str.Length = 128;
549 for (attr.Length = 0; attr.Length <= 2 * sizeof(attr); attr.Length++)
551 if (attr.Length == sizeof(attr))
552 test_all_kernel_objects( __LINE__, &attr, STATUS_SUCCESS, STATUS_SUCCESS );
553 else
554 test_all_kernel_objects( __LINE__, &attr, STATUS_INVALID_PARAMETER, STATUS_INVALID_PARAMETER );
556 attr.Length = sizeof(attr);
558 /* null attributes or ObjectName, with or without RootDirectory */
559 attr3.RootDirectory = 0;
560 attr2.ObjectName = attr3.ObjectName = NULL;
561 test_all_kernel_objects( __LINE__, &attr2, STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_NAME_INVALID );
562 test_all_kernel_objects( __LINE__, &attr3, STATUS_SUCCESS, STATUS_OBJECT_PATH_SYNTAX_BAD );
564 attr3.ObjectName = &str2;
565 pRtlInitUnicodeString( &str2, L"\\BaseNamedObjects\\Local" );
566 status = pNtOpenSymbolicLinkObject( &ret, SYMBOLIC_LINK_QUERY, &attr3 );
567 ok( status == STATUS_SUCCESS, "can't open BaseNamedObjects\\Local %x\n", status );
568 attr3.ObjectName = &str;
569 attr3.RootDirectory = ret;
570 test_all_kernel_objects( __LINE__, &attr3, STATUS_OBJECT_TYPE_MISMATCH, STATUS_OBJECT_TYPE_MISMATCH );
571 pNtClose( attr3.RootDirectory );
573 status = pNtCreateMutant( &ret, GENERIC_ALL, NULL, FALSE );
574 ok( status == STATUS_SUCCESS, "NULL: NtCreateMutant failed %x\n", status );
575 pNtClose( ret );
576 status = pNtOpenMutant( &ret, GENERIC_ALL, NULL );
577 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenMutant failed %x\n", status );
578 status = pNtCreateSemaphore( &ret, GENERIC_ALL, NULL, 1, 2 );
579 ok( status == STATUS_SUCCESS, "NULL: NtCreateSemaphore failed %x\n", status );
580 pNtClose( ret );
581 status = pNtOpenSemaphore( &ret, GENERIC_ALL, NULL );
582 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenSemaphore failed %x\n", status );
583 status = pNtCreateEvent( &ret, GENERIC_ALL, NULL, 1, 0 );
584 ok( status == STATUS_SUCCESS, "NULL: NtCreateEvent failed %x\n", status );
585 pNtClose( ret );
586 status = pNtOpenEvent( &ret, GENERIC_ALL, NULL );
587 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenEvent failed %x\n", status );
588 status = pNtCreateKeyedEvent( &ret, GENERIC_ALL, NULL, 0 );
589 ok( status == STATUS_SUCCESS, "NULL: NtCreateKeyedEvent failed %x\n", status );
590 pNtClose( ret );
591 status = pNtOpenKeyedEvent( &ret, GENERIC_ALL, NULL );
592 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenKeyedEvent failed %x\n", status );
593 status = pNtCreateTimer( &ret, GENERIC_ALL, NULL, NotificationTimer );
594 ok( status == STATUS_SUCCESS, "NULL: NtCreateTimer failed %x\n", status );
595 pNtClose( ret );
596 status = pNtOpenTimer( &ret, GENERIC_ALL, NULL );
597 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenTimer failed %x\n", status );
598 status = pNtCreateIoCompletion( &ret, GENERIC_ALL, NULL, 0 );
599 ok( status == STATUS_SUCCESS, "NULL: NtCreateCompletion failed %x\n", status );
600 pNtClose( ret );
601 status = pNtOpenIoCompletion( &ret, GENERIC_ALL, NULL );
602 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenCompletion failed %x\n", status );
603 status = pNtCreateJobObject( &ret, GENERIC_ALL, NULL );
604 ok( status == STATUS_SUCCESS, "NULL: NtCreateJobObject failed %x\n", status );
605 pNtClose( ret );
606 status = pNtOpenJobObject( &ret, GENERIC_ALL, NULL );
607 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenJobObject failed %x\n", status );
608 status = pNtCreateDirectoryObject( &ret, GENERIC_ALL, NULL );
609 ok( status == STATUS_SUCCESS, "NULL: NtCreateDirectoryObject failed %x\n", status );
610 pNtClose( ret );
611 status = pNtOpenDirectoryObject( &ret, GENERIC_ALL, NULL );
612 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenDirectoryObject failed %x\n", status );
613 status = pNtCreateSymbolicLinkObject( &ret, GENERIC_ALL, NULL, &target );
614 ok( status == STATUS_ACCESS_VIOLATION || broken( status == STATUS_SUCCESS), /* winxp */
615 "NULL: NtCreateSymbolicLinkObject failed %x\n", status );
616 if (!status) pNtClose( ret );
617 status = pNtOpenSymbolicLinkObject( &ret, GENERIC_ALL, NULL );
618 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenSymbolicLinkObject failed %x\n", status );
619 status = pNtCreateSection( &ret, SECTION_MAP_WRITE, NULL, &size, PAGE_READWRITE, SEC_COMMIT, 0 );
620 ok( status == STATUS_SUCCESS, "NULL: NtCreateSection failed %x\n", status );
621 pNtClose( ret );
622 status = pNtOpenSection( &ret, SECTION_MAP_WRITE, NULL );
623 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtOpenSection failed %x\n", status );
624 attr2.ObjectName = attr3.ObjectName = &str;
626 /* named pipes */
627 wcscpy( str.Buffer, pipeW );
628 for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + wcslen( pipeW )] = 'a';
629 str.Length = 0;
630 attr.RootDirectory = 0;
631 attr.Attributes = OBJ_CASE_INSENSITIVE;
632 timeout.QuadPart = -10000;
633 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
634 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
635 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
636 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr2, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
637 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
638 ok( status == STATUS_INVALID_HANDLE, "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
639 str.Length = 67;
640 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr2, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
641 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
642 ok( status == STATUS_OBJECT_NAME_INVALID, "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
643 str.Length = 128;
644 for (attr.Length = 0; attr.Length <= 2 * sizeof(attr); attr.Length++)
646 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
647 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
648 if (attr.Length == sizeof(attr))
650 ok( status == STATUS_SUCCESS, "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
651 pNtClose( ret );
653 else ok( status == STATUS_INVALID_PARAMETER,
654 "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
656 attr.Length = sizeof(attr);
657 str.Length = 65532;
658 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
659 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
660 ok( status == STATUS_SUCCESS, "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
661 pNtClose( ret );
662 str.Length = 65534;
663 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
664 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
665 ok( status == STATUS_OBJECT_NAME_INVALID, "%u: NtCreateNamedPipeFile failed %x\n", str.Length, status );
666 attr3.RootDirectory = 0;
667 attr2.ObjectName = attr3.ObjectName = NULL;
668 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr2, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
669 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
670 ok( status == STATUS_OBJECT_NAME_INVALID, "NULL: NtCreateNamedPipeFile failed %x\n", status );
671 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, &attr3, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
672 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
673 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NULL: NtCreateNamedPipeFile failed %x\n", status );
674 status = pNtCreateNamedPipeFile( &ret, GENERIC_ALL, NULL, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
675 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, 0, 0, 0, 1, 256, 256, &timeout );
676 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtCreateNamedPipeFile failed %x\n", status );
677 attr2.ObjectName = attr3.ObjectName = &str;
679 /* mailslots */
680 wcscpy( str.Buffer, mailslotW );
681 for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + wcslen( mailslotW )] = 'a';
682 str.Length = 0;
683 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr, &iosb, 0, 0, 0, NULL );
684 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
685 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr2, &iosb, 0, 0, 0, NULL );
686 ok( status == STATUS_INVALID_HANDLE, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
687 str.Length = 67;
688 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr2, &iosb, 0, 0, 0, NULL );
689 ok( status == STATUS_OBJECT_NAME_INVALID, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
690 str.Length = 128;
691 for (attr.Length = 0; attr.Length <= 2 * sizeof(attr); attr.Length++)
693 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr, &iosb, 0, 0, 0, NULL );
694 if (attr.Length == sizeof(attr))
696 ok( status == STATUS_SUCCESS, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
697 pNtClose( ret );
699 else ok( status == STATUS_INVALID_PARAMETER,
700 "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
702 attr.Length = sizeof(attr);
703 str.Length = 65532;
704 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr, &iosb, 0, 0, 0, NULL );
705 ok( status == STATUS_SUCCESS, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
706 pNtClose( ret );
707 str.Length = 65534;
708 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr, &iosb, 0, 0, 0, NULL );
709 ok( status == STATUS_OBJECT_NAME_INVALID, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
710 attr3.RootDirectory = 0;
711 attr2.ObjectName = attr3.ObjectName = NULL;
712 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr2, &iosb, 0, 0, 0, NULL );
713 ok( status == STATUS_OBJECT_NAME_INVALID, "NULL: NtCreateMailslotFile failed %x\n", status );
714 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr3, &iosb, 0, 0, 0, NULL );
715 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NULL: NtCreateMailslotFile failed %x\n", status );
716 status = pNtCreateMailslotFile( &ret, GENERIC_ALL, NULL, &iosb, 0, 0, 0, NULL );
717 ok( status == STATUS_INVALID_PARAMETER, "NULL: NtCreateMailslotFile failed %x\n", status );
718 attr2.ObjectName = attr3.ObjectName = &str;
720 /* registry keys */
721 wcscpy( str.Buffer, registryW );
722 for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + wcslen(registryW)] = 'a';
723 str.Length = 0;
724 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
725 todo_wine
726 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "%u: NtCreateKey failed %x\n", str.Length, status );
727 status = pNtCreateKey( &ret, GENERIC_ALL, &attr2, 0, NULL, 0, NULL );
728 ok( status == STATUS_INVALID_HANDLE, "%u: NtCreateKey failed %x\n", str.Length, status );
729 status = pNtOpenKey( &ret, GENERIC_ALL, &attr2 );
730 ok( status == STATUS_INVALID_HANDLE, "%u: NtOpenKey failed %x\n", str.Length, status );
731 str.Length = (wcslen( registryW ) + 250) * sizeof(WCHAR) + 1;
732 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
733 ok( status == STATUS_OBJECT_NAME_INVALID ||
734 status == STATUS_INVALID_PARAMETER ||
735 broken( status == STATUS_SUCCESS ), /* wow64 */
736 "%u: NtCreateKey failed %x\n", str.Length, status );
737 if (!status)
739 pNtDeleteKey( ret );
740 pNtClose( ret );
742 str.Length = (wcslen( registryW ) + 256) * sizeof(WCHAR);
743 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
744 ok( status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
745 "%u: NtCreateKey failed %x\n", str.Length, status );
746 if (!status)
748 status = pNtOpenKey( &ret2, KEY_READ, &attr );
749 ok( status == STATUS_SUCCESS, "%u: NtOpenKey failed %x\n", str.Length, status );
750 pNtClose( ret2 );
751 attr3.RootDirectory = ret;
752 str.Length = 0;
753 status = pNtOpenKey( &ret2, KEY_READ, &attr3 );
754 ok( status == STATUS_SUCCESS, "%u: NtOpenKey failed %x\n", str.Length, status );
755 pNtClose( ret2 );
756 pNtDeleteKey( ret );
757 pNtClose( ret );
759 str.Length = (wcslen( registryW ) + 256) * sizeof(WCHAR);
760 for (attr.Length = 0; attr.Length <= 2 * sizeof(attr); attr.Length++)
762 if (attr.Length == sizeof(attr))
764 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
765 ok( status == STATUS_SUCCESS, "%u: NtCreateKey failed %x\n", str.Length, status );
766 status = pNtOpenKey( &ret2, KEY_READ, &attr );
767 ok( status == STATUS_SUCCESS, "%u: NtOpenKey failed %x\n", str.Length, status );
768 pNtClose( ret2 );
769 pNtDeleteKey( ret );
770 pNtClose( ret );
772 else
774 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
775 ok( status == STATUS_INVALID_PARAMETER, "%u: NtCreateKey failed %x\n", str.Length, status );
776 status = pNtOpenKey( &ret2, KEY_READ, &attr );
777 ok( status == STATUS_INVALID_PARAMETER, "%u: NtOpenKey failed %x\n", str.Length, status );
780 attr.Length = sizeof(attr);
782 str.Length = (wcslen( registryW ) + 256) * sizeof(WCHAR) + 1;
783 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
784 ok( status == STATUS_OBJECT_NAME_INVALID ||
785 status == STATUS_INVALID_PARAMETER ||
786 broken( status == STATUS_SUCCESS ), /* win7 */
787 "%u: NtCreateKey failed %x\n", str.Length, status );
788 if (!status)
790 pNtDeleteKey( ret );
791 pNtClose( ret );
793 status = pNtOpenKey( &ret, GENERIC_ALL, &attr );
794 ok( status == STATUS_OBJECT_NAME_INVALID ||
795 status == STATUS_INVALID_PARAMETER ||
796 broken( status == STATUS_OBJECT_NAME_NOT_FOUND ), /* wow64 */
797 "%u: NtOpenKey failed %x\n", str.Length, status );
798 str.Length++;
799 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
800 ok( status == STATUS_INVALID_PARAMETER, "%u: NtCreateKey failed %x\n", str.Length, status );
801 status = pNtOpenKey( &ret, GENERIC_ALL, &attr );
802 todo_wine
803 ok( status == STATUS_INVALID_PARAMETER, "%u: NtOpenKey failed %x\n", str.Length, status );
804 str.Length = 2000;
805 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
806 ok( status == STATUS_INVALID_PARAMETER, "%u: NtCreateKey failed %x\n", str.Length, status );
807 status = pNtOpenKey( &ret, GENERIC_ALL, &attr );
808 todo_wine
809 ok( status == STATUS_INVALID_PARAMETER, "%u: NtOpenKey failed %x\n", str.Length, status );
810 /* some Windows versions change the error past 2050 chars, others past 4066 chars, some don't */
811 str.Length = 5000;
812 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
813 ok( status == STATUS_BUFFER_OVERFLOW ||
814 status == STATUS_BUFFER_TOO_SMALL ||
815 status == STATUS_INVALID_PARAMETER,
816 "%u: NtCreateKey failed %x\n", str.Length, status );
817 status = pNtOpenKey( &ret, GENERIC_ALL, &attr );
818 todo_wine
819 ok( status == STATUS_BUFFER_OVERFLOW ||
820 status == STATUS_BUFFER_TOO_SMALL ||
821 status == STATUS_INVALID_PARAMETER,
822 "%u: NtOpenKey failed %x\n", str.Length, status );
823 str.Length = 65534;
824 status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
825 ok( status == STATUS_OBJECT_NAME_INVALID ||
826 status == STATUS_BUFFER_OVERFLOW ||
827 status == STATUS_BUFFER_TOO_SMALL,
828 "%u: NtCreateKey failed %x\n", str.Length, status );
829 status = pNtOpenKey( &ret, GENERIC_ALL, &attr );
830 todo_wine
831 ok( status == STATUS_OBJECT_NAME_INVALID ||
832 status == STATUS_BUFFER_OVERFLOW ||
833 status == STATUS_BUFFER_TOO_SMALL,
834 "%u: NtOpenKey failed %x\n", str.Length, status );
835 attr3.RootDirectory = 0;
836 attr2.ObjectName = attr3.ObjectName = NULL;
837 status = pNtCreateKey( &ret, GENERIC_ALL, &attr2, 0, NULL, 0, NULL );
838 todo_wine
839 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE /* vista wow64 */,
840 "NULL: NtCreateKey failed %x\n", status );
841 status = pNtCreateKey( &ret, GENERIC_ALL, &attr3, 0, NULL, 0, NULL );
842 todo_wine
843 ok( status == STATUS_ACCESS_VIOLATION, "NULL: NtCreateKey failed %x\n", status );
844 status = pNtCreateKey( &ret, GENERIC_ALL, NULL, 0, NULL, 0, NULL );
845 ok( status == STATUS_ACCESS_VIOLATION, "NULL: NtCreateKey failed %x\n", status );
846 status = pNtOpenKey( &ret, GENERIC_ALL, &attr2 );
847 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE /* vista wow64 */,
848 "NULL: NtOpenKey failed %x\n", status );
849 status = pNtOpenKey( &ret, GENERIC_ALL, &attr3 );
850 ok( status == STATUS_ACCESS_VIOLATION, "NULL: NtOpenKey failed %x\n", status );
851 status = pNtOpenKey( &ret, GENERIC_ALL, NULL );
852 ok( status == STATUS_ACCESS_VIOLATION, "NULL: NtOpenKey failed %x\n", status );
853 attr2.ObjectName = attr3.ObjectName = &str;
855 HeapFree( GetProcessHeap(), 0, str.Buffer );
858 static void test_directory(void)
860 NTSTATUS status;
861 UNICODE_STRING str;
862 OBJECT_ATTRIBUTES attr;
863 HANDLE dir, dir1, h, h2;
864 WCHAR buffer[256];
865 ULONG len, full_len;
867 /* No name and/or no attributes */
868 status = pNtCreateDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
869 ok(status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* wow64 */, "got %#x\n", status);
870 status = pNtOpenDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
871 ok(status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* wow64 */, "got %#x\n", status);
873 status = pNtCreateDirectoryObject(&h, DIRECTORY_QUERY, NULL);
874 ok(status == STATUS_SUCCESS, "Failed to create Directory without attributes(%08x)\n", status);
875 pNtClose(h);
876 status = pNtOpenDirectoryObject(&h, DIRECTORY_QUERY, NULL);
877 ok(status == STATUS_INVALID_PARAMETER,
878 "NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
880 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
881 status = pNtCreateDirectoryObject( &dir, DIRECTORY_QUERY, &attr );
882 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
883 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
884 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NtOpenDirectoryObject got %08x\n", status );
886 /* Bad name */
887 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
889 RtlInitUnicodeString(&str, L"");
890 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
891 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
892 pNtClose(h);
893 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
894 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NtOpenDirectoryObject got %08x\n", status );
895 pNtClose(dir);
897 check_create_open_dir( NULL, L"BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD );
898 check_create_open_dir( NULL, L"\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID );
899 check_create_open_dir( NULL, L"\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID );
900 check_create_open_dir( NULL, L"\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID );
901 check_create_open_dir( NULL, L"\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND );
903 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\om.c-test");
904 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
905 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
906 status = pNtOpenDirectoryObject( &dir1, DIRECTORY_QUERY, &attr );
907 ok( status == STATUS_SUCCESS, "Failed to open directory %08x\n", status );
908 pNtClose(h);
909 pNtClose(dir1);
912 /* Use of root directory */
914 /* Can't use symlinks as a directory */
915 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\Local");
916 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
917 status = pNtOpenSymbolicLinkObject(&dir, SYMBOLIC_LINK_QUERY, &attr);
919 ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08x)\n", status);
920 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
921 RtlInitUnicodeString(&str, L"one more level");
922 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
923 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "NtCreateDirectoryObject got %08x\n", status );
925 RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\Local\\om.c-test" );
926 InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
927 status = pNtCreateDirectoryObject( &dir1, DIRECTORY_QUERY, &attr );
928 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
929 RtlInitUnicodeString( &str, L"om.c-test" );
930 InitializeObjectAttributes( &attr, &str, 0, dir, NULL );
931 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
932 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "Failed to open directory %08x\n", status );
934 RtlInitUnicodeString( &str, L"om.c-event" );
935 InitializeObjectAttributes( &attr, &str, 0, dir1, NULL );
936 status = pNtCreateEvent( &h, GENERIC_ALL, &attr, 1, 0 );
937 ok( status == STATUS_SUCCESS, "NtCreateEvent failed %x\n", status );
938 status = pNtOpenEvent( &h2, GENERIC_ALL, &attr );
939 ok( status == STATUS_SUCCESS, "NtOpenEvent failed %x\n", status );
940 pNtClose( h2 );
941 RtlInitUnicodeString( &str, L"om.c-test\\om.c-event" );
942 InitializeObjectAttributes( &attr, &str, 0, dir, NULL );
943 status = pNtOpenEvent( &h2, GENERIC_ALL, &attr );
944 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "NtOpenEvent failed %x\n", status );
945 RtlInitUnicodeString( &str, L"\\BasedNamedObjects\\Local\\om.c-test\\om.c-event" );
946 InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
947 status = pNtOpenEvent( &h2, GENERIC_ALL, &attr );
948 ok( status == STATUS_OBJECT_PATH_NOT_FOUND, "NtOpenEvent failed %x\n", status );
949 pNtClose( h );
950 pNtClose( dir1 );
952 str.Buffer = buffer;
953 str.MaximumLength = sizeof(buffer);
954 len = 0xdeadbeef;
955 memset( buffer, 0xaa, sizeof(buffer) );
956 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
957 ok( status == STATUS_SUCCESS, "NtQuerySymbolicLinkObject failed %08x\n", status );
958 full_len = str.Length + sizeof(WCHAR);
959 ok( len == full_len, "bad length %u/%u\n", len, full_len );
960 ok( buffer[len / sizeof(WCHAR) - 1] == 0, "no terminating null\n" );
962 str.MaximumLength = str.Length;
963 len = 0xdeadbeef;
964 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
965 ok( status == STATUS_BUFFER_TOO_SMALL, "NtQuerySymbolicLinkObject failed %08x\n", status );
966 ok( len == full_len, "bad length %u/%u\n", len, full_len );
968 str.MaximumLength = 0;
969 len = 0xdeadbeef;
970 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
971 ok( status == STATUS_BUFFER_TOO_SMALL, "NtQuerySymbolicLinkObject failed %08x\n", status );
972 ok( len == full_len, "bad length %u/%u\n", len, full_len );
974 str.MaximumLength = str.Length + sizeof(WCHAR);
975 len = 0xdeadbeef;
976 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
977 ok( status == STATUS_SUCCESS, "NtQuerySymbolicLinkObject failed %08x\n", status );
978 ok( len == full_len, "bad length %u/%u\n", len, full_len );
980 pNtClose(dir);
982 RtlInitUnicodeString(&str, L"\\BaseNamedObjects");
983 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
984 status = pNtOpenDirectoryObject( &dir, DIRECTORY_QUERY, &attr );
985 ok( status == STATUS_SUCCESS, "Failed to open directory %08x\n", status );
987 InitializeObjectAttributes(&attr, NULL, 0, dir, NULL);
988 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
989 ok( status == STATUS_OBJECT_NAME_INVALID, "NtOpenDirectoryObject got %08x\n", status );
991 check_create_open_dir( dir, L"", STATUS_SUCCESS );
992 check_create_open_dir( dir, L"\\", STATUS_OBJECT_PATH_SYNTAX_BAD );
993 check_create_open_dir( dir, L"\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD );
994 check_create_open_dir( dir, L"\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD );
995 check_create_open_dir( dir, L"om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND );
997 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
998 RtlInitUnicodeString(&str, L"om.c-test");
999 status = pNtCreateDirectoryObject( &dir1, DIRECTORY_QUERY, &attr );
1000 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1001 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
1002 ok( status == STATUS_SUCCESS, "Failed to open directory %08x\n", status );
1004 pNtClose(h);
1005 pNtClose(dir1);
1006 pNtClose(dir);
1008 /* Nested directories */
1009 RtlInitUnicodeString(&str, L"\\");
1010 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1011 status = pNtOpenDirectoryObject( &dir, DIRECTORY_QUERY, &attr );
1012 ok( status == STATUS_SUCCESS, "Failed to open directory %08x\n", status );
1013 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
1014 status = pNtOpenDirectoryObject( &h, DIRECTORY_QUERY, &attr );
1015 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NtOpenDirectoryObject got %08x\n", status );
1016 pNtClose(dir);
1018 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1019 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\om.c-test");
1020 status = pNtCreateDirectoryObject( &dir, DIRECTORY_QUERY, &attr );
1021 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1022 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\om.c-test\\one more level");
1023 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
1024 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1025 pNtClose(h);
1026 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
1027 RtlInitUnicodeString(&str, L"one more level");
1028 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
1029 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1030 pNtClose(h);
1032 pNtClose(dir);
1034 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1035 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\Global\\om.c-test");
1036 status = pNtCreateDirectoryObject( &dir, DIRECTORY_QUERY, &attr );
1037 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1038 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\Local\\om.c-test\\one more level");
1039 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
1040 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1041 pNtClose(h);
1042 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
1043 RtlInitUnicodeString(&str, L"one more level");
1044 status = pNtCreateDirectoryObject( &h, DIRECTORY_QUERY, &attr );
1045 ok( status == STATUS_SUCCESS, "Failed to create directory %08x\n", status );
1046 pNtClose(h);
1047 pNtClose(dir);
1049 /* Create other objects using RootDirectory */
1051 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1052 RtlInitUnicodeString(&str, L"\\BaseNamedObjects");
1053 status = pNtOpenDirectoryObject( &dir, DIRECTORY_QUERY, &attr );
1054 ok( status == STATUS_SUCCESS, "Failed to open directory %08x\n", status );
1055 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
1057 /* Test invalid paths */
1058 RtlInitUnicodeString(&str, L"\\om.c-mutant");
1059 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
1060 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
1061 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
1062 RtlInitUnicodeString(&str, L"\\om.c-mutant\\");
1063 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
1064 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
1065 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
1067 RtlInitUnicodeString(&str, L"om.c\\-mutant");
1068 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
1069 ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
1070 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
1072 RtlInitUnicodeString(&str, L"om.c-mutant");
1073 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
1074 ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status);
1075 pNtClose(h);
1077 pNtClose(dir);
1080 static void test_symboliclink(void)
1082 NTSTATUS status;
1083 UNICODE_STRING str, target;
1084 OBJECT_ATTRIBUTES attr;
1085 HANDLE dir, link, h, h2;
1086 IO_STATUS_BLOCK iosb;
1088 /* No name and/or no attributes */
1089 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
1090 RtlInitUnicodeString(&target, L"\\DosDevices");
1091 status = pNtCreateSymbolicLinkObject( NULL, SYMBOLIC_LINK_QUERY, &attr, &target );
1092 ok(status == STATUS_ACCESS_VIOLATION, "got %#x\n", status);
1093 status = pNtOpenSymbolicLinkObject( NULL, SYMBOLIC_LINK_QUERY, &attr );
1094 ok(status == STATUS_ACCESS_VIOLATION, "got %#x\n", status);
1096 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, NULL);
1097 ok(status == STATUS_ACCESS_VIOLATION,
1098 "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
1099 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL);
1100 ok(status == STATUS_INVALID_PARAMETER,
1101 "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
1103 /* No attributes */
1104 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, &target);
1105 ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_VIOLATION, /* nt4 */
1106 "NtCreateSymbolicLinkObject failed(%08x)\n", status);
1108 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
1109 memset(&target, 0, sizeof(target));
1110 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
1111 ok(status == STATUS_INVALID_PARAMETER, "got %#x\n", status);
1112 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
1113 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
1114 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
1116 /* Bad name */
1117 RtlInitUnicodeString(&target, L"anywhere");
1118 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1120 RtlInitUnicodeString(&str, L"");
1121 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
1122 ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
1123 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
1124 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
1125 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
1126 pNtClose(link);
1128 RtlInitUnicodeString(&str, L"\\");
1129 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr, &target);
1130 todo_wine ok(status == STATUS_OBJECT_TYPE_MISMATCH,
1131 "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
1133 RtlInitUnicodeString( &target, L"->Somewhere");
1135 RtlInitUnicodeString( &str, L"BaseNamedObjects" );
1136 status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
1137 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NtCreateSymbolicLinkObject got %08x\n", status );
1138 status = pNtOpenSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr );
1139 ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "NtOpenSymbolicLinkObject got %08x\n", status );
1141 RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\" );
1142 status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
1143 ok( status == STATUS_OBJECT_NAME_INVALID, "NtCreateSymbolicLinkObject got %08x\n", status );
1144 status = pNtOpenSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr );
1145 ok( status == STATUS_OBJECT_NAME_INVALID, "NtOpenSymbolicLinkObject got %08x\n", status );
1147 RtlInitUnicodeString( &str, L"\\\\BaseNamedObjects" );
1148 status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
1149 ok( status == STATUS_OBJECT_NAME_INVALID, "NtCreateSymbolicLinkObject got %08x\n", status );
1150 status = pNtOpenSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr );
1151 ok( status == STATUS_OBJECT_NAME_INVALID, "NtOpenSymbolicLinkObject got %08x\n", status );
1153 RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\\\om.c-test" );
1154 status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
1155 ok( status == STATUS_OBJECT_NAME_INVALID, "NtCreateSymbolicLinkObject got %08x\n", status );
1156 status = pNtOpenSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr );
1157 ok( status == STATUS_OBJECT_NAME_INVALID, "NtOpenSymbolicLinkObject got %08x\n", status );
1159 RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\om.c-test\\" );
1160 status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
1161 ok( status == STATUS_OBJECT_PATH_NOT_FOUND, "got %#x\n", status );
1162 status = pNtOpenSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr );
1163 ok( status == STATUS_OBJECT_PATH_NOT_FOUND, "got %#x\n", status );
1165 /* Compound test */
1166 dir = get_base_dir();
1167 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
1168 RtlInitUnicodeString(&str, L"test-link");
1169 RtlInitUnicodeString(&target, L"\\DosDevices");
1170 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
1171 ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
1173 RtlInitUnicodeString(&str, L"test-link\\NUL");
1174 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, 0);
1175 ok(status == STATUS_SUCCESS, "Failed to open NUL device(%08x)\n", status);
1176 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE);
1177 ok(status == STATUS_SUCCESS, "Failed to open NUL device(%08x)\n", status);
1179 pNtClose(h);
1180 pNtClose(link);
1181 pNtClose(dir);
1183 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1184 RtlInitUnicodeString(&str, L"\\BaseNamedObjects\\om.c-test");
1185 status = pNtCreateDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
1186 ok(status == STATUS_SUCCESS, "Got unexpected status %#x.\n", status);
1188 RtlInitUnicodeString(&str, L"\\DosDevices\\test_link");
1189 RtlInitUnicodeString(&target, L"\\BaseNamedObjects");
1190 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
1191 ok(status == STATUS_SUCCESS && !!link, "Got unexpected status %#x.\n", status);
1193 status = NtCreateFile(&h, GENERIC_READ | SYNCHRONIZE, &attr, &iosb, NULL, 0,
1194 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, NULL, 0 );
1195 ok(status == STATUS_OBJECT_TYPE_MISMATCH, "Got unexpected status %#x.\n", status);
1197 status = pNtOpenSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr );
1198 ok(status == STATUS_SUCCESS, "Got unexpected status %#x.\n", status);
1199 pNtClose(h);
1201 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1202 RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\om.c-test\\" );
1203 status = NtCreateFile(&h, GENERIC_READ | SYNCHRONIZE, &attr, &iosb, NULL, 0,
1204 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, NULL, 0 );
1205 ok(status == STATUS_OBJECT_NAME_INVALID, "Got unexpected status %#x.\n", status);
1207 InitializeObjectAttributes(&attr, &str, 0, link, NULL);
1208 RtlInitUnicodeString( &str, L"om.c-test\\test_object" );
1209 status = pNtCreateMutant( &h, GENERIC_ALL, &attr, FALSE );
1210 ok(status == STATUS_OBJECT_TYPE_MISMATCH, "Got unexpected status %#x.\n", status);
1212 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1213 RtlInitUnicodeString( &str, L"\\DosDevices\\test_link\\om.c-test\\test_object" );
1214 status = pNtCreateMutant( &h, GENERIC_ALL, &attr, FALSE );
1215 ok(status == STATUS_SUCCESS, "Got unexpected status %#x.\n", status);
1216 status = pNtOpenMutant( &h2, GENERIC_ALL, &attr );
1217 ok(status == STATUS_SUCCESS, "Got unexpected status %#x.\n", status);
1218 pNtClose(h2);
1219 RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\om.c-test\\test_object" );
1220 status = pNtCreateMutant( &h2, GENERIC_ALL, &attr, FALSE );
1221 ok(status == STATUS_OBJECT_NAME_COLLISION, "Got unexpected status %#x.\n", status);
1223 InitializeObjectAttributes(&attr, &str, 0, link, NULL);
1224 RtlInitUnicodeString( &str, L"om.c-test\\test_object" );
1225 status = pNtOpenMutant( &h2, GENERIC_ALL, &attr );
1226 ok(status == STATUS_OBJECT_TYPE_MISMATCH, "Got unexpected status %#x.\n", status);
1228 pNtClose(h);
1230 status = pNtOpenMutant( &h, GENERIC_ALL, &attr );
1231 ok(status == STATUS_OBJECT_TYPE_MISMATCH, "Got unexpected status %#x.\n", status);
1233 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
1234 RtlInitUnicodeString( &str, L"test_object" );
1235 status = pNtCreateMutant( &h, GENERIC_ALL, &attr, FALSE );
1236 ok(status == STATUS_SUCCESS, "Got unexpected status %#x.\n", status);
1237 status = pNtOpenMutant( &h2, GENERIC_ALL, &attr );
1238 ok(status == STATUS_SUCCESS, "Got unexpected status %#x.\n", status);
1239 pNtClose(h);
1240 pNtClose(h2);
1242 pNtClose(link);
1243 pNtClose(dir);
1246 #define test_file_info(a) _test_file_info(__LINE__,a)
1247 static void _test_file_info(unsigned line, HANDLE handle)
1249 IO_STATUS_BLOCK io;
1250 char buf[256];
1251 NTSTATUS status;
1253 status = pNtQueryInformationFile(handle, &io, buf, sizeof(buf), 0xdeadbeef);
1254 ok_(__FILE__,line)(status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* Vista+ */,
1255 "expected STATUS_NOT_IMPLEMENTED, got %x\n", status);
1257 status = pNtQueryInformationFile(handle, &io, buf, sizeof(buf), FileAccessInformation);
1258 ok_(__FILE__,line)(status == STATUS_SUCCESS, "FileAccessInformation returned %x\n", status);
1260 status = pNtQueryInformationFile(handle, &io, buf, sizeof(buf),
1261 FileIoCompletionNotificationInformation);
1262 ok_(__FILE__,line)(status == STATUS_SUCCESS || broken(status == STATUS_INVALID_INFO_CLASS) /* XP */,
1263 "FileIoCompletionNotificationInformation returned %x\n", status);
1266 #define test_no_file_info(a) _test_no_file_info(__LINE__,a)
1267 static void _test_no_file_info(unsigned line, HANDLE handle)
1269 IO_STATUS_BLOCK io;
1270 char buf[256];
1271 NTSTATUS status;
1273 status = pNtQueryInformationFile(handle, &io, buf, sizeof(buf), 0xdeadbeef);
1274 ok_(__FILE__,line)(status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* Vista+ */,
1275 "expected STATUS_NOT_IMPLEMENTED, got %x\n", status);
1277 status = pNtQueryInformationFile(handle, &io, buf, sizeof(buf), FileAccessInformation);
1278 ok_(__FILE__,line)(status == STATUS_OBJECT_TYPE_MISMATCH,
1279 "FileAccessInformation returned %x\n", status);
1281 status = pNtQueryInformationFile(handle, &io, buf, sizeof(buf),
1282 FileIoCompletionNotificationInformation);
1283 ok_(__FILE__,line)(status == STATUS_OBJECT_TYPE_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* XP */,
1284 "FileIoCompletionNotificationInformation returned %x\n", status);
1287 static BOOL compare_unicode_string( const UNICODE_STRING *string, const WCHAR *expect )
1289 return string->Length == wcslen( expect ) * sizeof(WCHAR)
1290 && !wcsnicmp( string->Buffer, expect, string->Length / sizeof(WCHAR) );
1293 #define test_object_type(a,b) _test_object_type(__LINE__,a,b)
1294 static void _test_object_type( unsigned line, HANDLE handle, const WCHAR *expected_name )
1296 char buffer[1024];
1297 UNICODE_STRING *str = (UNICODE_STRING *)buffer, expect;
1298 ULONG len = 0;
1299 NTSTATUS status;
1301 RtlInitUnicodeString( &expect, expected_name );
1303 memset( buffer, 0, sizeof(buffer) );
1304 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, sizeof(buffer), &len );
1305 ok_(__FILE__,line)( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
1306 ok_(__FILE__,line)( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
1307 ok_(__FILE__,line)( len >= sizeof(OBJECT_TYPE_INFORMATION) + str->Length, "unexpected len %u\n", len );
1308 ok_(__FILE__,line)(compare_unicode_string( str, expected_name ), "wrong name %s\n", debugstr_w( str->Buffer ));
1311 #define test_object_name(a,b,c) _test_object_name(__LINE__,a,b,c)
1312 static void _test_object_name( unsigned line, HANDLE handle, const WCHAR *expected_name, BOOL todo )
1314 char buffer[1024];
1315 UNICODE_STRING *str = (UNICODE_STRING *)buffer, expect;
1316 ULONG len = 0;
1317 NTSTATUS status;
1319 RtlInitUnicodeString( &expect, expected_name );
1321 memset( buffer, 0, sizeof(buffer) );
1322 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
1323 ok_(__FILE__,line)( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
1324 ok_(__FILE__,line)( len >= sizeof(OBJECT_NAME_INFORMATION) + str->Length, "unexpected len %u\n", len );
1325 todo_wine_if (todo)
1326 ok_(__FILE__,line)(compare_unicode_string( str, expected_name ), "wrong name %s\n", debugstr_w( str->Buffer ));
1329 static void test_query_object(void)
1331 static const WCHAR name[] = L"\\BaseNamedObjects\\test_event";
1332 HANDLE handle, client;
1333 char buffer[1024];
1334 NTSTATUS status;
1335 ULONG len, expected_len;
1336 OBJECT_ATTRIBUTES attr;
1337 UNICODE_STRING path, *str;
1338 char dir[MAX_PATH], tmp_path[MAX_PATH], file1[MAX_PATH + 16];
1339 WCHAR expect[100];
1340 LARGE_INTEGER size;
1341 BOOL ret;
1343 InitializeObjectAttributes( &attr, &path, 0, 0, 0 );
1345 handle = CreateEventA( NULL, FALSE, FALSE, "test_event" );
1347 len = 0;
1348 status = pNtQueryObject( handle, ObjectNameInformation, buffer, 0, &len );
1349 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
1350 ok( len >= sizeof(UNICODE_STRING) + sizeof(name), "unexpected len %u\n", len );
1352 len = 0;
1353 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, 0, &len );
1354 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
1355 ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + sizeof(L"Event"), "unexpected len %u\n", len );
1357 len = 0;
1358 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(UNICODE_STRING), &len );
1359 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
1360 ok( len >= sizeof(UNICODE_STRING) + sizeof(name), "unexpected len %u\n", len );
1362 len = 0;
1363 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, sizeof(OBJECT_TYPE_INFORMATION), &len );
1364 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
1365 ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + sizeof(L"Event"), "unexpected len %u\n", len );
1367 len = 0;
1368 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
1369 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
1370 ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
1371 str = (UNICODE_STRING *)buffer;
1372 ok( sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR) == len, "unexpected len %u\n", len );
1373 ok( str->Length >= sizeof(name) - sizeof(WCHAR), "unexpected len %u\n", str->Length );
1374 ok( len > sizeof(UNICODE_STRING) + sizeof("\\test_event") * sizeof(WCHAR),
1375 "name too short %s\n", wine_dbgstr_w(str->Buffer) );
1376 /* check for \\Sessions prefix in the name */
1377 swprintf( expect, ARRAY_SIZE(expect), L"\\Sessions\\%u%s", NtCurrentTeb()->Peb->SessionId, name );
1378 ok( (str->Length == wcslen( expect ) * sizeof(WCHAR) && !wcscmp( str->Buffer, expect )) ||
1379 broken( !wcscmp( str->Buffer, name )), /* winxp */
1380 "wrong name %s\n", wine_dbgstr_w(str->Buffer) );
1381 trace( "got %s len %u\n", wine_dbgstr_w(str->Buffer), len );
1383 len -= sizeof(WCHAR);
1384 status = pNtQueryObject( handle, ObjectNameInformation, buffer, len, &len );
1385 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
1386 ok( len >= sizeof(UNICODE_STRING) + sizeof(name), "unexpected len %u\n", len );
1388 test_object_type( handle, L"Event" );
1390 len -= sizeof(WCHAR);
1391 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, len, &len );
1392 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
1393 ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + sizeof(L"Event"), "unexpected len %u\n", len );
1395 test_no_file_info( handle );
1396 pNtClose( handle );
1398 handle = CreateEventA( NULL, FALSE, FALSE, NULL );
1399 len = 0;
1400 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
1401 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
1402 ok( len == sizeof(UNICODE_STRING), "unexpected len %u\n", len );
1403 str = (UNICODE_STRING *)buffer;
1404 ok( str->Length == 0, "unexpected len %u\n", len );
1405 ok( str->Buffer == NULL, "unexpected ptr %p\n", str->Buffer );
1406 test_no_file_info( handle );
1407 pNtClose( handle );
1409 GetWindowsDirectoryA( dir, MAX_PATH );
1410 handle = CreateFileA( dir, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1411 FILE_FLAG_BACKUP_SEMANTICS, 0 );
1412 len = 0;
1413 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
1414 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
1415 ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
1416 str = (UNICODE_STRING *)buffer;
1417 expected_len = sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR);
1418 ok( len == expected_len, "unexpected len %u\n", len );
1419 trace( "got %s len %u\n", wine_dbgstr_w(str->Buffer), len );
1421 len = 0;
1422 status = pNtQueryObject( handle, ObjectNameInformation, buffer, 0, &len );
1423 ok( status == STATUS_INFO_LENGTH_MISMATCH, "got %#x\n", status );
1424 ok( len == expected_len || broken(!len /* XP */ || len == sizeof(UNICODE_STRING) /* 2003 */),
1425 "unexpected len %u\n", len );
1427 len = 0;
1428 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(UNICODE_STRING), &len );
1429 ok( status == STATUS_BUFFER_OVERFLOW, "got %#x\n", status);
1430 ok( len == expected_len, "unexpected len %u\n", len );
1432 test_object_type( handle, L"File" );
1434 pNtClose( handle );
1436 GetTempPathA(MAX_PATH, tmp_path);
1437 GetTempFileNameA(tmp_path, "foo", 0, file1);
1438 handle = CreateFileA(file1, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
1439 test_object_type(handle, L"File");
1440 DeleteFileA( file1 );
1441 test_file_info( handle );
1442 pNtClose( handle );
1444 status = pNtCreateIoCompletion( &handle, IO_COMPLETION_ALL_ACCESS, NULL, 0 );
1445 ok( status == STATUS_SUCCESS, "NtCreateIoCompletion failed %x\n", status);
1447 test_object_type( handle, L"IoCompletion" );
1448 test_no_file_info( handle );
1450 pNtClose( handle );
1452 status = pNtCreateDirectoryObject( &handle, DIRECTORY_QUERY, NULL );
1453 ok(status == STATUS_SUCCESS, "Failed to create Directory %08x\n", status);
1455 test_object_type( handle, L"Directory" );
1456 test_no_file_info( handle );
1458 pNtClose( handle );
1460 size.u.LowPart = 256;
1461 size.u.HighPart = 0;
1462 status = pNtCreateSection( &handle, SECTION_MAP_WRITE, NULL, &size, PAGE_READWRITE, SEC_COMMIT, 0 );
1463 ok( status == STATUS_SUCCESS , "NtCreateSection returned %x\n", status );
1465 test_object_type( handle, L"Section" );
1466 test_no_file_info( handle );
1468 pNtClose( handle );
1470 handle = CreateMailslotA( "\\\\.\\mailslot\\test_mailslot", 100, 1000, NULL );
1471 ok( handle != INVALID_HANDLE_VALUE, "CreateMailslot failed err %u\n", GetLastError() );
1473 test_object_name( handle, L"\\Device\\Mailslot\\test_mailslot", FALSE );
1474 test_object_type( handle, L"File" );
1475 test_file_info( handle );
1477 client = CreateFileA( "\\\\.\\mailslot\\test_mailslot", 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
1478 ok( client != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError() );
1480 len = 0;
1481 status = pNtQueryObject( client, ObjectNameInformation, buffer, sizeof(buffer), &len );
1482 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
1483 str = (UNICODE_STRING *)buffer;
1484 ok( len == sizeof(UNICODE_STRING) + str->MaximumLength, "unexpected len %u\n", len );
1485 todo_wine
1486 ok( compare_unicode_string( str, L"\\Device\\Mailslot" ) ||
1487 compare_unicode_string( str, L"\\Device\\Mailslot\\test_mailslot" ) /* win8+ */,
1488 "wrong name %s\n", debugstr_w( str->Buffer ));
1490 test_object_type( client, L"File" );
1491 test_file_info( client );
1493 pNtClose( client );
1494 pNtClose( handle );
1496 handle = CreateFileA( "\\\\.\\mailslot", 0, 0, NULL, OPEN_EXISTING, 0, 0 );
1497 ok( handle != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError() );
1499 test_object_name( handle, L"\\Device\\Mailslot", FALSE );
1500 test_object_type( handle, L"File" );
1501 test_file_info( handle );
1503 pNtClose( handle );
1505 handle = CreateNamedPipeA( "\\\\.\\pipe\\test_pipe", PIPE_ACCESS_DUPLEX, PIPE_READMODE_BYTE,
1506 1, 1000, 1000, 1000, NULL );
1507 ok( handle != INVALID_HANDLE_VALUE, "CreateNamedPipe failed err %u\n", GetLastError() );
1509 test_object_name( handle, L"\\Device\\NamedPipe\\test_pipe", FALSE );
1510 test_object_type( handle, L"File" );
1511 test_file_info( handle );
1513 client = CreateFileA( "\\\\.\\pipe\\test_pipe", GENERIC_READ | GENERIC_WRITE,
1514 0, NULL, OPEN_EXISTING, 0, 0 );
1515 ok( client != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError() );
1517 test_object_type( client, L"File" );
1518 test_file_info( client );
1520 pNtClose( client );
1521 pNtClose( handle );
1523 handle = CreateFileA( "\\\\.\\pipe", 0, 0, NULL, OPEN_EXISTING, 0, 0 );
1524 ok( handle != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError() );
1526 test_object_name( handle, L"\\Device\\NamedPipe", FALSE );
1527 test_object_type( handle, L"File" );
1528 test_file_info( handle );
1530 pNtClose( handle );
1532 RtlInitUnicodeString( &path, L"\\REGISTRY\\Machine" );
1533 status = pNtCreateKey( &handle, KEY_READ, &attr, 0, 0, 0, 0 );
1534 ok( status == STATUS_SUCCESS, "NtCreateKey failed status %x\n", status );
1536 test_object_name( handle, L"\\REGISTRY\\MACHINE", FALSE );
1537 test_object_type( handle, L"Key" );
1539 pNtClose( handle );
1541 test_object_name( GetCurrentProcess(), L"", FALSE );
1542 test_object_type( GetCurrentProcess(), L"Process" );
1543 test_no_file_info( GetCurrentProcess() );
1545 test_object_name( GetCurrentThread(), L"", FALSE );
1546 test_object_type( GetCurrentThread(), L"Thread" );
1547 test_no_file_info( GetCurrentThread() );
1549 ret = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &handle);
1550 ok(ret, "OpenProcessToken failed: %u\n", GetLastError());
1552 test_object_name( handle, L"", FALSE );
1553 test_object_type( handle, L"Token" );
1554 test_no_file_info( handle );
1556 pNtClose(handle);
1559 static void test_type_mismatch(void)
1561 HANDLE h;
1562 NTSTATUS res;
1563 OBJECT_ATTRIBUTES attr;
1565 attr.Length = sizeof(attr);
1566 attr.RootDirectory = 0;
1567 attr.ObjectName = NULL;
1568 attr.Attributes = 0;
1569 attr.SecurityDescriptor = NULL;
1570 attr.SecurityQualityOfService = NULL;
1572 res = pNtCreateEvent( &h, 0, &attr, 0, 0 );
1573 ok(!res, "can't create event: %x\n", res);
1575 res = pNtReleaseSemaphore( h, 30, NULL );
1576 ok(res == STATUS_OBJECT_TYPE_MISMATCH, "expected 0xc0000024, got %x\n", res);
1578 pNtClose( h );
1581 static void test_event(void)
1583 HANDLE Event;
1584 HANDLE Event2;
1585 LONG prev_state = 0xdeadbeef;
1586 NTSTATUS status;
1587 UNICODE_STRING str;
1588 OBJECT_ATTRIBUTES attr;
1589 EVENT_BASIC_INFORMATION info;
1591 pRtlInitUnicodeString( &str, L"\\BaseNamedObjects\\testEvent" );
1592 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1594 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, 1, 0);
1595 ok( status == STATUS_SUCCESS, "NtCreateEvent failed %08x\n", status );
1597 status = pNtPulseEvent(Event, &prev_state);
1598 ok( status == STATUS_SUCCESS, "NtPulseEvent failed %08x\n", status );
1599 ok( !prev_state, "prev_state = %x\n", prev_state );
1601 status = pNtQueryEvent(Event, EventBasicInformation, &info, sizeof(info), NULL);
1602 ok( status == STATUS_SUCCESS, "NtQueryEvent failed %08x\n", status );
1603 ok( info.EventType == 1 && info.EventState == 0,
1604 "NtQueryEvent failed, expected 1 0, got %d %d\n", info.EventType, info.EventState );
1606 status = pNtOpenEvent(&Event2, GENERIC_ALL, &attr);
1607 ok( status == STATUS_SUCCESS, "NtOpenEvent failed %08x\n", status );
1609 pNtClose(Event);
1610 Event = Event2;
1612 status = pNtQueryEvent(Event, EventBasicInformation, &info, sizeof(info), NULL);
1613 ok( status == STATUS_SUCCESS, "NtQueryEvent failed %08x\n", status );
1614 ok( info.EventType == 1 && info.EventState == 0,
1615 "NtQueryEvent failed, expected 1 0, got %d %d\n", info.EventType, info.EventState );
1617 status = pNtSetEvent( Event, &prev_state );
1618 ok( status == STATUS_SUCCESS, "NtSetEvent failed: %08x\n", status );
1619 ok( !prev_state, "prev_state = %x\n", prev_state );
1621 status = pNtSetEvent( Event, &prev_state );
1622 ok( status == STATUS_SUCCESS, "NtSetEvent failed: %08x\n", status );
1623 ok( prev_state == 1, "prev_state = %x\n", prev_state );
1625 status = pNtResetEvent( Event, &prev_state );
1626 ok( status == STATUS_SUCCESS, "NtSetEvent failed: %08x\n", status );
1627 ok( prev_state == 1, "prev_state = %x\n", prev_state );
1629 status = pNtResetEvent( Event, &prev_state );
1630 ok( status == STATUS_SUCCESS, "NtSetEvent failed: %08x\n", status );
1631 ok( !prev_state, "prev_state = %x\n", prev_state );
1633 status = pNtPulseEvent( Event, &prev_state );
1634 ok( status == STATUS_SUCCESS, "NtPulseEvent failed %08x\n", status );
1635 ok( !prev_state, "prev_state = %x\n", prev_state );
1637 status = pNtSetEvent( Event, &prev_state );
1638 ok( status == STATUS_SUCCESS, "NtSetEvent failed: %08x\n", status );
1639 ok( !prev_state, "prev_state = %x\n", prev_state );
1641 status = pNtPulseEvent( Event, &prev_state );
1642 ok( status == STATUS_SUCCESS, "NtPulseEvent failed %08x\n", status );
1643 ok( prev_state == 1, "prev_state = %x\n", prev_state );
1645 pNtClose(Event);
1648 static const WCHAR keyed_nameW[] = L"\\BaseNamedObjects\\WineTestEvent";
1650 static DWORD WINAPI keyed_event_thread( void *arg )
1652 HANDLE handle;
1653 NTSTATUS status;
1654 LARGE_INTEGER timeout;
1655 OBJECT_ATTRIBUTES attr;
1656 UNICODE_STRING str;
1657 ULONG_PTR i;
1659 attr.Length = sizeof(attr);
1660 attr.RootDirectory = 0;
1661 attr.ObjectName = &str;
1662 attr.Attributes = 0;
1663 attr.SecurityDescriptor = NULL;
1664 attr.SecurityQualityOfService = NULL;
1665 RtlInitUnicodeString( &str, keyed_nameW );
1667 status = pNtOpenKeyedEvent( &handle, KEYEDEVENT_ALL_ACCESS, &attr );
1668 ok( !status, "NtOpenKeyedEvent failed %x\n", status );
1670 for (i = 0; i < 20; i++)
1672 if (i & 1)
1673 status = pNtWaitForKeyedEvent( handle, (void *)(i * 2), 0, NULL );
1674 else
1675 status = pNtReleaseKeyedEvent( handle, (void *)(i * 2), 0, NULL );
1676 ok( status == STATUS_SUCCESS, "%li: failed %x\n", i, status );
1677 Sleep( 20 - i );
1680 status = pNtReleaseKeyedEvent( handle, (void *)0x1234, 0, NULL );
1681 ok( status == STATUS_SUCCESS, "NtReleaseKeyedEvent %x\n", status );
1683 timeout.QuadPart = -10000;
1684 status = pNtWaitForKeyedEvent( handle, (void *)0x5678, 0, &timeout );
1685 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1686 status = pNtReleaseKeyedEvent( handle, (void *)0x9abc, 0, &timeout );
1687 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1689 NtClose( handle );
1690 return 0;
1693 static void test_keyed_events(void)
1695 OBJECT_ATTRIBUTES attr;
1696 UNICODE_STRING str;
1697 HANDLE handle, event, thread;
1698 NTSTATUS status;
1699 LARGE_INTEGER timeout;
1700 ULONG_PTR i;
1702 if (!pNtCreateKeyedEvent)
1704 win_skip( "Keyed events not supported\n" );
1705 return;
1708 attr.Length = sizeof(attr);
1709 attr.RootDirectory = 0;
1710 attr.ObjectName = &str;
1711 attr.Attributes = 0;
1712 attr.SecurityDescriptor = NULL;
1713 attr.SecurityQualityOfService = NULL;
1714 RtlInitUnicodeString( &str, keyed_nameW );
1716 status = pNtCreateKeyedEvent( &handle, KEYEDEVENT_ALL_ACCESS | SYNCHRONIZE, &attr, 0 );
1717 ok( !status, "NtCreateKeyedEvent failed %x\n", status );
1719 status = WaitForSingleObject( handle, 1000 );
1720 ok( status == 0, "WaitForSingleObject %x\n", status );
1722 timeout.QuadPart = -100000;
1723 status = pNtWaitForKeyedEvent( handle, (void *)255, 0, &timeout );
1724 ok( status == STATUS_INVALID_PARAMETER_1, "NtWaitForKeyedEvent %x\n", status );
1725 status = pNtReleaseKeyedEvent( handle, (void *)255, 0, &timeout );
1726 ok( status == STATUS_INVALID_PARAMETER_1, "NtReleaseKeyedEvent %x\n", status );
1728 status = pNtWaitForKeyedEvent( handle, (void *)254, 0, &timeout );
1729 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1730 status = pNtReleaseKeyedEvent( handle, (void *)254, 0, &timeout );
1731 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1733 status = pNtWaitForKeyedEvent( handle, NULL, 0, &timeout );
1734 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1735 status = pNtReleaseKeyedEvent( handle, NULL, 0, &timeout );
1736 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1738 status = pNtWaitForKeyedEvent( NULL, (void *)8, 0, &timeout );
1739 ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
1740 "NtWaitForKeyedEvent %x\n", status );
1741 status = pNtReleaseKeyedEvent( NULL, (void *)8, 0, &timeout );
1742 ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
1743 "NtReleaseKeyedEvent %x\n", status );
1745 status = pNtWaitForKeyedEvent( (HANDLE)0xdeadbeef, (void *)9, 0, &timeout );
1746 ok( status == STATUS_INVALID_PARAMETER_1, "NtWaitForKeyedEvent %x\n", status );
1747 status = pNtReleaseKeyedEvent( (HANDLE)0xdeadbeef, (void *)9, 0, &timeout );
1748 ok( status == STATUS_INVALID_PARAMETER_1, "NtReleaseKeyedEvent %x\n", status );
1750 status = pNtWaitForKeyedEvent( (HANDLE)0xdeadbeef, (void *)8, 0, &timeout );
1751 ok( status == STATUS_INVALID_HANDLE, "NtWaitForKeyedEvent %x\n", status );
1752 status = pNtReleaseKeyedEvent( (HANDLE)0xdeadbeef, (void *)8, 0, &timeout );
1753 ok( status == STATUS_INVALID_HANDLE, "NtReleaseKeyedEvent %x\n", status );
1755 thread = CreateThread( NULL, 0, keyed_event_thread, 0, 0, NULL );
1756 for (i = 0; i < 20; i++)
1758 if (i & 1)
1759 status = pNtReleaseKeyedEvent( handle, (void *)(i * 2), 0, NULL );
1760 else
1761 status = pNtWaitForKeyedEvent( handle, (void *)(i * 2), 0, NULL );
1762 ok( status == STATUS_SUCCESS, "%li: failed %x\n", i, status );
1763 Sleep( i );
1765 status = pNtWaitForKeyedEvent( handle, (void *)0x1234, 0, &timeout );
1766 ok( status == STATUS_SUCCESS, "NtWaitForKeyedEvent %x\n", status );
1767 status = pNtWaitForKeyedEvent( handle, (void *)0x5678, 0, &timeout );
1768 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1769 status = pNtReleaseKeyedEvent( handle, (void *)0x9abc, 0, &timeout );
1770 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1772 ok( WaitForSingleObject( thread, 30000 ) == 0, "wait failed\n" );
1774 NtClose( handle );
1776 /* test access rights */
1778 status = pNtCreateKeyedEvent( &handle, KEYEDEVENT_WAIT, &attr, 0 );
1779 ok( !status, "NtCreateKeyedEvent failed %x\n", status );
1780 status = pNtWaitForKeyedEvent( handle, (void *)8, 0, &timeout );
1781 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1782 status = pNtReleaseKeyedEvent( handle, (void *)8, 0, &timeout );
1783 ok( status == STATUS_ACCESS_DENIED, "NtReleaseKeyedEvent %x\n", status );
1784 NtClose( handle );
1786 status = pNtCreateKeyedEvent( &handle, KEYEDEVENT_WAKE, &attr, 0 );
1787 ok( !status, "NtCreateKeyedEvent failed %x\n", status );
1788 status = pNtWaitForKeyedEvent( handle, (void *)8, 0, &timeout );
1789 ok( status == STATUS_ACCESS_DENIED, "NtWaitForKeyedEvent %x\n", status );
1790 status = pNtReleaseKeyedEvent( handle, (void *)8, 0, &timeout );
1791 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1792 NtClose( handle );
1794 status = pNtCreateKeyedEvent( &handle, KEYEDEVENT_ALL_ACCESS, &attr, 0 );
1795 ok( !status, "NtCreateKeyedEvent failed %x\n", status );
1796 status = WaitForSingleObject( handle, 1000 );
1797 ok( status == WAIT_FAILED && GetLastError() == ERROR_ACCESS_DENIED,
1798 "WaitForSingleObject %x err %u\n", status, GetLastError() );
1799 status = pNtWaitForKeyedEvent( handle, (void *)8, 0, &timeout );
1800 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1801 status = pNtReleaseKeyedEvent( handle, (void *)8, 0, &timeout );
1802 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1803 NtClose( handle );
1805 /* GENERIC_READ gives wait access */
1806 status = pNtCreateKeyedEvent( &handle, GENERIC_READ, &attr, 0 );
1807 ok( !status, "NtCreateKeyedEvent failed %x\n", status );
1808 status = pNtWaitForKeyedEvent( handle, (void *)8, 0, &timeout );
1809 ok( status == STATUS_TIMEOUT, "NtWaitForKeyedEvent %x\n", status );
1810 status = pNtReleaseKeyedEvent( handle, (void *)8, 0, &timeout );
1811 ok( status == STATUS_ACCESS_DENIED, "NtReleaseKeyedEvent %x\n", status );
1812 NtClose( handle );
1814 /* GENERIC_WRITE gives wake access */
1815 status = pNtCreateKeyedEvent( &handle, GENERIC_WRITE, &attr, 0 );
1816 ok( !status, "NtCreateKeyedEvent failed %x\n", status );
1817 status = pNtWaitForKeyedEvent( handle, (void *)8, 0, &timeout );
1818 ok( status == STATUS_ACCESS_DENIED, "NtWaitForKeyedEvent %x\n", status );
1819 status = pNtReleaseKeyedEvent( handle, (void *)8, 0, &timeout );
1820 ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
1822 /* it's not an event */
1823 status = pNtPulseEvent( handle, NULL );
1824 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "NtPulseEvent %x\n", status );
1826 status = pNtCreateEvent( &event, GENERIC_ALL, &attr, FALSE, FALSE );
1827 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH /* 7+ */,
1828 "CreateEvent %x\n", status );
1830 NtClose( handle );
1832 status = pNtCreateEvent( &event, GENERIC_ALL, &attr, FALSE, FALSE );
1833 ok( status == 0, "CreateEvent %x\n", status );
1834 status = pNtWaitForKeyedEvent( event, (void *)8, 0, &timeout );
1835 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "NtWaitForKeyedEvent %x\n", status );
1836 status = pNtReleaseKeyedEvent( event, (void *)8, 0, &timeout );
1837 ok( status == STATUS_OBJECT_TYPE_MISMATCH, "NtReleaseKeyedEvent %x\n", status );
1838 NtClose( event );
1841 static void test_null_device(void)
1843 OBJECT_ATTRIBUTES attr;
1844 IO_STATUS_BLOCK iosb;
1845 UNICODE_STRING str;
1846 NTSTATUS status;
1847 DWORD num_bytes;
1848 OVERLAPPED ov;
1849 char buf[64];
1850 HANDLE null;
1851 BOOL ret;
1853 memset(buf, 0xAA, sizeof(buf));
1854 memset(&ov, 0, sizeof(ov));
1855 ov.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
1857 RtlInitUnicodeString(&str, L"\\Device\\Null");
1858 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
1859 status = pNtOpenSymbolicLinkObject(&null, SYMBOLIC_LINK_QUERY, &attr);
1860 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
1861 "expected STATUS_OBJECT_TYPE_MISMATCH, got %08x\n", status);
1863 status = pNtOpenFile(&null, GENERIC_READ | GENERIC_WRITE, &attr, &iosb,
1864 FILE_SHARE_READ | FILE_SHARE_WRITE, 0);
1865 ok(status == STATUS_SUCCESS,
1866 "expected STATUS_SUCCESS, got %08x\n", status);
1868 test_object_type(null, L"File");
1870 SetLastError(0xdeadbeef);
1871 ret = WriteFile(null, buf, sizeof(buf), &num_bytes, NULL);
1872 ok(!ret, "WriteFile unexpectedly succeeded\n");
1873 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1874 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1876 SetLastError(0xdeadbeef);
1877 ret = ReadFile(null, buf, sizeof(buf), &num_bytes, NULL);
1878 ok(!ret, "ReadFile unexpectedly succeeded\n");
1879 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1880 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1882 num_bytes = 0xdeadbeef;
1883 SetLastError(0xdeadbeef);
1884 ret = WriteFile(null, buf, sizeof(buf), &num_bytes, &ov);
1885 ok(ret, "got error %u\n", GetLastError());
1886 ok(num_bytes == sizeof(buf), "expected num_bytes = %u, got %u\n",
1887 (DWORD)sizeof(buf), num_bytes);
1889 num_bytes = 0xdeadbeef;
1890 SetLastError(0xdeadbeef);
1891 ret = ReadFile(null, buf, sizeof(buf), &num_bytes, &ov);
1892 ok(!ret, "expected failure\n");
1893 ok(GetLastError() == ERROR_HANDLE_EOF, "got error %u\n", GetLastError());
1895 pNtClose(null);
1897 null = CreateFileA("\\\\.\\Null", GENERIC_READ | GENERIC_WRITE,
1898 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1899 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1900 ok(null == INVALID_HANDLE_VALUE, "CreateFileA unexpectedly succeeded\n");
1901 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1902 "expected ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1904 null = CreateFileA("\\\\.\\Device\\Null", GENERIC_READ | GENERIC_WRITE,
1905 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1906 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1907 ok(null == INVALID_HANDLE_VALUE, "CreateFileA unexpectedly succeeded\n");
1908 ok(GetLastError() == ERROR_PATH_NOT_FOUND,
1909 "expected ERROR_PATH_NOT_FOUND, got %u\n", GetLastError());
1911 CloseHandle(ov.hEvent);
1914 static DWORD WINAPI mutant_thread( void *arg )
1916 MUTANT_BASIC_INFORMATION info;
1917 NTSTATUS status;
1918 HANDLE mutant;
1919 DWORD ret;
1921 mutant = arg;
1922 ret = WaitForSingleObject( mutant, 1000 );
1923 ok( ret == WAIT_OBJECT_0, "WaitForSingleObject failed %08x\n", ret );
1925 memset(&info, 0xcc, sizeof(info));
1926 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, sizeof(info), NULL);
1927 ok( status == STATUS_SUCCESS, "NtQueryMutant failed %08x\n", status );
1928 ok( info.CurrentCount == 0, "expected 0, got %d\n", info.CurrentCount );
1929 ok( info.OwnedByCaller == TRUE, "expected TRUE, got %d\n", info.OwnedByCaller );
1930 ok( info.AbandonedState == FALSE, "expected FALSE, got %d\n", info.AbandonedState );
1931 /* abandon mutant */
1933 return 0;
1936 static void test_mutant(void)
1938 MUTANT_BASIC_INFORMATION info;
1939 OBJECT_ATTRIBUTES attr;
1940 UNICODE_STRING str;
1941 NTSTATUS status;
1942 HANDLE mutant;
1943 HANDLE thread;
1944 DWORD ret;
1945 ULONG len;
1946 LONG prev;
1948 pRtlInitUnicodeString(&str, L"\\BaseNamedObjects\\test_mutant");
1949 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
1950 status = pNtCreateMutant(&mutant, GENERIC_ALL, &attr, TRUE);
1951 ok( status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status );
1953 /* bogus */
1954 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, 0, NULL);
1955 ok( status == STATUS_INFO_LENGTH_MISMATCH,
1956 "Failed to NtQueryMutant, expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status );
1957 status = pNtQueryMutant(mutant, 0x42, &info, sizeof(info), NULL);
1958 ok( status == STATUS_INVALID_INFO_CLASS || broken(status == STATUS_NOT_IMPLEMENTED), /* 32-bit on Vista/2k8 */
1959 "Failed to NtQueryMutant, expected STATUS_INVALID_INFO_CLASS, got %08x\n", status );
1960 status = pNtQueryMutant((HANDLE)0xdeadbeef, MutantBasicInformation, &info, sizeof(info), NULL);
1961 ok( status == STATUS_INVALID_HANDLE,
1962 "Failed to NtQueryMutant, expected STATUS_INVALID_HANDLE, got %08x\n", status );
1964 /* new */
1965 len = -1;
1966 memset(&info, 0xcc, sizeof(info));
1967 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, sizeof(info), &len);
1968 ok( status == STATUS_SUCCESS, "NtQueryMutant failed %08x\n", status );
1969 ok( info.CurrentCount == 0, "expected 0, got %d\n", info.CurrentCount );
1970 ok( info.OwnedByCaller == TRUE, "expected TRUE, got %d\n", info.OwnedByCaller );
1971 ok( info.AbandonedState == FALSE, "expected FALSE, got %d\n", info.AbandonedState );
1972 ok( len == sizeof(info), "got %u\n", len );
1974 ret = WaitForSingleObject( mutant, 1000 );
1975 ok( ret == WAIT_OBJECT_0, "WaitForSingleObject failed %08x\n", ret );
1977 memset(&info, 0xcc, sizeof(info));
1978 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, sizeof(info), NULL);
1979 ok( status == STATUS_SUCCESS, "NtQueryMutant failed %08x\n", status );
1980 ok( info.CurrentCount == -1, "expected -1, got %d\n", info.CurrentCount );
1981 ok( info.OwnedByCaller == TRUE, "expected TRUE, got %d\n", info.OwnedByCaller );
1982 ok( info.AbandonedState == FALSE, "expected FALSE, got %d\n", info.AbandonedState );
1984 prev = 0xdeadbeef;
1985 status = pNtReleaseMutant(mutant, &prev);
1986 ok( status == STATUS_SUCCESS, "NtQueryRelease failed %08x\n", status );
1987 ok( prev == -1, "NtQueryRelease failed, expected -1, got %d\n", prev );
1989 prev = 0xdeadbeef;
1990 status = pNtReleaseMutant(mutant, &prev);
1991 ok( status == STATUS_SUCCESS, "NtQueryRelease failed %08x\n", status );
1992 ok( prev == 0, "NtQueryRelease failed, expected 0, got %d\n", prev );
1994 memset(&info, 0xcc, sizeof(info));
1995 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, sizeof(info), NULL);
1996 ok( status == STATUS_SUCCESS, "NtQueryMutant failed %08x\n", status );
1997 ok( info.CurrentCount == 1, "expected 1, got %d\n", info.CurrentCount );
1998 ok( info.OwnedByCaller == FALSE, "expected FALSE, got %d\n", info.OwnedByCaller );
1999 ok( info.AbandonedState == FALSE, "expected FALSE, got %d\n", info.AbandonedState );
2001 /* abandoned */
2002 thread = CreateThread( NULL, 0, mutant_thread, mutant, 0, NULL );
2003 ret = WaitForSingleObject( thread, 1000 );
2004 ok( ret == WAIT_OBJECT_0, "WaitForSingleObject failed %08x\n", ret );
2005 CloseHandle( thread );
2007 memset(&info, 0xcc, sizeof(info));
2008 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, sizeof(info), NULL);
2009 ok( status == STATUS_SUCCESS, "NtQueryMutant failed %08x\n", status );
2010 ok( info.CurrentCount == 1, "expected 0, got %d\n", info.CurrentCount );
2011 ok( info.OwnedByCaller == FALSE, "expected FALSE, got %d\n", info.OwnedByCaller );
2012 ok( info.AbandonedState == TRUE, "expected TRUE, got %d\n", info.AbandonedState );
2014 ret = WaitForSingleObject( mutant, 1000 );
2015 ok( ret == WAIT_ABANDONED_0, "WaitForSingleObject failed %08x\n", ret );
2017 memset(&info, 0xcc, sizeof(info));
2018 status = pNtQueryMutant(mutant, MutantBasicInformation, &info, sizeof(info), NULL);
2019 ok( status == STATUS_SUCCESS, "NtQueryMutant failed %08x\n", status );
2020 ok( info.CurrentCount == 0, "expected 0, got %d\n", info.CurrentCount );
2021 ok( info.OwnedByCaller == TRUE, "expected TRUE, got %d\n", info.OwnedByCaller );
2022 ok( info.AbandonedState == FALSE, "expected FALSE, got %d\n", info.AbandonedState );
2024 NtClose( mutant );
2027 static void test_wait_on_address(void)
2029 DWORD ticks;
2030 SIZE_T size;
2031 NTSTATUS status;
2032 LARGE_INTEGER timeout;
2033 LONG64 address, compare;
2035 if (!pRtlWaitOnAddress)
2037 win_skip("RtlWaitOnAddress not supported, skipping test\n");
2038 return;
2041 if (0) /* crash on Windows */
2043 pRtlWaitOnAddress(&address, NULL, 8, NULL);
2044 pRtlWaitOnAddress(NULL, &compare, 8, NULL);
2045 pRtlWaitOnAddress(NULL, NULL, 8, NULL);
2048 /* don't crash */
2049 pRtlWakeAddressSingle(NULL);
2050 pRtlWakeAddressAll(NULL);
2052 /* invalid values */
2053 address = 0;
2054 compare = 0;
2055 status = pRtlWaitOnAddress(&address, &compare, 5, NULL);
2056 ok(status == STATUS_INVALID_PARAMETER, "got %x\n", status);
2058 /* values match */
2059 address = 0;
2060 compare = 0;
2061 pNtQuerySystemTime(&timeout);
2062 timeout.QuadPart += 100*10000;
2063 ticks = GetTickCount();
2064 status = pRtlWaitOnAddress(&address, &compare, 8, &timeout);
2065 ticks = GetTickCount() - ticks;
2066 ok(status == STATUS_TIMEOUT, "got 0x%08x\n", status);
2067 ok(ticks >= 90 && ticks <= 1000, "got %u\n", ticks);
2068 ok(address == 0, "got %s\n", wine_dbgstr_longlong(address));
2069 ok(compare == 0, "got %s\n", wine_dbgstr_longlong(compare));
2071 /* different address size */
2072 for (size = 1; size <= 4; size <<= 1)
2074 compare = ~0;
2075 compare <<= size * 8;
2077 timeout.QuadPart = -100 * 10000;
2078 ticks = GetTickCount();
2079 status = pRtlWaitOnAddress(&address, &compare, size, &timeout);
2080 ticks = GetTickCount() - ticks;
2081 ok(status == STATUS_TIMEOUT, "got 0x%08x\n", status);
2082 ok(ticks >= 90 && ticks <= 1000, "got %u\n", ticks);
2084 status = pRtlWaitOnAddress(&address, &compare, size << 1, &timeout);
2085 ok(!status, "got 0x%08x\n", status);
2087 address = 0;
2088 compare = 1;
2089 status = pRtlWaitOnAddress(&address, &compare, 8, NULL);
2090 ok(!status, "got 0x%08x\n", status);
2092 /* no waiters */
2093 address = 0;
2094 pRtlWakeAddressSingle(&address);
2095 ok(address == 0, "got %s\n", wine_dbgstr_longlong(address));
2096 pRtlWakeAddressAll(&address);
2097 ok(address == 0, "got %s\n", wine_dbgstr_longlong(address));
2100 static void test_process(void)
2102 OBJECT_ATTRIBUTES attr;
2103 CLIENT_ID cid;
2104 NTSTATUS status;
2105 HANDLE process;
2107 if (!pNtOpenProcess)
2109 win_skip( "NtOpenProcess not supported, skipping test\n" );
2110 return;
2113 InitializeObjectAttributes( &attr, NULL, 0, 0, NULL );
2115 cid.UniqueProcess = 0;
2116 cid.UniqueThread = 0;
2117 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, NULL, &cid );
2118 todo_wine ok( status == STATUS_ACCESS_VIOLATION, "NtOpenProcess returned %x\n", status );
2119 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, &attr, NULL );
2120 todo_wine ok( status == STATUS_INVALID_PARAMETER_MIX, "NtOpenProcess returned %x\n", status );
2122 cid.UniqueProcess = 0;
2123 cid.UniqueThread = 0;
2124 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, &attr, &cid );
2125 ok( status == STATUS_INVALID_CID, "NtOpenProcess returned %x\n", status );
2127 cid.UniqueProcess = ULongToHandle( 0xdeadbeef );
2128 cid.UniqueThread = ULongToHandle( 0xdeadbeef );
2129 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, &attr, &cid );
2130 ok( status == STATUS_INVALID_CID, "NtOpenProcess returned %x\n", status );
2132 cid.UniqueProcess = ULongToHandle( GetCurrentThreadId() );
2133 cid.UniqueThread = 0;
2134 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, &attr, &cid );
2135 ok( status == STATUS_INVALID_CID, "NtOpenProcess returned %x\n", status );
2137 cid.UniqueProcess = ULongToHandle( GetCurrentProcessId() );
2138 cid.UniqueThread = 0;
2139 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, &attr, &cid );
2140 ok( !status, "NtOpenProcess returned %x\n", status );
2141 pNtClose( process );
2143 cid.UniqueProcess = ULongToHandle( GetCurrentProcessId() );
2144 cid.UniqueThread = ULongToHandle( GetCurrentThreadId() );
2145 status = pNtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, &attr, &cid );
2146 ok( !status, "NtOpenProcess returned %x\n", status );
2147 pNtClose( process );
2150 START_TEST(om)
2152 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
2154 pNtCreateEvent = (void *)GetProcAddress(hntdll, "NtCreateEvent");
2155 pNtCreateJobObject = (void *)GetProcAddress(hntdll, "NtCreateJobObject");
2156 pNtOpenJobObject = (void *)GetProcAddress(hntdll, "NtOpenJobObject");
2157 pNtCreateKey = (void *)GetProcAddress(hntdll, "NtCreateKey");
2158 pNtOpenKey = (void *)GetProcAddress(hntdll, "NtOpenKey");
2159 pNtDeleteKey = (void *)GetProcAddress(hntdll, "NtDeleteKey");
2160 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
2161 pNtCreateMutant = (void *)GetProcAddress(hntdll, "NtCreateMutant");
2162 pNtOpenEvent = (void *)GetProcAddress(hntdll, "NtOpenEvent");
2163 pNtQueryEvent = (void *)GetProcAddress(hntdll, "NtQueryEvent");
2164 pNtPulseEvent = (void *)GetProcAddress(hntdll, "NtPulseEvent");
2165 pNtResetEvent = (void *)GetProcAddress(hntdll, "NtResetEvent");
2166 pNtSetEvent = (void *)GetProcAddress(hntdll, "NtSetEvent");
2167 pNtOpenMutant = (void *)GetProcAddress(hntdll, "NtOpenMutant");
2168 pNtQueryMutant = (void *)GetProcAddress(hntdll, "NtQueryMutant");
2169 pNtReleaseMutant = (void *)GetProcAddress(hntdll, "NtReleaseMutant");
2170 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
2171 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
2172 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
2173 pNtCreateNamedPipeFile = (void *)GetProcAddress(hntdll, "NtCreateNamedPipeFile");
2174 pNtOpenDirectoryObject = (void *)GetProcAddress(hntdll, "NtOpenDirectoryObject");
2175 pNtCreateDirectoryObject= (void *)GetProcAddress(hntdll, "NtCreateDirectoryObject");
2176 pNtOpenSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtOpenSymbolicLinkObject");
2177 pNtCreateSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtCreateSymbolicLinkObject");
2178 pNtQuerySymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtQuerySymbolicLinkObject");
2179 pNtCreateSemaphore = (void *)GetProcAddress(hntdll, "NtCreateSemaphore");
2180 pNtOpenSemaphore = (void *)GetProcAddress(hntdll, "NtOpenSemaphore");
2181 pNtCreateTimer = (void *)GetProcAddress(hntdll, "NtCreateTimer");
2182 pNtOpenTimer = (void *)GetProcAddress(hntdll, "NtOpenTimer");
2183 pNtCreateSection = (void *)GetProcAddress(hntdll, "NtCreateSection");
2184 pNtOpenSection = (void *)GetProcAddress(hntdll, "NtOpenSection");
2185 pNtQueryObject = (void *)GetProcAddress(hntdll, "NtQueryObject");
2186 pNtReleaseSemaphore = (void *)GetProcAddress(hntdll, "NtReleaseSemaphore");
2187 pNtCreateKeyedEvent = (void *)GetProcAddress(hntdll, "NtCreateKeyedEvent");
2188 pNtOpenKeyedEvent = (void *)GetProcAddress(hntdll, "NtOpenKeyedEvent");
2189 pNtWaitForKeyedEvent = (void *)GetProcAddress(hntdll, "NtWaitForKeyedEvent");
2190 pNtReleaseKeyedEvent = (void *)GetProcAddress(hntdll, "NtReleaseKeyedEvent");
2191 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
2192 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
2193 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
2194 pNtQuerySystemTime = (void *)GetProcAddress(hntdll, "NtQuerySystemTime");
2195 pRtlWaitOnAddress = (void *)GetProcAddress(hntdll, "RtlWaitOnAddress");
2196 pRtlWakeAddressAll = (void *)GetProcAddress(hntdll, "RtlWakeAddressAll");
2197 pRtlWakeAddressSingle = (void *)GetProcAddress(hntdll, "RtlWakeAddressSingle");
2198 pNtOpenProcess = (void *)GetProcAddress(hntdll, "NtOpenProcess");
2200 test_case_sensitive();
2201 test_namespace_pipe();
2202 test_name_collisions();
2203 test_name_limits();
2204 test_directory();
2205 test_symboliclink();
2206 test_query_object();
2207 test_type_mismatch();
2208 test_event();
2209 test_mutant();
2210 test_keyed_events();
2211 test_null_device();
2212 test_wait_on_address();
2213 test_process();