+
+ /* If TargetProcess is the System process, we do get a kernel handle */
+ Status = ZwDuplicateObject(ZwCurrentProcess(),
+ Handle,
+ SystemProcessHandle,
+ &NewHandle,
+ DIRECTORY_ALL_ACCESS,
+ OBJ_KERNEL_HANDLE,
+ 0);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ if (!skip(NT_SUCCESS(Status), "DuplicateHandle failed\n"))
+ {
+ ok(IsKernelHandle(NewHandle), "New handle = %p\n", NewHandle);
+ CheckObject(NewHandle, 3UL, 2UL, 0, DIRECTORY_ALL_ACCESS);
+ CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
+
+ Status = ObCloseHandle(NewHandle, UserMode);
+ ok_eq_hex(Status, STATUS_INVALID_HANDLE);
+ CheckObject(NewHandle, 3UL, 2UL, 0, DIRECTORY_ALL_ACCESS);
+ CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
+
+ if (IsKernelHandle(NewHandle))
+ {
+ Status = ObCloseHandle(NewHandle, KernelMode);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ CheckObject(Handle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
+ }
+ }