all: misc updates
This commit is contained in:
+4
-4
@@ -169,8 +169,8 @@ inline void set_le24(void *p, unsigned v) noexcept {
|
||||
}
|
||||
|
||||
inline unsigned get_le26(const void *p) noexcept { return get_le32(p) & 0x03ffffff; }
|
||||
inline unsigned get_le19_5(const void *p) noexcept { return 0x7ffff & (get_le32(p) >> 5); }
|
||||
inline unsigned get_le14_5(const void *p) noexcept { return 0x03fff & (get_le32(p) >> 5); }
|
||||
inline unsigned get_le19_5(const void *p) noexcept { return 0x0007ffff & (get_le32(p) >> 5); }
|
||||
inline unsigned get_le14_5(const void *p) noexcept { return 0x00003fff & (get_le32(p) >> 5); }
|
||||
|
||||
inline void set_le26(void *p, unsigned v) noexcept {
|
||||
// preserve the top 6 bits
|
||||
@@ -180,10 +180,10 @@ inline void set_le26(void *p, unsigned v) noexcept {
|
||||
(ne32_to_le32(v) & ne32_to_le32(0x03ffffff)));
|
||||
}
|
||||
inline void set_le19_5(void *p, unsigned v) noexcept {
|
||||
set_le32(p, (get_le32(p) & 0xff00001f) | ((v & 0x07ffff) << 5));
|
||||
set_le32(p, (get_le32(p) & 0xff00001f) | ((v & 0x0007ffff) << 5));
|
||||
}
|
||||
inline void set_le14_5(void *p, unsigned v) noexcept {
|
||||
set_le32(p, (get_le32(p) & 0xfff8001f) | ((v & 0x003fff) << 5));
|
||||
set_le32(p, (get_le32(p) & 0xfff8001f) | ((v & 0x00003fff) << 5));
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
@@ -115,8 +115,6 @@ TEST_CASE("basic xspan usage") {
|
||||
}
|
||||
|
||||
SUBCASE("XSPAN_x_VAR") {
|
||||
XSPAN_0_VAR(char, a0, nullptr);
|
||||
|
||||
XSPAN_0_VAR(char, b0, buf);
|
||||
XSPAN_P_VAR(char, bp, buf);
|
||||
|
||||
@@ -135,7 +133,6 @@ TEST_CASE("basic xspan usage") {
|
||||
XSPAN_0_VAR(const char, const z0p, yp);
|
||||
XSPAN_0_VAR(const char, const z0s, xs);
|
||||
|
||||
CHECK((a0 == nullptr));
|
||||
CHECK(c0 == b0);
|
||||
CHECK(cp == bp);
|
||||
CHECK(cs == bp);
|
||||
@@ -144,9 +141,13 @@ TEST_CASE("basic xspan usage") {
|
||||
CHECK(x0 == z0p);
|
||||
CHECK(xp == z0s);
|
||||
|
||||
#if WITH_XSPAN >= 1 || __cplusplus >= 201103L
|
||||
XSPAN_0_VAR(char, a0, nullptr);
|
||||
CHECK((a0 == nullptr));
|
||||
CHECK_NOTHROW(raw_bytes(a0, 0));
|
||||
CHECK_THROWS(raw_bytes(a0, 1));
|
||||
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
|
||||
#endif
|
||||
|
||||
CHECK(raw_bytes(b0, 0) == buf);
|
||||
CHECK(raw_bytes(bp, 0) == buf);
|
||||
|
||||
@@ -202,6 +202,11 @@ typedef upx_int64_t upx_off_t;
|
||||
# undef __unix__
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_DUP) && (HAVE_DUP + 0 == 0)
|
||||
# undef dup
|
||||
# define dup(x) (-1)
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
# define STDIN_FILENO (fileno(stdin))
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
/*static*/ void FileBase::chmod(const char *name, int mode) {
|
||||
#if (HAVE_CHMOD)
|
||||
#if HAVE_CHMOD
|
||||
if (::chmod(name, mode) != 0)
|
||||
throwIOException(name, errno);
|
||||
#else
|
||||
|
||||
+2
-2
@@ -799,12 +799,12 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, byte *location, upx_uint64
|
||||
// Note that original (*location).displ is ignored.
|
||||
if (strcmp(type, "24") == 0) {
|
||||
if (3 & value)
|
||||
internal_error("unaligned word diplacement");
|
||||
internal_error("unaligned word displacement");
|
||||
// FIXME: displacement overflow?
|
||||
set_be32(location, (0xfc000003 & get_be32(location)) + (0x03fffffc & value));
|
||||
} else if (strcmp(type, "14") == 0) {
|
||||
if (3 & value)
|
||||
internal_error("unaligned word diplacement");
|
||||
internal_error("unaligned word displacement");
|
||||
// FIXME: displacement overflow?
|
||||
set_be32(location, (0xffff0003 & get_be32(location)) + (0x0000fffc & value));
|
||||
} else
|
||||
|
||||
+2
-3
@@ -566,8 +566,7 @@ unsigned Packer::getRandomId() const {
|
||||
int fd = open("/dev/urandom", O_RDONLY | O_BINARY);
|
||||
if (fd < 0)
|
||||
fd = open("/dev/random", O_RDONLY | O_BINARY);
|
||||
if (fd >= 0)
|
||||
{
|
||||
if (fd >= 0) {
|
||||
if (read(fd, &id, 4) != 4)
|
||||
id = 0;
|
||||
close(fd);
|
||||
@@ -583,7 +582,7 @@ unsigned Packer::getRandomId() const {
|
||||
id ^= (unsigned) tv.tv_sec;
|
||||
id ^= ((unsigned) tv.tv_usec) << 12; // shift into high-bits
|
||||
#endif
|
||||
#if (HAVE_GETPID)
|
||||
#if HAVE_GETPID
|
||||
id ^= (unsigned) getpid();
|
||||
#endif
|
||||
id ^= (unsigned) fi->st.st_ino;
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ unsigned Packer::unoptimizeReloc(SPAN_S(const byte) & in, MemBuffer &out, SPAN_P
|
||||
}
|
||||
}
|
||||
in = fix + 1; // advance
|
||||
assert(relocnum == ptr_udiff_bytes(relocs, out) / 4);
|
||||
assert(relocnum == ptr_udiff_bytes(relocs, raw_bytes(out, 0)) / 4);
|
||||
return relocnum;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,9 +124,13 @@ inline typename MemBufferBase<T>::pointer raw_index_bytes(const MemBufferBase<T>
|
||||
typename std::enable_if<std::is_same<A, B>::value, RType>::type
|
||||
#define C MemBufferBase
|
||||
#define XSPAN_FWD_C_IS_MEMBUFFER 1
|
||||
#if WITH_XSPAN >= 1
|
||||
#define D XSPAN_NS(Ptr)
|
||||
#endif
|
||||
#include "xspan_fwd.h"
|
||||
#undef XSPAN_FWD_C_IS_MEMBUFFER
|
||||
#undef C
|
||||
#undef D
|
||||
#undef XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+1
-1
@@ -680,7 +680,7 @@ bool file_exists(const char *name) {
|
||||
return true;
|
||||
|
||||
/* return true if we can lstat it */
|
||||
#if (HAVE_LSTAT)
|
||||
#if HAVE_LSTAT
|
||||
// mem_clear(&st);
|
||||
r = lstat(name, &st);
|
||||
if (r != -1)
|
||||
|
||||
@@ -224,8 +224,12 @@ XSPAN_NAMESPACE_END
|
||||
#if 1
|
||||
|
||||
#define C XSPAN_NS(Ptr)
|
||||
template <class T>
|
||||
class MemBufferBase;
|
||||
#define D MemBufferBase
|
||||
#include "xspan_fwd.h"
|
||||
#undef C
|
||||
#undef D
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+12
-12
@@ -40,7 +40,7 @@
|
||||
#define USE_FTIME 1
|
||||
#elif ((ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_CC_INTELC || ACC_CC_MSC))
|
||||
#define USE__FUTIME 1
|
||||
#elif (HAVE_UTIME)
|
||||
#elif HAVE_UTIME
|
||||
#define USE_UTIME 1
|
||||
#endif
|
||||
|
||||
@@ -62,7 +62,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
int r;
|
||||
struct stat st;
|
||||
mem_clear(&st);
|
||||
#if (HAVE_LSTAT)
|
||||
#if HAVE_LSTAT
|
||||
r = lstat(iname, &st);
|
||||
#else
|
||||
r = stat(iname, &st);
|
||||
@@ -104,7 +104,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
fi.st = st;
|
||||
fi.sopen(iname, O_RDONLY | O_BINARY, SH_DENYWR);
|
||||
|
||||
#if (USE_FTIME)
|
||||
#if USE_FTIME
|
||||
struct ftime fi_ftime;
|
||||
mem_clear(&fi_ftime);
|
||||
if (opt->preserve_timestamp) {
|
||||
@@ -124,7 +124,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
if (opt->output_name) {
|
||||
strcpy(tname, opt->output_name);
|
||||
if (opt->force_overwrite || opt->force >= 2) {
|
||||
#if (HAVE_CHMOD)
|
||||
#if HAVE_CHMOD
|
||||
r = chmod(tname, 0777);
|
||||
IGNORE_ERROR(r);
|
||||
#endif
|
||||
@@ -173,10 +173,10 @@ void do_one_file(const char *iname, char *oname) {
|
||||
|
||||
// copy time stamp
|
||||
if (oname[0] && opt->preserve_timestamp && fo.isOpen()) {
|
||||
#if (USE_FTIME)
|
||||
#if USE_FTIME
|
||||
r = setftime(fo.getFd(), &fi_ftime);
|
||||
IGNORE_ERROR(r);
|
||||
#elif (USE__FUTIME)
|
||||
#elif USE__FUTIME
|
||||
struct _utimbuf u;
|
||||
u.actime = st.st_atime;
|
||||
u.modtime = st.st_mtime;
|
||||
@@ -197,7 +197,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
throwIOException("could not create a backup file name");
|
||||
FileBase::rename(iname, bakname);
|
||||
} else {
|
||||
#if (HAVE_CHMOD)
|
||||
#if HAVE_CHMOD
|
||||
r = chmod(iname, 0777);
|
||||
IGNORE_ERROR(r);
|
||||
#endif
|
||||
@@ -211,7 +211,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
oname[0] = 0; // done with oname
|
||||
const char *name = opt->output_name ? opt->output_name : iname;
|
||||
UNUSED(name);
|
||||
#if (USE_UTIME)
|
||||
#if USE_UTIME
|
||||
// copy time stamp
|
||||
if (opt->preserve_timestamp) {
|
||||
struct utimbuf u;
|
||||
@@ -221,21 +221,21 @@ void do_one_file(const char *iname, char *oname) {
|
||||
IGNORE_ERROR(r);
|
||||
}
|
||||
#endif
|
||||
#if (HAVE_CHOWN)
|
||||
#if HAVE_CHOWN
|
||||
// copy the group ownership
|
||||
if (opt->preserve_ownership) {
|
||||
r = chown(name, -1, st.st_gid);
|
||||
IGNORE_ERROR(r);
|
||||
}
|
||||
#endif
|
||||
#if (HAVE_CHMOD)
|
||||
#if HAVE_CHMOD
|
||||
// copy permissions
|
||||
if (opt->preserve_mode) {
|
||||
r = chmod(name, st.st_mode);
|
||||
IGNORE_ERROR(r);
|
||||
}
|
||||
#endif
|
||||
#if (HAVE_CHOWN)
|
||||
#if HAVE_CHOWN
|
||||
// copy the user ownership
|
||||
if (opt->preserve_ownership) {
|
||||
r = chown(name, st.st_uid, -1);
|
||||
@@ -253,7 +253,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
|
||||
static void unlink_ofile(char *oname) {
|
||||
if (oname && oname[0]) {
|
||||
#if (HAVE_CHMOD)
|
||||
#if HAVE_CHMOD
|
||||
int r;
|
||||
r = chmod(oname, 0777);
|
||||
IGNORE_ERROR(r);
|
||||
|
||||
Reference in New Issue
Block a user