From 967ecafc3356672d888f1dc93d3b9d78724d0c19 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 21 Sep 2009 05:41:49 +0200 Subject: [PATCH] Small compatibility updates. --- src/file.cpp | 1 + src/p_mach.cpp | 30 ++++++++++++++++++++++++++---- src/p_mach.h | 21 +++++++++------------ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 2a6ec294..c6ed419e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -366,6 +366,7 @@ off_t OutputFile::st_size() const return bytes_written; // too big if seek()+write() instead of rewrite() } struct stat my_st; + my_st.st_size = 0; if (::fstat(_fd, &my_st) != 0) throwIOException(_name, errno); return my_st.st_size; diff --git a/src/p_mach.cpp b/src/p_mach.cpp index e2c3a01e..35115645 100644 --- a/src/p_mach.cpp +++ b/src/p_mach.cpp @@ -71,7 +71,11 @@ static const static const #include "stub/powerpc-darwin.dylib-entry.h" -static unsigned lc_segment[2]; +static const unsigned lc_segment[2] = { + 0x1, 0x19 + //Mach_segment_command::LC_SEGMENT, + //Mach_segment_command::LC_SEGMENT_64 +}; template PackMachBase::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype, @@ -83,8 +87,6 @@ PackMachBase::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype, { MachClass::compileTimeAssertions(); bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL); - lc_segment[0] = Mach_segment_command::LC_SEGMENT; - lc_segment[1] = Mach_segment_command::LC_SEGMENT_64; } template @@ -117,24 +119,44 @@ const int *PackMachARMEL::getCompressionMethods(int method, int level) const } +PackMachPPC32::PackMachPPC32(InputFile *f) : super(f, Mach_header::CPU_TYPE_POWERPC, + Mach_header::MH_EXECUTE, Mach_thread_command::PPC_THREAD_STATE, + sizeof(Mach_ppc_thread_state)>>2, sizeof(threado)) +{ } + const int *PackMachPPC32::getFilters() const { static const int filters[] = { 0xd0, FT_END }; return filters; } +PackMachI386::PackMachI386(InputFile *f) : super(f, Mach_header::CPU_TYPE_I386, + Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::x86_THREAD_STATE32, + sizeof(Mach_i386_thread_state)>>2, sizeof(threado)) +{ } + int const *PackMachI386::getFilters() const { static const int filters[] = { 0x49, FT_END }; return filters; } +PackMachAMD64::PackMachAMD64(InputFile *f) : super(f, Mach_header::CPU_TYPE_X86_64, + Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::x86_THREAD_STATE64, + sizeof(Mach_AMD64_thread_state)>>2, sizeof(threado)) +{ } + int const *PackMachAMD64::getFilters() const { static const int filters[] = { 0x49, FT_END }; return filters; } +PackMachARMEL::PackMachARMEL(InputFile *f) : super(f, Mach_header::CPU_TYPE_ARM, + Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::ARM_THREAD_STATE, + sizeof(Mach_ARM_thread_state)>>2, sizeof(threado)) +{ } + int const *PackMachARMEL::getFilters() const { static const int filters[] = { 0x50, FT_END }; @@ -472,7 +494,7 @@ void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader #undef PAGE_MASK64 #undef PAGE_SIZE64 -#define PAGE_MASK64 (~(uint64_t)0<<12) +#define PAGE_MASK64 (~(acc_uint64l_t)0<<12) #define PAGE_SIZE64 -PAGE_MASK64 template diff --git a/src/p_mach.h b/src/p_mach.h index d406cff6..809190ce 100644 --- a/src/p_mach.h +++ b/src/p_mach.h @@ -388,7 +388,11 @@ struct MachClass_64 typedef typename TP::U32 TE32; typedef typename TP::U64 TE64; typedef N_Mach::MachITypes MachITypes; +#if (ACC_CC_BORLANDC) + typedef TE64 Addr; +#else typedef typename MachITypes::Addr Addr; +#endif // Mach types typedef N_Mach::Mach_header64 Mach_header; @@ -402,6 +406,7 @@ struct MachClass_64 static void compileTimeAssertions() { BeLePolicy::compileTimeAssertions(); + COMPILE_TIME_ASSERT(sizeof(Addr) == 8) } }; @@ -589,9 +594,7 @@ class PackMachPPC32 : public PackMachBase typedef PackMachBase super; public: - PackMachPPC32(InputFile *f) : super(f, Mach_header::CPU_TYPE_POWERPC, - Mach_header::MH_EXECUTE, Mach_thread_command::PPC_THREAD_STATE, - sizeof(Mach_ppc_thread_state)>>2, sizeof(threado)) { } + PackMachPPC32(InputFile *f); virtual int getFormat() const { return UPX_F_MACH_PPC32; } virtual const char *getName() const { return "Mach/ppc32"; } @@ -640,9 +643,7 @@ class PackMachI386 : public PackMachBase typedef PackMachBase super; public: - PackMachI386(InputFile *f) : super(f, Mach_header::CPU_TYPE_I386, - Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::x86_THREAD_STATE32, - sizeof(Mach_i386_thread_state)>>2, sizeof(threado)) { } + PackMachI386(InputFile *f); virtual int getFormat() const { return UPX_F_MACH_i386; } virtual const char *getName() const { return "Mach/i386"; } @@ -691,9 +692,7 @@ class PackMachAMD64 : public PackMachBase typedef PackMachBase super; public: - PackMachAMD64(InputFile *f) : super(f, Mach_header::CPU_TYPE_X86_64, - Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::x86_THREAD_STATE64, - sizeof(Mach_AMD64_thread_state)>>2, sizeof(threado)) { } + PackMachAMD64(InputFile *f); virtual int getFormat() const { return UPX_F_MACH_AMD64; } virtual const char *getName() const { return "Mach/AMD64"; } @@ -726,9 +725,7 @@ class PackMachARMEL : public PackMachBase typedef PackMachBase super; public: - PackMachARMEL(InputFile *f) : super(f, Mach_header::CPU_TYPE_ARM, - Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::ARM_THREAD_STATE, - sizeof(Mach_ARM_thread_state)>>2, sizeof(threado)) { } + PackMachARMEL(InputFile *f); virtual int getFormat() const { return UPX_F_MACH_ARMEL; } virtual const char *getName() const { return "Mach/ARMEL"; }