source: trunk/gcc/libjava/gnu/gcj/runtime/natSharedLibLoader.cc

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1// natSharedLibLoader.cc - Implementation of FirstThread native methods.
2
3/* Copyright (C) 2001, 2003 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
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. */
22static gnu::gcj::runtime::SharedLibLoader* curLoader;
23
24typedef void (*ClassHookFunc) (jclass);
25
26static void
27::register_hook(jclass cls)
28{
29 curLoader->registerClass(cls->getName(), cls);
30}
31
32struct 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
47void
48gnu::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 = "SharedLibLoader is not supported on this platform";
66 throw new java::lang::UnsupportedOperationException(JvNewStringLatin1(msg));
67#endif
68}
69
70void
71gnu::gcj::runtime::SharedLibLoader::finalize()
72{
73#ifdef HAVE_DLOPEN
74 dlclose (handler);
75#endif
76}
Note: See TracBrowser for help on using the repository browser.