proxygen
folly::exception_wrapper::ExceptionPtr Struct Reference

Public Member Functions

bool has_exception_ () const
 
std::exception const * as_exception_ () const
 
std::type_info const * as_type_ () const
 

Static Public Member Functions

static std::uintptr_t as_int_ (std::exception_ptr const &ptr, std::exception const &e) noexcept
 
static std::uintptr_t as_int_ (std::exception_ptr const &ptr, AnyException e) noexcept
 
static void copy_ (exception_wrapper const *from, exception_wrapper *to)
 
static void move_ (exception_wrapper *from, exception_wrapper *to)
 
static void delete_ (exception_wrapper *that)
 
static void throw_ (exception_wrapper const *that)
 
static std::type_info const * type_ (exception_wrapper const *that)
 
static std::exception const * get_exception_ (exception_wrapper const *that)
 
static exception_wrapper get_exception_ptr_ (exception_wrapper const *that)
 

Public Attributes

std::exception_ptr ptr_
 
std::uintptr_t exception_or_type_
 

Static Public Attributes

static VTable const ops_
 

Detailed Description

Definition at line 256 of file ExceptionWrapper.h.

Member Function Documentation

std::exception const * folly::exception_wrapper::ExceptionPtr::as_exception_ ( ) const
inline

Definition at line 138 of file ExceptionWrapper-inl.h.

References upload::const.

Referenced by get_exception_().

139  {
140  return reinterpret_cast<std::exception const*>(exception_or_type_);
141 }
const
Definition: upload.py:398
std::uintptr_t folly::exception_wrapper::ExceptionPtr::as_int_ ( std::exception_ptr const &  ptr,
std::exception const &  e 
)
inlinestaticnoexcept

Definition at line 99 of file ExceptionWrapper-inl.h.

References upload::const, folly::FOLLY_PACK_ATTR, FOLLY_PACK_PUSH, folly::kMicrosoftAbiVer, and ptr.

Referenced by folly::exception_wrapper::exception_wrapper().

101  {
102  if (!kMicrosoftAbiVer) {
103  return reinterpret_cast<std::uintptr_t>(&e);
104  } else {
105  // On Windows, as of MSVC2017, all thrown exceptions are copied to the stack
106  // first. Thus, we cannot depend on exception references associated with an
107  // exception_ptr to be live for the duration of the exception_ptr. We need
108  // to directly access the heap allocated memory inside the exception_ptr.
109  //
110  // std::exception_ptr is an opaque reinterpret_cast of
111  // std::shared_ptr<__ExceptionPtr>
112  // __ExceptionPtr is a non-virtual class with two members, a union and a
113  // bool. The union contains the now-undocumented EHExceptionRecord, which
114  // contains a struct which contains a void* which points to the heap
115  // allocated exception.
116  // We derive the offset to pExceptionObject via manual means.
118  struct Win32ExceptionPtr {
119  char offset[8 + 4 * sizeof(void*)];
120  void* exceptionObject;
121  } FOLLY_PACK_ATTR;
123 
124  auto* win32ExceptionPtr =
125  reinterpret_cast<std::shared_ptr<Win32ExceptionPtr> const*>(&ptr)
126  ->get();
127  return reinterpret_cast<std::uintptr_t>(win32ExceptionPtr->exceptionObject);
128  }
129 }
void * ptr
FOLLY_PACK_PUSH struct folly::Unaligned< T, typename std::enable_if< std::is_pod< T >::value >::type > FOLLY_PACK_ATTR
constexpr auto kMicrosoftAbiVer
Definition: Portability.h:397
FOLLY_PACK_PUSH
const
Definition: upload.py:398
std::uintptr_t folly::exception_wrapper::ExceptionPtr::as_int_ ( std::exception_ptr const &  ptr,
AnyException  e 
)
inlinestaticnoexcept

Definition at line 130 of file ExceptionWrapper-inl.h.

132  {
133  return reinterpret_cast<std::uintptr_t>(e.typeinfo_) + 1;
134 }
std::type_info const * folly::exception_wrapper::ExceptionPtr::as_type_ ( ) const
inline

