From a764e59e1d3a8e330f0d484fdb26b35ca3f0b2e4 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 22 Mar 2008 02:15:12 +0000 Subject: bringing pdj-0.8.3 into the main branch svn path=/trunk/externals/loaders/pdj/; revision=9621 --- src/pdj-linux.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/pdj-linux.c (limited to 'src/pdj-linux.c') 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 +#include +#include +#include +#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; +} -- cgit v1.2.1