1 /* darwin.cc - class loader stuff for Darwin. */
3 /* Copyright (C) 2004 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
15 /* In theory, we should be able to do:
16 #include <mach-o/getsect.h>
17 #include <mach-o/dyld.h>
19 but all the types in these headers changed between Panther and Tiger,
20 so the only way to be avoid type mismatches is to declare the routines
25 extern "C" void _dyld_register_func_for_add_image
26 (void (*func
)(const struct mach_header
*mh
, intptr_t vmaddr_slide
));
27 extern "C" void _dyld_register_func_for_remove_image
28 (void (*func
)(const struct mach_header
*mh
, intptr_t vmaddr_slide
));
29 extern "C" char *getsectdatafromheader
30 (const struct mach_header
*mhp
, const char *segname
, const char *sectname
,
33 /* When a new image is loaded, look to see if it has a jcr section
34 and if so register the classes listed in it. */
37 darwin_java_register_dyld_add_image_hook (const struct mach_header
*mh
,
43 fde
= getsectdatafromheader (mh
, "__DATA", "jcr", &sz
);
47 /* As far as I can tell, you're only supposed to load shared
48 libraries while having a lock on java.lang.Class. So there's
49 no need to synchronize on anything here. (I'm not sure how exactly
50 you can ensure this given lazy library loading. FIXME.) */
52 _Jv_RegisterClasses_Counted ((const jclass
*) (fde
+ slide
),
53 sz
/ sizeof (jclass
*));
56 static struct darwin_constructor_s
{
57 darwin_constructor_s()
59 _dyld_register_func_for_add_image
60 (darwin_java_register_dyld_add_image_hook
);
61 /* At present, you mustn't unload any java plugin. */