diff options
| author | Po Lu | 2023-09-07 09:35:59 +0800 |
|---|---|---|
| committer | Po Lu | 2023-09-07 09:35:59 +0800 |
| commit | 8b25edfbda6ed8973b483f700571e00a60f27002 (patch) | |
| tree | 994ff56260b8f6d582400ac511ee42f0cfa8af3e | |
| parent | 241616831024c9c9fe2b2378b611db0a560b9675 (diff) | |
| download | emacs-8b25edfbda6ed8973b483f700571e00a60f27002.tar.gz emacs-8b25edfbda6ed8973b483f700571e00a60f27002.zip | |
Port Proced to Android
* configure.ac (HAVE_PROCFS): Define if opsys is `android'.
* src/android.c (android_set_task_name): New function.
(android_run_select_thread, android_run_debug_thread): Set the
name of the LWP for debugging purposes.
* src/process.c (create_process): Set F_SETPIPE_SZ on Android in
addition to GNU/Linux.
* src/sysdep.c (procfs_ttyname, system_process_attributes)
[__ANDROID__]: Enable procfs_ttyname on Android systems.
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | src/android.c | 46 | ||||
| -rw-r--r-- | src/process.c | 5 | ||||
| -rw-r--r-- | src/sysdep.c | 10 |
4 files changed, 55 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac index f92339225b5..ee13b2e0659 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -6513,7 +6513,7 @@ case $opsys in | |||
| 6513 | esac | 6513 | esac |
| 6514 | 6514 | ||
| 6515 | case $opsys in | 6515 | case $opsys in |
| 6516 | gnu-* | solaris | cygwin ) | 6516 | gnu-* | android | solaris | cygwin ) |
| 6517 | dnl FIXME Can't we test if this exists (eg /proc/$$)? | 6517 | dnl FIXME Can't we test if this exists (eg /proc/$$)? |
| 6518 | AC_DEFINE([HAVE_PROCFS], [1], [Define if you have the /proc filesystem.]) | 6518 | AC_DEFINE([HAVE_PROCFS], [1], [Define if you have the /proc filesystem.]) |
| 6519 | ;; | 6519 | ;; |
diff --git a/src/android.c b/src/android.c index b501a66b25d..76014cbcb3a 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -282,6 +282,46 @@ static volatile sig_atomic_t android_pselect_interrupted; | |||
| 282 | 282 | ||
| 283 | #endif | 283 | #endif |
| 284 | 284 | ||
| 285 | /* Set the task name of the current task to NAME, a string at most 16 | ||
| 286 | characters in length. | ||
| 287 | |||
| 288 | This name is displayed as that of the task (LWP)'s pthread in | ||
| 289 | GDB. */ | ||
| 290 | |||
| 291 | static void | ||
| 292 | android_set_task_name (const char *name) | ||
| 293 | { | ||
| 294 | char proc_name[INT_STRLEN_BOUND (long) | ||
| 295 | + sizeof "/proc/self/task//comm"]; | ||
| 296 | int fd; | ||
| 297 | pid_t lwp; | ||
| 298 | size_t length; | ||
| 299 | |||
| 300 | lwp = gettid (); | ||
| 301 | sprintf (proc_name, "/proc/self/task/%ld/comm", (long) lwp); | ||
| 302 | fd = open (proc_name, O_WRONLY | O_TRUNC); | ||
| 303 | |||
| 304 | if (fd < 1) | ||
| 305 | goto failure; | ||
| 306 | |||
| 307 | length = strlen (name); | ||
| 308 | |||
| 309 | if (write (fd, name, MIN (16, length)) < 0) | ||
| 310 | goto failure; | ||
| 311 | |||
| 312 | close (fd); | ||
| 313 | return; | ||
| 314 | |||
| 315 | failure: | ||
| 316 | __android_log_print (ANDROID_LOG_WARN, __func__, | ||
| 317 | "Failed to set task name for LWP %ld: %s", | ||
| 318 | (long) lwp, strerror (errno)); | ||
| 319 | |||
| 320 | /* Close the file descriptor if it is already set. */ | ||
| 321 | if (fd >= 0) | ||
| 322 | close (fd); | ||
| 323 | } | ||
| 324 | |||
| 285 | static void * | 325 | static void * |
| 286 | android_run_select_thread (void *data) | 326 | android_run_select_thread (void *data) |
| 287 | { | 327 | { |
| @@ -298,6 +338,9 @@ android_run_select_thread (void *data) | |||
| 298 | int sig; | 338 | int sig; |
| 299 | #endif | 339 | #endif |
| 300 | 340 | ||
| 341 | /* Set the name of this thread's LWP for debugging purposes. */ | ||
| 342 | android_set_task_name ("`android_select'"); | ||
| 343 | |||
| 301 | #if __ANDROID_API__ < 16 | 344 | #if __ANDROID_API__ < 16 |
| 302 | /* A completely different implementation is used when building for | 345 | /* A completely different implementation is used when building for |
| 303 | Android versions earlier than 16, because pselect with a signal | 346 | Android versions earlier than 16, because pselect with a signal |
| @@ -797,6 +840,9 @@ android_run_debug_thread (void *data) | |||
| 797 | char *line; | 840 | char *line; |
| 798 | size_t n; | 841 | size_t n; |
| 799 | 842 | ||
| 843 | /* Set the name of this thread's LWP for debugging purposes. */ | ||
| 844 | android_set_task_name ("`android_debug'"); | ||
| 845 | |||
| 800 | fd = (int) (intptr_t) data; | 846 | fd = (int) (intptr_t) data; |
| 801 | file = fdopen (fd, "r"); | 847 | file = fdopen (fd, "r"); |
| 802 | 848 | ||
diff --git a/src/process.c b/src/process.c index 08cb810ec13..dbd677e59d7 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -2206,9 +2206,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2206 | inchannel = p->open_fd[READ_FROM_SUBPROCESS]; | 2206 | inchannel = p->open_fd[READ_FROM_SUBPROCESS]; |
| 2207 | forkout = p->open_fd[SUBPROCESS_STDOUT]; | 2207 | forkout = p->open_fd[SUBPROCESS_STDOUT]; |
| 2208 | 2208 | ||
| 2209 | #if defined(GNU_LINUX) && defined(F_SETPIPE_SZ) | 2209 | #if (defined (GNU_LINUX) || defined __ANDROID__) \ |
| 2210 | && defined (F_SETPIPE_SZ) | ||
| 2210 | fcntl (inchannel, F_SETPIPE_SZ, read_process_output_max); | 2211 | fcntl (inchannel, F_SETPIPE_SZ, read_process_output_max); |
| 2211 | #endif | 2212 | #endif /* (GNU_LINUX || __ANDROID__) && F_SETPIPE_SZ */ |
| 2212 | } | 2213 | } |
| 2213 | 2214 | ||
| 2214 | if (!NILP (p->stderrproc)) | 2215 | if (!NILP (p->stderrproc)) |
diff --git a/src/sysdep.c b/src/sysdep.c index 52fbfbd1eb1..f49fed7da1e 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -3452,7 +3452,7 @@ make_lisp_timeval (struct timeval t) | |||
| 3452 | 3452 | ||
| 3453 | #endif | 3453 | #endif |
| 3454 | 3454 | ||
| 3455 | #if defined (GNU_LINUX) || defined (CYGWIN) | 3455 | #if defined (GNU_LINUX) || defined (CYGWIN) || defined __ANDROID__ |
| 3456 | 3456 | ||
| 3457 | static Lisp_Object | 3457 | static Lisp_Object |
| 3458 | time_from_jiffies (unsigned long long ticks, Lisp_Object hz, Lisp_Object form) | 3458 | time_from_jiffies (unsigned long long ticks, Lisp_Object hz, Lisp_Object form) |
| @@ -3500,7 +3500,7 @@ get_up_time (void) | |||
| 3500 | return up; | 3500 | return up; |
| 3501 | } | 3501 | } |
| 3502 | 3502 | ||
| 3503 | # ifdef GNU_LINUX | 3503 | # if defined GNU_LINUX || defined __ANDROID__ |
| 3504 | #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff) | 3504 | #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff) |
| 3505 | #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12)) | 3505 | #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12)) |
| 3506 | 3506 | ||
| @@ -3546,7 +3546,7 @@ procfs_ttyname (int rdev) | |||
| 3546 | unblock_input (); | 3546 | unblock_input (); |
| 3547 | return build_string (name); | 3547 | return build_string (name); |
| 3548 | } | 3548 | } |
| 3549 | # endif /* GNU_LINUX */ | 3549 | # endif /* GNU_LINUX || __ANDROID__ */ |
| 3550 | 3550 | ||
| 3551 | static uintmax_t | 3551 | static uintmax_t |
| 3552 | procfs_get_total_memory (void) | 3552 | procfs_get_total_memory (void) |
| @@ -3695,9 +3695,9 @@ system_process_attributes (Lisp_Object pid) | |||
| 3695 | attrs = Fcons (Fcons (Qppid, INT_TO_INTEGER (ppid)), attrs); | 3695 | attrs = Fcons (Fcons (Qppid, INT_TO_INTEGER (ppid)), attrs); |
| 3696 | attrs = Fcons (Fcons (Qpgrp, INT_TO_INTEGER (pgrp)), attrs); | 3696 | attrs = Fcons (Fcons (Qpgrp, INT_TO_INTEGER (pgrp)), attrs); |
| 3697 | attrs = Fcons (Fcons (Qsess, INT_TO_INTEGER (sess)), attrs); | 3697 | attrs = Fcons (Fcons (Qsess, INT_TO_INTEGER (sess)), attrs); |
| 3698 | # ifdef GNU_LINUX | 3698 | # if defined GNU_LINUX || defined __ANDROID__ |
| 3699 | attrs = Fcons (Fcons (Qttname, procfs_ttyname (tty)), attrs); | 3699 | attrs = Fcons (Fcons (Qttname, procfs_ttyname (tty)), attrs); |
| 3700 | # endif | 3700 | # endif /* GNU_LINUX || __ANDROID__ */ |
| 3701 | attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (tpgid)), attrs); | 3701 | attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (tpgid)), attrs); |
| 3702 | attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (minflt)), attrs); | 3702 | attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (minflt)), attrs); |
| 3703 | attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (majflt)), attrs); | 3703 | attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (majflt)), attrs); |