blob: c85b59dc9782995752d3806c92c4d0e9ee0825d8 [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_LEDGER_LIB_COROUTINE_CONTEXT_STACK_H_
#define SRC_LEDGER_LIB_COROUTINE_CONTEXT_STACK_H_
#include <lib/zx/vmar.h>
#include <lib/zx/vmo.h>
#include <stddef.h>
namespace context {
struct InternalContext;
using Context = InternalContext;
// A stack to be used with |MakeContext|.
class Stack {
public:
// Creates a new stack. |stack_size| is the minimal size of the new stack.
explicit Stack(size_t stack_size = 64 * 1024);
~Stack();
// Releases the memory associated with this stack. After this call, the stack
// is ready to be used again, but its content is not specified.
void Release();
size_t stack_size() const { return stack_size_; }
static size_t shadow_call_stack_size() { return kShadowCallStackSize; }
uintptr_t safe_stack() const { return safe_stack_; }
#if __has_feature(safe_stack)
uintptr_t unsafe_stack() const { return unsafe_stack_; };
#endif
#if __has_feature(shadow_call_stack)
uintptr_t shadow_call_stack() const { return shadow_call_stack_; };
#endif
private:
const size_t stack_size_;
zx::vmo vmo_;
zx::vmar safe_stack_mapping_;
uintptr_t safe_stack_;
#if __has_feature(safe_stack)
zx::vmar unsafe_stack_mapping_;
uintptr_t unsafe_stack_;
#endif
#if __has_feature(shadow_call_stack)
zx::vmar shadow_call_stack_mapping_;
uintptr_t shadow_call_stack_;
static constexpr size_t kShadowCallStackSize = ZX_PAGE_SIZE;
#else
static constexpr size_t kShadowCallStackSize = 0;
#endif
};
} // namespace context
#endif // SRC_LEDGER_LIB_COROUTINE_CONTEXT_STACK_H_