1 /* darwin.cc - class loader stuff for Darwin. */
3 /* Copyright (C) 2004, 2007 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
24 #if !defined (__LP64__)
26 # define JAVA_MACH_HEADER mach_header
27 # define mh_size_t uint32_t
28 extern "C" void _dyld_register_func_for_add_image
29 (void (*func
)(const struct mach_header
*mh
, intptr_t vmaddr_slide
));
30 extern "C" void _dyld_register_func_for_remove_image
31 (void (*func
)(const struct mach_header
*mh
, intptr_t vmaddr_slide
));
32 extern "C" char *getsectdatafromheader
33 (const struct mach_header
*mhp
, const char *segname
, const char *sectname
,
35 # define GETSECTDATA getsectdatafromheader
37 struct mach_header_64
;
38 # define JAVA_MACH_HEADER mach_header_64
39 # define mh_size_t uint64_t
40 extern "C" void _dyld_register_func_for_add_image
41 (void (*func
)(const struct mach_header_64
*mh
, intptr_t vmaddr_slide
));
42 extern "C" void _dyld_register_func_for_remove_image
43 (void (*func
)(const struct mach_header_64
*mh
, intptr_t vmaddr_slide
));
44 extern "C" char *getsectdatafromheader_64
45 (const struct mach_header_64
*mhp
, const char *segname
,
46 const char *sectname
, uint64_t *size
);
47 # define GETSECTDATA getsectdatafromheader_64
50 /* When a new image is loaded, look to see if it has a jcr section
51 and if so register the classes listed in it. */
54 darwin_java_register_dyld_add_image_hook (const struct JAVA_MACH_HEADER
*mh
,
60 fde
= GETSECTDATA (mh
, "__DATA", "jcr", &sz
);
64 /* As far as I can tell, you're only supposed to load shared
65 libraries while having a lock on java.lang.Class. So there's
66 no need to synchronize on anything here. (I'm not sure how exactly
67 you can ensure this given lazy library loading. FIXME.) */
69 _Jv_RegisterClasses_Counted ((const jclass
*) (fde
+ slide
),
70 sz
/ sizeof (jclass
*));
73 static struct darwin_constructor_s
{
74 darwin_constructor_s()
76 _dyld_register_func_for_add_image
77 (darwin_java_register_dyld_add_image_hook
);
78 /* At present, you mustn't unload any java plugin. */