diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2008-03-22 02:15:12 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2008-03-22 02:15:12 +0000 |
commit | a764e59e1d3a8e330f0d484fdb26b35ca3f0b2e4 (patch) | |
tree | c4ecadccdecf2809b99c0da0545f255a6ad25bb5 /src/pdj-linux.c |
bringing pdj-0.8.3 into the main branchsvn2git-root
svn path=/trunk/externals/loaders/pdj/; revision=9621
Diffstat (limited to 'src/pdj-linux.c')
-rw-r--r-- | src/pdj-linux.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/pdj-linux.c b/src/pdj-linux.c new file mode 100644 index 0000000..63bb015 --- /dev/null +++ b/src/pdj-linux.c @@ -0,0 +1,91 @@ +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <dlfcn.h> +#include "pdj.h" + +int getuglylibpath(char *path) { + char buffer[BUFFER_SIZE]; + FILE *f; + + sprintf(buffer, "/proc/%d/maps", getpid()); + f = fopen(buffer, "r"); + if ( f == NULL ) { + perror("pdj: unable to map :"); + strcpy(path, "."); + return 1; + } + + while(!feof(f)) { + fgets(buffer, BUFFER_SIZE-1, f); + if ( strstr(buffer, "pdj.pd_linux") != NULL ) { + buffer[strlen(buffer) - 14] = 0; + strcpy(path, buffer+49); + fclose(f); + return 0; + } + } + + /* not found, check in the current dir :( */ + post("pdj: humm... pdj path library not found, setting current path"); + strcpy(path, "."); + fclose(f); + return 1; +} + + +JNI_CreateJavaVM_func *linkjvm(char *vm_type) { + JNI_CreateJavaVM_func *func; + char work[BUFFER_SIZE]; + char *javahome = pdj_getProperty("pdj.JAVA_HOME"); + void *libVM; + + if ( javahome == NULL ) { + javahome = getenv("JAVA_HOME"); + } else { + sprintf(work, "%s/jre/lib/i386/%s/libjvm.so", javahome, vm_type); + libVM = dlopen(work, RTLD_LAZY); + + if ( libVM == NULL ) { + post("pdj: unable to use the JVM specified at pdj.JAVA_HOME"); + javahome = getenv("JAVA_HOME"); + } + } + + if ( javahome == NULL ) { + post("pdj: using JVM from the LD_LIBRARY_PATH"); + libVM = dlopen("libjava.so", RTLD_LAZY); + } else { + post("pdj: using JVM %s", javahome); + /* using LD_LIBRARY_PATH + putenv doesn't work, load std jvm libs + * with absolute path. order is important. + */ + sprintf(work, "%s/jre/lib/i386/%s/libjvm.so", javahome, vm_type); + dlopen(work, RTLD_LAZY); + + sprintf(work, "%s/jre/lib/i386/libverify.so", javahome); + dlopen(work, RTLD_LAZY); + + sprintf(work, "%s/jre/lib/i386/libjava.so", javahome); + dlopen(work, RTLD_LAZY); + + sprintf(work, "%s/jre/lib/i386/libmlib_image.so", javahome); + dlopen(work, RTLD_LAZY); + + /* ELF should support dynamic LD_LIBRARY_PATH :( :( :( */ + sprintf(work, "%s/jre/lib/i386/libjava.so", javahome); + libVM = dlopen(work, RTLD_LAZY); + } + + if ( libVM == 0 ) { + error("pdj: %s", dlerror()); + return NULL; + } + + func = dlsym(libVM, "JNI_CreateJavaVM"); + if ( func == 0 ) { + error("pdj: %s", dlerror()); + return NULL; + } + return func; +} |