From 6e1812ed38adc8b0dade74396cf3596fa0f41b35 Mon Sep 17 00:00:00 2001 From: MacroModel <33865334+MacroModel@users.noreply.github.com> Date: Sat, 9 Nov 2024 06:32:34 +0800 Subject: [PATCH] update --- include/fast_io_hosted/filesystem/nt.h | 2 +- include/fast_io_hosted/platforms/nt.h | 225 ++++++++++++++++-- .../platforms/nt/nt_definitions.h | 81 +++++-- .../fast_io_hosted/platforms/nt/nt_linker.h | 68 ++++++ .../platforms/win32/msvc_linker_32.h | 2 + .../platforms/win32/msvc_linker_32_i686.h | 2 + .../platforms/win32/msvc_linker_64.h | 2 + include/fast_io_hosted/process/win32.h | 39 +-- 8 files changed, 372 insertions(+), 49 deletions(-) diff --git a/include/fast_io_hosted/filesystem/nt.h b/include/fast_io_hosted/filesystem/nt.h index bafc63ccf..28c0c8e82 100644 --- a/include/fast_io_hosted/filesystem/nt.h +++ b/include/fast_io_hosted/filesystem/nt.h @@ -129,7 +129,7 @@ inline nt_dirent *set_nt_dirent(nt_dirent *entry, bool start) } auto id_ful_dir_info{d_info.IdFullDirInfo}; - entry->d_ino = static_cast<::std::uint_least64_t>(id_ful_dir_info->FileId.QuadPart); + entry->d_ino = static_cast<::std::uint_least64_t>(id_ful_dir_info->FileId); entry->native_d_namlen = id_ful_dir_info->FileNameLength / sizeof(char16_t); diff --git a/include/fast_io_hosted/platforms/nt.h b/include/fast_io_hosted/platforms/nt.h index bcdafbc40..31795d9e6 100644 --- a/include/fast_io_hosted/platforms/nt.h +++ b/include/fast_io_hosted/platforms/nt.h @@ -472,9 +472,9 @@ inline ::std::uint_least64_t nt_calculate_current_file_offset(void *__restrict h { ::fast_io::win32::nt::io_status_block block; ::std::uint_least64_t fps{}; - auto status{::fast_io::win32::nt::nt_query_information_file < family == ::fast_io::nt_family::zw > (handle, __builtin_addressof(block), __builtin_addressof(fps), - static_cast<::std::uint_least32_t>(sizeof(::std::uint_least64_t)), - ::fast_io::win32::nt::file_information_class::FilePositionInformation)}; + auto status{::fast_io::win32::nt::nt_query_information_file(handle, __builtin_addressof(block), __builtin_addressof(fps), + static_cast<::std::uint_least32_t>(sizeof(::std::uint_least64_t)), + ::fast_io::win32::nt::file_information_class::FilePositionInformation)}; if (status) { throw_nt_error(status); @@ -502,8 +502,8 @@ inline ::std::byte *nt_read_pread_some_bytes_common_impl(void *__restrict handle { // some poeple in zwclose7 forum said we do not need to initialize io_status_block ::fast_io::win32::nt::io_status_block block; - auto const status{::fast_io::win32::nt::nt_read_file < family == ::fast_io::nt_family::zw > (handle, nullptr, nullptr, nullptr, __builtin_addressof(block), first, - ::fast_io::details::read_write_bytes_compute<::std::uint_least32_t>(first, last), pbyteoffset, nullptr)}; + auto const status{::fast_io::win32::nt::nt_read_file(handle, nullptr, nullptr, nullptr, __builtin_addressof(block), first, + ::fast_io::details::read_write_bytes_compute<::std::uint_least32_t>(first, last), pbyteoffset, nullptr)}; if (status) { throw_nt_error(status); @@ -532,8 +532,8 @@ inline ::std::byte const *nt_write_pwrite_some_bytes_common_impl(void *__restric ::std::int_least64_t *pbyteoffset) { ::fast_io::win32::nt::io_status_block block; - auto const status{::fast_io::win32::nt::nt_write_file < family == ::fast_io::nt_family::zw > (handle, nullptr, nullptr, nullptr, __builtin_addressof(block), first, - ::fast_io::details::read_write_bytes_compute<::std::uint_least32_t>(first, last), pbyteoffset, nullptr)}; + auto const status{::fast_io::win32::nt::nt_write_file(handle, nullptr, nullptr, nullptr, __builtin_addressof(block), first, + ::fast_io::details::read_write_bytes_compute<::std::uint_least32_t>(first, last), pbyteoffset, nullptr)}; if (status) { throw_nt_error(status); @@ -1025,7 +1025,7 @@ template inline ::fast_io::intfpos_t io_stream_seek_bytes_define(basic_nt_family_io_observer handle, ::fast_io::intfpos_t offset, seekdir s) { - return ::fast_io::win32::nt::details::nt_seek_impl < family == nt_family::zw > (handle.handle, offset, s); + return ::fast_io::win32::nt::details::nt_seek_impl(handle.handle, offset, s); } template @@ -1061,7 +1061,7 @@ struct nt_family_file_lock requires(sizeof(int_type) >= sizeof(::std::int_least64_t)) inline bool try_lock(basic_flock_request &__restrict t) noexcept { - return ::fast_io::win32::nt::details::nt_family_file_try_lock_impl < family == nt_family::zw > (this->handle, t); + return ::fast_io::win32::nt::details::nt_family_file_try_lock_impl(this->handle, t); } }; @@ -1126,12 +1126,12 @@ class basic_nt_family_file : public basic_nt_family_io_observer } explicit basic_nt_family_file(io_dup_t, basic_nt_family_io_observer wiob) : basic_nt_family_io_observer{ - ::fast_io::win32::nt::details::nt_dup_impl < family == nt_family::zw > (wiob.handle)} + ::fast_io::win32::nt::details::nt_dup_impl(wiob.handle)} { } explicit basic_nt_family_file(nt_fs_dirent fsdirent, open_mode om, perms pm = static_cast(436)) : basic_nt_family_io_observer{ - ::fast_io::win32::nt::details::nt_family_create_file_fs_dirent_impl < family == nt_family::zw > (fsdirent.handle, fsdirent.filename.c_str(), fsdirent.filename.size(), {om, pm})} + ::fast_io::win32::nt::details::nt_family_create_file_fs_dirent_impl(fsdirent.handle, fsdirent.filename.c_str(), fsdirent.filename.size(), {om, pm})} { } template <::fast_io::constructible_to_os_c_str T> @@ -1166,7 +1166,7 @@ class basic_nt_family_file : public basic_nt_family_io_observer { if (this->handle) [[likely]] { - auto status{::fast_io::win32::nt::nt_close < family == nt_family::zw > (this->handle)}; + auto status{::fast_io::win32::nt::nt_close(this->handle)}; this->handle = nullptr; // POSIX standard says we should never call close(2) again even close syscall fails if (status) [[unlikely]] { @@ -1184,12 +1184,12 @@ class basic_nt_family_file : public basic_nt_family_io_observer } basic_nt_family_file(basic_nt_family_file const &other) : basic_nt_family_io_observer( - ::fast_io::win32::nt::details::nt_dup_impl < family == nt_family::zw > (other.handle)) + ::fast_io::win32::nt::details::nt_dup_impl(other.handle)) { } basic_nt_family_file &operator=(basic_nt_family_file const &other) { - this->handle = ::fast_io::win32::nt::details::nt_dup2_impl < family == nt_family::zw > (other.handle, this->handle); + this->handle = ::fast_io::win32::nt::details::nt_dup2_impl(other.handle, this->handle); return *this; } constexpr basic_nt_family_file(basic_nt_family_file &&__restrict other) noexcept @@ -1216,6 +1216,203 @@ class basic_nt_family_file : public basic_nt_family_io_observer } }; +namespace win32::nt::details +{ +inline constexpr unix_timestamp to_unix_timestamp(::std::uint_least64_t date_time) noexcept +{ + /* + 116444736000000000 + 18446744073709551616 + 999999999 + 1000000000 + */ + + constexpr ::std::uint_least64_t gap{11644473600000ULL * 10000ULL}; + constexpr ::std::uint_least64_t mul_factor{uint_least64_subseconds_per_second / 10000000u}; + ::std::uint_least64_t unix_time{date_time - gap}; + if (date_time < gap) [[unlikely]] + { + unix_time = 0; + } + return {static_cast<::std::int_least64_t>(unix_time / 10000000ULL), + static_cast<::std::uint_least64_t>(unix_time % 10000000ULL) * mul_factor}; +} + +inline file_type file_type_impl(::std::uint_least32_t DeviceType) +{ + if (DeviceType > 0x2B) + { + if (DeviceType != 80) [[unlikely]] + { + return file_type::unknown; + } + return file_type::character; + } + if (DeviceType == 43 || DeviceType == 21) + { + return file_type::character; + } + if (DeviceType > 0x15) + { + if (DeviceType > 0x1D) + { + if (DeviceType != 31 && DeviceType != 32 && DeviceType != 33 && DeviceType != 34 && DeviceType == 36) [[likely]] + { + return file_type::regular; + } + return file_type::unknown; + } + switch (DeviceType) + { + case 0x1D: + [[fallthrough]]; + case 0x16: + return file_type::character; + case 0x17: + [[unlikely]] return file_type::unknown; + case 0x18: + [[fallthrough]]; + case 0x1B: + [[fallthrough]]; + case 0x28: + return file_type::character; + default: + [[unlikely]] return file_type::unknown; + } + } + if (DeviceType > 8) + { + if (DeviceType != 11 && DeviceType != 15) + { + if (DeviceType == 17) [[likely]] + { + return file_type::fifo; + } + return file_type::unknown; + } + return file_type::character; + } + return file_type::regular; +} + + +template +inline posix_file_status nt_status_impl(void *__restrict handle) +{ + ::fast_io::win32::nt::io_status_block isb{}; + + ::fast_io::win32::nt::file_fs_device_type ffdt{}; + auto status{::fast_io::win32::nt::nt_query_volume_information_file(handle, __builtin_addressof(isb), __builtin_addressof(ffdt), sizeof(ffdt), + ::fast_io::win32::nt::fs_information_class::FileFsDeviceInformation)}; + if (status) [[unlikely]] + { + throw_nt_error(status); + } + + auto ft{file_type_impl(ffdt.DeviceType)}; + + if (ft == file_type::fifo || ft == file_type::character) + { + return posix_file_status{0, + 0, + static_cast(436), + ft, + 1, + 0, + 0, + static_cast<::std::uintmax_t>(reinterpret_cast<::std::size_t>(handle)), + 0, + 131072, + 0, + {}, + {}, + {}, + {}, + 0, + 0}; + } + + ::fast_io::win32::nt::file_basic_information fbi{}; + status = ::fast_io::win32::nt::nt_query_information_file(handle, __builtin_addressof(isb), __builtin_addressof(fbi), sizeof(fbi), + ::fast_io::win32::nt::file_information_class::FileBasicInformation); + + if (status) [[unlikely]] + { + throw_nt_error(status); + } + + ::fast_io::win32::nt::file_internal_information fii{}; + status = ::fast_io::win32::nt::nt_query_information_file(handle, __builtin_addressof(isb), __builtin_addressof(fii), sizeof(fii), + ::fast_io::win32::nt::file_information_class::FileInternalInformation); + + if (status) [[unlikely]] + { + throw_nt_error(status); + } + + struct + { + ::fast_io::win32::nt::file_fs_volume_information FileFsVolume; + char16_t Name[255]; + } ffvi; + + status = ::fast_io::win32::nt::nt_query_volume_information_file(handle, __builtin_addressof(isb), __builtin_addressof(ffvi), sizeof(ffvi), + ::fast_io::win32::nt::fs_information_class::FileFsVolumeInformation); + if (status) [[unlikely]] + { + throw_nt_error(status); + } + + ::fast_io::win32::nt::file_standard_information fsi{}; + status = ::fast_io::win32::nt::nt_query_information_file(handle, __builtin_addressof(isb), __builtin_addressof(fsi), sizeof(fsi), + ::fast_io::win32::nt::file_information_class::FileStandardInformation); + + if (status) [[unlikely]] + { + throw_nt_error(status); + } + + ::std::uintmax_t file_size{static_cast<::std::uintmax_t>(fsi.end_of_file)}; + ::std::underlying_type_t pm{0444}; + if ((fbi.FileAttributes & 0x1) == 0x0) + { + pm |= 0222; + } + if ((fbi.FileAttributes & 0x400) == 0x400) + { + ft = file_type::symlink; + } + else if ((fbi.FileAttributes & 0x10) == 0x10) + { + ft = file_type::directory; + } + return posix_file_status{static_cast<::std::uintmax_t>(ffvi.FileFsVolume.VolumeSerialNumber), + static_cast<::std::uintmax_t>(fii.IndexNumber), + static_cast(pm), + ft, + static_cast<::std::uintmax_t>(fsi.number_of_links), + 0, + 0, + 0, + file_size, + 131072, + file_size >> 9, + to_unix_timestamp(fbi.LastAccessTime), + to_unix_timestamp(fbi.LastWriteTime), + to_unix_timestamp(fbi.ChangeTime), + to_unix_timestamp(fbi.CreationTime), + 0, + 0}; +} + +} // namespace win32::nt::details + +template +inline posix_file_status status(basic_nt_family_io_observer wiob) +{ + return win32::nt::details::nt_status_impl(wiob.handle); +} + template <::std::integral char_type> using basic_nt_io_observer = basic_nt_family_io_observer; diff --git a/include/fast_io_hosted/platforms/nt/nt_definitions.h b/include/fast_io_hosted/platforms/nt/nt_definitions.h index 64de06241..59f35049e 100644 --- a/include/fast_io_hosted/platforms/nt/nt_definitions.h +++ b/include/fast_io_hosted/platforms/nt/nt_definitions.h @@ -3,6 +3,21 @@ namespace fast_io::win32::nt { +union large_integer +{ + struct DUMMYSTRUCTNAMETYPE + { + ::std::uint_least32_t LowPart; + ::std::int_least32_t HighPart; + } DUMMYSTRUCTNAME; + struct uTYPE + { + ::std::uint_least32_t LowPart; + ::std::int_least32_t HighPart; + } u; + ::std::int_least64_t QuadPart; +}; + struct ansi_string { ::std::uint_least16_t Length; @@ -178,7 +193,7 @@ struct file_id_full_dir_information ::std::uint_least32_t FileAttributes; ::std::uint_least32_t FileNameLength; ::std::uint_least32_t EaSize; - large_integer FileId; + ::std::uint_least64_t FileId; char16_t FileName[1]; }; @@ -215,7 +230,7 @@ struct file_id_both_dir_information ::std::uint_least32_t EaSize; char ShortNameLength; char16_t ShortName[12]; - large_integer FileId; + ::std::uint_least64_t FileId; char16_t FileName[1]; }; @@ -237,6 +252,20 @@ struct file_standard_information int directory; }; +struct file_basic_information +{ + ::std::uint_least64_t CreationTime; + ::std::uint_least64_t LastAccessTime; + ::std::uint_least64_t LastWriteTime; + ::std::uint_least64_t ChangeTime; + ::std::uint_least32_t FileAttributes; +}; + +struct file_internal_information +{ + ::std::uint_least64_t IndexNumber; +}; + enum class process_information_class { ProcessBasicInformation, // q: PROCESS_BASIC_INFORMATION, PROCESS_EXTENDED_BASIC_INFORMATION @@ -648,21 +677,6 @@ enum class object_information_class ObjectHandleInformation = 4 }; -union large_integer -{ - struct DUMMYSTRUCTNAMETYPE - { - ::std::uint_least32_t LowPart; - ::std::int_least32_t HighPart; - } DUMMYSTRUCTNAME; - struct uTYPE - { - ::std::uint_least32_t LowPart; - ::std::int_least32_t HighPart; - } u; - ::std::int_least64_t QuadPart; -}; - enum class section_inherit { ViewShare = 1, @@ -792,4 +806,37 @@ struct ps_std_handle_info ::std::uint_least32_t StdHandleSubsystemType; }; +enum class fs_information_class +{ + FileFsVolumeInformation = 1, + FileFsLabelInformation, + FileFsSizeInformation, + FileFsDeviceInformation, + FileFsAttributeInformation, + FileFsControlInformation, + FileFsFullSizeInformation, + FileFsObjectIdInformation, + FileFsDriverPathInformation, + FileFsVolumeFlagsInformation, + FileFsSectorSizeInformation, + FileFsDataCopyInformation, + FileFsMetadataSizeInformation, + FileFsFullSizeInformationEx, + FileFsMaximumInformation +}; + +struct file_fs_device_type +{ + ::std::uint_least32_t DeviceType; + ::std::uint_least32_t Characteristics; +}; + +struct file_fs_volume_information +{ + ::std::uint_least64_t VolumeCreationTime; + ::std::uint_least32_t VolumeSerialNumber; + ::std::uint_least32_t VolumeLabelLength; + ::std::uint_least8_t SupportsObjects; + char16_t VolumeLabel[1]; +}; } // namespace fast_io::win32::nt diff --git a/include/fast_io_hosted/platforms/nt/nt_linker.h b/include/fast_io_hosted/platforms/nt/nt_linker.h index dc7a6df0a..ac3e9403e 100644 --- a/include/fast_io_hosted/platforms/nt/nt_linker.h +++ b/include/fast_io_hosted/platforms/nt/nt_linker.h @@ -2514,4 +2514,72 @@ extern void #endif ; +#if defined(_MSC_VER) && !defined(__clang__) +__declspec(dllimport) +#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__)) +[[__gnu__::__dllimport__]] +#endif +#if (__has_cpp_attribute(__gnu__::__stdcall__) && !defined(__WINE__)) +[[__gnu__::__stdcall__]] +#endif +extern ::std::uint_least32_t +#if (!__has_cpp_attribute(__gnu__::__stdcall__) && !defined(__WINE__)) && defined(_MSC_VER) + __stdcall +#endif + NtQueryVolumeInformationFile(void *__restrict, io_status_block *__restrict, void *__restrict, ::std::uint_least32_t, + fs_information_class) noexcept +#if defined(__clang__) || defined(__GNUC__) +#if SIZE_MAX <= UINT_LEAST32_MAX && (defined(__x86__) || defined(_M_IX86) || defined(__i386__)) +#if !defined(__clang__) + __asm__("NtQueryVolumeInformationFile@20") +#else + __asm__("_NtQueryVolumeInformationFile@20") +#endif +#else + __asm__("NtQueryVolumeInformationFile") +#endif +#endif + ; + +#if defined(_MSC_VER) && !defined(__clang__) +__declspec(dllimport) +#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__)) +[[__gnu__::__dllimport__]] +#endif +#if (__has_cpp_attribute(__gnu__::__stdcall__) && !defined(__WINE__)) +[[__gnu__::__stdcall__]] +#endif +extern ::std::uint_least32_t +#if (!__has_cpp_attribute(__gnu__::__stdcall__) && !defined(__WINE__)) && defined(_MSC_VER) + __stdcall +#endif + ZwQueryVolumeInformationFile(void *__restrict, io_status_block *__restrict, void *__restrict, ::std::uint_least32_t, + fs_information_class) noexcept +#if defined(__clang__) || defined(__GNUC__) +#if SIZE_MAX <= UINT_LEAST32_MAX && (defined(__x86__) || defined(_M_IX86) || defined(__i386__)) +#if !defined(__clang__) + __asm__("ZwQueryVolumeInformationFile@20") +#else + __asm__("_ZwQueryVolumeInformationFile@20") +#endif +#else + __asm__("ZwQueryVolumeInformationFile") +#endif +#endif + ; + +template + requires(sizeof...(Args) == 5) +inline ::std::uint_least32_t nt_query_volume_information_file(Args... args) noexcept +{ + if constexpr (zw) + { + return ZwQueryVolumeInformationFile(args...); + } + else + { + return NtQueryVolumeInformationFile(args...); + } +} + } // namespace fast_io::win32::nt diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_32.h b/include/fast_io_hosted/platforms/win32/msvc_linker_32.h index 2088168ae..efec9c8a9 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_32.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_32.h @@ -209,6 +209,8 @@ #pragma comment(linker,"/alternatename:__imp_?ZwQuerySystemInformation@nt@win32@fast_io@@YAIW4system_information_class@123@PAXIPAI@Z=__imp_ZwQuerySystemInformation") #pragma comment(linker,"/alternatename:__imp_?NtFreeVirtualMemory@nt@win32@fast_io@@YAIPAXPAPAXPAII@Z=__imp_NtFreeVirtualMemory") #pragma comment(linker,"/alternatename:__imp_?ZwFreeVirtualMemory@nt@win32@fast_io@@YAIPAXPAPAXPAII@Z=__imp_ZwFreeVirtualMemory") +#pragma comment(linker,"/alternatename:__imp_?NtQueryVolumeInformationFile@nt@win32@fast_io@@YAIPIAXPIAUio_status_block@123@0IW4fs_information_class@123@@Z=__imp_NtQueryVolumeInformationFile") +#pragma comment(linker,"/alternatename:__imp_?ZwQueryVolumeInformationFile@nt@win32@fast_io@@YAIPIAXPIAUio_status_block@123@0IW4fs_information_class@123@@Z=__imp_ZwQueryVolumeInformationFile") //msvc #pragma comment(linker,"/alternatename:__imp_?msvc__RTtypeid@msvc@fast_io@@YAPAXPAX@Z=__imp___RTtypeid") #pragma comment(linker,"/alternatename:?msvc__RTtypeid@msvc@fast_io@@YAPAXPAX@Z=__RTtypeid") diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h b/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h index 590b24df2..5b537131f 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h @@ -209,6 +209,8 @@ #pragma comment(linker,"/alternatename:__imp_?ZwQuerySystemInformation@nt@win32@fast_io@@YGIW4system_information_class@123@PAXIPAI@Z=__imp__ZwQuerySystemInformation@16") #pragma comment(linker,"/alternatename:__imp_?NtFreeVirtualMemory@nt@win32@fast_io@@YGIPAXPAPAXPAII@Z=__imp__NtFreeVirtualMemory@16") #pragma comment(linker,"/alternatename:__imp_?ZwFreeVirtualMemory@nt@win32@fast_io@@YGIPAXPAPAXPAII@Z=__imp__ZwFreeVirtualMemory@16") +#pragma comment(linker,"/alternatename:__imp_?NtQueryVolumeInformationFile@nt@win32@fast_io@@YGIPIAXPIAUio_status_block@123@0IW4fs_information_class@123@@Z=__imp__NtQueryVolumeInformationFile@20") +#pragma comment(linker,"/alternatename:__imp_?ZwQueryVolumeInformationFile@nt@win32@fast_io@@YGIPIAXPIAUio_status_block@123@0IW4fs_information_class@123@@Z=__imp__ZwQueryVolumeInformationFile@20") // msvc #pragma comment(linker,"/alternatename:__imp_?msvc__RTtypeid@msvc@fast_io@@YAPAXPAX@Z=__imp____RTtypeid") #pragma comment(linker,"/alternatename:?msvc__RTtypeid@msvc@fast_io@@YAPAXPAX@Z=___RTtypeid") diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_64.h b/include/fast_io_hosted/platforms/win32/msvc_linker_64.h index c7147c68a..7a09800eb 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_64.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_64.h @@ -208,6 +208,8 @@ #pragma comment(linker,"/alternatename:__imp_?NtQuerySystemInformation@nt@win32@fast_io@@YAIW4system_information_class@123@PEAXIPEAI@Z=__imp_NtQuerySystemInformation") #pragma comment(linker,"/alternatename:__imp_?NtFreeVirtualMemory@nt@win32@fast_io@@YAIPEAXPEAPEAXPEA_KI@Z=__imp_NtFreeVirtualMemory") #pragma comment(linker,"/alternatename:__imp_?ZwFreeVirtualMemory@nt@win32@fast_io@@YAIPEAXPEAPEAXPEA_KI@Z=__imp_ZwFreeVirtualMemory") +#pragma comment(linker,"/alternatename:__imp_?NtQueryVolumeInformationFile@nt@win32@fast_io@@YAIPEIAXPEIAUio_status_block@123@0IW4fs_information_class@123@@Z=__imp_NtQueryVolumeInformationFile") +#pragma comment(linker,"/alternatename:__imp_?ZwQueryVolumeInformationFile@nt@win32@fast_io@@YAIPEIAXPEIAUio_status_block@123@0IW4fs_information_class@123@@Z=__imp_ZwQueryVolumeInformationFile") // msvc #pragma comment(linker,"/alternatename:__imp_?msvc__RTtypeid@msvc@fast_io@@YAPEAXPEAX@Z=__imp___RTtypeid") #pragma comment(linker,"/alternatename:?msvc__RTtypeid@msvc@fast_io@@YAPEAXPEAX@Z=__RTtypeid") diff --git a/include/fast_io_hosted/process/win32.h b/include/fast_io_hosted/process/win32.h index 21d48d4a1..a4f57d546 100644 --- a/include/fast_io_hosted/process/win32.h +++ b/include/fast_io_hosted/process/win32.h @@ -194,30 +194,35 @@ inline win32_user_process_information win32_process_create_impl(void *__restrict mg1.clear(); hg1.clear(); + auto address_begin{pszFilename}; + // change nt path to dos path - char16_t DosDevice[4]{}; - char16_t NtPath[64]; - char16_t *RetStr{}; - ::std::size_t NtPathLen{}; - for (char16_t i{65}; i < static_cast(26 + 65); i++) + if (pszFilename[0] == u'\\') { - DosDevice[0] = i; - DosDevice[1] = u':'; - if (::fast_io::win32::QueryDosDeviceW(DosDevice, NtPath, 64)) + char16_t DosDevice[4]{}; + char16_t NtPath[64]; + char16_t *RetStr{}; + ::std::size_t NtPathLen{}; + for (char16_t i{65}; i < static_cast(26 + 65); i++) { - NtPathLen = ::fast_io::cstr_len(NtPath); - - if (::fast_io::freestanding::my_memcmp(pszFilename, NtPath, NtPathLen * sizeof(char16_t)) == 0) [[unlikely]] + DosDevice[0] = i; + DosDevice[1] = u':'; + if (::fast_io::win32::QueryDosDeviceW(DosDevice, NtPath, 64)) { - goto next; + NtPathLen = ::fast_io::cstr_len(NtPath); + + if (::fast_io::freestanding::my_memcmp(pszFilename, NtPath, NtPathLen * sizeof(char16_t)) == 0) [[unlikely]] + { + goto next; + } } } + throw_win32_error(0x3); + next: + address_begin += NtPathLen - 2; + address_begin[0] = DosDevice[0]; + address_begin[1] = u':'; } - throw_win32_error(0x3); - next: - auto address_begin{pszFilename + NtPathLen - 2}; - address_begin[0] = DosDevice[0]; - address_begin[1] = u':'; // create process ::fast_io::win32::startupinfow si{sizeof(si)};