diff options
| author | Po Lu | 2023-05-01 09:31:58 +0800 |
|---|---|---|
| committer | Po Lu | 2023-05-01 09:31:58 +0800 |
| commit | 5550816f5962943abd81fbf68901dad575f18c06 (patch) | |
| tree | 9fcb1305b7a3e80a349a9fba6f192d8b348cf7a5 /src/android.c | |
| parent | 9a7c645dd4ef38b72787e932d444a61ed4e04c63 (diff) | |
| download | emacs-5550816f5962943abd81fbf68901dad575f18c06.tar.gz emacs-5550816f5962943abd81fbf68901dad575f18c06.zip | |
Work around system restrictions regarding exec
* doc/emacs/android.texi (Android Environment): Document
`android-use-exec-loader'.
* exec/exec1.c (main): Set program group of child process.
* src/android.c (android_rewrite_spawn_argv): New function.
* src/android.h: Update prototypes.
* src/androidfns.c (syms_of_androidfns): New variable
`android_use_exec_loader'.
* src/callproc.c (emacs_spawn): Rewrite the argument vector to
use exec1 if necessary.
Diffstat (limited to 'src/android.c')
| -rw-r--r-- | src/android.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/android.c b/src/android.c index 3798758ff16..ce8f277e120 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -6514,6 +6514,89 @@ android_free_cursor (android_cursor cursor) | |||
| 6514 | android_destroy_handle (cursor); | 6514 | android_destroy_handle (cursor); |
| 6515 | } | 6515 | } |
| 6516 | 6516 | ||
| 6517 | |||
| 6518 | |||
| 6519 | /* Process execution. | ||
| 6520 | |||
| 6521 | Newer Android systems use SELinux to restrict user programs from | ||
| 6522 | executing programs installed in the application data directory for | ||
| 6523 | security reasons. Emacs uses a `loader' binary installed in the | ||
| 6524 | application data directory to manually load executables and replace | ||
| 6525 | the `execve' system call. */ | ||
| 6526 | |||
| 6527 | enum | ||
| 6528 | { | ||
| 6529 | /* Maximum number of arguments available. */ | ||
| 6530 | MAXARGS = 1024, | ||
| 6531 | }; | ||
| 6532 | |||
| 6533 | /* Rewrite the command line given in *ARGV to utilize the `exec1' | ||
| 6534 | bootstrap binary if necessary. | ||
| 6535 | |||
| 6536 | Value is 0 upon success, else 1. Set errno upon failure. | ||
| 6537 | |||
| 6538 | ARGV holds a pointer to a NULL-terminated array of arguments given | ||
| 6539 | to `emacs_spawn'. */ | ||
| 6540 | |||
| 6541 | int | ||
| 6542 | android_rewrite_spawn_argv (const char ***argv) | ||
| 6543 | { | ||
| 6544 | static const char *new_args[MAXARGS]; | ||
| 6545 | static char exec1_name[PATH_MAX], loader_name[PATH_MAX]; | ||
| 6546 | size_t i, nargs; | ||
| 6547 | |||
| 6548 | /* This isn't required on Android 9 or earlier. */ | ||
| 6549 | |||
| 6550 | if (android_api_level < 29 || !android_use_exec_loader) | ||
| 6551 | return 0; | ||
| 6552 | |||
| 6553 | /* Get argv[0]; this should never be NULL. | ||
| 6554 | Then, verify that it exists and is executable. */ | ||
| 6555 | |||
| 6556 | eassert (**argv); | ||
| 6557 | if (access (**argv, R_OK | X_OK)) | ||
| 6558 | return 1; | ||
| 6559 | |||
| 6560 | /* Count the number of arguments in *argv. */ | ||
| 6561 | |||
| 6562 | nargs = 0; | ||
| 6563 | while ((*argv)[nargs]) | ||
| 6564 | ++nargs; | ||
| 6565 | |||
| 6566 | /* nargs now holds the number of arguments in argv. If it's larger | ||
| 6567 | than MAXARGS, return failure. */ | ||
| 6568 | |||
| 6569 | if (nargs + 2 > MAXARGS) | ||
| 6570 | { | ||
| 6571 | errno = E2BIG; | ||
| 6572 | return 1; | ||
| 6573 | } | ||
| 6574 | |||
| 6575 | /* Fill in the name of `libexec1.so'. */ | ||
| 6576 | snprintf (exec1_name, PATH_MAX, "%s/libexec1.so", | ||
| 6577 | android_lib_dir); | ||
| 6578 | |||
| 6579 | /* And libloader.so. */ | ||
| 6580 | snprintf (loader_name, PATH_MAX, "%s/libloader.so", | ||
| 6581 | android_lib_dir); | ||
| 6582 | |||
| 6583 | /* Now fill in the first two arguments. */ | ||
| 6584 | new_args[0] = exec1_name; | ||
| 6585 | new_args[1] = loader_name; | ||
| 6586 | |||
| 6587 | /* And insert the rest. */ | ||
| 6588 | for (i = 0; i < nargs; ++i) | ||
| 6589 | new_args[i + 2] = (*argv)[i]; | ||
| 6590 | |||
| 6591 | /* Replace argv. */ | ||
| 6592 | *argv = new_args; | ||
| 6593 | |||
| 6594 | /* Return success. */ | ||
| 6595 | return 0; | ||
| 6596 | } | ||
| 6597 | |||
| 6598 | |||
| 6599 | |||
| 6517 | #else /* ANDROID_STUBIFY */ | 6600 | #else /* ANDROID_STUBIFY */ |
| 6518 | 6601 | ||
| 6519 | /* X emulation functions for Android. */ | 6602 | /* X emulation functions for Android. */ |