elf-fdpic.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright 2003, 2004 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. In addition to the permissions in the GNU Lesser General Public
  8. License, the Free Software Foundation gives you unlimited
  9. permission to link the compiled version of this file with other
  10. programs, and to distribute those programs without any restriction
  11. coming from the use of this file. (The GNU Lesser General Public
  12. License restrictions do apply in other respects; for example, they
  13. cover modification of the file, and distribution when not linked
  14. into another program.)
  15. The GNU C Library is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Library General Public License for more details.
  19. You should have received a copy of the GNU Lesser General Public
  20. License along with the GNU C Library; see the file COPYING.LIB. If
  21. not, see <http://www.gnu.org/licenses/>. */
  22. #ifndef _BITS_ELF_FDPIC_H
  23. #define _BITS_ELF_FDPIC_H
  24. /* These data structures are described in the FDPIC ABI extension.
  25. The kernel passes a process a memory map, such that for every LOAD
  26. segment there is an elf32_fdpic_loadseg entry. A pointer to an
  27. elf32_fdpic_loadmap is passed in r7 at start-up, and a pointer to
  28. an additional such map is passed in r8 for the interpreter, when
  29. there is one. */
  30. #include <elf.h>
  31. /* This data structure represents a PT_LOAD segment. */
  32. struct elf32_fdpic_loadseg
  33. {
  34. /* Core address to which the segment is mapped. */
  35. Elf32_Addr addr;
  36. /* VMA recorded in the program header. */
  37. Elf32_Addr p_vaddr;
  38. /* Size of this segment in memory. */
  39. Elf32_Word p_memsz;
  40. };
  41. struct elf32_fdpic_loadmap {
  42. /* Protocol version number, must be zero. */
  43. Elf32_Half version;
  44. /* Number of segments in this map. */
  45. Elf32_Half nsegs;
  46. /* The actual memory map. */
  47. struct elf32_fdpic_loadseg segs[/*nsegs*/];
  48. };
  49. struct elf32_fdpic_loadaddr {
  50. struct elf32_fdpic_loadmap *map;
  51. void *got_value;
  52. };
  53. /* Map a pointer's VMA to its corresponding address according to the
  54. load map. */
  55. static __always_inline void *
  56. __reloc_pointer (void *p,
  57. const struct elf32_fdpic_loadmap *map)
  58. {
  59. int c;
  60. #if 0
  61. if (map->version != 0)
  62. /* Crash. */
  63. ((void(*)())0)();
  64. #endif
  65. /* No special provision is made for NULL. We don't want NULL
  66. addresses to go through relocation, so they shouldn't be in
  67. .rofixup sections, and, if they're present in dynamic
  68. relocations, they shall be mapped to the NULL address without
  69. undergoing relocations. */
  70. for (c = 0;
  71. /* Take advantage of the fact that the loadmap is ordered by
  72. virtual addresses. In general there will only be 2 entries,
  73. so it's not profitable to do a binary search. */
  74. c < map->nsegs && p >= (void*)map->segs[c].p_vaddr;
  75. c++)
  76. {
  77. /* This should be computed as part of the pointer comparison
  78. above, but we want to use the carry in the comparison, so we
  79. can't convert it to an integer type beforehand. */
  80. unsigned long offset = (char*)p - (char*)map->segs[c].p_vaddr;
  81. /* We only check for one-past-the-end for the last segment,
  82. assumed to be the data segment, because other cases are
  83. ambiguous in the absence of padding between segments, and
  84. rofixup already serves as padding between text and data.
  85. Unfortunately, unless we special-case the last segment, we
  86. fail to relocate the _end symbol. */
  87. if (offset < map->segs[c].p_memsz
  88. || (offset == map->segs[c].p_memsz && c + 1 == map->nsegs))
  89. return (char*)map->segs[c].addr + offset;
  90. }
  91. /* We might want to crash instead. */
  92. return (void*)-1;
  93. }
  94. # define __RELOC_POINTER(ptr, loadaddr) \
  95. (__reloc_pointer ((void*)(ptr), \
  96. (loadaddr).map))
  97. void*
  98. __self_reloc (const struct elf32_fdpic_loadmap *map, void ***p, void ***e);
  99. #endif /* _BITS_ELF_FDPIC_H */