diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index dacf5d2338..8e789a7912 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -418,12 +418,12 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, #ifdef __APPLE__ unsigned size = 32; char buffer[size]; - long minorVersion, majorVersion; + int32_t minorVersion, majorVersion; Gestalt(gestaltSystemVersionMajor, &majorVersion); Gestalt(gestaltSystemVersionMinor, &minorVersion); - snprintf(buffer, size, "%ld.%ld", majorVersion, minorVersion); + snprintf(buffer, size, "%d.%d", majorVersion, minorVersion); r = e->NewStringUTF(buffer); #else struct utsname system_id; diff --git a/makefile b/makefile index a3a9b30f58..4a72aa1d7e 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -MAKEFLAGS = -s +#MAKEFLAGS = -s name = avian version = 0.2 diff --git a/readme.txt b/readme.txt index cada02ffa9..e5baf534d9 100644 --- a/readme.txt +++ b/readme.txt @@ -53,7 +53,7 @@ Avian can currently target the following platforms: Linux (i386 and x86_64) Win32 (i386) - Mac OS X (i386 and 32-bit PowerPC) + Mac OS X (i386, x86_64 and 32-bit PowerPC) Building diff --git a/src/binaryToObject/mach-o.cpp b/src/binaryToObject/mach-o.cpp index 3921cb2f9d..d153694b5c 100644 --- a/src/binaryToObject/mach-o.cpp +++ b/src/binaryToObject/mach-o.cpp @@ -12,10 +12,12 @@ #include "stdio.h" #include "string.h" +#define MH_MAGIC_64 0xfeedfacf #define MH_MAGIC 0xfeedface #define MH_OBJECT 1 +#define LC_SEGMENT_64 0x19 #define LC_SEGMENT 1 #define LC_SYMTAB 2 @@ -35,13 +37,19 @@ #define CPU_SUBTYPE_POWERPC_ALL 0 #if (BITS_PER_WORD == 64) +# define Magic MH_MAGIC_64 +# define Segment LC_SEGMENT_64 # define FileHeader mach_header_64 # define SegmentCommand segment_command_64 # define Section section_64 +# define NList struct nlist_64 #elif (BITS_PER_WORD == 32) +# define Magic MH_MAGIC +# define Segment LC_SEGMENT # define FileHeader mach_header # define SegmentCommand segment_command # define Section section +# define NList struct nlist #else # error #endif @@ -92,6 +100,16 @@ struct section_64 { uint32_t reserved3; }; +struct nlist_64 { + union { + uint32_t n_strx; + } n_un; + uint8_t n_type; + uint8_t n_sect; + uint16_t n_desc; + uint64_t n_value; +}; + struct mach_header { uint32_t magic; cpu_type_t cputype; @@ -173,7 +191,7 @@ writeObject(const uint8_t* data, unsigned size, FILE* out, unsigned endNameLength = strlen(endName) + 1; FileHeader header = { - MH_MAGIC, // magic + Magic, // magic cpuType, cpuSubType, MH_OBJECT, // filetype, @@ -185,7 +203,7 @@ writeObject(const uint8_t* data, unsigned size, FILE* out, }; SegmentCommand segment = { - LC_SEGMENT, // cmd + Segment, // cmd sizeof(SegmentCommand) + sizeof(Section), // cmdsize "", // segname 0, // vmaddr @@ -237,11 +255,11 @@ writeObject(const uint8_t* data, unsigned size, FILE* out, + sizeof(Section) + sizeof(symtab_command) + pad(size) - + (sizeof(struct nlist) * 2), // stroff + + (sizeof(NList) * 2), // stroff 1 + startNameLength + endNameLength, // strsize }; - struct nlist symbolList[] = { + NList symbolList[] = { { 1, // n_un N_SECT | N_EXT, // n_type @@ -284,7 +302,7 @@ bool MAKE_NAME(writeMachO, BITS_PER_WORD, Object) (uint8_t* data, unsigned size, FILE* out, const char* startName, const char* endName, const char* architecture, unsigned alignment, - bool, bool executable) + bool writable, bool) { cpu_type_t cpuType; cpu_subtype_t cpuSubType; @@ -304,7 +322,7 @@ MAKE_NAME(writeMachO, BITS_PER_WORD, Object) const char* segmentName; const char* sectionName; - if (executable) { + if (writable) { segmentName = "__RWX"; sectionName = "__rwx"; } else { diff --git a/src/binaryToObject/main.cpp b/src/binaryToObject/main.cpp index 351ecb1b2c..0200dd4123 100644 --- a/src/binaryToObject/main.cpp +++ b/src/binaryToObject/main.cpp @@ -170,7 +170,7 @@ main(int argc, const char** argv) fclose(out); } else { - fprintf(stderr, "unable to open %d\n", argv[2]); + fprintf(stderr, "unable to open %s\n", argv[2]); } munmap(data, size); diff --git a/src/heap.cpp b/src/heap.cpp index d73d98cc89..5067909498 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -1650,14 +1650,14 @@ collect(Context* c) c->lastCollectionTime = now; fprintf(stderr, - " - collect: %4"LLD"ms; " - "total: %4"LLD"ms; " - "run: %4"LLD"ms; " - "total: %4"LLD"ms\n", - collection, - c->totalCollectionTime, - run, - c->totalTime - c->totalCollectionTime); + " - collect: %4dms; " + "total: %4dms; " + "run: %4dms; " + "total: %4dms\n", + static_cast(collection), + static_cast(c->totalCollectionTime), + static_cast(run), + static_cast(c->totalTime - c->totalCollectionTime)); fprintf(stderr, " - gen1: %8d/%8d bytes\n", diff --git a/src/machine.h b/src/machine.h index 3b485cf20a..aa753bb32f 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2336,8 +2336,8 @@ wait(Thread* t, object o, int64_t milliseconds) System::Monitor* m = objectMonitor(t, o, false); if (DebugMonitors) { - fprintf(stderr, "thread %p waits %"LLD" millis on %p for %x\n", - t, milliseconds, m, hash); + fprintf(stderr, "thread %p waits %d millis on %p for %x\n", + t, static_cast(milliseconds), m, hash); } if (m and m->owner() == t->systemThread) { diff --git a/src/posix.cpp b/src/posix.cpp index 97cc3ea841..daba932e04 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -11,6 +11,7 @@ #ifdef __APPLE__ # include "CoreFoundation/CoreFoundation.h" # undef assert +# define _XOPEN_SOURCE #endif #include "sys/mman.h" @@ -51,22 +52,26 @@ class MutexResource { pthread_mutex_t* m; }; +const int InvalidSignal = -1; const int VisitSignal = SIGUSR1; -#ifdef __APPLE__ -const int SegFaultSignal = SIGBUS; -#else const int SegFaultSignal = SIGSEGV; +#ifdef __APPLE__ +const int AltSegFaultSignal = SIGBUS; +#else +const int AltSegFaultSignal = InvalidSignal; #endif const int InterruptSignal = SIGUSR2; const unsigned VisitSignalIndex = 0; const unsigned SegFaultSignalIndex = 1; -const unsigned InterruptSignalIndex = 2; +const unsigned AltSegFaultSignalIndex = 2; +const unsigned InterruptSignalIndex = 3; class MySystem; MySystem* system; -const int signals[] = { VisitSignal, SegFaultSignal, InterruptSignal }; +const int signals[] = { VisitSignal, SegFaultSignal, AltSegFaultSignal, + InterruptSignal }; void handleSignal(int signal, siginfo_t* info, void* context); @@ -553,13 +558,8 @@ class MySystem: public System { } virtual void* tryAllocateExecutable(unsigned sizeInBytes) { -#ifdef __x86_64__ - const unsigned Extra = MAP_32BIT; -#else - const unsigned Extra = 0; -#endif void* p = mmap(0, sizeInBytes, PROT_EXEC | PROT_READ - | PROT_WRITE, MAP_PRIVATE | MAP_ANON | Extra, -1, 0); + | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (p == MAP_FAILED) { return 0; @@ -607,7 +607,12 @@ class MySystem: public System { } virtual Status handleSegFault(SignalHandler* handler) { - return registerHandler(handler, SegFaultSignalIndex); + Status s = registerHandler(handler, SegFaultSignalIndex); + if (s == 0 and AltSegFaultSignal != InvalidSignal) { + return registerHandler(handler, AltSegFaultSignalIndex); + } else { + return s; + } } virtual Status visit(System::Thread* st, System::Thread* sTarget, @@ -814,8 +819,13 @@ handleSignal(int signal, siginfo_t* info, void* context) system->visitLock->notifyAll(t); } break; - case SegFaultSignal: { - index = SegFaultSignalIndex; + case SegFaultSignal: + case AltSegFaultSignal: { + if (signal == SegFaultSignal) { + index = SegFaultSignalIndex; + } else { + index = AltSegFaultSignalIndex; + } bool jump = system->handlers[index]->handleSignal (&ip, &base, &stack, &thread); @@ -829,7 +839,7 @@ handleSignal(int signal, siginfo_t* info, void* context) sigset_t set; sigemptyset(&set); - sigaddset(&set, SegFaultSignal); + sigaddset(&set, signal); sigprocmask(SIG_UNBLOCK, &set, 0); vmJump(ip, base, stack, thread, 0, 0); diff --git a/src/x86.S b/src/x86.S index 5b11db56d6..fa7c75b2c2 100644 --- a/src/x86.S +++ b/src/x86.S @@ -291,7 +291,14 @@ LOCAL(float): jne LOCAL(exit) LOCAL(copy): +#ifdef __APPLE__ + // as of OS X 10.6, Apple is still using an assembler that doesn't + // understand movq SSE,GPR, but movd does the same thing, despite + // the name + movd %xmm0,%rax +#else movq %xmm0,%rax +#endif LOCAL(exit): movq %rbp,%rsp diff --git a/src/x86.h b/src/x86.h index 9a132deb05..7dd86c482b 100644 --- a/src/x86.h +++ b/src/x86.h @@ -56,10 +56,24 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t*, #elif defined ARCH_x86_64 -# define IP_REGISTER(context) (context->uc_mcontext.gregs[REG_RIP]) -# define BASE_REGISTER(context) (context->uc_mcontext.gregs[REG_RBP]) -# define STACK_REGISTER(context) (context->uc_mcontext.gregs[REG_RSP]) -# define THREAD_REGISTER(context) (context->uc_mcontext.gregs[REG_RBX]) +# ifdef __APPLE__ +# if __DARWIN_UNIX03 && defined(_STRUCT_X86_EXCEPTION_STATE32) +# define IP_REGISTER(context) (context->uc_mcontext->__ss.__rip) +# define BASE_REGISTER(context) (context->uc_mcontext->__ss.__rbp) +# define STACK_REGISTER(context) (context->uc_mcontext->__ss.__rsp) +# define THREAD_REGISTER(context) (context->uc_mcontext->__ss.__rbx) +# else +# define IP_REGISTER(context) (context->uc_mcontext->ss.rip) +# define BASE_REGISTER(context) (context->uc_mcontext->ss.rbp) +# define STACK_REGISTER(context) (context->uc_mcontext->ss.rsp) +# define THREAD_REGISTER(context) (context->uc_mcontext->ss.rbx) +# endif +# else +# define IP_REGISTER(context) (context->uc_mcontext.gregs[REG_RIP]) +# define BASE_REGISTER(context) (context->uc_mcontext.gregs[REG_RBP]) +# define STACK_REGISTER(context) (context->uc_mcontext.gregs[REG_RSP]) +# define THREAD_REGISTER(context) (context->uc_mcontext.gregs[REG_RBX]) +# endif extern "C" uint64_t # ifdef PLATFORM_WINDOWS @@ -81,7 +95,7 @@ dynamicCall(void* function, uint64_t* arguments, UNUSED uint8_t* argumentTypes, } # else inline uint64_t -dynamicCall(void* function, uint64_t* arguments, uint8_t* argumentTypes, +dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, unsigned argumentCount, unsigned, unsigned returnType) { const unsigned GprCount = 6;