From 7624b2e9006423f693757489d3e254f5e9d500d1 Mon Sep 17 00:00:00 2001 From: isidorostsa Date: Thu, 19 Dec 2024 16:08:56 +0200 Subject: [PATCH] get_stack_pointer to .cpp, prevent errors when using different compilers to build/use hpx --- libs/core/coroutines/CMakeLists.txt | 1 + .../coroutines/detail/get_stack_pointer.hpp | 25 +---------- .../src/detail/get_stack_pointer.cpp | 41 +++++++++++++++++++ 3 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 libs/core/coroutines/src/detail/get_stack_pointer.cpp diff --git a/libs/core/coroutines/CMakeLists.txt b/libs/core/coroutines/CMakeLists.txt index 2daf23eaa050..be45613ed397 100644 --- a/libs/core/coroutines/CMakeLists.txt +++ b/libs/core/coroutines/CMakeLists.txt @@ -72,6 +72,7 @@ set(coroutines_sources detail/context_posix.cpp detail/coroutine_impl.cpp detail/coroutine_self.cpp + detail/get_stack_pointer.cpp detail/posix_utility.cpp detail/tss.cpp swapcontext.cpp diff --git a/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp b/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp index 26660534fccb..ff4a3c13a897 100644 --- a/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp +++ b/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #include @@ -28,28 +29,6 @@ #include namespace hpx::threads::coroutines::detail { - - inline std::size_t get_stack_ptr() noexcept - { -#if defined(HPX_HAVE_BUILTIN_FRAME_ADDRESS) - return std::size_t(__builtin_frame_address(0)); -#else - std::size_t stack_ptr = (std::numeric_limits::max)(); -#if defined(__x86_64__) || defined(__amd64) - asm("movq %%rsp, %0" : "=r"(stack_ptr)); -#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \ - defined(__i686__) - asm("movl %%esp, %0" : "=r"(stack_ptr)); -#elif defined(__powerpc__) - void* stack_ptr_p = &stack_ptr; - asm("stw %%r1, 0(%0)" : "=&r"(stack_ptr_p)); -#elif defined(__arm__) - asm("mov %0, sp" : "=r"(stack_ptr)); -#elif defined(__riscv) - __asm__ __volatile__("add %0, x0, sp" : "=r"(stack_ptr)); -#endif - return stack_ptr; -#endif - } + HPX_CORE_EXPORT std::size_t get_stack_ptr() noexcept; } // namespace hpx::threads::coroutines::detail #endif diff --git a/libs/core/coroutines/src/detail/get_stack_pointer.cpp b/libs/core/coroutines/src/detail/get_stack_pointer.cpp new file mode 100644 index 000000000000..a9c841dd328a --- /dev/null +++ b/libs/core/coroutines/src/detail/get_stack_pointer.cpp @@ -0,0 +1,41 @@ +// Copyright (c) 2013-2016 Thomas Heller +// Copyright (c) 2022 Christopher Taylor +// +// SPDX-License-Identifier: BSL-1.0 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +#if !defined(HPX_WINDOWS) + +#include +#include + +namespace hpx::threads::coroutines::detail { + + std::size_t get_stack_ptr() noexcept + { +#if defined(HPX_HAVE_BUILTIN_FRAME_ADDRESS) + return std::size_t(__builtin_frame_address(0)); +#else + std::size_t stack_ptr = (std::numeric_limits::max)(); +#if defined(__x86_64__) || defined(__amd64) + asm("movq %%rsp, %0" : "=r"(stack_ptr)); +#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \ + defined(__i686__) + asm("movl %%esp, %0" : "=r"(stack_ptr)); +#elif defined(__powerpc__) + void* stack_ptr_p = &stack_ptr; + asm("stw %%r1, 0(%0)" : "=&r"(stack_ptr_p)); +#elif defined(__arm__) + asm("mov %0, sp" : "=r"(stack_ptr)); +#elif defined(__riscv) + __asm__ __volatile__("add %0, x0, sp" : "=r"(stack_ptr)); +#endif + return stack_ptr; +#endif + } +} // namespace hpx::threads::coroutines::detail +#endif