all: assorted cleanups; introduce undocumented '--sysinfo' option
This commit is contained in:
+2
-1
@@ -280,6 +280,7 @@ void upx_memswap(void *a, void *b, size_t n) {
|
||||
static void memswap_no_overlap(byte *a, byte *b, size_t n) {
|
||||
#if defined(__clang__) && __clang_major__ < 15
|
||||
// work around a clang < 15 ICE (Internal Compiler Error)
|
||||
// @COMPILER_BUG @CLANG_BUG
|
||||
upx_memswap(a, b, n);
|
||||
#else // clang bug
|
||||
upx_alignas_max byte tmp_buf[16];
|
||||
@@ -763,7 +764,7 @@ int fn_strcmp(const char *n1, const char *n2) {
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// misc.
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
bool set_method_name(char *buf, size_t size, int method, int level) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* windows_lean.h -- <windows.h> include wrapper
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(WIN32_LEAN_AND_MEAN)
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && (_MSC_VER >= 1000 && _MSC_VER < 1200)) && !defined(__clang__)
|
||||
/* avoid -W4 warnings in <conio.h> */
|
||||
#pragma warning(disable : 4032)
|
||||
/* avoid -W4 warnings in <windows.h> */
|
||||
#pragma warning(disable : 4201 4214 4514)
|
||||
#endif
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
/* avoid warnings in some versions of <windows.h> */
|
||||
#pragma warning(disable : 5105)
|
||||
#endif
|
||||
|
||||
#if defined(__RSXNT__) && !defined(timeval)
|
||||
#define timeval win32_timeval /* struct timeval already in <sys/time.h> */
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
+40
-17
@@ -28,6 +28,7 @@
|
||||
|
||||
#if WITH_XSPAN
|
||||
|
||||
// namespace
|
||||
#if 1
|
||||
#define XSPAN_NAMESPACE_NAME XSpan
|
||||
#define XSPAN_NAMESPACE_BEGIN namespace XSPAN_NAMESPACE_NAME {
|
||||
@@ -51,12 +52,12 @@ noinline void xspan_fail_range_range(void) may_throw;
|
||||
void xspan_check_range(const void *ptr, const void *base, ptrdiff_t size_in_bytes) may_throw;
|
||||
|
||||
// help constructor to distinguish between number of elements and bytes
|
||||
struct XSpanCount {
|
||||
explicit forceinline XSpanCount(size_t n) noexcept : count(n) {}
|
||||
struct XSpanCount final {
|
||||
explicit forceinline constexpr XSpanCount(size_t n) noexcept : count(n) {}
|
||||
size_t count; // public
|
||||
};
|
||||
struct XSpanSizeInBytes {
|
||||
explicit forceinline XSpanSizeInBytes(size_t bytes) noexcept : size_in_bytes(bytes) {}
|
||||
struct XSpanSizeInBytes final {
|
||||
explicit forceinline constexpr XSpanSizeInBytes(size_t bytes) noexcept : size_in_bytes(bytes) {}
|
||||
size_t size_in_bytes; // public
|
||||
};
|
||||
|
||||
@@ -117,8 +118,8 @@ struct XSpan_is_convertible : public std::is_convertible<From *, To *> {};
|
||||
#else
|
||||
// manual implementation
|
||||
|
||||
namespace detail {
|
||||
// helper for "void"
|
||||
namespace XSpan_detail {
|
||||
// XSpan_void_to_T - helper for "void"
|
||||
template <class T, class U>
|
||||
struct XSpan_void_to_T {
|
||||
typedef U type;
|
||||
@@ -131,19 +132,18 @@ template <class T>
|
||||
struct XSpan_void_to_T<T, const void> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
// XSpan_ptr_is_convertible
|
||||
template <class From, class To>
|
||||
struct XSpan_ptr_is_convertible : public std::false_type {};
|
||||
template <class T>
|
||||
struct XSpan_ptr_is_convertible<T, T> : public std::true_type {};
|
||||
template <class T>
|
||||
struct XSpan_ptr_is_convertible<T, const T> : public std::true_type {};
|
||||
} // namespace detail
|
||||
} // namespace XSpan_detail
|
||||
|
||||
template <class From, class To>
|
||||
struct XSpan_is_convertible
|
||||
: public detail::XSpan_ptr_is_convertible<From,
|
||||
typename detail::XSpan_void_to_T<From, To>::type> {};
|
||||
struct XSpan_is_convertible : public XSpan_detail::XSpan_ptr_is_convertible<
|
||||
From, typename XSpan_detail::XSpan_void_to_T<From, To>::type> {};
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
@@ -193,15 +193,38 @@ template <class T>
|
||||
struct Ptr;
|
||||
|
||||
// XSpanInternalDummyArg: some type that is hard to match by accident
|
||||
class XSpanInternalDummyArgFake; // not implemented on purpose
|
||||
// (this should result in efficient code and fully get optimized away)
|
||||
#if 0
|
||||
// too simple, can be matched by nullptr
|
||||
class XSpanInternalDummyArgFake; // not implemented on purpose
|
||||
typedef XSpanInternalDummyArgFake *XSpanInternalDummyArg;
|
||||
#define XSpanInternalDummyArgInit nullptr
|
||||
#else
|
||||
struct XSpanInternalDummyArg {
|
||||
explicit forceinline XSpanInternalDummyArg(int, XSpanInternalDummyArgFake *) noexcept {}
|
||||
#elif 1
|
||||
// use an enum
|
||||
struct XSpanInternalDummyArg final {
|
||||
enum DummyEnum {};
|
||||
explicit forceinline constexpr XSpanInternalDummyArg(DummyEnum &&) noexcept {}
|
||||
};
|
||||
#define XSpanInternalDummyArgInit (XSPAN_NS(XSpanInternalDummyArg)(0, nullptr))
|
||||
#define XSpanInternalDummyArgInit \
|
||||
(XSPAN_NS(XSpanInternalDummyArg)(XSPAN_NS(XSpanInternalDummyArg)::DummyEnum{}))
|
||||
#else
|
||||
// use a class with a private constructor
|
||||
struct XSpanInternalDummyArg final {
|
||||
static forceinline constexpr XSpanInternalDummyArg make() noexcept {
|
||||
return XSpanInternalDummyArg{};
|
||||
}
|
||||
private:
|
||||
explicit forceinline constexpr XSpanInternalDummyArg() noexcept {}
|
||||
#if !(ACC_CC_MSC) // MSVC wants to use the copy and move constructors; correct or compiler bug?
|
||||
// @COMPILER_BUG @MSVC_BUG
|
||||
XSpanInternalDummyArg(const XSpanInternalDummyArg &) = delete;
|
||||
XSpanInternalDummyArg(XSpanInternalDummyArg &&) noexcept = delete;
|
||||
XSpanInternalDummyArg &operator=(const XSpanInternalDummyArg &) = delete;
|
||||
XSpanInternalDummyArg &operator=(XSpanInternalDummyArg &&) noexcept = delete;
|
||||
#endif
|
||||
};
|
||||
#define XSpanInternalDummyArgInit \
|
||||
(XSPAN_NS(XSpanInternalDummyArg)(XSPAN_NS(XSpanInternalDummyArg)::make()))
|
||||
#endif
|
||||
|
||||
// poison a pointer: point to a non-null invalid address
|
||||
@@ -209,7 +232,7 @@ struct XSpanInternalDummyArg {
|
||||
// - this should be efficient (so no mmap() guard page etc.)
|
||||
// - this should play nice with runtime checkers like ASAN, MSAN, valgrind, etc.
|
||||
// - this should play nice with static analyzers like clang-tidy etc.
|
||||
static forceinline void *XSPAN_GET_POISON_VOID_PTR() {
|
||||
static forceinline void *XSPAN_GET_POISON_VOID_PTR() noexcept {
|
||||
// return (void *) (upx_uintptr_t) 251; // NOLINT(performance-no-int-to-ptr)
|
||||
return (void *) 251;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
|
||||
// debug - internal sanity check; also serves as pseudo-documentation
|
||||
#if DEBUG
|
||||
noinline void assertInvariants() const {
|
||||
noinline void assertInvariants() const may_throw {
|
||||
if __acc_cte (configRequirePtr)
|
||||
assert(ptr != nullptr);
|
||||
if __acc_cte (configRequireBase)
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
xspan_check_range(ptr, base, size_in_bytes);
|
||||
}
|
||||
#else
|
||||
forceinline void assertInvariants() const noexcept {}
|
||||
forceinline constexpr void assertInvariants() const noexcept {}
|
||||
#endif
|
||||
|
||||
static inline pointer makeNotNull(pointer p) {
|
||||
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
// inverse logic for ensuring valid pointers from existing objects
|
||||
inline pointer ensurePtr() const { return ptr; }
|
||||
// debug
|
||||
inline void assertInvariants() const noexcept {}
|
||||
forceinline constexpr void assertInvariants() const noexcept {}
|
||||
|
||||
public:
|
||||
#if XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION || 1
|
||||
|
||||
Reference in New Issue
Block a user