aboutsummaryrefslogtreecommitdiffstats
path: root/exec/exec.c
diff options
context:
space:
mode:
authorPo Lu2023-05-02 20:45:57 +0800
committerPo Lu2023-05-02 20:45:57 +0800
commitc47716f95b8fda9438047d2683a415a65c18ecbd (patch)
tree947c45293556f41ce02426889890b3442f2b7b36 /exec/exec.c
parentf4512cca0b996e5343ebe57511f45a29f64c4a8e (diff)
downloademacs-c47716f95b8fda9438047d2683a415a65c18ecbd.tar.gz
emacs-c47716f95b8fda9438047d2683a415a65c18ecbd.zip
Update Android port
* exec/config.h.in (__bool_true_false_are_defined): * exec/configure.ac (REENTRANT): New definition. (READLINKAT_SYSCALL, READLINK_SYSCALL): New defines. Set on all hosts. * exec/exec.c (MIN, MAX): Remove redundant declarations. Move to config.h. (exec_0): Copy name of executable into NAME when !REENTRANT. * exec/exec.h (struct exec_tracee): New struct `exec_file'. * exec/trace.c (remove_tracee, handle_exec, handle_readlinkat) (process_system_call, after_fork): Handle readlinkat system calls.
Diffstat (limited to 'exec/exec.c')
-rw-r--r--exec/exec.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/exec/exec.c b/exec/exec.c
index 7f2cc75338b..17051428658 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -31,14 +31,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/mman.h> 32#include <sys/mman.h>
33 33
34#ifndef MIN
35#define MIN(a, b) ((a) < (b) ? (a) : (b))
36#endif /* MIN */
37
38#ifndef MAX
39#define MAX(a, b) ((a) < (b) ? (b) : (a))
40#endif /* MAX */
41
42#include "exec.h" 34#include "exec.h"
43 35
44#if defined __mips__ && !defined MIPS_NABI 36#if defined __mips__ && !defined MIPS_NABI
@@ -938,6 +930,10 @@ format_pid (char *in, unsigned int pid)
938 with #!; in that case, find the program to open and use that 930 with #!; in that case, find the program to open and use that
939 instead. 931 instead.
940 932
933 If REENTRANT is not defined, NAME is actually a buffer of size
934 PATH_MAX + 80. In that case, copy over the file name actually
935 opened.
936
941 Next, read the executable header, and add the necessary memory 937 Next, read the executable header, and add the necessary memory
942 mappings for each file. Finally, return the action data and its 938 mappings for each file. Finally, return the action data and its
943 size in *SIZE. 939 size in *SIZE.
@@ -948,7 +944,7 @@ format_pid (char *in, unsigned int pid)
948 Value is NULL upon failure, with errno set accordingly. */ 944 Value is NULL upon failure, with errno set accordingly. */
949 945
950char * 946char *
951exec_0 (const char *name, struct exec_tracee *tracee, 947exec_0 (char *name, struct exec_tracee *tracee,
952 size_t *size, USER_REGS_STRUCT *regs) 948 size_t *size, USER_REGS_STRUCT *regs)
953{ 949{
954 int fd, rc, i; 950 int fd, rc, i;
@@ -961,7 +957,8 @@ exec_0 (const char *name, struct exec_tracee *tracee,
961#if defined __mips__ && !defined MIPS_NABI 957#if defined __mips__ && !defined MIPS_NABI
962 int fpu_mode; 958 int fpu_mode;
963#endif /* defined __mips__ && !defined MIPS_NABI */ 959#endif /* defined __mips__ && !defined MIPS_NABI */
964 char buffer[PATH_MAX + 80], *rewrite; 960 char buffer[80], buffer1[PATH_MAX + 80], *rewrite;
961 ssize_t link_size;
965 size_t remaining; 962 size_t remaining;
966 963
967 /* If name is not absolute, then make it relative to TRACEE's 964 /* If name is not absolute, then make it relative to TRACEE's
@@ -971,18 +968,43 @@ exec_0 (const char *name, struct exec_tracee *tracee,
971 { 968 {
972 /* Clear `buffer'. */ 969 /* Clear `buffer'. */
973 memset (buffer, 0, sizeof buffer); 970 memset (buffer, 0, sizeof buffer);
971 memset (buffer1, 0, sizeof buffer);
974 972
975 /* Copy over /proc, the PID, and /cwd/. */ 973 /* Copy over /proc, the PID, and /cwd/. */
976 rewrite = stpcpy (buffer, "/proc/"); 974 rewrite = stpcpy (buffer, "/proc/");
977 rewrite = format_pid (rewrite, tracee->pid); 975 rewrite = format_pid (rewrite, tracee->pid);
978 rewrite = stpcpy (rewrite, "/cwd/"); 976 stpcpy (rewrite, "/cwd");
977
978 /* Resolve this symbolic link. */
979
980 link_size = readlink (buffer, buffer1,
981 PATH_MAX + 1);
982
983 if (link_size < 0)
984 return NULL;
985
986 /* Check that the name is a reasonable size. */
987
988 if (link_size > PATH_MAX)
989 {
990 /* The name is too long. */
991 errno = ENAMETOOLONG;
992 return NULL;
993 }
994
995 /* Add a directory separator if necessary. */
996
997 if (!link_size || buffer1[link_size - 1] != '/')
998 buffer1[link_size] = '/', link_size++;
979 999
980 /* Make sure there is enough free space. */ 1000 rewrite = buffer1 + link_size;
981 remaining = buffer + sizeof buffer - rewrite - 1; 1001 remaining = buffer1 + sizeof buffer1 - rewrite - 1;
982 rewrite = stpncpy (rewrite, name, remaining); 1002 rewrite = stpncpy (rewrite, name, remaining);
983 1003
984 /* Replace name with buffer. */ 1004 /* Replace name with buffer1. */
985 name = buffer; 1005#ifndef REENTRANT
1006 strcpy (name, buffer1);
1007#endif /* REENTRANT */
986 } 1008 }
987 1009
988 fd = open (name, O_RDONLY); 1010 fd = open (name, O_RDONLY);