2
0

loader.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * loader.h: prototypes for linux-user guest binary loader
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef LINUX_USER_LOADER_H
  18. #define LINUX_USER_LOADER_H
  19. typedef struct {
  20. const void *cache;
  21. unsigned int cache_size;
  22. int fd;
  23. } ImageSource;
  24. /**
  25. * imgsrc_read: Read from ImageSource
  26. * @dst: destination for read
  27. * @offset: offset within file for read
  28. * @len: size of the read
  29. * @img: ImageSource to read from
  30. * @errp: Error details.
  31. *
  32. * Read into @dst, using the cache when possible.
  33. */
  34. bool imgsrc_read(void *dst, off_t offset, size_t len,
  35. const ImageSource *img, Error **errp);
  36. /**
  37. * imgsrc_read_alloc: Read from ImageSource
  38. * @offset: offset within file for read
  39. * @size: size of the read
  40. * @img: ImageSource to read from
  41. * @errp: Error details.
  42. *
  43. * Read into newly allocated memory, using the cache when possible.
  44. */
  45. void *imgsrc_read_alloc(off_t offset, size_t len,
  46. const ImageSource *img, Error **errp);
  47. /**
  48. * imgsrc_mmap: Map from ImageSource
  49. *
  50. * If @src has a file descriptor, pass on to target_mmap. Otherwise,
  51. * this is "mapping" from a host buffer, which resolves to memcpy.
  52. * Therefore, flags must be MAP_PRIVATE | MAP_FIXED; the argument is
  53. * retained for clarity.
  54. */
  55. abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot,
  56. int flags, const ImageSource *src, abi_ulong offset);
  57. /*
  58. * Read a good amount of data initially, to hopefully get all the
  59. * program headers loaded.
  60. */
  61. #define BPRM_BUF_SIZE 1024
  62. /*
  63. * This structure is used to hold the arguments that are
  64. * used when loading binaries.
  65. */
  66. struct linux_binprm {
  67. char buf[BPRM_BUF_SIZE] __attribute__((aligned));
  68. ImageSource src;
  69. abi_ulong p;
  70. int e_uid, e_gid;
  71. int argc, envc;
  72. char **argv;
  73. char **envp;
  74. char *filename; /* Name of binary */
  75. int (*core_dump)(int, const CPUArchState *); /* coredump routine */
  76. };
  77. void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
  78. abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
  79. abi_ulong stringp, int push_ptr);
  80. int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  81. struct target_pt_regs *regs, struct image_info *infop,
  82. struct linux_binprm *);
  83. uint32_t get_elf_eflags(int fd);
  84. int load_elf_binary(struct linux_binprm *bprm, struct image_info *info);
  85. int load_flt_binary(struct linux_binprm *bprm, struct image_info *info);
  86. abi_long memcpy_to_target(abi_ulong dest, const void *src,
  87. unsigned long len);
  88. extern unsigned long guest_stack_size;
  89. #if defined(TARGET_S390X) || defined(TARGET_AARCH64) || defined(TARGET_ARM)
  90. uint32_t get_elf_hwcap(void);
  91. const char *elf_hwcap_str(uint32_t bit);
  92. #endif
  93. #if defined(TARGET_AARCH64) || defined(TARGET_ARM)
  94. uint64_t get_elf_hwcap2(void);
  95. const char *elf_hwcap2_str(uint32_t bit);
  96. #endif
  97. #endif /* LINUX_USER_LOADER_H */