From 242577f90d39c401dc765512ca89bc056593edd2 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 10 Mar 2022 13:24:15 -0800 Subject: [PATCH] os: add working stack logic for macOS --- .../diag/impl/diag_symbol_impl.os.macos.cpp | 33 +++++++++++++++++++ .../source/os/impl/os_debug_impl.os.macos.hpp | 21 +++++------- 2 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 libraries/libstratosphere/source/diag/impl/diag_symbol_impl.os.macos.cpp diff --git a/libraries/libstratosphere/source/diag/impl/diag_symbol_impl.os.macos.cpp b/libraries/libstratosphere/source/diag/impl/diag_symbol_impl.os.macos.cpp new file mode 100644 index 000000000..a0f1f9848 --- /dev/null +++ b/libraries/libstratosphere/source/diag/impl/diag_symbol_impl.os.macos.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "diag_symbol_impl.hpp" + +namespace ams::diag::impl { + + uintptr_t GetSymbolNameImpl(char *dst, size_t dst_size, uintptr_t address) { + /* TODO: How should we do this on macOS? */ + AMS_UNUSED(dst, dst_size, address); + return 0; + } + + size_t GetSymbolSizeImpl(uintptr_t address) { + /* TODO: How should we do this on macOS? */ + AMS_UNUSED(address); + return 0; + } + +} diff --git a/libraries/libstratosphere/source/os/impl/os_debug_impl.os.macos.hpp b/libraries/libstratosphere/source/os/impl/os_debug_impl.os.macos.hpp index 637460a11..1bb7fa0fa 100644 --- a/libraries/libstratosphere/source/os/impl/os_debug_impl.os.macos.hpp +++ b/libraries/libstratosphere/source/os/impl/os_debug_impl.os.macos.hpp @@ -25,22 +25,17 @@ namespace ams::os::impl { AMS_ASSERT(out_stack != nullptr); AMS_ASSERT(out_size != nullptr); - /* Get the current stack by pthread */ - pthread_attr_t attr; - pthread_attr_init(std::addressof(attr)); - ON_SCOPE_EXIT { pthread_attr_destroy(std::addressof(attr)); }; + /* Get the current pthread. */ + const auto self = pthread_self(); - const auto getattr_res = pthread_getattr_np(pthread_self(), std::addressof(attr)); - AMS_ABORT_UNLESS(getattr_res == 0); + /* Get the thread stack. */ + uintptr_t stack_bottom = reinterpret_cast(pthread_get_stackaddr_np(self)); + size_t stack_size = pthread_get_stacksize_np(self); - /* Get the thread satck. */ - void *base = nullptr; - size_t size = 0; - const auto getstack_res = pthread_getattr_np(pthread_self(), std::addressof(attr)); - AMS_ABORT_UNLESS(getstack_res == 0); + uintptr_t stack_top = stack_bottom - stack_size; - *out_stack = reinterpret_cast(base); - *out_size = size; + *out_stack = stack_top; + *out_size = stack_size; } static void QueryMemoryInfo(os::MemoryInfo *out) {