| 1 | // natSharedLibLoader.cc - Implementation of FirstThread native methods.
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright (C) 2001 Free Software Foundation
|
|---|
| 4 |
|
|---|
| 5 | This file is part of libgcj.
|
|---|
| 6 |
|
|---|
| 7 | This software is copyrighted work licensed under the terms of the
|
|---|
| 8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|---|
| 9 | details. */
|
|---|
| 10 |
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 |
|
|---|
| 13 | #include <gcj/cni.h>
|
|---|
| 14 | #include <gnu/gcj/runtime/SharedLibLoader.h>
|
|---|
| 15 | #include <java/io/IOException.h>
|
|---|
| 16 | #include <java/lang/UnsupportedOperationException.h>
|
|---|
| 17 |
|
|---|
| 18 | #ifdef HAVE_DLOPEN
|
|---|
| 19 | #include <dlfcn.h>
|
|---|
| 20 |
|
|---|
| 21 | /* Only used during dlopen, while having a lock on Class.class. */
|
|---|
| 22 | static gnu::gcj::runtime::SharedLibLoader* curLoader;
|
|---|
| 23 |
|
|---|
| 24 | typedef void (*ClassHookFunc) (jclass);
|
|---|
| 25 |
|
|---|
| 26 | static void
|
|---|
| 27 | ::register_hook(jclass cls)
|
|---|
| 28 | {
|
|---|
| 29 | curLoader->registerClass(cls->getName(), cls);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | struct SharedLibDummy
|
|---|
| 33 | {
|
|---|
| 34 | ClassHookFunc saved;
|
|---|
| 35 | SharedLibDummy()
|
|---|
| 36 | {
|
|---|
| 37 | saved = _Jv_RegisterClassHook;
|
|---|
| 38 | }
|
|---|
| 39 | ~SharedLibDummy()
|
|---|
| 40 | {
|
|---|
| 41 | _Jv_RegisterClassHook = saved;
|
|---|
| 42 | curLoader = NULL;
|
|---|
| 43 | }
|
|---|
| 44 | };
|
|---|
| 45 | #endif
|
|---|
| 46 |
|
|---|
| 47 | void
|
|---|
| 48 | gnu::gcj::runtime::SharedLibLoader::init(jbyteArray libname, jint flags)
|
|---|
| 49 | {
|
|---|
| 50 | #ifdef HAVE_DLOPEN
|
|---|
| 51 | char *lname = (char*) elements(libname);
|
|---|
| 52 | if (flags==0)
|
|---|
| 53 | flags = RTLD_LAZY;
|
|---|
| 54 | JvSynchronize dummy1(&java::lang::Class::class$);
|
|---|
| 55 | SharedLibDummy dummy2;
|
|---|
| 56 | curLoader = this;
|
|---|
| 57 | _Jv_RegisterClassHook = ::register_hook;
|
|---|
| 58 | void *h = dlopen(lname, flags);
|
|---|
| 59 | if (h == NULL)
|
|---|
| 60 | {
|
|---|
| 61 | const char *msg = dlerror();
|
|---|
| 62 | }
|
|---|
| 63 | handler = (gnu::gcj::RawData*) h;
|
|---|
| 64 | #else
|
|---|
| 65 | const char *msg = "ShareedLibLoader is not supported on this platform";
|
|---|
| 66 | throw new java::lang::UnsupportedOperationException(JvNewStringLatin1(msg));
|
|---|
| 67 | #endif
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void
|
|---|
| 71 | gnu::gcj::runtime::SharedLibLoader::finalize()
|
|---|
| 72 | {
|
|---|
| 73 | #ifdef HAVE_DLOPEN
|
|---|
| 74 | dlclose (handler);
|
|---|
| 75 | #endif
|
|---|
| 76 | }
|
|---|