From d84fc60f96f8e384efa3e76452d21098e4519886 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 11 Jul 2022 01:06:29 -0600 Subject: [PATCH] LibCore: Add support for compiling for Android with API Version >= 30 Most changes are around user and group management, which are exposed in the Android NDK differently than other Unices. We require version 30 for memfd_create, version 28 for posix_spawn, and so on. It's possible a shim for memfd_create could be used, but since Google is mandating new apps use API level 30 as of Nov 2022, this seems suitable. --- Userland/Libraries/LibCore/CMakeLists.txt | 4 +++- Userland/Libraries/LibCore/Group.cpp | 2 +- Userland/Libraries/LibCore/Group.h | 2 +- Userland/Libraries/LibCore/System.cpp | 12 +++++++----- Userland/Libraries/LibCore/System.h | 6 ++++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibCore/CMakeLists.txt b/Userland/Libraries/LibCore/CMakeLists.txt index 96940c060d..a22ab5245f 100644 --- a/Userland/Libraries/LibCore/CMakeLists.txt +++ b/Userland/Libraries/LibCore/CMakeLists.txt @@ -1,5 +1,4 @@ set(SOURCES - Account.cpp AnonymousBuffer.cpp ArgsParser.cpp ConfigFile.cpp @@ -38,6 +37,9 @@ set(SOURCES UDPServer.cpp Version.cpp ) +if (NOT ANDROID) + list(APPEND SOURCES Account.cpp) +endif() serenity_lib(LibCore core) target_link_libraries(LibCore LibC LibCrypt) diff --git a/Userland/Libraries/LibCore/Group.cpp b/Userland/Libraries/LibCore/Group.cpp index 259ede81bc..e38aace24e 100644 --- a/Userland/Libraries/LibCore/Group.cpp +++ b/Userland/Libraries/LibCore/Group.cpp @@ -11,7 +11,7 @@ namespace Core { -#ifndef AK_OS_BSD_GENERIC +#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) ErrorOr Group::add_group(Group& group) { if (group.name().is_empty()) diff --git a/Userland/Libraries/LibCore/Group.h b/Userland/Libraries/LibCore/Group.h index 6f49007fb7..1e291e7a53 100644 --- a/Userland/Libraries/LibCore/Group.h +++ b/Userland/Libraries/LibCore/Group.h @@ -15,7 +15,7 @@ namespace Core { class Group { public: -#ifndef AK_OS_BSD_GENERIC +#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) static ErrorOr add_group(Group& group); #endif diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index a3b1972bdf..770569b987 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #ifdef __serenity__ +# include # include #endif @@ -182,7 +182,7 @@ ErrorOr profiling_free_buffer(pid_t pid) } #endif -#ifndef AK_OS_BSD_GENERIC +#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) ErrorOr> getspent() { errno = 0; @@ -917,17 +917,19 @@ ErrorOr uname() return uts; } +#ifndef AK_OS_ANDROID ErrorOr adjtime(const struct timeval* delta, struct timeval* old_delta) { -#ifdef __serenity__ +# ifdef __serenity__ int rc = syscall(SC_adjtime, delta, old_delta); HANDLE_SYSCALL_RETURN_VALUE("adjtime", rc, {}); -#else +# else if (::adjtime(delta, old_delta) < 0) return Error::from_syscall("adjtime"sv, -errno); return {}; -#endif +# endif } +#endif ErrorOr exec(StringView filename, Span arguments, SearchInPath search_in_path, Optional> environment) { diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index a3b4072899..e25c2e7777 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -26,7 +26,7 @@ #include #include -#ifndef AK_OS_BSD_GENERIC +#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) # include #endif @@ -78,7 +78,7 @@ ALWAYS_INLINE ErrorOr unveil(std::nullptr_t, std::nullptr_t) return unveil(StringView {}, StringView {}); } -#ifndef AK_OS_BSD_GENERIC +#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) ErrorOr> getspent(); ErrorOr> getspnam(StringView name); #endif @@ -157,7 +157,9 @@ ErrorOr unlink(StringView path); ErrorOr utime(StringView path, Optional); ErrorOr uname(); ErrorOr> pipe2(int flags); +#ifndef AK_OS_ANDROID ErrorOr adjtime(const struct timeval* delta, struct timeval* old_delta); +#endif enum class SearchInPath { No, Yes,