darwin.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* darwin.cc - class loader stuff for Darwin. */
  2. /* Copyright (C) 2004, 2007 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. #include <config.h>
  8. #include <jvm.h>
  9. /* In theory, we should be able to do:
  10. #include <mach-o/getsect.h>
  11. #include <mach-o/dyld.h>
  12. but all the types in these headers changed between Panther and Tiger,
  13. so the only way to be avoid type mismatches is to declare the routines
  14. ourself. */
  15. #include <stdint.h>
  16. #if !defined (__LP64__)
  17. struct mach_header;
  18. # define JAVA_MACH_HEADER mach_header
  19. # define mh_size_t uint32_t
  20. extern "C" void _dyld_register_func_for_add_image
  21. (void (*func)(const struct mach_header *mh, intptr_t vmaddr_slide));
  22. extern "C" void _dyld_register_func_for_remove_image
  23. (void (*func)(const struct mach_header *mh, intptr_t vmaddr_slide));
  24. extern "C" char *getsectdatafromheader
  25. (const struct mach_header *mhp, const char *segname, const char *sectname,
  26. uint32_t *size);
  27. # define GETSECTDATA getsectdatafromheader
  28. #else
  29. struct mach_header_64;
  30. # define JAVA_MACH_HEADER mach_header_64
  31. # define mh_size_t uint64_t
  32. extern "C" void _dyld_register_func_for_add_image
  33. (void (*func)(const struct mach_header_64 *mh, intptr_t vmaddr_slide));
  34. extern "C" void _dyld_register_func_for_remove_image
  35. (void (*func)(const struct mach_header_64 *mh, intptr_t vmaddr_slide));
  36. extern "C" char *getsectdatafromheader_64
  37. (const struct mach_header_64 *mhp, const char *segname,
  38. const char *sectname, uint64_t *size);
  39. # define GETSECTDATA getsectdatafromheader_64
  40. #endif
  41. /* When a new image is loaded, look to see if it has a jcr section
  42. and if so register the classes listed in it. */
  43. static void
  44. darwin_java_register_dyld_add_image_hook (const struct JAVA_MACH_HEADER *mh,
  45. intptr_t slide)
  46. {
  47. char *fde;
  48. mh_size_t sz;
  49. fde = GETSECTDATA (mh, "__DATA", "jcr", &sz);
  50. if (! fde)
  51. return;
  52. /* As far as I can tell, you're only supposed to load shared
  53. libraries while having a lock on java.lang.Class. So there's
  54. no need to synchronize on anything here. (I'm not sure how exactly
  55. you can ensure this given lazy library loading. FIXME.) */
  56. _Jv_RegisterClasses_Counted ((const jclass *) (fde + slide),
  57. sz / sizeof (jclass *));
  58. }
  59. static struct darwin_constructor_s{
  60. darwin_constructor_s()
  61. {
  62. _dyld_register_func_for_add_image
  63. (darwin_java_register_dyld_add_image_hook);
  64. /* At present, you mustn't unload any java plugin. */
  65. };
  66. } darwin_constructor;