Definition at line 142 of file ExceptionWrapper-inl.h.

References upload::const.

Referenced by type_().

142  {
143  return reinterpret_cast<std::type_info const*>(exception_or_type_ - 1);
144 }
const
Definition: upload.py:398
void folly::exception_wrapper::ExceptionPtr::copy_ ( exception_wrapper const *  from,
exception_wrapper to 
)
inlinestatic

Definition at line 146 of file ExceptionWrapper-inl.h.

References folly::exception_wrapper::eptr_.

148  {
149  ::new (static_cast<void*>(&to->eptr_)) ExceptionPtr(from->eptr_);
150 }
std::enable_if< detail::is_chrono_conversion< Tgt, Src >::value, Tgt >::type to(const Src &value)
Definition: Conv.h:677
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
void folly::exception_wrapper::ExceptionPtr::delete_ ( exception_wrapper that)
inlinestatic

Definition at line 157 of file ExceptionWrapper-inl.h.

References folly::exception_wrapper::eptr_, folly::exception_wrapper::uninit_, and folly::exception_wrapper::vptr_.

157  {
158  that->eptr_.~ExceptionPtr();
159  that->vptr_ = &uninit_;
160 }
static VTable const uninit_
std::exception const * folly::exception_wrapper::ExceptionPtr::get_exception_ ( exception_wrapper const *  that)
inlinestatic

Definition at line 172 of file ExceptionWrapper-inl.h.

References as_exception_(), folly::exception_wrapper::eptr_, and has_exception_().

173  {
174  return that->eptr_.has_exception_() ? that->eptr_.as_exception_() : nullptr;
175 }
exception_wrapper folly::exception_wrapper::ExceptionPtr::get_exception_ptr_ ( exception_wrapper const *  that)
inlinestatic

Definition at line 176 of file ExceptionWrapper-inl.h.

177  {
178  return *that;
179 }
bool folly::exception_wrapper::ExceptionPtr::has_exception_ ( ) const
inline

Definition at line 135 of file ExceptionWrapper-inl.h.

Referenced by get_exception_().

135  {
136  return 0 == exception_or_type_ % 2;
137 }
void folly::exception_wrapper::ExceptionPtr::move_ ( exception_wrapper from,
exception_wrapper to 
)
inlinestatic

Definition at line 151 of file ExceptionWrapper-inl.h.

References folly::exception_wrapper::eptr_, and folly::gen::move.

153  {
154  ::new (static_cast<void*>(&to->eptr_)) ExceptionPtr(std::move(from->eptr_));
155  delete_(from);
156 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
std::enable_if< detail::is_chrono_conversion< Tgt, Src >::value, Tgt >::type to(const Src &value)
Definition: Conv.h:677
static void delete_(exception_wrapper *that)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
void folly::exception_wrapper::ExceptionPtr::throw_ ( exception_wrapper const *  that)
inlinestatic

Definition at line 161 of file ExceptionWrapper-inl.h.

References folly::exception_wrapper::eptr_, and ptr_.

162  {
163  std::rethrow_exception(that->eptr_.ptr_);
164 }
void rethrow_exception(std::exception_ptr ep)
std::type_info const * folly::exception_wrapper::ExceptionPtr::type_ ( exception_wrapper const *  that)
inlinestatic

Definition at line 165 of file ExceptionWrapper-inl.h.

References as_type_(), and folly::exception_wrapper::eptr_.

166  {
167  if (auto e = get_exception_(that)) {
168  return &typeid(*e);
169  }
170  return that->eptr_.as_type_();
171 }
static std::exception const * get_exception_(exception_wrapper const *that)

Member Data Documentation

std::uintptr_t folly::exception_wrapper::ExceptionPtr::exception_or_type_

Definition at line 258 of file ExceptionWrapper.h.

exception_wrapper::VTable const folly::exception_wrapper::ExceptionPtr::ops_
static
std::exception_ptr folly::exception_wrapper::ExceptionPtr::ptr_

The documentation for this struct was generated from the following files: