Skip to content

Commit a646386

Browse files
authored
update nt (#1198)
* update nt * fix
1 parent ea602ef commit a646386

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

include/fast_io_hosted/file_loaders/nt_file_loader.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ inline auto nt_load_file_options_impl(nt_mmap_options const &options, Args &&...
102102

103103
template <::fast_io::nt_family family>
104104
requires(family == ::fast_io::nt_family::nt || family == ::fast_io::nt_family::zw)
105-
class nt_family_file_loader
105+
class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
106106
{
107107
public:
108108
using value_type = char;
@@ -455,4 +455,19 @@ inline constexpr basic_io_scatter_t<char> print_alias_define(::fast_io::io_alias
455455
using nt_file_loader = nt_family_file_loader<::fast_io::nt_family::nt>;
456456
using zw_file_loader = nt_family_file_loader<::fast_io::nt_family::zw>;
457457

458+
namespace freestanding
459+
{
460+
template <::fast_io::nt_family family>
461+
struct is_trivially_copyable_or_relocatable<nt_family_file_loader<family>>
462+
{
463+
inline static constexpr bool value = true;
464+
};
465+
466+
template <::fast_io::nt_family family>
467+
struct is_zero_default_constructible<nt_family_file_loader<family>>
468+
{
469+
inline static constexpr bool value = true;
470+
};
471+
} // namespace freestanding
472+
458473
} // namespace fast_io

include/fast_io_hosted/file_loaders/posix_file_loader.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ inline auto posix_load_file_options_impl(::fast_io::posix_mmap_options const &op
8585

8686
} // namespace details
8787

88-
class posix_file_loader
88+
class posix_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
8989
{
9090
public:
9191
using value_type = char;
@@ -396,4 +396,13 @@ inline constexpr basic_io_scatter_t<char> print_alias_define(io_alias_t, posix_f
396396
return {load.data(), load.size()};
397397
}
398398

399+
namespace freestanding
400+
{
401+
template <>
402+
struct is_trivially_copyable_or_relocatable<posix_file_loader>
403+
{
404+
inline static constexpr bool value = true;
405+
};
406+
407+
} // namespace freestanding
399408
} // namespace fast_io

include/fast_io_hosted/file_loaders/win32_file_loader.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ inline void win32_unload_address(void const *address) noexcept
115115
} // namespace win32::details
116116

117117
template <win32_family family>
118-
class win32_family_file_loader
118+
class win32_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
119119
{
120120
public:
121121
using value_type = char;
@@ -440,4 +440,19 @@ using win32_file_loader_9xa = win32_family_file_loader<win32_family::ansi_9x>;
440440
using win32_file_loader_ntw = win32_family_file_loader<win32_family::wide_nt>;
441441
using win32_file_loader = win32_family_file_loader<win32_family::native>;
442442

443+
namespace freestanding
444+
{
445+
template <::fast_io::win32_family family>
446+
struct is_trivially_copyable_or_relocatable<win32_family_file_loader<family>>
447+
{
448+
inline static constexpr bool value = true;
449+
};
450+
451+
template <::fast_io::win32_family family>
452+
struct is_zero_default_constructible<win32_family_file_loader<family>>
453+
{
454+
inline static constexpr bool value = true;
455+
};
456+
} // namespace freestanding
457+
443458
} // namespace fast_io

include/fast_io_hosted/filesystem/posix_at.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,13 @@ inline void posix_utimensat_impl(int dirfd, char const *path, unix_timestamp_opt
382382
struct timespec *tsptr{ts};
383383
system_call_throw_error(
384384
#if defined(__linux__)
385-
#if defined(__NR_utimensat64)
386-
system_call<__NR_utimensat64, int>
387-
#else
385+
#if defined(__NR_utimensat_time64)
386+
system_call<__NR_utimensat_time64, int>
387+
#elif defined(__NR_utimensat)
388388
system_call<__NR_utimensat, int>
389+
#else
390+
::fast_io::posix::libc_utimensat
389391
#endif
390-
391392
#else
392393
::fast_io::posix::libc_utimensat
393394
#endif

include/fast_io_hosted/platforms/nt/nt_definitions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,4 +1364,9 @@ enum class virtual_memory_information_class
13641364
VmCfgCallTargetInformation
13651365
};
13661366

1367+
struct file_allocation_information
1368+
{
1369+
::std::int_least64_t AllocationSize;
1370+
};
1371+
13671372
} // namespace fast_io::win32::nt

include/fast_io_hosted/platforms/win32.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ inline void check_win32_9xa_dir_is_valid(win32_9xa_dir_handle const &h)
959959
::fast_io::win32::win32_find_dataa wfda{};
960960
tlc_win32_9xa_dir_handle_path_str temp_find_path{concat_tlc_win32_9xa_dir_handle_path_str(h.path, u8"\\*")};
961961
auto find_struct{::fast_io::win32::FindFirstFileA(reinterpret_cast<char const *>(temp_find_path.c_str()), __builtin_addressof(wfda))};
962-
if (find_struct == reinterpret_cast<void *>(static_cast<::std::ptrdiff_t>(-1)))
962+
if (find_struct == reinterpret_cast<void *>(static_cast<::std::ptrdiff_t>(-1))) [[unlikely]]
963963
{
964964
throw_win32_error(0x5);
965965
}
@@ -969,14 +969,39 @@ inline void check_win32_9xa_dir_is_valid(win32_9xa_dir_handle const &h)
969969
}
970970
}
971971

972+
inline bool get_win32_9xa_dir_validity(win32_9xa_dir_handle const &h)
973+
{
974+
::fast_io::win32::win32_find_dataa wfda{};
975+
tlc_win32_9xa_dir_handle_path_str temp_find_path{concat_tlc_win32_9xa_dir_handle_path_str(h.path, u8"\\*")};
976+
auto find_struct{::fast_io::win32::FindFirstFileA(reinterpret_cast<char const *>(temp_find_path.c_str()), __builtin_addressof(wfda))};
977+
if (find_struct == reinterpret_cast<void *>(static_cast<::std::ptrdiff_t>(-1))) [[unlikely]]
978+
{
979+
return false;
980+
}
981+
else
982+
{
983+
::fast_io::win32::FindClose(find_struct);
984+
return true;
985+
}
986+
}
987+
972988
template <bool throw_eh = false>
973989
inline void close_win32_9xa_dir_handle(win32_9xa_dir_handle &h) noexcept(!throw_eh)
974990
{
975991
if constexpr (throw_eh)
976992
{
977-
check_win32_9xa_dir_is_valid(h);
993+
// Make sure to successfully close even if an exception is thrown.
994+
bool const is_win32_9xa_dir_validid{get_win32_9xa_dir_validity(h)};
995+
h.path.clear();
996+
if (!is_win32_9xa_dir_validid) [[unlikely]]
997+
{
998+
throw_win32_error(0x5);
999+
}
1000+
}
1001+
else
1002+
{
1003+
h.path.clear();
9781004
}
979-
h.path.clear();
9801005
}
9811006

9821007
inline win32_9xa_dir_handle win32_9xa_dir_dup_impl(win32_9xa_dir_handle const &h)

0 commit comments

Comments
 (0)