From 99af4647808632604f903e2024420d6ccfd5ebee Mon Sep 17 00:00:00 2001 From: MacroModel Date: Mon, 15 Sep 2025 12:45:02 +0800 Subject: [PATCH 1/2] update nt --- .../file_loaders/nt_file_loader.h | 17 ++++++++++++++++- .../file_loaders/posix_file_loader.h | 11 ++++++++++- .../file_loaders/win32_file_loader.h | 17 ++++++++++++++++- include/fast_io_hosted/filesystem/posix_at.h | 9 +++++---- .../platforms/nt/nt_definitions.h | 5 +++++ 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/include/fast_io_hosted/file_loaders/nt_file_loader.h b/include/fast_io_hosted/file_loaders/nt_file_loader.h index c0d76e399..49913ff07 100644 --- a/include/fast_io_hosted/file_loaders/nt_file_loader.h +++ b/include/fast_io_hosted/file_loaders/nt_file_loader.h @@ -102,7 +102,7 @@ inline auto nt_load_file_options_impl(nt_mmap_options const &options, Args &&... template <::fast_io::nt_family family> requires(family == ::fast_io::nt_family::nt || family == ::fast_io::nt_family::zw) -class nt_family_file_loader +class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE { public: using value_type = char; @@ -455,4 +455,19 @@ inline constexpr basic_io_scatter_t print_alias_define(::fast_io::io_alias using nt_file_loader = nt_family_file_loader<::fast_io::nt_family::nt>; using zw_file_loader = nt_family_file_loader<::fast_io::nt_family::zw>; +namespace freestanding +{ +template <::fast_io::nt_family family> +struct is_trivially_copyable_or_relocatable> +{ + inline static constexpr bool value = true; +}; + +template <::fast_io::nt_family family> +struct is_zero_default_constructible> +{ + inline static constexpr bool value = true; +}; +} // namespace freestanding + } // namespace fast_io diff --git a/include/fast_io_hosted/file_loaders/posix_file_loader.h b/include/fast_io_hosted/file_loaders/posix_file_loader.h index fc8834e76..dad93fd5d 100644 --- a/include/fast_io_hosted/file_loaders/posix_file_loader.h +++ b/include/fast_io_hosted/file_loaders/posix_file_loader.h @@ -85,7 +85,7 @@ inline auto posix_load_file_options_impl(::fast_io::posix_mmap_options const &op } // namespace details -class posix_file_loader +class posix_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE { public: using value_type = char; @@ -396,4 +396,13 @@ inline constexpr basic_io_scatter_t print_alias_define(io_alias_t, posix_f return {load.data(), load.size()}; } +namespace freestanding +{ +template <> +struct is_trivially_copyable_or_relocatable +{ + inline static constexpr bool value = true; +}; + +} // namespace freestanding } // namespace fast_io diff --git a/include/fast_io_hosted/file_loaders/win32_file_loader.h b/include/fast_io_hosted/file_loaders/win32_file_loader.h index e588cfa2c..2cdb1c1e3 100644 --- a/include/fast_io_hosted/file_loaders/win32_file_loader.h +++ b/include/fast_io_hosted/file_loaders/win32_file_loader.h @@ -115,7 +115,7 @@ inline void win32_unload_address(void const *address) noexcept } // namespace win32::details template -class win32_family_file_loader +class win32_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE { public: using value_type = char; @@ -440,4 +440,19 @@ using win32_file_loader_9xa = win32_family_file_loader; using win32_file_loader_ntw = win32_family_file_loader; using win32_file_loader = win32_family_file_loader; +namespace freestanding +{ +template <::fast_io::win32_family family> +struct is_trivially_copyable_or_relocatable> +{ + inline static constexpr bool value = true; +}; + +template <::fast_io::win32_family family> +struct is_zero_default_constructible> +{ + inline static constexpr bool value = true; +}; +} // namespace freestanding + } // namespace fast_io diff --git a/include/fast_io_hosted/filesystem/posix_at.h b/include/fast_io_hosted/filesystem/posix_at.h index 94b9379a6..3f8b95314 100644 --- a/include/fast_io_hosted/filesystem/posix_at.h +++ b/include/fast_io_hosted/filesystem/posix_at.h @@ -382,12 +382,13 @@ inline void posix_utimensat_impl(int dirfd, char const *path, unix_timestamp_opt struct timespec *tsptr{ts}; system_call_throw_error( #if defined(__linux__) -#if defined(__NR_utimensat64) - system_call<__NR_utimensat64, int> -#else +#if defined(__NR_utimensat_time64) + system_call<__NR_utimensat_time64, int> +#elif defined(__NR_utimensat) system_call<__NR_utimensat, int> +#else + ::fast_io::posix::libc_utimensat #endif - #else ::fast_io::posix::libc_utimensat #endif diff --git a/include/fast_io_hosted/platforms/nt/nt_definitions.h b/include/fast_io_hosted/platforms/nt/nt_definitions.h index f964003d2..c802141cf 100644 --- a/include/fast_io_hosted/platforms/nt/nt_definitions.h +++ b/include/fast_io_hosted/platforms/nt/nt_definitions.h @@ -1364,4 +1364,9 @@ enum class virtual_memory_information_class VmCfgCallTargetInformation }; +struct file_allocation_information +{ + ::std::int_least64_t AllocationSize; +}; + } // namespace fast_io::win32::nt From 62b0830aa50d83e00ec3a93326dc7165c48505ca Mon Sep 17 00:00:00 2001 From: MacroModel Date: Tue, 16 Sep 2025 00:05:55 +0800 Subject: [PATCH 2/2] fix --- include/fast_io_hosted/platforms/win32.h | 31 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/include/fast_io_hosted/platforms/win32.h b/include/fast_io_hosted/platforms/win32.h index fd6e93934..0b240aaf9 100644 --- a/include/fast_io_hosted/platforms/win32.h +++ b/include/fast_io_hosted/platforms/win32.h @@ -959,7 +959,7 @@ inline void check_win32_9xa_dir_is_valid(win32_9xa_dir_handle const &h) ::fast_io::win32::win32_find_dataa wfda{}; tlc_win32_9xa_dir_handle_path_str temp_find_path{concat_tlc_win32_9xa_dir_handle_path_str(h.path, u8"\\*")}; auto find_struct{::fast_io::win32::FindFirstFileA(reinterpret_cast(temp_find_path.c_str()), __builtin_addressof(wfda))}; - if (find_struct == reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))) + if (find_struct == reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))) [[unlikely]] { throw_win32_error(0x5); } @@ -969,14 +969,39 @@ inline void check_win32_9xa_dir_is_valid(win32_9xa_dir_handle const &h) } } +inline bool get_win32_9xa_dir_validity(win32_9xa_dir_handle const &h) +{ + ::fast_io::win32::win32_find_dataa wfda{}; + tlc_win32_9xa_dir_handle_path_str temp_find_path{concat_tlc_win32_9xa_dir_handle_path_str(h.path, u8"\\*")}; + auto find_struct{::fast_io::win32::FindFirstFileA(reinterpret_cast(temp_find_path.c_str()), __builtin_addressof(wfda))}; + if (find_struct == reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))) [[unlikely]] + { + return false; + } + else + { + ::fast_io::win32::FindClose(find_struct); + return true; + } +} + template inline void close_win32_9xa_dir_handle(win32_9xa_dir_handle &h) noexcept(!throw_eh) { if constexpr (throw_eh) { - check_win32_9xa_dir_is_valid(h); + // Make sure to successfully close even if an exception is thrown. + bool const is_win32_9xa_dir_validid{get_win32_9xa_dir_validity(h)}; + h.path.clear(); + if (!is_win32_9xa_dir_validid) [[unlikely]] + { + throw_win32_error(0x5); + } + } + else + { + h.path.clear(); } - h.path.clear(); } inline win32_9xa_dir_handle win32_9xa_dir_dup_impl(win32_9xa_dir_handle const &h)