From 513125638303b9b595d48ffe6a94894b8be79789 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 6 Mar 2022 14:13:10 -0800 Subject: [PATCH] add basic tests for os::Event/SystemEvent functionality --- libstratosphere/libstratosphere.mk | 4 ++++ libstratosphere/source/fs/fs_access_log.cpp | 4 ++-- .../os/impl/os_inter_process_event_impl.os.linux.cpp | 7 +++++-- .../os/impl/os_inter_process_event_impl.os.macos.cpp | 7 +++++-- .../impl/os_internal_condition_variable_impl.pthread.cpp | 2 +- .../os/impl/os_multiple_wait_target_impl.os.linux.cpp | 5 +++++ .../os/impl/os_multiple_wait_target_impl.os.macos.cpp | 5 +++++ .../source/os/impl/os_tick_manager_impl.os.windows.hpp | 4 ++-- 8 files changed, 29 insertions(+), 9 deletions(-) diff --git a/libstratosphere/libstratosphere.mk b/libstratosphere/libstratosphere.mk index e741ef1f..e854123b 100644 --- a/libstratosphere/libstratosphere.mk +++ b/libstratosphere/libstratosphere.mk @@ -146,6 +146,10 @@ hos_stratosphere_api.o: CXXFLAGS += -fno-lto init_operator_new.o: CXXFLAGS += -fno-lto init_libnx_shim.os.horizon.o: CXXFLAGS += -fno-lto +ifeq ($(ATMOSPHERE_OS_NAME),windows) +os_%.o: CXXFLAGS += -fno-lto +endif + #--------------------------------------------------------------------------------- %_bin.h %.bin.o : %.bin #--------------------------------------------------------------------------------- diff --git a/libstratosphere/source/fs/fs_access_log.cpp b/libstratosphere/source/fs/fs_access_log.cpp index c665aa49..7f5e9074 100644 --- a/libstratosphere/source/fs/fs_access_log.cpp +++ b/libstratosphere/source/fs/fs_access_log.cpp @@ -543,7 +543,7 @@ namespace ams::fs::impl { bool IsEnabledFileSystemAccessorAccessLog(const char *mount_name) { /* Get the accessor. */ - impl::FileSystemAccessor *accessor; + impl::FileSystemAccessor *accessor = nullptr; if (R_FAILED(impl::Find(std::addressof(accessor), mount_name))) { return true; } @@ -553,7 +553,7 @@ namespace ams::fs::impl { void EnableFileSystemAccessorAccessLog(const char *mount_name) { /* Get the accessor. */ - impl::FileSystemAccessor *accessor; + impl::FileSystemAccessor *accessor = nullptr; AMS_FS_R_ABORT_UNLESS(impl::Find(std::addressof(accessor), mount_name)); accessor->SetAccessLogEnabled(true); } diff --git a/libstratosphere/source/os/impl/os_inter_process_event_impl.os.linux.cpp b/libstratosphere/source/os/impl/os_inter_process_event_impl.os.linux.cpp index 2fd36239..ae994499 100644 --- a/libstratosphere/source/os/impl/os_inter_process_event_impl.os.linux.cpp +++ b/libstratosphere/source/os/impl/os_inter_process_event_impl.os.linux.cpp @@ -41,8 +41,11 @@ namespace ams::os::impl { res = ::ppoll(std::addressof(pfd), 1, ns >= 0 ? std::addressof(ts) : nullptr, nullptr); } while (res < 0 && errno == EINTR); - AMS_ASSERT(res == 0); - return pfd.revents & POLLIN; + AMS_ASSERT(res == 0 || res == 1); + + const bool signaled = pfd.revents & POLLIN; + AMS_ASSERT(signaled == (res == 1)); + return signaled; } } diff --git a/libstratosphere/source/os/impl/os_inter_process_event_impl.os.macos.cpp b/libstratosphere/source/os/impl/os_inter_process_event_impl.os.macos.cpp index 486a1b8f..4270eec8 100644 --- a/libstratosphere/source/os/impl/os_inter_process_event_impl.os.macos.cpp +++ b/libstratosphere/source/os/impl/os_inter_process_event_impl.os.macos.cpp @@ -48,8 +48,11 @@ namespace ams::os::impl { res = ::poll(std::addressof(pfd), 1, timeout); } while (res < 0 && errno == EINTR); - AMS_ASSERT(res == 0); - return pfd.revents & POLLIN; + AMS_ASSERT(res == 0 || res == 1); + + const bool signaled = pfd.revents & POLLIN; + AMS_ASSERT(signaled == (res == 1)); + return signaled; } } diff --git a/libstratosphere/source/os/impl/os_internal_condition_variable_impl.pthread.cpp b/libstratosphere/source/os/impl/os_internal_condition_variable_impl.pthread.cpp index 225bb490..c18a98bf 100644 --- a/libstratosphere/source/os/impl/os_internal_condition_variable_impl.pthread.cpp +++ b/libstratosphere/source/os/impl/os_internal_condition_variable_impl.pthread.cpp @@ -62,7 +62,7 @@ namespace ams::os::impl { const auto res = pthread_cond_timedwait(std::addressof(m_pthread_cond), std::addressof(cs->Get()->m_pthread_mutex), std::addressof(ts)); if (res != 0) { - AMS_ABORT_UNLESS(errno == ETIMEDOUT); + AMS_ABORT_UNLESS(res == ETIMEDOUT); return ConditionVariableStatus::TimedOut; } diff --git a/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.linux.cpp b/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.linux.cpp index 1045ba72..83750fbe 100644 --- a/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.linux.cpp +++ b/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.linux.cpp @@ -93,4 +93,9 @@ namespace ams::os::impl { } } + Result MultiWaitLinuxImpl::ReplyAndReceiveImpl(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target) { + AMS_UNUSED(out_index, num, arr, array_size, ns, reply_target); + R_ABORT_UNLESS(os::ResultNotImplemented()); + } + } diff --git a/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.macos.cpp b/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.macos.cpp index 923bb46c..31d92d5b 100644 --- a/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.macos.cpp +++ b/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.macos.cpp @@ -97,4 +97,9 @@ namespace ams::os::impl { } } + Result MultiWaitMacosImpl::ReplyAndReceiveImpl(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target) { + AMS_UNUSED(out_index, num, arr, array_size, ns, reply_target); + R_ABORT_UNLESS(os::ResultNotImplemented()); + } + } diff --git a/libstratosphere/source/os/impl/os_tick_manager_impl.os.windows.hpp b/libstratosphere/source/os/impl/os_tick_manager_impl.os.windows.hpp index 50dc0a59..e09ca29f 100644 --- a/libstratosphere/source/os/impl/os_tick_manager_impl.os.windows.hpp +++ b/libstratosphere/source/os/impl/os_tick_manager_impl.os.windows.hpp @@ -50,7 +50,7 @@ namespace ams::os::impl { ALWAYS_INLINE Tick GetTick() const { LARGE_INTEGER freq; - ::QueryPerformanceFrequency(std::addressof(freq)); + ::QueryPerformanceCounter(std::addressof(freq)); return Tick(static_cast(freq.QuadPart)); } @@ -58,7 +58,7 @@ namespace ams::os::impl { LARGE_INTEGER freq; PerformOrderingForGetSystemTickOrdered(); - ::QueryPerformanceFrequency(std::addressof(freq)); + ::QueryPerformanceCounter(std::addressof(freq)); PerformOrderingForGetSystemTickOrdered(); return Tick(static_cast(freq.QuadPart));