diff options
Diffstat (limited to 'exec/exec.h')
| -rw-r--r-- | exec/exec.h | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/exec/exec.h b/exec/exec.h new file mode 100644 index 00000000000..8ee74d7ca8b --- /dev/null +++ b/exec/exec.h | |||
| @@ -0,0 +1,201 @@ | |||
| 1 | /* Program execution for Emacs. | ||
| 2 | |||
| 3 | Copyright (C) 2023 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation, either version 3 of the License, or (at | ||
| 10 | your option) any later version. | ||
| 11 | |||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | #ifndef _EXEC_H_ | ||
| 23 | #define _EXEC_H_ | ||
| 24 | |||
| 25 | #ifdef HAVE_STDINT_H | ||
| 26 | #include <stdint.h> | ||
| 27 | #endif /* HAVE_STDINT_H */ | ||
| 28 | |||
| 29 | #include <sys/types.h> | ||
| 30 | |||
| 31 | #include USER_HEADER | ||
| 32 | |||
| 33 | /* Define a replacement for `uint64_t' if it's not present in the C | ||
| 34 | library. */ | ||
| 35 | |||
| 36 | #ifndef UINT64_MAX | ||
| 37 | |||
| 38 | typedef struct | ||
| 39 | { | ||
| 40 | uint32_t word1; | ||
| 41 | uint32_t word2; | ||
| 42 | } xint64_t; | ||
| 43 | |||
| 44 | #else /* UINT64_MAX */ | ||
| 45 | typedef uint64_t xint64_t; | ||
| 46 | #endif /* !UINT64_MAX */ | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | /* 32-bit ELF headers. */ | ||
| 51 | |||
| 52 | struct elf_header_32 | ||
| 53 | { | ||
| 54 | unsigned char e_ident[16]; | ||
| 55 | uint16_t e_type; | ||
| 56 | uint16_t e_machine; | ||
| 57 | uint32_t e_version; | ||
| 58 | uint32_t e_entry; | ||
| 59 | uint32_t e_phoff; | ||
| 60 | uint32_t e_shoff; | ||
| 61 | uint32_t e_flags; | ||
| 62 | uint16_t e_ehsize; | ||
| 63 | uint16_t e_phentsize; | ||
| 64 | uint16_t e_phnum; | ||
| 65 | uint16_t e_shentsize; | ||
| 66 | uint16_t e_shnum; | ||
| 67 | uint16_t e_shstrndx; | ||
| 68 | }; | ||
| 69 | |||
| 70 | struct program_header_32 | ||
| 71 | { | ||
| 72 | uint32_t p_type; | ||
| 73 | uint32_t p_offset; | ||
| 74 | uint32_t p_vaddr; | ||
| 75 | uint32_t p_paddr; | ||
| 76 | uint32_t p_filesz; | ||
| 77 | uint32_t p_memsz; | ||
| 78 | uint32_t p_flags; | ||
| 79 | uint32_t p_align; | ||
| 80 | }; | ||
| 81 | |||
| 82 | struct dt_entry_32 | ||
| 83 | { | ||
| 84 | uint32_t d_tag; | ||
| 85 | uint32_t d_val; | ||
| 86 | }; | ||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | struct elf_header_64 | ||
| 91 | { | ||
| 92 | unsigned char e_ident[16]; | ||
| 93 | uint16_t e_type; | ||
| 94 | uint16_t e_machine; | ||
| 95 | uint32_t e_version; | ||
| 96 | xint64_t e_entry; | ||
| 97 | xint64_t e_phoff; | ||
| 98 | xint64_t e_shoff; | ||
| 99 | uint32_t e_flags; | ||
| 100 | uint16_t e_ehsize; | ||
| 101 | uint16_t e_phentsize; | ||
| 102 | uint16_t e_phnum; | ||
| 103 | uint16_t e_shentsize; | ||
| 104 | uint16_t e_shnum; | ||
| 105 | uint16_t e_shstrndx; | ||
| 106 | }; | ||
| 107 | |||
| 108 | struct program_header_64 | ||
| 109 | { | ||
| 110 | uint32_t p_type; | ||
| 111 | uint32_t p_flags; | ||
| 112 | xint64_t p_offset; | ||
| 113 | xint64_t p_vaddr; | ||
| 114 | xint64_t p_paddr; | ||
| 115 | xint64_t p_filesz; | ||
| 116 | xint64_t p_memsz; | ||
| 117 | xint64_t p_align; | ||
| 118 | }; | ||
| 119 | |||
| 120 | struct dt_entry_64 | ||
| 121 | { | ||
| 122 | xint64_t d_tag; | ||
| 123 | xint64_t d_val; | ||
| 124 | }; | ||
| 125 | |||
| 126 | |||
| 127 | |||
| 128 | /* Define some types to the correct values. */ | ||
| 129 | |||
| 130 | #ifdef EXEC_64 | ||
| 131 | typedef struct elf_header_64 elf_header; | ||
| 132 | typedef struct program_header_64 program_header; | ||
| 133 | typedef struct dt_entry_64 dt_entry; | ||
| 134 | #else /* !EXEC_64 */ | ||
| 135 | typedef struct elf_header_32 elf_header; | ||
| 136 | typedef struct program_header_32 program_header; | ||
| 137 | typedef struct dt_entry_32 dt_entry; | ||
| 138 | #endif /* EXEC_64 */ | ||
| 139 | |||
| 140 | |||
| 141 | |||
| 142 | /* Defined in trace.c. */ | ||
| 143 | |||
| 144 | /* Structure describing a process being traced. */ | ||
| 145 | |||
| 146 | struct exec_tracee | ||
| 147 | { | ||
| 148 | /* The next process being traced. */ | ||
| 149 | struct exec_tracee *next; | ||
| 150 | |||
| 151 | /* The thread ID of this process. */ | ||
| 152 | pid_t pid; | ||
| 153 | |||
| 154 | /* Whether or not the tracee is currently waiting for a system call | ||
| 155 | to complete. */ | ||
| 156 | bool waiting_for_syscall : 1; | ||
| 157 | |||
| 158 | /* Whether or not the tracee has been created but is not yet | ||
| 159 | processed by `handle_clone'. */ | ||
| 160 | bool new_child : 1; | ||
| 161 | |||
| 162 | #ifndef REENTRANT | ||
| 163 | /* Name of the executable being run. */ | ||
| 164 | char *exec_file; | ||
| 165 | #endif /* !REENTRANT */ | ||
| 166 | }; | ||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | #ifdef __aarch64__ | ||
| 171 | |||
| 172 | extern int aarch64_get_regs (pid_t, USER_REGS_STRUCT *); | ||
| 173 | extern int aarch64_set_regs (pid_t, USER_REGS_STRUCT *, bool); | ||
| 174 | |||
| 175 | #endif /* __aarch64__ */ | ||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | extern USER_WORD user_alloca (struct exec_tracee *, USER_REGS_STRUCT *, | ||
| 180 | USER_REGS_STRUCT *, USER_WORD); | ||
| 181 | extern int user_copy (struct exec_tracee *, const unsigned char *, | ||
| 182 | USER_WORD, USER_WORD); | ||
| 183 | extern void exec_init (const char *); | ||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | extern int tracing_execve (const char *, char *const *, | ||
| 188 | char *const *); | ||
| 189 | extern int after_fork (pid_t); | ||
| 190 | extern pid_t exec_waitpid (pid_t, int *, int); | ||
| 191 | |||
| 192 | |||
| 193 | |||
| 194 | /* Defined in exec.c. */ | ||
| 195 | |||
| 196 | extern char *exec_0 (char *, struct exec_tracee *, | ||
| 197 | size_t *, USER_REGS_STRUCT *); | ||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | #endif /* _EXEC_H_ */ | ||