1
0
mirror of https://github.com/libuv/libuv synced 2025-03-28 21:13:16 +00:00

Add another test case

Signed-off-by: Yage Hu <me@huyage.dev>
This commit is contained in:
Yage Hu 2024-06-13 11:02:17 -07:00
parent fb3cab3255
commit cd9bc28f05
4 changed files with 58 additions and 30 deletions

View File

@ -843,20 +843,14 @@ void fs__openat(uv_fs_t* req) {
options |= FILE_DIRECTORY_FILE;
}
HMODULE ntdll = GetModuleHandle("ntdll.dll");
RtlInitUnicodeString _RtlInitUnicodeString =
(RtlInitUnicodeString) GetProcAddress(ntdll, "RtlInitUnicodeString");
NtCreateFile _NtCreateFile =
(NtCreateFile) GetProcAddress(ntdll, "NtCreateFile");
_RtlInitUnicodeString(&str, req->file.pathw);
pRtlInitUnicodeString(&str, req->file.pathw);
InitializeObjectAttributes(&obj,
&str,
OBJ_CASE_INSENSITIVE,
req->fs.info.hFile_out,
NULL);
NTSTATUS status = _NtCreateFile(&file,
NTSTATUS status = pNtCreateFile(&file,
access,
&obj,
&isb,

View File

@ -27,7 +27,9 @@
/* Ntdll function pointers */
sRtlGetVersion pRtlGetVersion;
sRtlInitUnicodeString pRtlInitUnicodeString;
sRtlNtStatusToDosError pRtlNtStatusToDosError;
sNtCreateFile pNtCreateFile;
sNtDeviceIoControlFile pNtDeviceIoControlFile;
sNtQueryInformationFile pNtQueryInformationFile;
sNtSetInformationFile pNtSetInformationFile;
@ -70,6 +72,17 @@ void uv__winapi_init(void) {
uv_fatal_error(GetLastError(), "GetProcAddress");
}
pRtlInitUnicodeString =
(sRtlInitUnicodeString) GetProcAddress(ntdll_module, "RtlInitUnicodeString");
if (pRtlInitUnicodeString == NULL) {
uv_fatal_error(GetLastError(), "GetProcAddress");
}
pNtCreateFile = (sNtCreateFile) GetProcAddress(ntdll_module, "NtCreateFile");
if (pNtCreateFile == NULL) {
uv_fatal_error(GetLastError(), "GetProcAddress");
}
pNtDeviceIoControlFile = (sNtDeviceIoControlFile) GetProcAddress(
ntdll_module,
"NtDeviceIoControlFile");

View File

@ -4637,9 +4637,27 @@ typedef VOID (NTAPI *PIO_APC_ROUTINE)
typedef NTSTATUS (NTAPI *sRtlGetVersion)
(PRTL_OSVERSIONINFOW lpVersionInformation);
typedef VOID (NTAPI *sRtlInitUnicodeString)(
PUNICODE_STRING DestinationString,
__drv_aliasesMem PCWSTR SourceString
);
typedef ULONG (NTAPI *sRtlNtStatusToDosError)
(NTSTATUS Status);
typedef NTSTATUS (NTAPI *sNtCreateFile)
(PHANDLE FileHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PIO_STATUS_BLOCK IoStatusBlock,
PLARGE_INTEGER AllocationSize,
ULONG FileAttributes,
ULONG ShareAccess,
ULONG CreateDisposition,
ULONG CreateOptions,
PVOID EaBuffer,
ULONG EaLength);
typedef NTSTATUS (NTAPI *sNtDeviceIoControlFile)
(HANDLE FileHandle,
HANDLE Event,
@ -4795,13 +4813,6 @@ typedef DWORD (WINAPI *sPowerRegisterSuspendResumeNotification)
_PHPOWERNOTIFY RegistrationHandle);
/* from wdm.h */
typedef VOID (NTAPI *RtlInitUnicodeString)(
PUNICODE_STRING DestinationString,
__drv_aliasesMem PCWSTR SourceString
);
/* from Winuser.h */
typedef VOID (CALLBACK* WINEVENTPROC)
(HWINEVENTHOOK hWinEventHook,
@ -4854,7 +4865,9 @@ typedef BOOL(WINAPI* sGetFileInformationByName)(
/* Ntdll function pointers */
extern sRtlGetVersion pRtlGetVersion;
extern sRtlInitUnicodeString pRtlInitUnicodeString;
extern sRtlNtStatusToDosError pRtlNtStatusToDosError;
extern sNtCreateFile pNtCreateFile;
extern sNtDeviceIoControlFile pNtDeviceIoControlFile;
extern sNtQueryInformationFile pNtQueryInformationFile;
extern sNtSetInformationFile pNtSetInformationFile;
@ -4880,21 +4893,6 @@ typedef int (WINAPI *uv_sGetHostNameW)
extern uv_sGetHostNameW pGetHostNameW;
/* from winternl.h */
typedef NTSTATUS (__stdcall *NtCreateFile)(
OUT PHANDLE FileHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN PLARGE_INTEGER AllocationSize OPTIONAL,
IN ULONG FileAttributes,
IN ULONG ShareAccess,
IN ULONG CreateDisposition,
IN ULONG CreateOptions,
IN PVOID EaBuffer OPTIONAL,
IN ULONG EaLength
);
/* from ntdef.h */
#ifndef InitializeObjectAttributes
#define InitializeObjectAttributes( p, n, a, r, s ) { \

View File

@ -3254,12 +3254,17 @@ TEST_IMPL(fs_openat) {
/* Setup. */
unlink("test/fixtures/test_dir/test_file_not_exist");
unlink("test/fixtures/test_dir/test_file");
rmdir("test/fixtures/test_dir/nested_dir");
rmdir("test/fixtures/test_dir");
loop = uv_default_loop();
r = uv_fs_mkdir(NULL, &req, "test/fixtures/test_dir", 0755, NULL);
ASSERT_OK(r);
uv_fs_req_cleanup(&req);
r = uv_fs_mkdir(NULL, &req, "test/fixtures/test_dir/nested_dir", 0755, NULL);
ASSERT_OK(r);
uv_fs_req_cleanup(&req);
r = uv_fs_open(NULL,
&req,
@ -3324,6 +3329,23 @@ TEST_IMPL(fs_openat) {
uv_fs_req_cleanup(&req);
}
// Open a nested dir
{
r = uv_fs_openat(NULL,
&req,
dirfd,
"nested_dir",
UV_FS_O_RDONLY | UV_FS_O_DIRECTORY,
S_IWUSR | S_IRUSR,
NULL);
ASSERT_OK(r);
uv_fs_req_cleanup(&req);
fd = (uv_os_fd_t) req.result;
r = uv_fs_close(NULL, &req, fd, NULL);
ASSERT_OK(r);
uv_fs_req_cleanup(&req);
}
// Create a new file
{
r = uv_fs_openat(NULL,
@ -3390,6 +3412,7 @@ TEST_IMPL(fs_openat) {
/* Cleanup */
unlink("test/fixtures/test_dir/test_file_not_exist");
unlink("test/fixtures/test_dir/test_file");
rmdir("test/fixtures/test_dir/nested_dir");
rmdir("test/fixtures/test_dir");
MAKE_VALGRIND_HAPPY(loop);