From 53d9debcf4de881b5b7cd74004c2e698602b4e98 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 30 Jan 2024 14:18:01 -0800 Subject: [PATCH] util: refactor to use DETECT_OS_ANDROID except leaving u_endian.h behind to use __ANDROID__ directly to be consistent with the rest in that file, which deserves a different refactor Signed-off-by: Yiwei Zhang Reviewed-by: Yonggang Luo Part-of: --- src/util/anon_file.c | 4 ++-- src/util/libsync.h | 6 ++++-- src/util/os_memory_fd.c | 2 +- src/util/perf/cpu_trace.h | 3 ++- src/util/tests/cache_test.cpp | 3 ++- src/util/u_debug_stack.c | 2 +- src/util/u_endian.h | 2 +- src/util/u_process.c | 4 ++-- src/util/u_thread.c | 4 ++-- 9 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/util/anon_file.c b/src/util/anon_file.c index dacc8e737af..bc674c4b66f 100644 --- a/src/util/anon_file.c +++ b/src/util/anon_file.c @@ -46,7 +46,7 @@ #include #endif -#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(HAVE_MKOSTEMP) || defined(ANDROID)) +#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(HAVE_MKOSTEMP) || DETECT_OS_ANDROID) static int set_cloexec_or_close(int fd) { @@ -70,7 +70,7 @@ err: } #endif -#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(ANDROID)) +#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || DETECT_OS_ANDROID) static int create_tmpfile_cloexec(char *tmpname) { diff --git a/src/util/libsync.h b/src/util/libsync.h index 60e3e5db67e..f810b7ceb45 100644 --- a/src/util/libsync.h +++ b/src/util/libsync.h @@ -38,11 +38,13 @@ #include #include +#include "util/detect_os.h" + #if defined(__cplusplus) extern "C" { #endif -#ifdef ANDROID +#if DETECT_OS_ANDROID /* On Android, rely on the system's libsync instead of rolling our own * sync_wait() and sync_merge(). This gives us compatibility with pre-4.7 * Android kernels. @@ -157,7 +159,7 @@ sync_valid_fd(int fd) return ioctl(fd, SYNC_IOC_FILE_INFO, &info) >= 0; } -#endif /* !ANDROID */ +#endif /* DETECT_OS_ANDROID */ /* accumulate fd2 into fd1. If *fd1 is not a valid fd then dup fd2, * otherwise sync_merge() and close the old *fd1. This can be used diff --git a/src/util/os_memory_fd.c b/src/util/os_memory_fd.c index 63735a70c9d..bb74ffc608f 100644 --- a/src/util/os_memory_fd.c +++ b/src/util/os_memory_fd.c @@ -128,7 +128,7 @@ os_malloc_aligned_fd(size_t size, size_t alignment, int *fd, char const *fd_name if(mem_fd < 0) return NULL; -#if defined(HAVE_MEMFD_CREATE) || defined(ANDROID) +#if defined(HAVE_MEMFD_CREATE) || DETECT_OS_ANDROID // Seal fd, so no one can grow or shrink the memory. if (fcntl(mem_fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_SEAL) != 0) goto fail; diff --git a/src/util/perf/cpu_trace.h b/src/util/perf/cpu_trace.h index 6cebb51bafd..75db0f7badd 100644 --- a/src/util/perf/cpu_trace.h +++ b/src/util/perf/cpu_trace.h @@ -9,6 +9,7 @@ #include "u_perfetto.h" #include "u_gpuvis.h" +#include "util/detect_os.h" #include "util/macros.h" #if defined(HAVE_PERFETTO) @@ -33,7 +34,7 @@ * * https://github.com/android/ndk/issues/1178 */ -#elif defined(ANDROID) && !defined(__cplusplus) +#elif DETECT_OS_ANDROID && !defined(__cplusplus) #include diff --git a/src/util/tests/cache_test.cpp b/src/util/tests/cache_test.cpp index 23732e325fe..48d723b4742 100644 --- a/src/util/tests/cache_test.cpp +++ b/src/util/tests/cache_test.cpp @@ -37,6 +37,7 @@ #include #include +#include "util/detect_os.h" #include "util/mesa-sha1.h" #include "util/disk_cache.h" #include "util/disk_cache_os.h" @@ -190,7 +191,7 @@ test_disk_cache_create(void *mem_ctx, const char *cache_dir_name, disk_cache_destroy(cache); -#ifdef ANDROID +#if DETECT_OS_ANDROID /* Android doesn't try writing to disk (just calls the cache callbacks), so * the directory tests below don't apply. */ diff --git a/src/util/u_debug_stack.c b/src/util/u_debug_stack.c index 9cfb61a32e6..ee3cbd11e88 100644 --- a/src/util/u_debug_stack.c +++ b/src/util/u_debug_stack.c @@ -179,7 +179,7 @@ debug_backtrace_print(FILE *f, frame_ip(&backtrace[i])); } } -#elif defined(ANDROID) +#elif DETECT_OS_ANDROID /* Not implemented here; see u_debug_stack_android.cpp */ #else /* ! HAVE_LIBUNWIND */ diff --git a/src/util/u_endian.h b/src/util/u_endian.h index 661628e1822..b01f73017ae 100644 --- a/src/util/u_endian.h +++ b/src/util/u_endian.h @@ -82,7 +82,7 @@ # define UTIL_ARCH_BIG_ENDIAN 1 #endif -#elif defined(_WIN32) || defined(ANDROID) +#elif defined(_WIN32) || defined(__ANDROID__) #define UTIL_ARCH_LITTLE_ENDIAN 1 #define UTIL_ARCH_BIG_ENDIAN 0 diff --git a/src/util/u_process.c b/src/util/u_process.c index 6ad19de416e..23ab4bc0927 100644 --- a/src/util/u_process.c +++ b/src/util/u_process.c @@ -103,7 +103,7 @@ __getProgramName() { return strdup(program_invocation_short_name); } -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) || defined(ANDROID) || defined(__NetBSD__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) || DETECT_OS_ANDROID || defined(__NetBSD__) #if defined(__NetBSD__) # include #endif @@ -170,7 +170,7 @@ __getProgramName() #endif #if defined(GET_PROGRAM_NAME_NOT_AVAILABLE) -#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__UCLIBC__) || defined(ANDROID) +#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__UCLIBC__) || DETECT_OS_ANDROID /* This is a hack. It's said to work on OpenBSD, NetBSD and GNU. * Rogelio M.Serrano Jr. reported it's also working with UCLIBC. It's * used as a last resort, if there is no documented facility available. */ diff --git a/src/util/u_thread.c b/src/util/u_thread.c index c5087338bc9..8c3ac224371 100644 --- a/src/util/u_thread.c +++ b/src/util/u_thread.c @@ -20,7 +20,7 @@ #include #endif -#if DETECT_OS_LINUX && !defined(ANDROID) +#if DETECT_OS_LINUX && !DETECT_OS_ANDROID #include #elif defined(_WIN32) && !defined(HAVE_PTHREAD) #include @@ -37,7 +37,7 @@ int util_get_current_cpu(void) { -#if DETECT_OS_LINUX && !defined(ANDROID) +#if DETECT_OS_LINUX && !DETECT_OS_ANDROID return sched_getcpu(); #elif defined(_WIN32) && !defined(HAVE_PTHREAD)