Commit 5c3b9d59 authored by Chad Austin's avatar Chad Austin Committed by Facebook GitHub Bot

detect ucontext's swapcontext at build time

Summary:
Instead of assuming every posix-y system has ucontext.h, detect
swapcontext's existence at build time. Android NDK provides ucontext.h
but not its corresponding functions.

Reviewed By: yfeldblum

Differential Revision: D23695665

fbshipit-source-id: 9e49c6fbf553abff6249d55c780c09cc19d0bb48
parent 5c7de7b4
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
#cmakedefine FOLLY_HAVE_LIBUNWIND 1 #cmakedefine FOLLY_HAVE_LIBUNWIND 1
#cmakedefine FOLLY_HAVE_DWARF 1 #cmakedefine FOLLY_HAVE_DWARF 1
#cmakedefine FOLLY_HAVE_ELF 1 #cmakedefine FOLLY_HAVE_ELF 1
#cmakedefine FOLLY_HAVE_SWAPCONTEXT 1
#cmakedefine FOLLY_HAVE_BACKTRACE 1 #cmakedefine FOLLY_HAVE_BACKTRACE 1
#cmakedefine FOLLY_USE_SYMBOLIZER 1 #cmakedefine FOLLY_USE_SYMBOLIZER 1
#define FOLLY_DEMANGLE_MAX_SYMBOL_SIZE 1024 #define FOLLY_DEMANGLE_MAX_SYMBOL_SIZE 1024
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CheckCXXSymbolExists)
include(CheckIncludeFileCXX) include(CheckIncludeFileCXX)
include(CheckFunctionExists) include(CheckFunctionExists)
...@@ -149,6 +150,11 @@ find_package(LibUnwind) ...@@ -149,6 +150,11 @@ find_package(LibUnwind)
list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES}) list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES})
list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBUNWIND_INCLUDE_DIRS}) list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBUNWIND_INCLUDE_DIRS})
cmake_push_check_state()
set(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE)
check_cxx_symbol_exists(swapcontext ucontext.h FOLLY_HAVE_SWAPCONTEXT)
cmake_pop_check_state()
set(FOLLY_USE_SYMBOLIZER OFF) set(FOLLY_USE_SYMBOLIZER OFF)
CHECK_INCLUDE_FILE_CXX(elf.h FOLLY_HAVE_ELF) CHECK_INCLUDE_FILE_CXX(elf.h FOLLY_HAVE_ELF)
if (LIBUNWIND_FOUND) if (LIBUNWIND_FOUND)
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <folly/portability/SysMman.h> #include <folly/portability/SysMman.h>
#include <folly/portability/Unistd.h> #include <folly/portability/Unistd.h>
#ifndef _WIN32 #if FOLLY_HAVE_SWAPCONTEXT
// folly/portability/Config.h (thus features.h) must be included // folly/portability/Config.h (thus features.h) must be included
// first, and _XOPEN_SOURCE must be defined to unable the context // first, and _XOPEN_SOURCE must be defined to unable the context
// functions on macOS. // functions on macOS.
...@@ -373,6 +373,8 @@ void SafeStackTracePrinter::printStackTrace(bool symbolize) { ...@@ -373,6 +373,8 @@ void SafeStackTracePrinter::printStackTrace(bool symbolize) {
} }
} }
#if FOLLY_HAVE_SWAPCONTEXT
// Stack utilities used by UnsafeSelfAllocateStackTracePrinter // Stack utilities used by UnsafeSelfAllocateStackTracePrinter
namespace { namespace {
// Size of mmap-allocated stack. Not to confuse with sigaltstack. // Size of mmap-allocated stack. Not to confuse with sigaltstack.
...@@ -463,6 +465,8 @@ void UnsafeSelfAllocateStackTracePrinter::printSymbolizedStackTrace() { ...@@ -463,6 +465,8 @@ void UnsafeSelfAllocateStackTracePrinter::printSymbolizedStackTrace() {
} }
} }
#endif // FOLLY_HAVE_SWAPCONTEXT
#endif // FOLLY_USE_SYMBOLIZER #endif // FOLLY_USE_SYMBOLIZER
} // namespace symbolizer } // namespace symbolizer
......
...@@ -242,6 +242,8 @@ class SafeStackTracePrinter { ...@@ -242,6 +242,8 @@ class SafeStackTracePrinter {
std::unique_ptr<FrameArray<kMaxStackTraceDepth>> addresses_; std::unique_ptr<FrameArray<kMaxStackTraceDepth>> addresses_;
}; };
#if FOLLY_HAVE_SWAPCONTEXT
/** /**
* Use this class in rare situations where signal handlers are running in a * Use this class in rare situations where signal handlers are running in a
* tiny stack specified by sigaltstack. * tiny stack specified by sigaltstack.
...@@ -258,6 +260,8 @@ class UnsafeSelfAllocateStackTracePrinter : public SafeStackTracePrinter { ...@@ -258,6 +260,8 @@ class UnsafeSelfAllocateStackTracePrinter : public SafeStackTracePrinter {
const long pageSizeUnchecked_ = sysconf(_SC_PAGESIZE); const long pageSizeUnchecked_ = sysconf(_SC_PAGESIZE);
}; };
#endif // FOLLY_HAVE_SWAPCONTEXT
#endif // FOLLY_USE_SYMBOLIZER #endif // FOLLY_USE_SYMBOLIZER
} // namespace symbolizer } // namespace symbolizer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment