| 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 | |
| 18 | #ifndef LINUX_USER_LOADER_H |
| 19 | #define LINUX_USER_LOADER_H |
| 20 | |
| 21 | typedef struct { |
| 22 | const void *cache; |
| 23 | unsigned int cache_size; |
| 24 | int fd; |
| 25 | } ImageSource; |
| 26 | |
| 27 | /** |
| 28 | * imgsrc_read: Read from ImageSource |
| 29 | * @dst: destination for read |
| 30 | * @offset: offset within file for read |
| 31 | * @len: size of the read |
| 32 | * @img: ImageSource to read from |
| 33 | * @errp: Error details. |
| 34 | * |
| 35 | * Read into @dst, using the cache when possible. |
| 36 | */ |
| 37 | bool imgsrc_read(void *dst, off_t offset, size_t len, |
| 38 | const ImageSource *img, Error **errp); |
| 39 | |
| 40 | /** |
| 41 | * imgsrc_read_alloc: Read from ImageSource |
| 42 | * @offset: offset within file for read |
| 43 | * @size: size of the read |
| 44 | * @img: ImageSource to read from |
| 45 | * @errp: Error details. |
| 46 | * |
| 47 | * Read into newly allocated memory, using the cache when possible. |
| 48 | */ |
| 49 | void *imgsrc_read_alloc(off_t offset, size_t len, |
| 50 | const ImageSource *img, Error **errp); |
| 51 | |
| 52 | /** |
| 53 | * imgsrc_mmap: Map from ImageSource |
| 54 | * |
| 55 | * If @src has a file descriptor, pass on to target_mmap. Otherwise, |
| 56 | * this is "mapping" from a host buffer, which resolves to memcpy. |
| 57 | * Therefore, flags must be MAP_PRIVATE | MAP_FIXED; the argument is |
| 58 | * retained for clarity. |
| 59 | */ |
| 60 | abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, |
| 61 | int flags, const ImageSource *src, abi_ulong offset); |
| 62 | |
| 63 | /* |
| 64 | * Read a good amount of data initially, to hopefully get all the |
| 65 | * program headers loaded. |
| 66 | */ |
| 67 | #define BPRM_BUF_SIZE 1024 |
| 68 | |
| 69 | /* |
| 70 | * This structure is used to hold the arguments that are |
| 71 | * used when loading binaries. |
| 72 | */ |
| 73 | struct linux_binprm { |
| 74 | char buf[BPRM_BUF_SIZE] __attribute__((aligned)); |
| 75 | ImageSource src; |
| 76 | abi_ulong p; |
| 77 | int e_uid, e_gid; |
| 78 | int argc, envc; |
| 79 | char **argv; |
| 80 | char **envp; |
| 81 | char *filename; /* Name of binary */ |
| 82 | int (*core_dump)(int, const CPUArchState *); /* coredump routine */ |
| 83 | }; |
| 84 | |
| 85 | abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, |
| 86 | abi_ulong stringp, int push_ptr); |
| 87 | int loader_exec(int fdexec, const char *filename, char **argv, char **envp, |
| 88 | struct image_info *infop, struct linux_binprm *); |
| 89 | |
| 90 | uint32_t get_elf_eflags(int fd); |
| 91 | int load_elf_binary(struct linux_binprm *bprm, struct image_info *info); |
| 92 | int load_flt_binary(struct linux_binprm *bprm, struct image_info *info); |
| 93 | |
| 94 | abi_long memcpy_to_target(abi_ulong dest, const void *src, |
| 95 | unsigned long len); |
| 96 | |
| 97 | extern unsigned long guest_stack_size; |
| 98 | |
| 99 | /* Note that Elf32 and Elf64 use uint32_t for e_flags. */ |
| 100 | const char *get_elf_cpu_model(uint32_t eflags); |
| 101 | |
| 102 | abi_ulong get_elf_hwcap(CPUState *cs); |
| 103 | abi_ulong get_elf_hwcap2(CPUState *cs); |
| 104 | const char *elf_hwcap_str(uint32_t bit); |
| 105 | const char *elf_hwcap2_str(uint32_t bit); |
| 106 | const char *get_elf_platform(CPUState *cs); |
| 107 | const char *get_elf_base_platform(CPUState *cs); |
| 108 | bool init_guest_commpage(void); |
| 109 | |
| 110 | struct target_elf_gregset_t; |
| 111 | void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *); |
| 112 | /* Only defined by a target whose target_elf.h sets HAVE_ELF_CORE_FPREGS. */ |
| 113 | struct target_elf_fpregset_t; |
| 114 | void elf_core_copy_fpregs(struct target_elf_fpregset_t *, const CPUArchState *); |
| 115 | |
| 116 | typedef struct { |
| 117 | const uint8_t *image; |
| 118 | const uint32_t *relocs; |
| 119 | unsigned image_size; |
| 120 | unsigned reloc_count; |
| 121 | unsigned sigreturn_ofs; |
| 122 | unsigned rt_sigreturn_ofs; |
| 123 | unsigned sigreturn_region_start_ofs; |
| 124 | unsigned sigreturn_region_end_ofs; |
| 125 | } VdsoImageInfo; |
| 126 | |
| 127 | /* Note that both Elf32_Word and Elf64_Word are uint32_t. */ |
| 128 | const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags); |
| 129 | |
| 130 | bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, |
| 131 | const uint32_t *data, |
| 132 | struct image_info *info, |
| 133 | Error **errp); |
| 134 | |
| 135 | #endif /* LINUX_USER_LOADER_H */ |