From 6b992e496f4c054909c6eb6708e5188a8ff0bc1b Mon Sep 17 00:00:00 2001 From: Force Charlie Date: Mon, 26 Aug 2024 23:05:32 +0800 Subject: [PATCH] Sync bela and wsudo add --retain --- .vscode/settings.json | 3 +- lib/exec/appcontainer.cc | 24 ++- lib/exec/exec.hpp | 1 + vendor/bela.lock | 2 +- vendor/bela/CMakeLists.txt | 8 +- vendor/bela/ReadMe.md | 2 +- vendor/bela/include/bela/__phmap/VERSION | 2 +- vendor/bela/include/bela/__phmap/phmap.h | 29 ++- .../bela/include/bela/__phmap/phmap_config.h | 9 + vendor/bela/include/bela/charconv.hpp | 140 +++++++------ vendor/bela/src/belahash/blake3.lock | 2 +- vendor/bela/src/belahash/blake3/.gitignore | 3 + .../bela/src/belahash/blake3/CMakeLists.txt | 192 ++++++++++++------ vendor/bela/src/belahash/blake3/blake3.c | 25 +-- vendor/bela/src/belahash/blake3/blake3.h | 2 +- .../src/belahash/blake3/blake3_dispatch.c | 11 +- vendor/bela/src/belahash/blake3/blake3_impl.h | 4 +- vendor/bela/src/belahash/blake3/blake3_neon.c | 8 +- wsudo/wsudo.cc | 8 +- wsudo/wsudo.hpp | 1 + 20 files changed, 292 insertions(+), 184 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bf23b315..1d3f7cc0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -88,5 +88,6 @@ "any": "cpp", "codecvt": "cpp", "ranges": "cpp" - } + }, + "cmake.configureOnOpen": true } \ No newline at end of file diff --git a/lib/exec/appcontainer.cc b/lib/exec/appcontainer.cc index ff7f862e..7a038b99 100644 --- a/lib/exec/appcontainer.cc +++ b/lib/exec/appcontainer.cc @@ -3,7 +3,7 @@ #include #include #include -//#include +// #include #define PUGIXML_HEADER_ONLY 1 #include #include @@ -121,11 +121,16 @@ bool MakeDeriveSID(PSID &appcontainersid, capabilities_t &cas, appcommand &cmd, if (cmd.appid.empty()) { cmd.appid = appid; } - DeleteAppContainerProfile(cmd.appid.data()); // ignore error + if (!cmd.retain) { + DeleteAppContainerProfile(cmd.appid.data()); // ignore error + } if (CreateAppContainerProfile(cmd.appid.data(), cmd.appid.data(), cmd.appid.data(), (cas.empty() ? NULL : cas.data()), (DWORD)cas.size(), &appcontainersid) != S_OK) { - ec = bela::make_system_error_code(L"MakeDeriveSID "); - return false; + auto hr = ::DeriveAppContainerSidFromAppContainerName(cmd.appid.data(), &appcontainersid); + if (FAILED(hr)) { + ec = bela::make_system_error_code(L"MakeDeriveSID "); + return false; + } } return true; } @@ -170,11 +175,16 @@ bool MakeSID(PSID &appcontainersid, capabilities_t &cas, appcommand &cmd, bela:: if (cmd.appid.empty()) { cmd.appid = appid; } - DeleteAppContainerProfile(cmd.appid.data()); // ignore error + if (!cmd.retain) { + DeleteAppContainerProfile(cmd.appid.data()); // ignore error + } if (CreateAppContainerProfile(cmd.appid.data(), cmd.appid.data(), cmd.appid.data(), (cas.empty() ? NULL : cas.data()), (DWORD)cas.size(), &appcontainersid) != S_OK) { - ec = bela::make_system_error_code(L"MakeSID "); - return false; + auto hr = ::DeriveAppContainerSidFromAppContainerName(cmd.appid.data(), &appcontainersid); + if (FAILED(hr)) { + ec = bela::make_system_error_code(L"MakeDeriveSID "); + return false; + } } return true; } diff --git a/lib/exec/exec.hpp b/lib/exec/exec.hpp index 785f2637..983c77bb 100644 --- a/lib/exec/exec.hpp +++ b/lib/exec/exec.hpp @@ -51,6 +51,7 @@ struct appcommand { visible_t visible; uint32_t pid{0}; bool islpac{false}; + bool retain{false}; bool initialize(bela::error_code &ec); bool execute(bela::error_code &ec); }; diff --git a/vendor/bela.lock b/vendor/bela.lock index 1ab325e0..8abd5af4 100644 --- a/vendor/bela.lock +++ b/vendor/bela.lock @@ -1 +1 @@ -https://github.com/fcharlie/bela/tree/bec4b4ae18a7158c2060d1f0d73f042579f30b4e +https://github.com/fcharlie/bela/tree/d92666ad2af8316ad9902723813d201a6217097a diff --git a/vendor/bela/CMakeLists.txt b/vendor/bela/CMakeLists.txt index 356b7f25..4420f9e2 100644 --- a/vendor/bela/CMakeLists.txt +++ b/vendor/bela/CMakeLists.txt @@ -1,5 +1,5 @@ # bela sources -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.27) project(bela CXX C ASM) @@ -21,11 +21,11 @@ option(BELA_ENABLE_ASSEMBLY_FILES "bela enable assembly files" OFF) message(STATUS "CMAKE_ASM_COMPILER_ID ${CMAKE_ASM_COMPILER_ID}") if(NOT (DEFINED CMAKE_CXX_STANDARD)) - set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD 23) endif() -if(CMAKE_CXX_STANDARD LESS 20 OR CMAKE_CXX_STANDARD STREQUAL "98") - message(FATAL_ERROR "Bela requires C++20 or later") +if(CMAKE_CXX_STANDARD LESS 23 OR CMAKE_CXX_STANDARD STREQUAL "98") + message(FATAL_ERROR "Bela requires C++23 or later") endif() set(CMAKE_CXX_STANDARD_REQUIRED YES) diff --git a/vendor/bela/ReadMe.md b/vendor/bela/ReadMe.md index 209648b2..326dfa85 100644 --- a/vendor/bela/ReadMe.md +++ b/vendor/bela/ReadMe.md @@ -3,7 +3,7 @@ [![license badge](https://img.shields.io/github/license/fcharlie/bela.svg)](LICENSE) [![Master Branch Status](https://github.com/fcharlie/bela/workflows/BelaCI/badge.svg)](https://github.com/fcharlie/bela/actions) -Modern C++20 library collection, better development experience on Windows (10,11) +Modern C++23 library collection, better development experience on Windows (10,11) A lot of the code supports wchar_t based on Abseil modifications, some of which come from Visual C++ STL. diff --git a/vendor/bela/include/bela/__phmap/VERSION b/vendor/bela/include/bela/__phmap/VERSION index bbfbfaae..d3a07f59 100644 --- a/vendor/bela/include/bela/__phmap/VERSION +++ b/vendor/bela/include/bela/__phmap/VERSION @@ -1,2 +1,2 @@ https://github.com/greg7mdp/parallel-hashmap.git -65775fa09fecaa65d0b0022ab6bf091c0e509445 +10368163ab1f4367d2f0685b5928b1c973ebd1ec diff --git a/vendor/bela/include/bela/__phmap/phmap.h b/vendor/bela/include/bela/__phmap/phmap.h index 87812bd2..d9a5b7b0 100644 --- a/vendor/bela/include/bela/__phmap/phmap.h +++ b/vendor/bela/include/bela/__phmap/phmap.h @@ -206,19 +206,23 @@ constexpr bool IsNoThrowSwappable(std::false_type /* is_swappable */) { // -------------------------------------------------------------------------- template uint32_t TrailingZeros(T x) { + uint32_t res; PHMAP_IF_CONSTEXPR(sizeof(T) == 8) - return base_internal::CountTrailingZerosNonZero64(static_cast(x)); + res = base_internal::CountTrailingZerosNonZero64(static_cast(x)); else - return base_internal::CountTrailingZerosNonZero32(static_cast(x)); + res = base_internal::CountTrailingZerosNonZero32(static_cast(x)); + return res; } // -------------------------------------------------------------------------- template uint32_t LeadingZeros(T x) { + uint32_t res; PHMAP_IF_CONSTEXPR(sizeof(T) == 8) - return base_internal::CountLeadingZeros64(static_cast(x)); + res = base_internal::CountLeadingZeros64(static_cast(x)); else - return base_internal::CountLeadingZeros32(static_cast(x)); + res = base_internal::CountLeadingZeros32(static_cast(x)); + return res; } // -------------------------------------------------------------------------- @@ -424,14 +428,10 @@ struct GroupSse2Impl #endif } -#ifdef __INTEL_COMPILER -#pragma warning push -#pragma warning disable 68 -#endif // Returns a bitmask representing the positions of empty or deleted slots. // ----------------------------------------------------------------------- BitMask MatchEmptyOrDeleted() const { - auto special = _mm_set1_epi8(static_cast(kSentinel)); + auto special = _mm_set1_epi8(static_cast(kSentinel)); return BitMask( static_cast(_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)))); } @@ -439,13 +439,10 @@ struct GroupSse2Impl // Returns the number of trailing empty or deleted elements in the group. // ---------------------------------------------------------------------- uint32_t CountLeadingEmptyOrDeleted() const { - auto special = _mm_set1_epi8(static_cast(kSentinel)); + auto special = _mm_set1_epi8(static_cast(kSentinel)); return TrailingZeros( static_cast(_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)) + 1)); } -#ifdef __INTEL_COMPILER -#pragma warning pop -#endif // ---------------------------------------------------------------------- void ConvertSpecialToEmptyAndFullToDeleted(ctrl_t* dst) const { @@ -581,8 +578,7 @@ inline size_t CapacityToGrowth(size_t capacity) assert(IsValidCapacity(capacity)); // `capacity*7/8` PHMAP_IF_CONSTEXPR (Group::kWidth == 8) { - if (capacity == 7) - { + if (capacity == 7) { // x-x/8 does not work when x==7. return 6; } @@ -598,8 +594,7 @@ inline size_t GrowthToLowerboundCapacity(size_t growth) { // `growth*8/7` PHMAP_IF_CONSTEXPR (Group::kWidth == 8) { - if (growth == 7) - { + if (growth == 7) { // x+(x-1)/7 does not work when x==7. return 8; } diff --git a/vendor/bela/include/bela/__phmap/phmap_config.h b/vendor/bela/include/bela/__phmap/phmap_config.h index b2e86549..a871ba0a 100644 --- a/vendor/bela/include/bela/__phmap/phmap_config.h +++ b/vendor/bela/include/bela/__phmap/phmap_config.h @@ -650,6 +650,15 @@ #define PHMAP_IF_CONSTEXPR(expr) if ((expr)) #endif +// ---------------------------------------------------------------------- +// builtin unreachable +// ---------------------------------------------------------------------- +#if PHMAP_HAVE_BUILTIN(__builtin_unreachable) + #define PHMAP_BUILTIN_UNREACHABLE() __builtin_unreachable() +#else + #define PHMAP_BUILTIN_UNREACHABLE() (void)0 +#endif + // ---------------------------------------------------------------------- // base/macros.h // ---------------------------------------------------------------------- diff --git a/vendor/bela/include/bela/charconv.hpp b/vendor/bela/include/bela/charconv.hpp index 659edb50..b3aff583 100644 --- a/vendor/bela/include/bela/charconv.hpp +++ b/vendor/bela/include/bela/charconv.hpp @@ -76,6 +76,7 @@ namespace std { } // namespace std */ +#include #include #include #include "macros.hpp" @@ -217,11 +218,14 @@ template struct __traits : __traits_base { } // namespace __itoa template -requires std::unsigned_integral -inline I __complement(I __x) { return I(~__x + 1); } + requires std::unsigned_integral +inline I __complement(I __x) { + return I(~__x + 1); +} template -requires std::unsigned_integral to_chars_result __to_chars_itoa(wchar_t *__first, wchar_t *__last, I __value) { + requires std::unsigned_integral +to_chars_result __to_chars_itoa(wchar_t *__first, wchar_t *__last, I __value) { using __tx = __itoa::__traits; auto __diff = __last - __first; @@ -232,7 +236,8 @@ requires std::unsigned_integral to_chars_result __to_chars_itoa(wchar_t *__fi } template -requires std::signed_integral to_chars_result __to_chars_itoa(wchar_t *__first, wchar_t *__last, I __value) { + requires std::signed_integral +to_chars_result __to_chars_itoa(wchar_t *__first, wchar_t *__last, I __value) { auto __x = bela::unsigned_cast(__value); if (__value < 0 && __first != __last) { *__first++ = '-'; @@ -285,7 +290,7 @@ template struct __integral; template <> struct __integral<2> { template - requires std::unsigned_integral + requires std::unsigned_integral static constexpr int __width(I __value) noexcept { // If value == 0 still need one digit. If the value != this has no // effect since the code scans for the most significant bit set. (Note @@ -294,7 +299,7 @@ template <> struct __integral<2> { } template - requires std::unsigned_integral + requires std::unsigned_integral static to_chars_result __to_chars(wchar_t *__first, wchar_t *__last, I __value) { ptrdiff_t __cap = __last - __first; int __n = __width(__value); @@ -321,7 +326,7 @@ template <> struct __integral<2> { template <> struct __integral<8> { template - requires std::unsigned_integral + requires std::unsigned_integral static constexpr int __width(I __value) noexcept { // If value == 0 still need one digit. If the value != this has no // effect since the code scans for the most significat bit set. (Note @@ -330,7 +335,7 @@ template <> struct __integral<8> { } template - requires std::unsigned_integral + requires std::unsigned_integral static to_chars_result __to_chars(wchar_t *__first, wchar_t *__last, I __value) { ptrdiff_t __cap = __last - __first; int __n = __width(__value); @@ -357,7 +362,7 @@ template <> struct __integral<8> { template <> struct __integral<16> { template - requires std::unsigned_integral + requires std::unsigned_integral static constexpr int __width(I __value) noexcept { // If value == 0 still need one digit. If the value != this has no // effect since the code scans for the most significat bit set. (Note @@ -366,7 +371,7 @@ template <> struct __integral<16> { } template - requires std::unsigned_integral + requires std::unsigned_integral static to_chars_result __to_chars(wchar_t *__first, wchar_t *__last, I __value) { ptrdiff_t __cap = __last - __first; int __n = __width(__value); @@ -397,29 +402,32 @@ template concept conversion_required = std::unsigned_integral && sizeof(I) < sizeof(unsigned); template -requires(!conversion_required) int __to_chars_integral_width(I __value) { + requires(!conversion_required) +int __to_chars_integral_width(I __value) { return __itoa::__integral::__width(__value); } template -requires conversion_required + requires conversion_required int __to_chars_integral_width(I __value) { // return bela::__to_chars_integral_width(static_cast(__value)); } template -requires(!conversion_required) to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value) { + requires(!conversion_required) +to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value) { return __itoa::__integral::__to_chars(__first, __last, __value); } template -requires conversion_required to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value) { + requires conversion_required +to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value) { return bela::__to_chars_integral(__first, __last, static_cast(__value)); } template -requires std::unsigned_integral + requires std::unsigned_integral int __to_chars_integral_width(I __value, unsigned __base) { unsigned __base_2 = __base * __base; unsigned __base_3 = __base_2 * __base; @@ -444,8 +452,8 @@ int __to_chars_integral_width(I __value, unsigned __base) { } template -requires std::unsigned_integral to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value, - int __base) { + requires std::unsigned_integral +to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value, int __base) { if (__base == 10) { return __to_chars_itoa(__first, __last, __value); } @@ -474,8 +482,8 @@ requires std::unsigned_integral to_chars_result __to_chars_integral(wchar_t * } template -requires std::signed_integral to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value, - int __base) { + requires std::signed_integral +to_chars_result __to_chars_integral(wchar_t *__first, wchar_t *__last, I __value, int __base) { auto __x = bela::unsigned_cast(__value); if (__value < 0 && __first != __last) { *__first++ = '-'; @@ -485,8 +493,8 @@ requires std::signed_integral to_chars_result __to_chars_integral(wchar_t *__ } template -requires bela::charconv_affirmed to_chars_result to_chars(wchar_t *first, wchar_t *last, I val, const int base) -noexcept { + requires bela::charconv_affirmed +to_chars_result to_chars(wchar_t *first, wchar_t *last, I val, const int base) noexcept { _BELA_ASSERT(2 <= base && base <= 36, "base not in [2, 36]"); if (base == 10) { return __to_chars_itoa(first, last, val); @@ -495,8 +503,10 @@ noexcept { } template -requires bela::charconv_affirmed to_chars_result to_chars(wchar_t *first, wchar_t *last, I val) -noexcept { return __to_chars_itoa(first, last, val); } + requires bela::charconv_affirmed +to_chars_result to_chars(wchar_t *first, wchar_t *last, I val) noexcept { + return __to_chars_itoa(first, last, val); +} struct from_chars_result { const wchar_t *ptr; @@ -590,7 +600,7 @@ inline from_chars_result __subject_seq_combinator(_It __first, _It __last, I &__ } template -requires std::unsigned_integral + requires std::unsigned_integral inline from_chars_result __from_chars_atoi(const wchar_t *__first, const wchar_t *__last, I &__value) { using __tx = __itoa::__traits; using __output_type = typename __tx::type; @@ -611,14 +621,14 @@ inline from_chars_result __from_chars_atoi(const wchar_t *__first, const wchar_t } template -requires std::signed_integral + requires std::signed_integral inline from_chars_result __from_chars_atoi(const wchar_t *__first, const wchar_t *__last, I &__value) { using __t = decltype(bela::unsigned_cast(__value)); return __sign_combinator(__first, __last, __value, __from_chars_atoi<__t>); } template -requires std::unsigned_integral + requires std::unsigned_integral inline from_chars_result __from_chars_integral(const wchar_t *__first, const wchar_t *__last, I &__value, int __base) { if (__base == 10) { return __from_chars_atoi(__first, __last, __value); @@ -657,7 +667,7 @@ inline from_chars_result __from_chars_integral(const wchar_t *__first, const wch } template -requires std::signed_integral + requires std::signed_integral inline from_chars_result __from_chars_integral(const wchar_t *__first, const wchar_t *__last, I &__value, const int __base) noexcept { using __t = decltype(bela::unsigned_cast(__value)); @@ -665,13 +675,13 @@ inline from_chars_result __from_chars_integral(const wchar_t *__first, const wch } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline from_chars_result from_chars(const wchar_t *first, const wchar_t *last, I &value) noexcept { return __from_chars_atoi(first, last, value); } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline from_chars_result from_chars(const wchar_t *first, const wchar_t *last, I &value, const int base) noexcept { _BELA_ASSERT(2 <= base && base <= 36, "base not in [2, 36]"); return __from_chars_integral(first, last, value, base); @@ -694,11 +704,13 @@ to_chars_result to_chars(wchar_t *const first, wchar_t *const last, const long d const int precision) noexcept; template -requires std::floating_point -inline auto to_chars(wchar_t *first, wchar_t *last, F value) noexcept { return to_chars(first, last, value); } + requires std::floating_point +inline auto to_chars(wchar_t *first, wchar_t *last, F value) noexcept { + return to_chars(first, last, value); +} template -requires std::floating_point + requires std::floating_point inline auto to_chars(wchar_t *first, wchar_t *last, F value, chars_format fmt) { return to_chars(first, last, value, fmt); } @@ -712,27 +724,31 @@ from_chars_result from_chars(const wchar_t *const first, const wchar_t *const la // Additional wrapper functions template -requires bela::charconv_affirmed -inline auto to_chars(wchar_t (&a)[N], I val, int base = 10) { return to_chars(a, a + N, val, base); } + requires bela::charconv_affirmed +inline auto to_chars(wchar_t (&a)[N], I val, int base = 10) { + return to_chars(a, a + N, val, base); +} template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto to_chars(char16_t (&a)[N], I val, int base = 10) { return to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, base); } template -requires bela::charconv_affirmed -inline auto to_chars(char (&a)[N], I val, int base = 10) { return std::to_chars(a, a + N, val, base); } + requires bela::charconv_affirmed +inline auto to_chars(char (&a)[N], I val, int base = 10) { + return std::to_chars(a, a + N, val, base); +} template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto to_chars(char8_t (&a)[N], I val, int base = 10) { return std::to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, base); } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto to_chars_view(wchar_t (&a)[N], I val, int base = 10) { if (auto res = to_chars(a, a + N, val, base); res) { return std::wstring_view{a, static_cast(res.ptr - a)}; @@ -741,7 +757,7 @@ inline auto to_chars_view(wchar_t (&a)[N], I val, int base = 10) { } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto to_chars_view(char16_t (&a)[N], I val, int base = 10) { if (auto res = to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, base); res) { return std::u16string_view{a, static_cast(reinterpret_cast(res.ptr) - a)}; @@ -750,7 +766,7 @@ inline auto to_chars_view(char16_t (&a)[N], I val, int base = 10) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(wchar_t (&a)[N], F val) { if (auto res = to_chars(a, a + N, val); res) { return std::wstring_view{a, static_cast(res.ptr - a)}; @@ -759,7 +775,7 @@ inline auto to_chars_view(wchar_t (&a)[N], F val) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char16_t (&a)[N], F val) { if (auto res = to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val); res) { return std::u16string_view{a, static_cast(reinterpret_cast(res.ptr) - a)}; @@ -768,7 +784,7 @@ inline auto to_chars_view(char16_t (&a)[N], F val) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(wchar_t (&a)[N], F val, chars_format fmt) { if (auto res = to_chars(a, a + N, val, fmt); res) { return std::wstring_view{a, static_cast(res.ptr - a)}; @@ -777,7 +793,7 @@ inline auto to_chars_view(wchar_t (&a)[N], F val, chars_format fmt) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char16_t (&a)[N], F val, chars_format fmt) { if (auto res = to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, fmt); res) { return std::u16string_view{a, static_cast(reinterpret_cast(res.ptr) - a)}; @@ -786,7 +802,7 @@ inline auto to_chars_view(char16_t (&a)[N], F val, chars_format fmt) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(wchar_t (&a)[N], F val, chars_format fmt, int precision) { if (auto res = to_chars(a, a + N, val, fmt, precision); res) { return std::wstring_view{a, static_cast(res.ptr - a)}; @@ -795,7 +811,7 @@ inline auto to_chars_view(wchar_t (&a)[N], F val, chars_format fmt, int precisio } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char16_t (&a)[N], F val, chars_format fmt, int precision) { if (auto res = to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, fmt, precision); res) { @@ -805,27 +821,27 @@ inline auto to_chars_view(char16_t (&a)[N], F val, chars_format fmt, int precisi } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto from_string_view(std::wstring_view sv, I &value) { return __from_chars_atoi(sv.data(), sv.data() + sv.size(), value); } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto from_string_view(std::u16string_view sv, I &value) { return __from_chars_atoi(reinterpret_cast(sv.data()), reinterpret_cast(sv.data() + sv.size()), value); } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto from_string_view(std::wstring_view sv, I &value, int base) { _BELA_ASSERT(2 <= base && base <= 36, "base not in [2, 36]"); return __from_chars_integral(sv.data(), sv.data() + sv.size(), value, base); } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto from_string_view(std::u16string_view sv, I &value, int base) { _BELA_ASSERT(2 <= base && base <= 36, "base not in [2, 36]"); return __from_chars_integral(reinterpret_cast(sv.data()), @@ -834,13 +850,13 @@ inline auto from_string_view(std::u16string_view sv, I &value, int base) { // bela::charconv float template -requires std::floating_point + requires std::floating_point inline auto from_string_view(std::wstring_view sv, F &value, chars_format fmt = chars_format::general) { return from_chars(sv.data(), sv.data() + sv.size(), value, fmt); } template -requires std::floating_point + requires std::floating_point inline auto from_string_view(std::u16string_view sv, F &value, chars_format fmt = chars_format::general) { return from_chars(reinterpret_cast(sv.data()), reinterpret_cast(sv.data() + sv.size()), value, fmt); @@ -848,7 +864,7 @@ inline auto from_string_view(std::u16string_view sv, F &value, chars_format fmt // std::charconv template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto to_chars_view(char (&a)[N], I val, int base = 10) { if (auto res = std::to_chars(a, a + N, val, base); res.ec == successful) { return std::string_view{a, static_cast(res.ptr - a)}; @@ -857,7 +873,7 @@ inline auto to_chars_view(char (&a)[N], I val, int base = 10) { } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto to_chars_view(char8_t (&a)[N], I val, int base = 10) { if (auto res = std::to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, base); res.ec == successful) { @@ -869,7 +885,7 @@ inline auto to_chars_view(char8_t (&a)[N], I val, int base = 10) { ///////// std::charconv float template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char (&a)[N], F val, chars_format fmt) { if (auto res = std::to_chars(a, a + N, val, fmt); res.ec == successful) { return std::string_view{a, static_cast(res.ptr - a)}; @@ -878,7 +894,7 @@ inline auto to_chars_view(char (&a)[N], F val, chars_format fmt) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char8_t (&a)[N], F val, chars_format fmt) { if (auto res = std::to_chars(reinterpret_cast(a), reinterpret_cast(a + N), val, fmt); res.ec == successful) { @@ -888,7 +904,7 @@ inline auto to_chars_view(char8_t (&a)[N], F val, chars_format fmt) { } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char (&a)[N], F val, chars_format fmt, int precision) { if (auto res = std::to_chars(a, a + N, val, fmt, precision); res) { return std::string_view{a, static_cast(res.ptr - a)}; @@ -897,7 +913,7 @@ inline auto to_chars_view(char (&a)[N], F val, chars_format fmt, int precision) } template -requires std::floating_point + requires std::floating_point inline auto to_chars_view(char8_t (&a)[N], F val, chars_format fmt, int precision) { if (auto res = std::to_chars(reinterpret_cast(a), reinterpret_cast(a + N), fmt, precision); res) { return std::u8string_view{a, static_cast(reinterpret_cast(res.ptr) - a)}; @@ -906,14 +922,14 @@ inline auto to_chars_view(char8_t (&a)[N], F val, chars_format fmt, int precisio } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto from_string_view(std::string_view sv, I &value, int base = 10) { _BELA_ASSERT(2 <= base && base <= 36, "base not in [2, 36]"); return std::from_chars(sv.data(), sv.data() + sv.size(), value, base); } template -requires bela::charconv_affirmed + requires bela::charconv_affirmed inline auto from_string_view(std::u8string_view sv, I &value, int base = 10) { _BELA_ASSERT(2 <= base && base <= 36, "base not in [2, 36]"); return std::from_chars(reinterpret_cast(sv.data()), @@ -921,13 +937,13 @@ inline auto from_string_view(std::u8string_view sv, I &value, int base = 10) { } template -requires std::floating_point + requires std::floating_point inline auto from_string_view(std::string_view sv, F &value, chars_format fmt = chars_format::general) { return std::from_chars(sv.data(), sv.data() + sv.size(), value, fmt); } template -requires std::floating_point + requires std::floating_point inline auto from_string_view(std::u8string_view sv, F &value, chars_format fmt = chars_format::general) { return std::from_chars(reinterpret_cast(sv.data()), reinterpret_cast(sv.data() + sv.size()), value, fmt); diff --git a/vendor/bela/src/belahash/blake3.lock b/vendor/bela/src/belahash/blake3.lock index 74922d5f..11c8febe 100644 --- a/vendor/bela/src/belahash/blake3.lock +++ b/vendor/bela/src/belahash/blake3.lock @@ -1,2 +1,2 @@ https://github.com/BLAKE3-team/BLAKE3 -4d32708f511fd85c6b0fb131295cc73224246738 +fc2f7e4206f016b0cac0593f23a7d5976ce066e6 diff --git a/vendor/bela/src/belahash/blake3/.gitignore b/vendor/bela/src/belahash/blake3/.gitignore index 0bf608ce..ff52a803 100644 --- a/vendor/bela/src/belahash/blake3/.gitignore +++ b/vendor/bela/src/belahash/blake3/.gitignore @@ -1,3 +1,6 @@ blake3 example +build/ *.o + +CMakeUserPresets.json diff --git a/vendor/bela/src/belahash/blake3/CMakeLists.txt b/vendor/bela/src/belahash/blake3/CMakeLists.txt index 47706d1a..3d674f96 100644 --- a/vendor/bela/src/belahash/blake3/CMakeLists.txt +++ b/vendor/bela/src/belahash/blake3/CMakeLists.txt @@ -1,7 +1,16 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) + +# respect C_EXTENSIONS OFF without explicitly setting C_STANDARD +if (POLICY CMP0128) + cmake_policy(SET CMP0128 NEW) +endif() +# mark_as_advanced does not implicitly create UNINITIALIZED cache entries +if (POLICY CMP0102) + cmake_policy(SET CMP0102 NEW) +endif() project(libblake3 - VERSION 1.4.0 + VERSION 1.5.2 DESCRIPTION "BLAKE3 C implementation" LANGUAGES C ASM ) @@ -9,14 +18,25 @@ project(libblake3 include(FeatureSummary) include(GNUInstallDirs) +# architecture lists for which to enable assembly / SIMD sources +set(BLAKE3_AMD64_NAMES amd64 AMD64 x86_64) +set(BLAKE3_X86_NAMES i686 x86 X86) +set(BLAKE3_ARMv8_NAMES aarch64 AArch64 arm64 ARM64 armv8 armv8a) # default SIMD compiler flag configuration (can be overriden by toolchains or CLI) -if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") +if(MSVC) set(BLAKE3_CFLAGS_SSE2 "/arch:SSE2" CACHE STRING "the compiler flags to enable SSE2") # MSVC has no dedicated sse4.1 flag (see https://learn.microsoft.com/en-us/cpp/build/reference/arch-x86?view=msvc-170) set(BLAKE3_CFLAGS_SSE4.1 "/arch:AVX" CACHE STRING "the compiler flags to enable SSE4.1") set(BLAKE3_CFLAGS_AVX2 "/arch:AVX2" CACHE STRING "the compiler flags to enable AVX2") set(BLAKE3_CFLAGS_AVX512 "/arch:AVX512" CACHE STRING "the compiler flags to enable AVX512") + set(BLAKE3_AMD64_ASM_SOURCES + blake3_avx2_x86-64_windows_msvc.asm + blake3_avx512_x86-64_windows_msvc.asm + blake3_sse2_x86-64_windows_msvc.asm + blake3_sse41_x86-64_windows_msvc.asm + ) + elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") @@ -24,11 +44,71 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" set(BLAKE3_CFLAGS_SSE4.1 "-msse4.1" CACHE STRING "the compiler flags to enable SSE4.1") set(BLAKE3_CFLAGS_AVX2 "-mavx2" CACHE STRING "the compiler flags to enable AVX2") set(BLAKE3_CFLAGS_AVX512 "-mavx512f -mavx512vl" CACHE STRING "the compiler flags to enable AVX512") + + if (WIN32) + set(BLAKE3_AMD64_ASM_SOURCES + blake3_avx2_x86-64_windows_gnu.S + blake3_avx512_x86-64_windows_gnu.S + blake3_sse2_x86-64_windows_gnu.S + blake3_sse41_x86-64_windows_gnu.S + ) + + elseif(UNIX) + set(BLAKE3_AMD64_ASM_SOURCES + blake3_avx2_x86-64_unix.S + blake3_avx512_x86-64_unix.S + blake3_sse2_x86-64_unix.S + blake3_sse41_x86-64_unix.S + ) + endif() + + if (CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_ARMv8_NAMES + AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8) + # 32-bit ARMv8 needs NEON to be enabled explicitly + set(BLAKE3_CFLAGS_NEON "-mfpu=neon" CACHE STRING "the compiler flags to enable NEON") + endif() endif() -# architecture lists for which to enable assembly / SIMD sources -set(BLAKE3_AMD64_NAMES amd64 AMD64 x86_64) -set(BLAKE3_X86_NAMES i686 x86 X86) -set(BLAKE3_ARMv8_NAMES aarch64 AArch64 arm64 ARM64 armv8 armv8a) + +mark_as_advanced(BLAKE3_CFLAGS_SSE2 BLAKE3_CFLAGS_SSE4.1 BLAKE3_CFLAGS_AVX2 BLAKE3_CFLAGS_AVX512 BLAKE3_CFLAGS_NEON) +mark_as_advanced(BLAKE3_AMD64_ASM_SOURCES) + +message(STATUS "BLAKE3 SIMD configuration: ${CMAKE_C_COMPILER_ARCHITECTURE_ID}") +if(MSVC AND DEFINED CMAKE_C_COMPILER_ARCHITECTURE_ID) + if(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "[Xx]86") + set(BLAKE3_SIMD_TYPE "x86-intrinsics" CACHE STRING "the SIMD acceleration type to use") + + elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "[Xx]64") + set(BLAKE3_SIMD_TYPE "amd64-asm" CACHE STRING "the SIMD acceleration type to use") + + elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "[Aa][Rr][Mm]64") + set(BLAKE3_SIMD_TYPE "neon-intrinsics" CACHE STRING "the SIMD acceleration type to use") + + else() + set(BLAKE3_SIMD_TYPE "none" CACHE STRING "the SIMD acceleration type to use") + endif() + +elseif(CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_AMD64_NAMES) + set(BLAKE3_SIMD_TYPE "amd64-asm" CACHE STRING "the SIMD acceleration type to use") + +elseif(CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_X86_NAMES + AND DEFINED BLAKE3_CFLAGS_SSE2 + AND DEFINED BLAKE3_CFLAGS_SSE4.1 + AND DEFINED BLAKE3_CFLAGS_AVX2 + AND DEFINED BLAKE3_CFLAGS_AVX512) + set(BLAKE3_SIMD_TYPE "x86-intrinsics" CACHE STRING "the SIMD acceleration type to use") + +elseif((CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_ARMv8_NAMES + OR ANDROID_ABI STREQUAL "armeabi-v7a" + OR BLAKE3_USE_NEON_INTRINSICS) + AND (DEFINED BLAKE3_CFLAGS_NEON + OR CMAKE_SIZEOF_VOID_P EQUAL 8)) + set(BLAKE3_SIMD_TYPE "neon-intrinsics" CACHE STRING "the SIMD acceleration type to use") + +else() + set(BLAKE3_SIMD_TYPE "none" CACHE STRING "the SIMD acceleration type to use") +endif() + +mark_as_advanced(BLAKE3_SIMD_TYPE) # library target add_library(blake3 @@ -41,73 +121,49 @@ add_library(BLAKE3::blake3 ALIAS blake3) # library configuration set(BLAKE3_PKGCONFIG_CFLAGS) if (BUILD_SHARED_LIBS) - target_compile_definitions(blake3 + target_compile_definitions(blake3 PUBLIC BLAKE3_DLL PRIVATE BLAKE3_DLL_EXPORTS ) list(APPEND BLAKE3_PKGCONFIG_CFLAGS -DBLAKE3_DLL) endif() -target_include_directories(blake3 PUBLIC $) +target_include_directories(blake3 PUBLIC + $ + $ +) set_target_properties(blake3 PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 0 C_VISIBILITY_PRESET hidden + C_EXTENSIONS OFF ) +target_compile_features(blake3 PUBLIC c_std_99) +# ensure C_EXTENSIONS OFF is respected without overriding CMAKE_C_STANDARD +# which may be set by the user or toolchain file +if (NOT POLICY CMP0128 AND NOT DEFINED CMAKE_C_STANDARD) + set_target_properties(blake3 PROPERTIES C_STANDARD 99) +endif() # optional SIMD sources -macro(BLAKE3_DISABLE_SIMD) - set(BLAKE3_SIMD_AMD64_ASM OFF) - set(BLAKE3_SIMD_X86_INTRINSICS OFF) - set(BLAKE3_SIMD_NEON_INTRINSICS OFF) - set_source_files_properties(blake3_dispatch.c PROPERTIES - COMPILE_DEFINITIONS BLAKE3_USE_NEON=0;BLAKE3_NO_SSE2;BLAKE3_NO_SSE41;BLAKE3_NO_AVX2;BLAKE3_NO_AVX512 - ) -endmacro() - -if(CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_AMD64_NAMES OR BLAKE3_USE_AMD64_ASM) +if(BLAKE3_SIMD_TYPE STREQUAL "amd64-asm") + if (NOT DEFINED BLAKE3_AMD64_ASM_SOURCES) + message(FATAL_ERROR "BLAKE3_SIMD_TYPE is set to 'amd64-asm' but no assembly sources are available for the target architecture.") + endif() set(BLAKE3_SIMD_AMD64_ASM ON) - if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") + if(MSVC) enable_language(ASM_MASM) - target_sources(blake3 PRIVATE - blake3_avx2_x86-64_windows_msvc.asm - blake3_avx512_x86-64_windows_msvc.asm - blake3_sse2_x86-64_windows_msvc.asm - blake3_sse41_x86-64_windows_msvc.asm - ) - - elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" - OR CMAKE_C_COMPILER_ID STREQUAL "Clang" - OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - if (WIN32) - target_sources(blake3 PRIVATE - blake3_avx2_x86-64_windows_gnu.S - blake3_avx512_x86-64_windows_gnu.S - blake3_sse2_x86-64_windows_gnu.S - blake3_sse41_x86-64_windows_gnu.S - ) - - elseif(UNIX) - target_sources(blake3 PRIVATE - blake3_avx2_x86-64_unix.S - blake3_avx512_x86-64_unix.S - blake3_sse2_x86-64_unix.S - blake3_sse41_x86-64_unix.S - ) - - else() - BLAKE3_DISABLE_SIMD() - endif() - - else() - BLAKE3_DISABLE_SIMD() endif() -elseif((CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_X86_NAMES OR BLAKE3_USE_X86_INTRINSICS) - AND DEFINED BLAKE3_CFLAGS_SSE2 - AND DEFINED BLAKE3_CFLAGS_SSE4.1 - AND DEFINED BLAKE3_CFLAGS_AVX2 - AND DEFINED BLAKE3_CFLAGS_AVX512) + target_sources(blake3 PRIVATE ${BLAKE3_AMD64_ASM_SOURCES}) + +elseif(BLAKE3_SIMD_TYPE STREQUAL "x86-intrinsics") + if (NOT DEFINED BLAKE3_CFLAGS_SSE2 + OR NOT DEFINED BLAKE3_CFLAGS_SSE4.1 + OR NOT DEFINED BLAKE3_CFLAGS_AVX2 + OR NOT DEFINED BLAKE3_CFLAGS_AVX512) + message(FATAL_ERROR "BLAKE3_SIMD_TYPE is set to 'x86-intrinsics' but no compiler flags are available for the target architecture.") + endif() set(BLAKE3_SIMD_X86_INTRINSICS ON) target_sources(blake3 PRIVATE @@ -121,24 +177,31 @@ elseif((CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_X86_NAMES OR BLAKE3_USE_X86_INTRIN set_source_files_properties(blake3_sse2.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_SSE2}") set_source_files_properties(blake3_sse41.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_SSE4.1}") -elseif(CMAKE_SYSTEM_PROCESSOR IN_LIST BLAKE3_ARMv8_NAMES - OR ((ANDROID_ABI STREQUAL "armeabi-v7a" - OR BLAKE3_USE_NEON_INTRINSICS) - AND (DEFINED BLAKE3_CFLAGS_NEON - OR CMAKE_SIZEOF_VOID_P EQUAL 8))) +elseif(BLAKE3_SIMD_TYPE STREQUAL "neon-intrinsics") set(BLAKE3_SIMD_NEON_INTRINSICS ON) target_sources(blake3 PRIVATE blake3_neon.c ) - set_source_files_properties(blake3_dispatch.c PROPERTIES COMPILE_DEFINITIONS BLAKE3_USE_NEON=1) + target_compile_definitions(blake3 PRIVATE + BLAKE3_USE_NEON=1 + ) if (DEFINED BLAKE3_CFLAGS_NEON) set_source_files_properties(blake3_neon.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_NEON}") endif() +elseif(BLAKE3_SIMD_TYPE STREQUAL "none") + target_compile_definitions(blake3 PRIVATE + BLAKE3_USE_NEON=0 + BLAKE3_NO_SSE2 + BLAKE3_NO_SSE41 + BLAKE3_NO_AVX2 + BLAKE3_NO_AVX512 + ) + else() - BLAKE3_DISABLE_SIMD() + message(FATAL_ERROR "BLAKE3_SIMD_TYPE is set to an unknown value: '${BLAKE3_SIMD_TYPE}'") endif() # cmake install support @@ -171,6 +234,7 @@ install(FILES "${CMAKE_BINARY_DIR}/libblake3.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # print feature summary +# add_feature_info cannot directly use the BLAKE3_SIMD_TYPE :( add_feature_info("AMD64 assembly" BLAKE3_SIMD_AMD64_ASM "The library uses hand written amd64 SIMD assembly.") add_feature_info("x86 SIMD intrinsics" BLAKE3_SIMD_X86_INTRINSICS "The library uses x86 SIMD intrinsics.") add_feature_info("NEON SIMD intrinsics" BLAKE3_SIMD_NEON_INTRINSICS "The library uses NEON SIMD intrinsics.") diff --git a/vendor/bela/src/belahash/blake3/blake3.c b/vendor/bela/src/belahash/blake3/blake3.c index 692f4b02..9becead0 100644 --- a/vendor/bela/src/belahash/blake3/blake3.c +++ b/vendor/bela/src/belahash/blake3/blake3.c @@ -134,9 +134,7 @@ INLINE void chunk_state_update(blake3_chunk_state *self, const uint8_t *input, input_len -= BLAKE3_BLOCK_LEN; } - size_t take = chunk_state_fill_buf(self, input, input_len); - input += take; - input_len -= take; + chunk_state_fill_buf(self, input, input_len); } INLINE output_t chunk_state_output(const blake3_chunk_state *self) { @@ -341,21 +339,24 @@ INLINE void compress_subtree_to_parent_node( size_t num_cvs = blake3_compress_subtree_wide(input, input_len, key, chunk_counter, flags, cv_array); assert(num_cvs <= MAX_SIMD_DEGREE_OR_2); - - // If MAX_SIMD_DEGREE is greater than 2 and there's enough input, + // The following loop never executes when MAX_SIMD_DEGREE_OR_2 is 2, because + // as we just asserted, num_cvs will always be <=2 in that case. But GCC + // (particularly GCC 8.5) can't tell that it never executes, and if NDEBUG is + // set then it emits incorrect warnings here. We tried a few different + // hacks to silence these, but in the end our hacks just produced different + // warnings (see https://github.com/BLAKE3-team/BLAKE3/pull/380). Out of + // desperation, we ifdef out this entire loop when we know it's not needed. +#if MAX_SIMD_DEGREE_OR_2 > 2 + // If MAX_SIMD_DEGREE_OR_2 is greater than 2 and there's enough input, // compress_subtree_wide() returns more than 2 chaining values. Condense // them into 2 by forming parent nodes repeatedly. uint8_t out_array[MAX_SIMD_DEGREE_OR_2 * BLAKE3_OUT_LEN / 2]; - // The second half of this loop condition is always true, and we just - // asserted it above. But GCC can't tell that it's always true, and if NDEBUG - // is set on platforms where MAX_SIMD_DEGREE_OR_2 == 2, GCC emits spurious - // warnings here. GCC 8.5 is particularly sensitive, so if you're changing - // this code, test it against that version. - while (num_cvs > 2 && num_cvs <= MAX_SIMD_DEGREE_OR_2) { + while (num_cvs > 2) { num_cvs = compress_parents_parallel(cv_array, num_cvs, key, flags, out_array); memcpy(cv_array, out_array, num_cvs * BLAKE3_OUT_LEN); } +#endif memcpy(out, cv_array, 2 * BLAKE3_OUT_LEN); } @@ -427,7 +428,7 @@ INLINE void hasher_merge_cv_stack(blake3_hasher *self, uint64_t total_len) { // of the whole tree, and it would need to be ROOT finalized. We can't // compress it until we know. // 2) This 64 KiB input might complete a larger tree, whose root node is -// similarly going to be the the root of the whole tree. For example, maybe +// similarly going to be the root of the whole tree. For example, maybe // we have 196 KiB (that is, 128 + 64) hashed so far. We can't compress the // node at the root of the 256 KiB subtree until we know how to finalize it. // diff --git a/vendor/bela/src/belahash/blake3/blake3.h b/vendor/bela/src/belahash/blake3/blake3.h index f694dcf2..c38545fe 100644 --- a/vendor/bela/src/belahash/blake3/blake3.h +++ b/vendor/bela/src/belahash/blake3/blake3.h @@ -30,7 +30,7 @@ extern "C" { #endif -#define BLAKE3_VERSION_STRING "1.5.0" +#define BLAKE3_VERSION_STRING "1.5.2" #define BLAKE3_KEY_LEN 32 #define BLAKE3_OUT_LEN 32 #define BLAKE3_BLOCK_LEN 64 diff --git a/vendor/bela/src/belahash/blake3/blake3_dispatch.c b/vendor/bela/src/belahash/blake3/blake3_dispatch.c index e681e871..c9abc13f 100644 --- a/vendor/bela/src/belahash/blake3/blake3_dispatch.c +++ b/vendor/bela/src/belahash/blake3/blake3_dispatch.c @@ -4,9 +4,12 @@ #include "blake3_impl.h" -#if defined(IS_X86) #if defined(_MSC_VER) #include +#endif + +#if defined(IS_X86) +#if defined(_MSC_VER) #include #elif defined(__GNUC__) #include @@ -32,9 +35,9 @@ #define ATOMIC_LOAD(x) x #define ATOMIC_STORE(x, y) x = y #elif defined(_MSC_VER) -#define ATOMIC_INT long -#define ATOMIC_LOAD(x) _InterlockedOr(&x, 0) -#define ATOMIC_STORE(x, y) _InterlockedExchange(&x, y) +#define ATOMIC_INT LONG +#define ATOMIC_LOAD(x) InterlockedOr(&x, 0) +#define ATOMIC_STORE(x, y) InterlockedExchange(&x, y) #else #define ATOMIC_INT int #define ATOMIC_LOAD(x) x diff --git a/vendor/bela/src/belahash/blake3/blake3_impl.h b/vendor/bela/src/belahash/blake3/blake3_impl.h index beab5cf5..98611c31 100644 --- a/vendor/bela/src/belahash/blake3/blake3_impl.h +++ b/vendor/bela/src/belahash/blake3/blake3_impl.h @@ -28,7 +28,7 @@ enum blake3_flags { #define INLINE static inline __attribute__((always_inline)) #endif -#if defined(__x86_64__) || defined(_M_X64) +#if (defined(__x86_64__) || defined(_M_X64)) && !defined(_M_ARM64EC) #define IS_X86 #define IS_X86_64 #endif @@ -38,7 +38,7 @@ enum blake3_flags { #define IS_X86_32 #endif -#if defined(__aarch64__) || defined(_M_ARM64) +#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) #define IS_AARCH64 #endif diff --git a/vendor/bela/src/belahash/blake3/blake3_neon.c b/vendor/bela/src/belahash/blake3/blake3_neon.c index 8a818fc7..53ce83c3 100644 --- a/vendor/bela/src/belahash/blake3/blake3_neon.c +++ b/vendor/bela/src/belahash/blake3/blake3_neon.c @@ -10,14 +10,12 @@ INLINE uint32x4_t loadu_128(const uint8_t src[16]) { // vld1q_u32 has alignment requirements. Don't use it. - uint32x4_t x; - memcpy(&x, src, 16); - return x; + return vreinterpretq_u32_u8(vld1q_u8(src)); } INLINE void storeu_128(uint32x4_t src, uint8_t dest[16]) { // vst1q_u32 has alignment requirements. Don't use it. - memcpy(dest, &src, 16); + vst1q_u8(dest, vreinterpretq_u8_u32(src)); } INLINE uint32x4_t add_128(uint32x4_t a, uint32x4_t b) { @@ -36,7 +34,7 @@ INLINE uint32x4_t set4(uint32_t a, uint32_t b, uint32_t c, uint32_t d) { } INLINE uint32x4_t rot16_128(uint32x4_t x) { - // The straightfoward implementation would be two shifts and an or, but that's + // The straightforward implementation would be two shifts and an or, but that's // slower on microarchitectures we've tested. See // https://github.com/BLAKE3-team/BLAKE3/pull/319. // return vorrq_u32(vshrq_n_u32(x, 16), vshlq_n_u32(x, 32 - 16)); diff --git a/wsudo/wsudo.cc b/wsudo/wsudo.cc index b2eb8849..4812b476 100644 --- a/wsudo/wsudo.cc +++ b/wsudo/wsudo.cc @@ -39,6 +39,7 @@ usage: wsudo command args... -L|--lpac Less Privileged AppContainer mode. --disable-alias Disable Privexec alias, By default, if Privexec exists alias, use it. --appid Set AppContainer ID name (compatible --appname) + --retain Retain AppContainer Profile (experimental) Select user can use the following flags: -a|--appcontainer AppContainer @@ -151,7 +152,8 @@ int App::ParseArgv(int argc, wchar_t **argv) { .Add(L"appid", bela::required_argument, 1001) .Add(L"disable-alias", bela::no_argument, 1002) .Add(L"appname", bela::required_argument, 1003) - .Add(L"new-console", bela::no_argument, 1004); + .Add(L"new-console", bela::no_argument, 1004) + .Add(L"retain", bela::no_argument, 1005); bela::error_code ec; auto result = pa.Execute( [&](int val, const wchar_t *va, const wchar_t *) { @@ -224,6 +226,9 @@ int App::ParseArgv(int argc, wchar_t **argv) { break; case 1004: break; + case 1005: + retain = true; + break; default: break; } @@ -329,6 +334,7 @@ int App::AppExecute() { cmd.cwd.assign(std::move(cwd)); cmd.islpac = lpac; cmd.visible = visible; + cmd.retain = retain; bela::error_code ec; if (!cmd.initialize(ec)) { bela::FPrintF(stderr, L"wsudo: initialize AppContainer: \x1b[31m%s\x1b[0m\n", ec.message); diff --git a/wsudo/wsudo.hpp b/wsudo/wsudo.hpp index dd0dcf3a..93b394dc 100644 --- a/wsudo/wsudo.hpp +++ b/wsudo/wsudo.hpp @@ -79,6 +79,7 @@ struct App { bool wait{false}; bool nowait{false}; bool console{true}; + bool retain{false}; int AppExecute(); int Execute(); int DelegateExecute();