diff --git a/include/compat/bionic_host_libc_runtime.h b/include/compat/bionic_host_libc_runtime.h index 5c8d44c..15c14d9 100644 --- a/include/compat/bionic_host_libc_runtime.h +++ b/include/compat/bionic_host_libc_runtime.h @@ -14,16 +14,16 @@ namespace mocktail::compat { // Android uses size_t fields here; glibc uses int and musl has no equivalent. // An all-zero fallback means unknown, not zero usage. struct BionicMallinfoSnapshot { - size_t arena = 0; - size_t ordblks = 0; - size_t smblks = 0; - size_t hblks = 0; - size_t hblkhd = 0; - size_t usmblks = 0; - size_t fsmblks = 0; - size_t uordblks = 0; - size_t fordblks = 0; - size_t keepcost = 0; + size_t arena; + size_t ordblks; + size_t smblks; + size_t hblks; + size_t hblkhd; + size_t usmblks; + size_t fsmblks; + size_t uordblks; + size_t fordblks; + size_t keepcost; }; struct BionicLocaleState; diff --git a/src/compat/bionic_host_libc_runtime.cc b/src/compat/bionic_host_libc_runtime.cc index 9ec8eff..324e2e9 100644 --- a/src/compat/bionic_host_libc_runtime.cc +++ b/src/compat/bionic_host_libc_runtime.cc @@ -323,8 +323,13 @@ int BionicStrError(int error_number, char* buffer, ::strerror_r(error_number, host_buffer.data(), host_buffer.size()); const char* message = HostStrErrorResult(host_result, host_buffer.data()); - std::array unknown_buffer{}; - if (message == nullptr) { + std::array unknown_buffer{}; + const char* unknown_message = HostStrErrorResult( + ::strerror_r(-1, unknown_buffer.data(), unknown_buffer.size()), + unknown_buffer.data()); + if (message == nullptr || + (error_number != 0 && unknown_message != nullptr && + std::strcmp(message, unknown_message) == 0)) { std::snprintf(unknown_buffer.data(), unknown_buffer.size(), "Unknown error %d", error_number); message = unknown_buffer.data(); diff --git a/src/compat/bionic_pthread_create_runtime.cc b/src/compat/bionic_pthread_create_runtime.cc index e34fcf6..af5ff8e 100644 --- a/src/compat/bionic_pthread_create_runtime.cc +++ b/src/compat/bionic_pthread_create_runtime.cc @@ -114,7 +114,7 @@ int CopySupportedThreadAttributes(const MocktailBionicPthreadAttr& source, if (RejectRealtimeScheduling(source.sched_policy)) { return EPERM; } - if (source.sched_policy != SCHED_NORMAL) { + if (source.sched_policy != SCHED_OTHER) { result = pthread_attr_setschedpolicy(destination, source.sched_policy); if (result != 0) { return result; diff --git a/src/runtime/external_launch_broker.cc b/src/runtime/external_launch_broker.cc index 3ea4632..b723e28 100644 --- a/src/runtime/external_launch_broker.cc +++ b/src/runtime/external_launch_broker.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/tests/bionic_host_libc_runtime_test.cc b/tests/bionic_host_libc_runtime_test.cc index 663bea7..b67e753 100644 --- a/tests/bionic_host_libc_runtime_test.cc +++ b/tests/bionic_host_libc_runtime_test.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "libc_shim/libc_shim.h" @@ -214,9 +215,18 @@ TEST(BionicHostLibcRuntimeTest, UsesBionicPosixStrErrorContract) { EXPECT_NE(std::strstr(buffer.data(), "Invalid"), nullptr); EXPECT_EQ(errno, EDOM); - buffer.fill('\0'); - EXPECT_EQ(mocktail_bionic_strerror_r(4567, buffer.data(), buffer.size()), 0); - EXPECT_NE(std::strstr(buffer.data(), "4567"), nullptr); + EXPECT_EQ(mocktail_bionic_strerror_r(0, buffer.data(), buffer.size()), 0); + EXPECT_STREQ(buffer.data(), std::strerror(0)); + EXPECT_EQ(errno, EDOM); + + for (const int error_number : {-1, 4567, INT_MIN, INT_MAX}) { + errno = EDOM; + ASSERT_EQ(mocktail_bionic_strerror_r(error_number, buffer.data(), + buffer.size()), 0); + EXPECT_EQ(std::string(buffer.data()), + "Unknown error " + std::to_string(error_number)); + EXPECT_EQ(errno, EDOM); + } std::array truncated{}; errno = 0; diff --git a/third_party/mcpelauncher-linker/include/assert.h b/third_party/mcpelauncher-linker/include/assert.h index 7205cce..3ffb4a1 100644 --- a/third_party/mcpelauncher-linker/include/assert.h +++ b/third_party/mcpelauncher-linker/include/assert.h @@ -1,4 +1,5 @@ +#include #include "../bionic/libc/include/assert.h" #ifdef __BIONIC__ #undef __BIONIC__ -#endif \ No newline at end of file +#endif diff --git a/third_party/mcpelauncher-linker/include/compat.h b/third_party/mcpelauncher-linker/include/compat.h index 4f435e0..4ce7490 100644 --- a/third_party/mcpelauncher-linker/include/compat.h +++ b/third_party/mcpelauncher-linker/include/compat.h @@ -15,8 +15,12 @@ typedef std::atomic_int atomic_int; typedef std::atomic_uint atomic_uint; #endif +#ifndef PAGE_SIZE #define PAGE_SIZE 4096 +#endif +#ifndef PAGE_MASK #define PAGE_MASK (~(PAGE_SIZE - 1)) +#endif #if !defined(__APPLE__) && !defined(__FreeBSD__) #define DEF_WEAK(a) #define __BIONIC_ALIGN(__value, __alignment) (((__value) + (__alignment)-1) & ~((__alignment)-1)) diff --git a/third_party/mcpelauncher-linker/include/sys/cdefs.h b/third_party/mcpelauncher-linker/include/sys/cdefs.h index 3e6455b..53749da 100644 --- a/third_party/mcpelauncher-linker/include/sys/cdefs.h +++ b/third_party/mcpelauncher-linker/include/sys/cdefs.h @@ -1,6 +1,12 @@ #pragma once #ifndef __APPLE__ +#pragma push_macro("_FORTIFY_SOURCE") +#pragma push_macro("__bos") +#undef _FORTIFY_SOURCE +#undef __bos #include "../../bionic/libc/include/sys/cdefs.h" +#pragma pop_macro("__bos") +#pragma pop_macro("_FORTIFY_SOURCE") #endif #if defined(__has_include_next) #if __has_include_next()