Module: Mesa
Branch: main
Commit: a72035f9c55e035592c0c1bf92d564b76f20eed7
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a72035f9c55e035592c0c1bf92d564b76f20eed7

Author: Eric Engestrom <[email protected]>
Date:   Wed Feb  1 17:58:02 2023 +0000

util: avoid calling kcmp on Android

On some combinations of Android version and kernel version, calling kcmp
results in seccomp killing the process.

As there doesn't seem to be a way to query for that in advance, skip
this check altogether on Android.

Signed-off-by: Eric Engestrom <[email protected]>
Reviewed-by: Rob Clark <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20180>

---

 meson.build        | 10 ++++++++++
 meson_options.txt  |  5 +++++
 src/util/os_file.c |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index a5dc7d0ba03..01b688a2f5d 100644
--- a/meson.build
+++ b/meson.build
@@ -851,6 +851,16 @@ if with_platform_android
   ]
 endif
 
+# On Android, seccomp kills the process on kernels without
+# CONFIG_KCMP/CONFIG_CHECKPOINT_RESTORE if it attemps to use KCMP.
+# Since we can't detect that, err on the side of caution and disable
+# KCMP by default on Android.
+if get_option('allow-kcmp') \
+    .disable_auto_if(with_platform_android) \
+    .allowed()
+  pre_args += '-DALLOW_KCMP'
+endif
+
 prog_python = import('python').find_installation('python3')
 has_mako = run_command(
   prog_python, '-c',
diff --git a/meson_options.txt b/meson_options.txt
index 27f6af7de53..69cea01f32c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -427,6 +427,11 @@ option(
   value : 25,
   description : 'Android Platform SDK version. Default: Nougat version.'
 )
+option(
+   'allow-kcmp',
+   type : 'feature',
+   description : 'Allow using KCMP_FILE to compare file descriptions. auto = 
allowed everywhere except on Android'
+)
 option(
   'zstd',
   type : 'feature',
diff --git a/src/util/os_file.c b/src/util/os_file.c
index 18149b2a4fd..5fb30f2d908 100644
--- a/src/util/os_file.c
+++ b/src/util/os_file.c
@@ -194,7 +194,7 @@ os_read_file(const char *filename, size_t *size)
    return buf;
 }
 
-#if DETECT_OS_LINUX
+#if DETECT_OS_LINUX && ALLOW_KCMP
 
 #include <sys/syscall.h>
 #include <unistd.h>

Reply via email to