Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /* TODO:
  2. * notify gdb of unload
  3. * for non-prelinked libraries, find a way to decrement libbase
  4. */
  5. static void call_destructors(soinfo *si);
  6. unsigned unload_library(soinfo *si)
  7. {
  8. unsigned *d;
  9. if (si->refcount == 1) {
  10. TRACE("%5d unloading '%s'\n", pid, si->name);
  11. call_destructors(si);
  12.  
  13. /*
  14. * Make sure that we undo the PT_GNU_RELRO protections we added
  15. * in link_image. This is needed to undo the DT_NEEDED hack below.
  16. */
  17. if ((si->gnu_relro_start != 0) && (si->gnu_relro_len != 0)) {
  18. Elf_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
  19. unsigned len = (si->gnu_relro_start - start) + si->gnu_relro_len;
  20. if (mprotect((void *) start, len, PROT_READ | PROT_WRITE) < 0)
  21. DL_ERR("%5d %s: could not undo GNU_RELRO protections. "
  22. "Expect a crash soon. errno=%d (%s)",
  23. pid, si->name, errno, strerror(errno));
  24.  
  25. }
  26.  
  27. for(d = si->dynamic; *d; d += 2) {
  28. if(d[0] == DT_NEEDED){
  29. soinfo *lsi = (soinfo *)d[1];
  30.  
  31. // The next line will segfault if the we don't undo the
  32. // PT_GNU_RELRO protections (see comments above and in
  33. // link_image().
  34. d[1] = 0;
  35.  
  36. if (validate_soinfo(lsi)) {
  37. TRACE("%5d %s needs to unload %s\n", pid,
  38. si->name, lsi->name);
  39. unload_library(lsi);
  40. }
  41. else
  42. DL_ERR("%5d %s: could not unload dependent library",
  43. pid, si->name);
  44. }
  45. }
  46.  
  47. munmap((char *)si->base, si->size);
  48. notify_gdb_of_unload(si);
  49. free_info(si);
  50. si->refcount = 0;
  51. }
  52. else {
  53. si->refcount--;
  54. INFO("%5d not unloading '%s', decrementing refcount to %d\n",
  55. pid, si->name, si->refcount);
  56. }
  57. return si->refcount;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement