aboutsummaryrefslogtreecommitdiffstats
path: root/exec/exec.c
diff options
context:
space:
mode:
authorPo Lu2023-05-01 21:23:12 +0800
committerPo Lu2023-05-01 21:23:12 +0800
commitb9de6e35b79cbc10909a856df6b1caa770bd4ac4 (patch)
tree6cfbd5ef7419bcd80f26443b134cc1b3e5754780 /exec/exec.c
parentda6f0d9c6fd4b2a097f02a6e8f1b2aa33a6bf307 (diff)
downloademacs-b9de6e35b79cbc10909a856df6b1caa770bd4ac4.tar.gz
emacs-b9de6e35b79cbc10909a856df6b1caa770bd4ac4.zip
Fix cwd relative process execution on Android
* exec/exec.c (format_pid): New function. (exec_0): Make cwd relative file names relative to /proc/pid/cwd. * exec/trace.c (handle_exec): Handle EINTR. (process_system_call): Report failure without clobbering x0.
Diffstat (limited to 'exec/exec.c')
-rw-r--r--exec/exec.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/exec/exec.c b/exec/exec.c
index 662c8bf69d2..c7a73f221f5 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
26#include <assert.h> 26#include <assert.h>
27#include <string.h> 27#include <string.h>
28#include <ctype.h> 28#include <ctype.h>
29#include <stdlib.h>
29 30
30#include <sys/ptrace.h> 31#include <sys/ptrace.h>
31#include <sys/param.h> 32#include <sys/param.h>
@@ -808,6 +809,35 @@ insert_args (struct exec_tracee *tracee, USER_REGS_STRUCT *regs,
808 809
809 810
810 811
812/* Format PID, an unsigned process identifier, in base 10. Place the
813 result in *IN, and return a pointer to the byte after the
814 result. REM should be NULL. */
815
816static char *
817format_pid (char *in, unsigned int pid)
818{
819 unsigned int digits[32], *fill;
820
821 fill = digits;
822
823 for (; pid != 0; pid = pid / 10)
824 *fill++ = pid % 10;
825
826 /* Insert 0 if the number would otherwise be empty. */
827
828 if (fill == digits)
829 *fill++ = 0;
830
831 while (fill != digits)
832 {
833 --fill;
834 *in++ = '0' + *fill;
835 }
836
837 *in = '\0';
838 return in;
839}
840
811/* Return a sequence of actions required to load the executable under 841/* Return a sequence of actions required to load the executable under
812 the file NAME for the given TRACEE. First, see if the file starts 842 the file NAME for the given TRACEE. First, see if the file starts
813 with #!; in that case, find the program to open and use that 843 with #!; in that case, find the program to open and use that
@@ -836,6 +866,29 @@ exec_0 (const char *name, struct exec_tracee *tracee,
836#if defined __mips__ && !defined MIPS_NABI 866#if defined __mips__ && !defined MIPS_NABI
837 int fpu_mode; 867 int fpu_mode;
838#endif /* defined __mips__ && !defined MIPS_NABI */ 868#endif /* defined __mips__ && !defined MIPS_NABI */
869 char buffer[PATH_MAX + 80], *rewrite;
870 size_t remaining;
871
872 /* If name is not absolute, then make it relative to TRACEE's
873 cwd. Use stpcpy, as sprintf is not reentrant. */
874
875 if (name[0] && name[0] != '/')
876 {
877 /* Clear `buffer'. */
878 memset (buffer, 0, sizeof buffer);
879
880 /* Copy over /proc, the PID, and /cwd/. */
881 rewrite = stpcpy (buffer, "/proc/");
882 rewrite = format_pid (rewrite, tracee->pid);
883 rewrite = stpcpy (rewrite, "/cwd/");
884
885 /* Make sure there is enough free space. */
886 remaining = buffer + sizeof buffer - rewrite - 1;
887 rewrite = stpncpy (rewrite, name, remaining);
888
889 /* Replace name with buffer. */
890 name = buffer;
891 }
839 892
840 fd = open (name, O_RDONLY); 893 fd = open (name, O_RDONLY);
841 if (fd < 0) 894 if (fd < 0)