diff --git a/misc/podman/rebuild-stubs/Dockerfile b/misc/podman/rebuild-stubs/Dockerfile index bbce87ff..8fbc1e2b 100644 --- a/misc/podman/rebuild-stubs/Dockerfile +++ b/misc/podman/rebuild-stubs/Dockerfile @@ -79,15 +79,17 @@ RUN useradd upx -U --uid 2000 --shell /bin/bash -m \ # symlink upx-stubtools && ln -s /usr/local/bin/bin-upx-20221212 .local/bin/bin-upx \ # some convenience settings according to upx developer preferences + && echo "alias path='echo PATH=\"\$PATH\"'" >> .bashrc \ && echo "alias md=mkdir" >> .bashrc \ && echo "alias rd=rmdir" >> .bashrc \ && echo 'mdd() { mkdir "$1" && cd "$1"; }' >> .bashrc \ && echo 'm() { make "$@"; }' >> .bashrc \ + && echo 'mm() { make -j8 "$@"; }' >> .bashrc \ && echo 'tn() { time nice "$@"; }' >> .bashrc \ && echo 'tnm() { time nice make "$@"; }' >> .bashrc \ - && echo 'tnmm() { time nice make -j "$@"; }' >> .bashrc \ + && echo 'tnmm() { time nice make -j8 "$@"; }' >> .bashrc \ && echo 'source /usr/share/bash-completion/completions/make' >> .bashrc \ - && echo 'complete -F _make m tnm tnmm' >> .bashrc \ + && echo 'complete -F _make m mm tnm tnmm' >> .bashrc \ && echo 'eval "$(zoxide init bash)"' >> .bashrc \ && echo "alias zz=zi\nalias y=z\nalias yy=zi" >> .bashrc \ && echo "alias cd..='cd ..'" >> .bashrc \ diff --git a/misc/podman/rebuild-stubs/packages.txt b/misc/podman/rebuild-stubs/packages.txt index 04d2e0d1..45eb7a11 100644 --- a/misc/podman/rebuild-stubs/packages.txt +++ b/misc/podman/rebuild-stubs/packages.txt @@ -230,7 +230,7 @@ ii libsqlite3-0:amd64 3.45.1-1ubuntu2 amd64 ii libss2:amd64 1.47.0-2.4~exp1ubuntu4 amd64 command-line interface parsing library ii libssh-4:amd64 0.10.6-2build2 amd64 tiny C SSH library (OpenSSL flavor) ii libssh2-1t64:amd64 1.11.0-4.1build2 amd64 SSH2 client-side library -ii libssl3t64:amd64 3.0.13-0ubuntu3 amd64 Secure Sockets Layer toolkit - shared libraries +ii libssl3t64:amd64 3.0.13-0ubuntu3.1 amd64 Secure Sockets Layer toolkit - shared libraries ii libstdc++-13-dev:amd64 13.2.0-23ubuntu4 amd64 GNU Standard C++ Library v3 (development files) ii libstdc++6:amd64 14-20240412-0ubuntu1 amd64 GNU Standard C++ Library v3 ii libsystemd0:amd64 255.4-1ubuntu8 amd64 systemd utility library @@ -297,7 +297,7 @@ ii neovim 0.9.5-6ubuntu2 amd64 ii neovim-runtime 0.9.5-6ubuntu2 all heavily refactored vim fork (runtime files) ii netbase 6.4 all Basic TCP/IP networking system ii ninja-build 1.11.1-2 amd64 small build system closest in spirit to Make -ii openssl 3.0.13-0ubuntu3 amd64 Secure Sockets Layer toolkit - cryptographic utility +ii openssl 3.0.13-0ubuntu3.1 amd64 Secure Sockets Layer toolkit - cryptographic utility ii p7zip 16.02+transitional.1 all transitional package ii parallel 20231122+ds-1 all build and execute command lines from standard input in parallel ii passwd 1:4.13+dfsg1-4ubuntu3 amd64 change and administer password and group data @@ -361,7 +361,7 @@ ii zstd 1.5.5+dfsg2-2build1 amd64 ||/ Name Version Architecture Description Packages sorted by Installed-Size: - 964903 ===== TOTAL (355 packages) + 964904 ===== TOTAL (355 packages) 76943 valgrind amd64 72249 gcc-13-x86-64-linux-gnu amd64 37841 g++-13-x86-64-linux-gnu amd64 @@ -450,7 +450,7 @@ Packages sorted by Installed-Size: 2009 universal-ctags amd64 1980 aria2 amd64 1900 bash amd64 - 1884 openssl amd64 + 1885 openssl amd64 1798 zstd amd64 1796 procps amd64 1761 libdb5.3t64 amd64 diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index b63a10cc..6657a6c2 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -420,8 +420,12 @@ struct TestBELE { constexpr T zero = {}; constexpr T zero_copy = T::make(zero); assert_noexcept(zero_copy == 0); + assert_noexcept(!upx::has_single_bit(zero)); #if defined(upx_is_constant_evaluated) static_assert(zero_copy == 0); + static_assert(zero_copy == zero); + static_assert(!upx::has_single_bit(zero)); + static_assert(!upx::has_single_bit(zero_copy)); #endif } #if defined(upx_is_constant_evaluated) @@ -429,12 +433,15 @@ struct TestBELE { typedef typename T::integral_conversion_type U; constexpr T one = T::make(1); static_assert(one == 1); + static_assert(upx::has_single_bit(one)); constexpr T four = T::make(one + 3); static_assert(four == 4); + static_assert(upx::has_single_bit(four)); constexpr U all_bits_u = (U) T::make(U(0) - U(1)); constexpr T all_bits = T::make(all_bits_u); static_assert(all_bits == all_bits_u); static_assert(all_bits == T::make(one - 2)); + static_assert(!upx::has_single_bit(all_bits)); static_assert(one == one); static_assert(!(one == four)); static_assert(!(one == all_bits)); diff --git a/src/check/dt_cxxlib.cpp b/src/check/dt_cxxlib.cpp index edb8de38..b13d5282 100644 --- a/src/check/dt_cxxlib.cpp +++ b/src/check/dt_cxxlib.cpp @@ -50,7 +50,7 @@ TEST_CASE("std::vector") { } /************************************************************************* -// core util - UPX_CXX_DISABLE_xxx +// core util: UPX_CXX_DISABLE_xxx, noncopyable **************************************************************************/ namespace { @@ -166,6 +166,23 @@ struct Z2_X2 : public X2 { } // namespace test_disable_new_delete +TEST_CASE("upx::noncopyable") { + struct Test : private upx::noncopyable { + int v = 1; + }; + Test t = {}; + CHECK(t.v == 1); +#if (ACC_CC_MSC) // MSVC thinks that Test is not std::is_trivially_copyable; true or compiler bug? + // @COMPILER_BUG @MSVC_BUG + t.v = 0; +#else + mem_clear(&t); +#endif + CHECK(t.v == 0); + constexpr Test x = {}; + static_assert(x.v == 1); +} + /************************************************************************* // **************************************************************************/ @@ -190,6 +207,16 @@ static_assert(upx::is_same_any_v); +/************************************************************************* +// +**************************************************************************/ + +static_assert(!upx::has_single_bit(0)); +static_assert(upx::has_single_bit(1)); +static_assert(upx::has_single_bit(2)); +static_assert(!upx::has_single_bit(3)); +static_assert(upx::has_single_bit(4)); + /************************************************************************* // **************************************************************************/ @@ -212,25 +239,35 @@ static_assert(upx::align_gap(4, 4) == 0); static_assert(upx::min(1, 2) == 1); static_assert(upx::min(1, 2) == 1); -static_assert(upx::min(1, 2) == 1); -static_assert(upx::min(1ll, 2ll) == 1); +static_assert(upx::min(1, 2) == 1); +static_assert(upx::min(1, 2) == 1); static_assert(upx::max(1, 2) == 2); static_assert(upx::max(1, 2) == 2); +static_assert(upx::max(1, 2) == 2); +static_assert(upx::max(1, 2) == 2); + +static_assert(upx::min(1, 2) == 1); +static_assert(upx::min(1l, 2l) == 1); +static_assert(upx::min(1ll, 2ll) == 1); static_assert(upx::max(1, 2) == 2); +static_assert(upx::max(1l, 2l) == 2); static_assert(upx::max(1ll, 2ll) == 2); -static_assert(upx::min(0, 0) == 0); -static_assert(upx::min(0, 1) == 0); -static_assert(upx::min(1, 0) == 0); -static_assert(upx::max(0, 0) == 0); -static_assert(upx::max(0, 1) == 1); -static_assert(upx::max(1, 0) == 1); -static_assert(upx::umin(0u, 0u) == 0u); -static_assert(upx::umin(0u, 1u) == 0u); -static_assert(upx::umin(1u, 0u) == 0u); -static_assert(upx::umax(0u, 0u) == 0u); -static_assert(upx::umax(0u, 1u) == 1u); -static_assert(upx::umax(1u, 0u) == 1u); +static_assert(upx::umin(1, 2) == 1); +static_assert(upx::umin(1, 2) == 1); +static_assert(upx::umin(1, 2) == 1); +static_assert(upx::umin(1, 2) == 1); +static_assert(upx::umax(1, 2) == 2); +static_assert(upx::umax(1, 2) == 2); +static_assert(upx::umax(1, 2) == 2); +static_assert(upx::umax(1, 2) == 2); + +static_assert(upx::umin(1u, 2u) == 1); +static_assert(upx::umin(1ul, 2ul) == 1); +static_assert(upx::umin(1ull, 2ull) == 1); +static_assert(upx::umax(1u, 2u) == 2); +static_assert(upx::umax(1ul, 2ul) == 2); +static_assert(upx::umax(1ull, 2ull) == 2); static_assert(upx::wrapping_add(127, 2) == -127); static_assert(upx::wrapping_add(32767, 2) == -32767); @@ -241,6 +278,9 @@ static_assert(upx::wrapping_sub(-32767, 2) == 32767); static_assert(upx::wrapping_sub(-2147483647, 2) == 2147483647); static_assert(upx::wrapping_sub(-9223372036854775807ll, 2ll) == 9223372036854775807ll); +static_assert(upx::wrapping_add(255, 2) == 1); +static_assert(upx::wrapping_sub(1, 2) == 255); + /************************************************************************* // util **************************************************************************/ @@ -518,23 +558,6 @@ TEST_CASE("upx::ObjectDeleter 2") { } } -TEST_CASE("upx::noncopyable") { - struct Test : private upx::noncopyable { - int v = 1; - }; - Test t = {}; - CHECK(t.v == 1); -#if (ACC_CC_MSC) // MSVC thinks that Test is not std::is_trivially_copyable; true or compiler bug? - // @COMPILER_BUG @MSVC_BUG - t.v = 0; -#else - mem_clear(&t); -#endif - CHECK(t.v == 0); - constexpr Test x = {}; - static_assert(x.v == 1); -} - /************************************************************************* // namespace upx::compile_time **************************************************************************/ diff --git a/src/compress/compress_lzma.cpp b/src/compress/compress_lzma.cpp index bd8686e1..7006181a 100644 --- a/src/compress/compress_lzma.cpp +++ b/src/compress/compress_lzma.cpp @@ -127,11 +127,11 @@ static bool prepare_result(lzma_compress_result_t *res, unsigned src_len, int me // cconf overrides if (lcconf) { - oassign(res->pos_bits, lcconf->pos_bits); - oassign(res->lit_pos_bits, lcconf->lit_pos_bits); - oassign(res->lit_context_bits, lcconf->lit_context_bits); - oassign(res->dict_size, lcconf->dict_size); - oassign(res->num_fast_bytes, lcconf->num_fast_bytes); + upx::oassign(res->pos_bits, lcconf->pos_bits); + upx::oassign(res->lit_pos_bits, lcconf->lit_pos_bits); + upx::oassign(res->lit_context_bits, lcconf->lit_context_bits); + upx::oassign(res->dict_size, lcconf->dict_size); + upx::oassign(res->num_fast_bytes, lcconf->num_fast_bytes); } // limit dictionary size diff --git a/src/compress/compress_zlib.cpp b/src/compress/compress_zlib.cpp index 95f5a504..bc2a7540 100644 --- a/src/compress/compress_zlib.cpp +++ b/src/compress/compress_zlib.cpp @@ -97,9 +97,9 @@ int upx_zlib_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi zlib_compress_config_t::strategy_t strategy; // cconf overrides if (lcconf) { - oassign(mem_level, lcconf->mem_level); - oassign(window_bits, lcconf->window_bits); - oassign(strategy, lcconf->strategy); + upx::oassign(mem_level, lcconf->mem_level); + upx::oassign(window_bits, lcconf->window_bits); + upx::oassign(strategy, lcconf->strategy); } z_stream s; diff --git a/src/conf.h b/src/conf.h index 6d9c6979..77e43cd7 100644 --- a/src/conf.h +++ b/src/conf.h @@ -465,9 +465,6 @@ noreturn void throwAssertFailed(const char *expr, const char *file, int line, co // C++ support library #include "util/cxxlib.h" -using upx::is_same_any_v; -using upx::noncopyable; -using upx::OptVar; using upx::tribool; #define usizeof(expr) (upx::UnsignedSizeOf::value) @@ -649,11 +646,11 @@ struct bzip2_compress_config_t final { }; struct lzma_compress_config_t final { - typedef OptVar pos_bits_t; // pb - typedef OptVar lit_pos_bits_t; // lp - typedef OptVar lit_context_bits_t; // lc - typedef OptVar dict_size_t; - typedef OptVar num_fast_bytes_t; + typedef upx::OptVar pos_bits_t; // pb + typedef upx::OptVar lit_pos_bits_t; // lp + typedef upx::OptVar lit_context_bits_t; // lc + typedef upx::OptVar dict_size_t; + typedef upx::OptVar num_fast_bytes_t; pos_bits_t pos_bits; // pb lit_pos_bits_t lit_pos_bits; // lp @@ -673,9 +670,9 @@ struct ucl_compress_config_t final : public REAL_ucl_compress_config_t { }; struct zlib_compress_config_t final { - typedef OptVar mem_level_t; // ml - typedef OptVar window_bits_t; // wb - typedef OptVar strategy_t; // st + typedef upx::OptVar mem_level_t; // ml + typedef upx::OptVar window_bits_t; // wb + typedef upx::OptVar strategy_t; // st mem_level_t mem_level; // ml window_bits_t window_bits; // wb diff --git a/src/filter/filter_impl.cpp b/src/filter/filter_impl.cpp index e010192a..ed066a15 100644 --- a/src/filter/filter_impl.cpp +++ b/src/filter/filter_impl.cpp @@ -28,8 +28,6 @@ #include "../conf.h" #include "../filter.h" -static unsigned umin(const unsigned a, const unsigned b) { return (a <= b) ? a : b; } - #define set_dummy(p, v) ((void) 0) #define get_8(p) (*(p)) #define set_8(p, v) (*(p) = (v)) diff --git a/src/filter/ppcbxx.h b/src/filter/ppcbxx.h index 3837fabc..331ca47b 100644 --- a/src/filter/ppcbxx.h +++ b/src/filter/ppcbxx.h @@ -44,7 +44,7 @@ static int F(Filter *f) { // scan const byte *b = f->buf; #endif - const unsigned size = umin(f->buf_len, 0u - (~0u << (32 - (6 + W_CTO)))); + const unsigned size = upx::umin(f->buf_len, 0u - (~0u << (32 - (6 + W_CTO)))); const unsigned size4 = size - 4; unsigned ic; @@ -123,7 +123,7 @@ static int F(Filter *f) { #ifdef U static int U(Filter *f) { byte *b = f->buf; - const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u << (32 - (6 + W_CTO)))); + const unsigned size4 = upx::umin(f->buf_len - 4, 0u - (~0u << (32 - (6 + W_CTO)))); const unsigned addvalue = f->addvalue; unsigned ic; diff --git a/src/linker.h b/src/linker.h index 169a24e3..c0b32de0 100644 --- a/src/linker.h +++ b/src/linker.h @@ -31,7 +31,7 @@ // ElfLinker **************************************************************************/ -class ElfLinker : private noncopyable { +class ElfLinker : private upx::noncopyable { friend class Packer; public: @@ -114,7 +114,7 @@ protected: const char *type); }; -struct ElfLinker::Section : private noncopyable { +struct ElfLinker::Section : private upx::noncopyable { char *name = nullptr; void *input = nullptr; byte *output = nullptr; @@ -128,7 +128,7 @@ struct ElfLinker::Section : private noncopyable { ~Section() noexcept; }; -struct ElfLinker::Symbol : private noncopyable { +struct ElfLinker::Symbol : private upx::noncopyable { char *name = nullptr; Section *section = nullptr; upx_uint64_t offset = 0; @@ -137,7 +137,7 @@ struct ElfLinker::Symbol : private noncopyable { ~Symbol() noexcept; }; -struct ElfLinker::Relocation : private noncopyable { +struct ElfLinker::Relocation : private upx::noncopyable { const Section *section = nullptr; unsigned offset = 0; const char *type = nullptr; diff --git a/src/main.cpp b/src/main.cpp index a322eb44..b9c0aa77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -343,7 +343,8 @@ done: } template -static int getoptvar(OptVar *var, const char *arg_fatal) { +static int getoptvar(upx::OptVar *var, + const char *arg_fatal) { T v = default_value; int r = getoptvar(&v, min_value, max_value, arg_fatal); if (r == 0) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index ad11847d..5de594a0 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -43,7 +43,7 @@ #include "p_lx_elf.h" #include "ui.h" -using upx::umax, upx::umin; +using upx::umin; #define PT_LOAD32 Elf32_Phdr::PT_LOAD #define PT_LOAD64 Elf64_Phdr::PT_LOAD @@ -1304,15 +1304,6 @@ PackLinuxElf64arm::~PackLinuxElf64arm() { } -static unsigned -umax(unsigned a, unsigned b) -{ - if (a <= b) { - return b; - } - return a; -} - void PackLinuxElf32x86::addStubEntrySections(Filter const *ft, unsigned m_decompr) { (void)m_decompr; // FIXME @@ -1467,9 +1458,9 @@ PackLinuxElf32::buildLinuxLoader( } else { cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold; - unsigned fold_hdrlen = umax(0x80, usizeof(hf->ehdr) + + unsigned fold_hdrlen = upx::umax(0x80u, usizeof(hf->ehdr) + get_te16(&hf->ehdr.e_phentsize) * get_te16(&hf->ehdr.e_phnum) + - sizeof(l_info) ); + usizeof(l_info) ); uncLoader = fold_hdrlen + fold; sz_unc = ((szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen)); method = ph.method; @@ -1573,9 +1564,9 @@ PackLinuxElf64::buildLinuxLoader( } else { cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold; - unsigned fold_hdrlen = umax(0x80, usizeof(hf->ehdr) + + unsigned fold_hdrlen = upx::umax(0x80u, usizeof(hf->ehdr) + get_te16(&hf->ehdr.e_phentsize) * get_te16(&hf->ehdr.e_phnum) + - sizeof(l_info) ); + usizeof(l_info) ); uncLoader = fold_hdrlen + fold; sz_unc = ((szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen)); method = ph.method; diff --git a/src/packer.cpp b/src/packer.cpp index 1d37f0ea..ecfa2c76 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -193,16 +193,16 @@ bool Packer::compress(SPAN_P(byte) i_ptr, unsigned i_len, SPAN_P(byte) o_ptr, #endif } if (M_IS_LZMA(method)) { - oassign(cconf.conf_lzma.pos_bits, opt->crp.crp_lzma.pos_bits); - oassign(cconf.conf_lzma.lit_pos_bits, opt->crp.crp_lzma.lit_pos_bits); - oassign(cconf.conf_lzma.lit_context_bits, opt->crp.crp_lzma.lit_context_bits); - oassign(cconf.conf_lzma.dict_size, opt->crp.crp_lzma.dict_size); - oassign(cconf.conf_lzma.num_fast_bytes, opt->crp.crp_lzma.num_fast_bytes); + upx::oassign(cconf.conf_lzma.pos_bits, opt->crp.crp_lzma.pos_bits); + upx::oassign(cconf.conf_lzma.lit_pos_bits, opt->crp.crp_lzma.lit_pos_bits); + upx::oassign(cconf.conf_lzma.lit_context_bits, opt->crp.crp_lzma.lit_context_bits); + upx::oassign(cconf.conf_lzma.dict_size, opt->crp.crp_lzma.dict_size); + upx::oassign(cconf.conf_lzma.num_fast_bytes, opt->crp.crp_lzma.num_fast_bytes); } if (M_IS_DEFLATE(method)) { - oassign(cconf.conf_zlib.mem_level, opt->crp.crp_zlib.mem_level); - oassign(cconf.conf_zlib.window_bits, opt->crp.crp_zlib.window_bits); - oassign(cconf.conf_zlib.strategy, opt->crp.crp_zlib.strategy); + upx::oassign(cconf.conf_zlib.mem_level, opt->crp.crp_zlib.mem_level); + upx::oassign(cconf.conf_zlib.window_bits, opt->crp.crp_zlib.window_bits); + upx::oassign(cconf.conf_zlib.strategy, opt->crp.crp_zlib.strategy); } if (uip->ui_pass >= 0) uip->ui_pass++; diff --git a/src/packer.h b/src/packer.h index 4995e47a..395491dd 100644 --- a/src/packer.h +++ b/src/packer.h @@ -267,11 +267,14 @@ protected: #else // try to detect TE16 vs TE32 vs TE64 size mismatches; note that byte is explicitly allowed template - static inline constexpr bool is_te16_type = is_same_any_v; + static inline constexpr bool is_te16_type = + upx::is_same_any_v; template - static inline constexpr bool is_te32_type = is_same_any_v; + static inline constexpr bool is_te32_type = + upx::is_same_any_v; template - static inline constexpr bool is_te64_type = is_same_any_v; + static inline constexpr bool is_te64_type = + upx::is_same_any_v; template using enable_if_te16 = std::enable_if_t, T>; template diff --git a/src/pefile.h b/src/pefile.h index dc78f4ad..c4446ef6 100644 --- a/src/pefile.h +++ b/src/pefile.h @@ -371,7 +371,7 @@ protected: IMAGE_REL_BASED_DIR64 = 10, }; - class Interval final : private noncopyable { + class Interval final : private upx::noncopyable { SPAN_0(byte) base = nullptr; unsigned ivcapacity = 0; // for ivarr public: @@ -397,7 +397,7 @@ protected: static int __acc_cdecl_qsort compare(const void *p1, const void *p2); }; - class Reloc final : private noncopyable { + class Reloc final : private upx::noncopyable { // these are set in the constructor: byte *start = nullptr; unsigned start_size_in_bytes = 0; @@ -433,7 +433,7 @@ protected: void finish(byte *(&result_ptr), unsigned &result_size); // => transfer ownership }; - class Resource final : private noncopyable { + class Resource final : private upx::noncopyable { struct res_dir_entry; struct res_dir; struct res_data; @@ -489,7 +489,7 @@ protected: */ }; - class Export final : private noncopyable { + class Export final : private upx::noncopyable { struct alignas(1) export_dir_t { byte _[12]; // flags, timedate, version LE32 name; diff --git a/src/util/cxxlib.h b/src/util/cxxlib.h index 172524b6..109ba617 100644 --- a/src/util/cxxlib.h +++ b/src/util/cxxlib.h @@ -141,6 +141,17 @@ private: #define UPX_CXX_DISABLE_NEW_DELETE_NO_VIRTUAL(Klass) private: #endif +class noncopyable { +protected: + forceinline constexpr noncopyable() noexcept {} +#if __cplusplus >= 202002L + forceinline constexpr ~noncopyable() noexcept = default; +#else + forceinline ~noncopyable() noexcept = default; +#endif + UPX_CXX_DISABLE_COPY_MOVE(noncopyable) +}; + /************************************************************************* // **************************************************************************/ @@ -178,21 +189,21 @@ forceinline constexpr bool has_single_bit(T x) noexcept { template inline constexpr T align_down(const T &x, const T &alignment) noexcept { - // assert_noexcept(has_single_bit(alignment)); + // assert_noexcept(has_single_bit(alignment)); // (not constexpr) T r = {}; r = (x / alignment) * alignment; return r; } template inline constexpr T align_up(const T &x, const T &alignment) noexcept { - // assert_noexcept(has_single_bit(alignment)); + // assert_noexcept(has_single_bit(alignment)); // (not constexpr) T r = {}; r = ((x + (alignment - 1)) / alignment) * alignment; return r; } template inline constexpr T align_gap(const T &x, const T &alignment) noexcept { - // assert_noexcept(has_single_bit(alignment)); + // assert_noexcept(has_single_bit(alignment)); // (not constexpr) T r = {}; r = align_up(x, alignment) - x; return r; @@ -209,7 +220,7 @@ forceinline constexpr T max(const T &a, const T &b) noexcept { template inline constexpr bool is_uminmax_type = - is_same_any_v; + is_same_any_v; template , T> > forceinline constexpr T umin(const T &a, const T &b) noexcept { @@ -343,17 +354,6 @@ struct MallocDeleter final { } }; -class noncopyable { -protected: - forceinline constexpr noncopyable() noexcept {} -#if __cplusplus >= 202002L - forceinline constexpr ~noncopyable() noexcept = default; -#else - forceinline ~noncopyable() noexcept = default; -#endif - UPX_CXX_DISABLE_COPY_MOVE(noncopyable) -}; - /************************************************************************* // compile_time **************************************************************************/ diff --git a/src/util/util.h b/src/util/util.h index 2319472e..4cd026bb 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -93,9 +93,9 @@ T *NewArray(upx_uint64_t n) may_throw { // ptr util **************************************************************************/ -// also see CHERI cheri_address_get() -forceinline upx_ptraddr_t ptr_get_address(const void *p) { return (upx_uintptr_t) p; } -forceinline upx_ptraddr_t ptr_get_address(upx_uintptr_t p) { return p; } +// TODO later: CHERI; see cheri_address_get() +forceinline upx_ptraddr_t ptr_get_address(const void *p) noexcept { return (upx_uintptr_t) p; } +forceinline upx_ptraddr_t ptr_get_address(upx_uintptr_t p) noexcept { return p; } // ptrdiff_t with nullptr checks and asserted size; will throw on failure // NOTE: returns size_in_bytes, not number of elements! @@ -138,6 +138,7 @@ forceinline void ptr_check_no_overlap(const void *a, size_t a_size, const void * // - this should play nice with static analyzers like clang-tidy etc. // NOTE: this is clearly UB (Undefined Behaviour), and stricter compilers or // architectures may need a more advanced/costly implementation in the future +// TODO later: CHERI template inline void ptr_invalidate_and_poison(T *(&ptr)) noexcept { ptr = (T *) (void *) 251; // 0x000000fb // NOLINT(performance-no-int-to-ptr)