add support for LZMA on Windows

This commit is contained in:
Joel Dice 2012-06-02 15:43:42 -06:00
parent f07a8c7ec4
commit d61501453f
7 changed files with 109 additions and 24 deletions

View File

@ -71,6 +71,8 @@ ifeq ($(build-platform),cygwin)
native-path = cygpath -m
endif
windows-path = echo
path-separator = :
ifneq (,$(filter mingw32 cygwin,$(build-platform)))
@ -500,8 +502,9 @@ ld := $(cc)
build-ld := $(build-cc)
ifdef msvc
windows-java-home := $(shell cygpath -m "$(JAVA_HOME)")
zlib := $(shell cygpath -m "$(win32)/msvc")
windows-path = $(native-path)
windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)")
zlib := $(shell $(windows-path) "$(win32)/msvc")
cxx = "$(msvc)/BIN/cl.exe"
cc = $(cxx)
ld = "$(msvc)/BIN/link.exe"
@ -512,6 +515,11 @@ ifdef msvc
-Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \
-I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \
-DTARGET_BYTES_PER_WORD=$(pointer-size)
ifneq ($(lzma),)
cflags += -I$(shell $(windows-path) "$(lzma)")
endif
shared = -dll
lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \
-DEFAULTLIB:zlib -MANIFEST -debug
@ -638,7 +646,7 @@ generator-sources = \
$(src)/finder.cpp
ifneq ($(lzma),)
common-cflags += -I$(lzma)/C -DAVIAN_USE_LZMA -D_7ZIP_ST
common-cflags += -I$(lzma) -DAVIAN_USE_LZMA -D_7ZIP_ST
vm-sources += \
$(src)/lzma-decode.cpp
@ -673,7 +681,7 @@ ifneq ($(lzma),)
lzma-encoder-lzma-sources = $(lzma-encode-sources) $(lzma-decode-sources)
lzma-encoder-lzma-objects = \
$(call c-objects,$(lzma-encoder-lzma-sources),$(lzma)/C,$(build))
$(call generator-c-objects,$(lzma-encoder-lzma-sources),$(lzma)/C,$(build))
lzma-loader = $(build)/lzma/load.o
endif
@ -904,7 +912,7 @@ $(test-extra-dep): $(test-extra-sources)
define compile-object
@echo "compiling $(@)"
@mkdir -p $(dir $(@))
$(cxx) $(cflags) -c $(<) $(call output,$(@))
$(cxx) $(cflags) -c $$($(windows-path) $(<)) $(call output,$(@))
endef
define compile-asm-object
@ -993,7 +1001,7 @@ $(generator-objects): $(generator-depends)
$(generator-objects): $(build)/%-build.o: $(src)/%.cpp
$(compile-generator-object)
$(generator-lzma-objects): $(build)/%-build.o: $(lzma)/C/%.c
$(build)/%-build.o: $(lzma)/C/%.c
$(compile-generator-object)
$(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp

View File

@ -10022,7 +10022,7 @@ compileVirtualThunk(MyThread* t, unsigned index, unsigned* size)
sprintf(RUNTIME_ARRAY_BODY(virtualThunkName), "%s%d", virtualThunkBaseName, index);
logCompile(t, start, *size, 0, virtualThunkName, 0);
logCompile(t, start, *size, 0, RUNTIME_ARRAY_BODY(virtualThunkName), 0);
return reinterpret_cast<uintptr_t>(start);
}

View File

@ -9,7 +9,7 @@
details. */
#include "lzma-util.h"
#include "LzmaDec.h"
#include "C/LzmaDec.h"
using namespace vm;

View File

@ -9,7 +9,7 @@
details. */
#include "lzma-util.h"
#include "LzmaEnc.h"
#include "C/LzmaEnc.h"
using namespace vm;

View File

@ -12,7 +12,7 @@
#define LZMA_UTIL_H
#include "lzma.h"
#include "Types.h"
#include "C/Types.h"
#include "system.h"
#include "allocator.h"

View File

@ -2,22 +2,31 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "LzmaDec.h"
#include "C/LzmaDec.h"
#ifdef __MINGW32__
#if (defined __MINGW32__) || (defined _MSC_VER)
# define EXPORT __declspec(dllexport)
# include <io.h>
# define open _open
# define write _write
# define close _close
# ifdef _MSC_VER
# define S_IRWXU (_S_IREAD | _S_IWRITE)
# define and &&
# endif
#else
# define EXPORT __attribute__ ((visibility("default")))
# include <dlfcn.h>
# include <unistd.h>
# include <errno.h>
# define O_BINARY 0
#endif
#if defined __MINGW32__ && ! defined __x86_64__
#if (! defined __x86_64__) && ((defined __MINGW32__) || (defined _MSC_VER))
# define SYMBOL(x) binary_exe_##x
#else
# define SYMBOL(x) _binary_exe_##x
@ -44,6 +53,70 @@ myFree(void*, void* address)
free(address);
}
#if (defined __MINGW32__) || (defined _MSC_VER)
void*
openLibrary(const char* name)
{
return LoadLibrary(name);
}
void*
librarySymbol(void* library, const char* name)
{
void* address;
FARPROC p = GetProcAddress(static_cast<HMODULE>(library), name);
memcpy(&address, &p, sizeof(void*));
return address;
}
const char*
libraryError(void*)
{
return "unknown error";
}
const char*
temporaryFileName(char* buffer, unsigned size)
{
unsigned c = GetTempPathA(size, buffer);
if (c) {
if (GetTempFileNameA(buffer, "223", 0, buffer + c)) {
DeleteFileA(buffer + c);
return buffer + c;
}
}
return 0;
}
#else
void*
openLibrary(const char* name)
{
return dlopen(name, RTLD_LAZY | RTLD_LOCAL);
}
void*
librarySymbol(void* library, const char* name)
{
return dlsym(library, name);
}
const char*
libraryError(void*)
{
return dlerror();
}
const char*
temporaryFileName(char* buffer, unsigned)
{
return tmpnam(buffer);
}
#endif
} // namespace
int
@ -67,28 +140,31 @@ main(int ac, const char** av)
(out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start),
PropHeaderSize, LZMA_FINISH_END, &status, &allocator))
{
char name[L_tmpnam];
if (tmpnam(name)) {
int file = open(name, O_CREAT | O_EXCL | O_WRONLY, S_IRWXU);
const unsigned BufferSize = 1024;
char buffer[BufferSize];
const char* name = temporaryFileName(buffer, BufferSize);
if (name) {
int file = open(name, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, S_IRWXU);
if (file != -1) {
SizeT result = write(file, out, outSize);
free(out);
if (close(file) == 0 and outSize == result) {
void* library = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
void* library = openLibrary(name);
unlink(name);
if (library) {
void* main = dlsym(library, "main");
void* main = librarySymbol(library, "avianMain");
if (main) {
int (*mainFunction)(int, const char**);
int (*mainFunction)(const char*, int, const char**);
memcpy(&mainFunction, &main, sizeof(void*));
return mainFunction(ac, av);
return mainFunction(name, ac, av);
} else {
fprintf(stderr, "unable to find main in %s", name);
}
} else {
fprintf(stderr, "unable to dlopen %s: %s\n", name, dlerror());
fprintf(stderr, "unable to load %s: %s\n", name,
libraryError(library));
}
} else {
unlink(name);

View File

@ -2925,6 +2925,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder,
shutdownLock(0),
libraries(0),
errorLog(0),
bootimage(0),
types(0),
roots(0),
finalizers(0),