From 5667a9704f154dfb68b4294f475d25e30ab6b0d7 Mon Sep 17 00:00:00 2001 From: Brian Watling Date: Thu, 3 Sep 2015 13:13:26 -0700 Subject: [PATCH] Allow (read-only) access to a fiber's stack details Summary: Allow users to access the stack pointer and stack size Reviewed By: @alikhtarov Differential Revision: D2407252 --- folly/experimental/fibers/Fiber.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/folly/experimental/fibers/Fiber.h b/folly/experimental/fibers/Fiber.h index 78624882..0732dd71 100644 --- a/folly/experimental/fibers/Fiber.h +++ b/folly/experimental/fibers/Fiber.h @@ -54,6 +54,21 @@ class Fiber { Fiber& operator=(const Fiber&) = delete; ~Fiber(); + + /** + * Retrieve this fiber's base stack and stack size. + * + * @return This fiber's stack pointer and stack size. + */ + std::pair getStack() const { + void* const stack = + std::min(fcontext_.stackLimit(), fcontext_.stackBase()); + const size_t size = std::abs( + reinterpret_cast(fcontext_.stackBase()) - + reinterpret_cast(fcontext_.stackLimit())); + return { stack, size }; + } + private: enum State { INVALID, /**< Does't have task function */ -- 2.34.1