add support for FreeBSD

This commit is contained in:
Damjan Jovanovic 2012-08-02 10:36:16 -06:00 committed by Joel Dice
parent 57e318bbec
commit c1aa0b46b5
11 changed files with 60 additions and 10 deletions

View File

@ -578,6 +578,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name,
} else if (strcmp(chars, "os.name") == 0) {
#ifdef __APPLE__
r = e->NewStringUTF("Mac OS X");
#elif defined __FreeBSD__
r = e->NewStringUTF("FreeBSD");
#else
r = e->NewStringUTF("Linux");
#endif

View File

@ -31,6 +31,8 @@
# include <errno.h>
# include <netdb.h>
# include <sys/select.h>
# include <arpa/inet.h>
# include <netinet/in.h>
# include <netinet/ip.h>
# include <netinet/tcp.h>
# include <sys/socket.h>

View File

@ -334,6 +334,16 @@ ifeq ($(platform),qnx)
rdynamic = -Wl,--export-dynamic
endif
ifeq ($(platform),freebsd)
# There is no -ldl on FreeBSD
build-lflags = $(common-lflags) -lz -lpthread
lflags = $(common-lflags) -lpthread
# include/freebsd instead of include/linux
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
"-I$(JAVA_HOME)/include/freebsd" -I$(src) -pthread
cflags = $(build-cflags)
endif
ifeq ($(platform),darwin)
ifeq (${OSX_SDK_SYSROOT},)
OSX_SDK_SYSROOT = 10.4u
@ -855,6 +865,10 @@ ifeq ($(target-platform),darwin)
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_DARWIN
endif
ifeq ($(target-platform),freebsd)
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_FREEBSD
endif
class-name = $(patsubst $(1)/%.class,%,$(2))
class-names = $(foreach x,$(2),$(call class-name,$(1),$(x)))

View File

@ -197,8 +197,8 @@ public:
const unsigned machine;
ElfPlatform(PlatformInfo::Architecture arch):
Platform(PlatformInfo(PlatformInfo::Linux, arch)),
ElfPlatform(PlatformInfo::OperatingSystem os, PlatformInfo::Architecture arch):
Platform(PlatformInfo(os, arch)),
machine(getElfPlatform(arch)) {}
class FileWriter {
@ -372,10 +372,15 @@ public:
}
};
ElfPlatform<uint32_t> elfx86Platform(PlatformInfo::x86);
ElfPlatform<uint32_t> elfArmPlatform(PlatformInfo::Arm);
ElfPlatform<uint32_t, false> elfPowerPCPlatform(PlatformInfo::PowerPC);
ElfPlatform<uint64_t> elfx86_64Platform(PlatformInfo::x86_64);
ElfPlatform<uint32_t> elfLinuxX86Platform(PlatformInfo::Linux, PlatformInfo::x86);
ElfPlatform<uint32_t> elfLinuxArmPlatform(PlatformInfo::Linux, PlatformInfo::Arm);
ElfPlatform<uint32_t, false> elfLinuxPowerPCPlatform(PlatformInfo::Linux, PlatformInfo::PowerPC);
ElfPlatform<uint64_t> elfLinuxX86_64Platform(PlatformInfo::Linux, PlatformInfo::x86_64);
ElfPlatform<uint32_t> elfFreeBSDx86Platform(PlatformInfo::FreeBSD, PlatformInfo::x86);
ElfPlatform<uint32_t> elfFreeBSDArmPlatform(PlatformInfo::FreeBSD, PlatformInfo::Arm);
ElfPlatform<uint32_t, false> elfFreeBSDPowerPCPlatform(PlatformInfo::FreeBSD, PlatformInfo::PowerPC);
ElfPlatform<uint64_t> elfFreeBSDx86_64Platform(PlatformInfo::FreeBSD, PlatformInfo::x86_64);
} // namespace

View File

