aboutsummaryrefslogtreecommitdiffstats
path: root/exec/exec.h
diff options
context:
space:
mode:
authorPo Lu2023-04-30 21:37:19 +0800
committerPo Lu2023-04-30 21:37:19 +0800
commit368f6f3942a1f8b9483763a6ac24b3b3021e92bf (patch)
tree284ff92e18076ed7a8be3d2775ee450922b3166d /exec/exec.h
parent4289ed6cffdb5ea758a78037fe385fd7c4e23677 (diff)
downloademacs-368f6f3942a1f8b9483763a6ac24b3b3021e92bf.tar.gz
emacs-368f6f3942a1f8b9483763a6ac24b3b3021e92bf.zip
Add helper binary `exec1'
* .gitignore: New files. * Makefile.in (mostlyclean_dirs): Add libexec, if its Makefile exists. * autogen.sh (do_git): Autoreconf in exec as well. * configure.ac: Configure libexec on Android. * exec/Makefile.in: * exec/README: * exec/config-mips.m4.in: * exec/config.guess: * exec/config.h.in: * exec/config.sub: * exec/configure: * exec/configure.ac: * exec/deps.mk: * exec/exec.c (MIN, struct exec_open_command) (struct exec_map_command, struct exec_jump_command) (write_open_command, write_load_command, process_interpreter_1) (process_interpreter, process_program_header, insert_args) (exec_0): * exec/exec.h (_EXEC_H_, struct elf_header_32) (struct program_header_32, struct dt_entry_32) (struct elf_header_64, struct program_header_64) (struct dt_entry_64, struct exec_tracee): * exec/exec1.c (main): * exec/install-sh (scriptversion): * exec/loader-aarch64.s (_start): * exec/loader-armeabi.s (_start): * exec/loader-mips64el.s (__start): * exec/loader-mipsel.s (__start): * exec/loader-x86.s (_start): * exec/loader-x86_64.s (_start): * exec/mipsel-user.h (_MIPSEL_USER_H_): * exec/mipsfpu.c (MIPS_ABI_FP_ANY, fpu_reqs, valid_abi_p) (fp_mode_for_abi, cpu_supports_fr0_p, determine_fpu_mode): * exec/mipsfpu.h (_MIPSFPU_H_, FP_FR0): * exec/test.c (print_usage, main): * exec/trace.c (MAX_TRACEES, aarch64_set_regs, read_memory) (user_alloca, user_copy, remove_tracee, handle_clone) (syscall_trap_p, handle_exec, process_system_call, tracing_execve) (after_fork, find_tracee, exec_waitpid, exec_init): New files. * java/Makefile.in (CROSS_EXEC_BINS): Add exec1 and loader. ($(CROSS_EXEC_BINS) &): New target.
Diffstat (limited to 'exec/exec.h')
-rw-r--r--exec/exec.h192
1 files changed, 192 insertions, 0 deletions
diff --git a/exec/exec.h b/exec/exec.h
new file mode 100644
index 00000000000..0f6a8a893b6
--- /dev/null
+++ b/exec/exec.h
@@ -0,0 +1,192 @@
1/* Program execution for Emacs.
2
3Copyright (C) 2023 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
38typedef struct
39{
40 uint32_t word1;
41 uint32_t word2;
42} xint64_t;
43
44#else /* UINT64_MAX */
45typedef uint64_t xint64_t;
46#endif /* !UINT64_MAX */
47
48
49
50/* 32-bit ELF headers. */
51
52struct 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
70struct 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
82struct dt_entry_32
83{
84 uint32_t d_tag;
85 uint32_t d_val;
86};
87
88
89
90struct 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
108struct 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
120struct 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
131typedef struct elf_header_64 elf_header;
132typedef struct program_header_64 program_header;
133typedef struct dt_entry_64 dt_entry;
134#else /* !EXEC_64 */
135typedef struct elf_header_32 elf_header;
136typedef struct program_header_32 program_header;
137typedef 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
146struct 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;
157};
158
159
160
161#ifdef __aarch64__
162
163extern int aarch64_get_regs (pid_t, USER_REGS_STRUCT *);
164extern int aarch64_set_regs (pid_t, USER_REGS_STRUCT *, bool);
165
166#endif /* __aarch64__ */
167
168
169
170extern USER_WORD user_alloca (struct exec_tracee *, USER_REGS_STRUCT *,
171 USER_REGS_STRUCT *, USER_WORD);
172extern int user_copy (struct exec_tracee *, const unsigned char *,
173 USER_WORD, USER_WORD);
174extern void exec_init (const char *);
175
176
177
178extern int tracing_execve (const char *, char *const *,
179 char *const *);
180extern int after_fork (pid_t);
181extern pid_t exec_waitpid (pid_t, int *, int);
182
183
184
185/* Defined in exec.c. */
186
187extern char *exec_0 (const char *, struct exec_tracee *,
188 size_t *, USER_REGS_STRUCT *);
189
190
191
192#endif /* _EXEC_H_ */