elf-fdpic.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. #ifndef _BITS_ELF_FDPIC_H
  16. #define _BITS_ELF_FDPIC_H
  17. /* These data structures are described in the FDPIC ABI extension.
  18. The kernel passes a process a memory map, such that for every LOAD
  19. segment there is an elf32_fdpic_loadseg entry. A pointer to an
  20. elf32_fdpic_loadmap is passed in GR8 at start-up, and a pointer to
  21. an additional such map is passed in GR9 for the interpreter, when
  22. there is one. */
  23. #include <elf.h>
  24. /* This data structure represents a PT_LOAD segment. */
  25. struct elf32_fdpic_loadseg
  26. {
  27. /* Core address to which the segment is mapped. */
  28. Elf32_Addr addr;
  29. /* VMA recorded in the program header. */
  30. Elf32_Addr p_vaddr;
  31. /* Size of this segment in memory. */
  32. Elf32_Word p_memsz;
  33. };
  34. struct elf32_fdpic_loadmap {
  35. /* Protocol version number, must be zero. */
  36. Elf32_Half version;
  37. /* Number of segments in this map. */
  38. Elf32_Half nsegs;
  39. /* The actual memory map. */
  40. struct elf32_fdpic_loadseg segs[/*nsegs*/];
  41. };
  42. struct elf32_fdpic_loadaddr {
  43. struct elf32_fdpic_loadmap *map;
  44. void *got_value;
  45. };
  46. /* Map a pointer's VMA to its corresponding address according to the
  47. load map. */
  48. inline static void *
  49. __reloc_pointer (void *p,
  50. const struct elf32_fdpic_loadmap *map)
  51. {
  52. int c;
  53. #if 0
  54. if (map->version != 0)
  55. /* Crash. */
  56. ((void(*)())0)();
  57. #endif
  58. /* No special provision is made for NULL. We don't want NULL
  59. addresses to go through relocation, so they shouldn't be in
  60. .rofixup sections, and, if they're present in dynamic
  61. relocations, they shall be mapped to the NULL address without
  62. undergoing relocations. */
  63. for (c = 0;
  64. /* Take advantage of the fact that the loadmap is ordered by
  65. virtual addresses. In general there will only be 2 entries,
  66. so it's not profitable to do a binary search. */
  67. c < map->nsegs && p >= (void*)map->segs[c].p_vaddr;
  68. c++)
  69. {
  70. /* This should be computed as part of the pointer comparison
  71. above, but we want to use the carry in the comparison, so we
  72. can't convert it to an integer type beforehand. */
  73. unsigned long offset = p - (void*)map->segs[c].p_vaddr;
  74. /* We explicitly refrain from checking for one-past-the-end.
  75. Zero-sized objects aren't legal, and it's expected that array
  76. addresses will be relocated before the addend that would make
  77. it one-past-the-end is added. This gives us a reasonable speed
  78. up, and we couldn't possibly disambiguate all cases anyway. */
  79. if (offset < map->segs[c].p_memsz)
  80. return (char*)map->segs[c].addr + offset;
  81. }
  82. /* We might want to crash instead. */
  83. return (void*)-1;
  84. }
  85. # define __RELOC_POINTER(ptr, loadaddr) \
  86. (__reloc_pointer ((void*)(ptr), \
  87. (loadaddr).map))
  88. #endif /* _BITS_ELF_FDPIC_H */