@ -92,6 +92,8 @@ PlatformInfo::OperatingSystem PlatformInfo::osFromString(const char* os) {
return Windows;
} else if(strcmp(os, "darwin") == 0) {
return Darwin;
} else if(strcmp(os, "freebsd") == 0) {
return FreeBSD;
} else {
return UnknownOS;
}
@ -122,4 +124,5 @@ Platform* Platform::getPlatform(PlatformInfo info) {
} // namespace tools
} // namespace avian
} // namespace avian

View File

@ -135,6 +135,7 @@ public:
Linux = AVIAN_PLATFORM_LINUX,
Windows = AVIAN_PLATFORM_WINDOWS,
Darwin = AVIAN_PLATFORM_DARWIN,
FreeBSD = AVIAN_PLATFORM_FREEBSD,
UnknownOS = AVIAN_PLATFORM_UNKNOWN
};
@ -193,4 +194,5 @@ public:
} // namespace avian
#endif
#endif

View File

@ -3002,6 +3002,8 @@ jvmInitProperties(Thread* t, uintptr_t* arguments)
local::setProperty(t, method, *properties, "path.separator", ":");
# ifdef __APPLE__
local::setProperty(t, method, *properties, "os.name", "Mac OS X");
# elif defined __FreeBSD__
local::setProperty(t, method, *properties, "os.name", "FreeBSD");
# else // not __APPLE__
local::setProperty(t, method, *properties, "os.name", "Linux");
# endif // not __APPLE__

View File

@ -23,6 +23,7 @@
#define AVIAN_PLATFORM_LINUX 1
#define AVIAN_PLATFORM_WINDOWS 2
#define AVIAN_PLATFORM_DARWIN 3
#define AVIAN_PLATFORM_FREEBSD 4
#define AVIAN_ARCH_UNKNOWN 0
#define AVIAN_ARCH_X86 (1 << 8)
@ -30,4 +31,5 @@
#define AVIAN_ARCH_ARM (3 << 8)
#define AVIAN_ARCH_POWERPC (4 << 8)
#endif
#endif

View File

@ -17,6 +17,9 @@
# include "sys/ucontext.h"
# undef assert
#else
# if defined __FreeBSD__
# include "limits.h"
# endif
# include "ucontext.h"
#endif
@ -797,6 +800,13 @@ class MySystem: public System {
}
virtual FileType stat(const char* name, unsigned* length) {
#ifdef __FreeBSD__
// Now the hack below causes the error "Dereferencing type-punned
// pointer will break strict aliasing rules", so another workaround
// is needed...
struct stat ss;
struct stat* s = &ss;
#else
// Ugly Hack Alert: It seems that the Apple iOS Simulator's stat
// implementation writes beyond the end of the struct stat we pass
// it, which can clobber unrelated parts of the stack. Perhaps
@ -806,6 +816,7 @@ class MySystem: public System {
// made up and seems to work.
void* array[ceiling(sizeof(struct stat), sizeof(void*)) + 8];
struct stat* s = reinterpret_cast<struct stat*>(array);
#endif
int r = ::stat(name, s);
if (r == 0) {

View File

@ -60,4 +60,5 @@
# error
#endif
#endif
#endif

View File

@ -70,6 +70,12 @@
# define THREAD_REGISTER(context) (context->uc_mcontext.cpu.ebx)
# define LINK_REGISTER(context) (context->uc_mcontext.cpu.ecx)
# define FRAME_REGISTER(context) (context->uc_mcontext.cpu.ebp)
# elif (defined __FreeBSD__)
# define IP_REGISTER(context) (context->uc_mcontext.mc_eip)
# define STACK_REGISTER(context) (context->uc_mcontext.mc_esp)
# define THREAD_REGISTER(context) (context->uc_mcontext.mc_ebx)
# define LINK_REGISTER(context) (context->uc_mcontext.mc_ecx)
# define FRAME_REGISTER(context) (context->uc_mcontext.mc_ebp)
# else
# define IP_REGISTER(context) (context->uc_mcontext.gregs[REG_EIP])
# define STACK_REGISTER(context) (context->uc_mcontext.gregs[REG_ESP])