diff options
| author | Po Lu | 2024-07-01 18:11:58 +0800 |
|---|---|---|
| committer | Po Lu | 2024-07-01 18:11:58 +0800 |
| commit | ebf5bcb9f0b6adeb97a3918b8f3845844c9091b0 (patch) | |
| tree | f7660b9380f715d48dfe4ff30a57e12965b6166d /exec/exec.c | |
| parent | 7c8d4e96ba6db19bdca20a87bafed024a84eb517 (diff) | |
| download | emacs-ebf5bcb9f0b6adeb97a3918b8f3845844c9091b0.tar.gz emacs-ebf5bcb9f0b6adeb97a3918b8f3845844c9091b0.zip | |
Optimize process execution on Android
* exec/configure.ac (REENTRANT): Remove option for reentrancy.
(PROGRAM_COUNTER, HAVE_SECCOMP): Define register providing the
program counter and enable seccomp if its headers are available.
* exec/exec.c (write_load_command): Avoid defining unused
variable.
(exec_0): Remove code specific to REENTRANT configurations.
* exec/exec.h (struct exec_tracee) <exec_data, data_size>: New
fields for loader instructions and their size.
* exec/exec1.c (main): Call exec_init before forking.
* exec/mipsel-user.h (ELF_NGREG): Delete definition.
(struct mipsel_regs): Reduce number of gregs to 32, but
introduce separate fields for special registers.
* exec/trace.c (use_seccomp_p): New variable; defile to false if
!HAVE_SECCOMP.
(remove_tracee): Cease providing for non-reentrant
configurations. Release executable data if present.
(handle_clone_prepare): Likewise. Resume process with
PTRACE_CONT if seccomp-based interception is enabled.
(handle_clone, check_signal): Resume processes as above.
(handle_exec): Divide into two functions, with only rewriting
the system call and generating instructions for the loader
remaining in the first, and copying such instructions into the
loader's stack removed into a new function, `finish_exec'.
(finish_exec): New function.
(handle_readlinkat, handle_openat): Abolish non-REENTRANT
configurations.
(process_system_call): Divide exec system calls into two phases,
disambiguated by the value of tracee->waiting_for_syscall. Typo
fixes. Accommodate syscall-exit-stops where the signal was
initially intercepted by `seccomp_system_call'.
(interesting_syscalls): New array.
(ARRAYELTS): New macro.
(seccomp_system_call, establish_seccomp_filter): New function.
(tracing_execve) [HAVE_SECCOMP]: Establish a seccomp filter if
this is to be enabled.
(after_fork): Provide PTRACE_O_TRACESECCOMP. Resume process
with PTRACE_CONT if seccomp-based interception is enabled.
(exec_waitpid): Resume process with PTRACE_CONT if seccomp-based
interception is enabled. Dispatch stops identifying as
PTRACE_EVENT_SECCOMP to `seccomp_system_call'.
(exec_init): Establish whether it is possible to enable seccomp.
Diffstat (limited to 'exec/exec.c')
| -rw-r--r-- | exec/exec.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/exec/exec.c b/exec/exec.c index cbe22d4f18c..fad345c532c 100644 --- a/exec/exec.c +++ b/exec/exec.c | |||
| @@ -292,7 +292,9 @@ write_load_command (program_header *header, bool use_alternate, | |||
| 292 | struct exec_map_command command1; | 292 | struct exec_map_command command1; |
| 293 | USER_WORD start, end; | 293 | USER_WORD start, end; |
| 294 | bool need_command1; | 294 | bool need_command1; |
| 295 | #ifndef PAGE_MASK | ||
| 295 | static long pagesize; | 296 | static long pagesize; |
| 297 | #endif /* !PAGE_MASK */ | ||
| 296 | 298 | ||
| 297 | /* First, write the commands necessary to map the specified segment | 299 | /* First, write the commands necessary to map the specified segment |
| 298 | itself. | 300 | itself. |
| @@ -306,14 +308,14 @@ write_load_command (program_header *header, bool use_alternate, | |||
| 306 | #ifdef HAVE_GETPAGESIZE | 308 | #ifdef HAVE_GETPAGESIZE |
| 307 | if (!pagesize) | 309 | if (!pagesize) |
| 308 | pagesize = getpagesize (); | 310 | pagesize = getpagesize (); |
| 309 | #else /* HAVE_GETPAGESIZE */ | 311 | #else /* !HAVE_GETPAGESIZE */ |
| 310 | if (!pagesize) | 312 | if (!pagesize) |
| 311 | pagesize = sysconf (_SC_PAGESIZE); | 313 | pagesize = sysconf (_SC_PAGESIZE); |
| 312 | #endif /* HAVE_GETPAGESIZE */ | 314 | #endif /* !HAVE_GETPAGESIZE */ |
| 313 | 315 | ||
| 314 | #define PAGE_MASK (~(pagesize - 1)) | 316 | #define PAGE_MASK (~(pagesize - 1)) |
| 315 | #define PAGE_SIZE (pagesize) | 317 | #define PAGE_SIZE (pagesize) |
| 316 | #endif /* PAGE_MASK */ | 318 | #endif /* !PAGE_MASK */ |
| 317 | 319 | ||
| 318 | start = header->p_vaddr & PAGE_MASK; | 320 | start = header->p_vaddr & PAGE_MASK; |
| 319 | end = ((header->p_vaddr + header->p_filesz | 321 | end = ((header->p_vaddr + header->p_filesz |
| @@ -895,10 +897,6 @@ format_pid (char *in, unsigned int pid) | |||
| 895 | with #!; in that case, find the program to open and use that | 897 | with #!; in that case, find the program to open and use that |
| 896 | instead. | 898 | instead. |
| 897 | 899 | ||
| 898 | If REENTRANT is not defined, NAME is actually a buffer of size | ||
| 899 | PATH_MAX + 80. In that case, copy over the file name actually | ||
| 900 | opened. | ||
| 901 | |||
| 902 | Next, read the executable header, and add the necessary memory | 900 | Next, read the executable header, and add the necessary memory |
| 903 | mappings for each file. Finally, return the action data and its | 901 | mappings for each file. Finally, return the action data and its |
| 904 | size in *SIZE. | 902 | size in *SIZE. |
| @@ -976,11 +974,6 @@ exec_0 (char *name, struct exec_tracee *tracee, | |||
| 976 | rewrite = buffer1 + link_size; | 974 | rewrite = buffer1 + link_size; |
| 977 | remaining = buffer1 + sizeof buffer1 - rewrite - 1; | 975 | remaining = buffer1 + sizeof buffer1 - rewrite - 1; |
| 978 | memcpy (rewrite, name, strnlen (name, remaining)); | 976 | memcpy (rewrite, name, strnlen (name, remaining)); |
| 979 | |||
| 980 | /* Replace name with buffer1. */ | ||
| 981 | #ifndef REENTRANT | ||
| 982 | strcpy (name, buffer1); | ||
| 983 | #endif /* REENTRANT */ | ||
| 984 | } | 977 | } |
| 985 | } | 978 | } |
| 986 | 979 | ||