zend_elf.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend JIT |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | https://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Dmitry Stogov <dmitry@php.net> |
  16. | Xinchen Hui <laruence@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef ZEND_ELF
  20. #define ZEND_ELF
  21. #if SIZEOF_SIZE_T == 8
  22. # define ELF64
  23. #else
  24. # undef ELF64
  25. #endif
  26. typedef struct _zend_elf_header {
  27. uint8_t emagic[4];
  28. uint8_t eclass;
  29. uint8_t eendian;
  30. uint8_t eversion;
  31. uint8_t eosabi;
  32. uint8_t eabiversion;
  33. uint8_t epad[7];
  34. uint16_t type;
  35. uint16_t machine;
  36. uint32_t version;
  37. uintptr_t entry;
  38. uintptr_t phofs;
  39. uintptr_t shofs;
  40. uint32_t flags;
  41. uint16_t ehsize;
  42. uint16_t phentsize;
  43. uint16_t phnum;
  44. uint16_t shentsize;
  45. uint16_t shnum;
  46. uint16_t shstridx;
  47. } zend_elf_header;
  48. typedef struct zend_elf_sectheader {
  49. uint32_t name;
  50. uint32_t type;
  51. uintptr_t flags;
  52. uintptr_t addr;
  53. uintptr_t ofs;
  54. uintptr_t size;
  55. uint32_t link;
  56. uint32_t info;
  57. uintptr_t align;
  58. uintptr_t entsize;
  59. } zend_elf_sectheader;
  60. #define ELFSECT_IDX_ABS 0xfff1
  61. enum {
  62. ELFSECT_TYPE_PROGBITS = 1,
  63. ELFSECT_TYPE_SYMTAB = 2,
  64. ELFSECT_TYPE_STRTAB = 3,
  65. ELFSECT_TYPE_NOBITS = 8,
  66. ELFSECT_TYPE_DYNSYM = 11,
  67. };
  68. #define ELFSECT_FLAGS_WRITE (1 << 0)
  69. #define ELFSECT_FLAGS_ALLOC (1 << 1)
  70. #define ELFSECT_FLAGS_EXEC (1 << 2)
  71. #define ELFSECT_FLAGS_TLS (1 << 10)
  72. typedef struct zend_elf_symbol {
  73. #ifdef ELF64
  74. uint32_t name;
  75. uint8_t info;
  76. uint8_t other;
  77. uint16_t sectidx;
  78. uintptr_t value;
  79. uint64_t size;
  80. #else
  81. uint32_t name;
  82. uintptr_t value;
  83. uint32_t size;
  84. uint8_t info;
  85. uint8_t other;
  86. uint16_t sectidx;
  87. #endif
  88. } zend_elf_symbol;
  89. #define ELFSYM_BIND(info) ((info) >> 4)
  90. #define ELFSYM_TYPE(info) ((info) & 0xf)
  91. #define ELFSYM_INFO(bind, type) (((bind) << 4) | (type))
  92. enum {
  93. ELFSYM_TYPE_DATA = 2,
  94. ELFSYM_TYPE_FUNC = 2,
  95. ELFSYM_TYPE_FILE = 4,
  96. };
  97. enum {
  98. ELFSYM_BIND_LOCAL = 0,
  99. ELFSYM_BIND_GLOBAL = 1,
  100. };
  101. void zend_elf_load_symbols(void);
  102. #endif