-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Upstream ptrauth support in libc++ and libc++abi #84573
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,21 @@ | |
#include <atomic> | ||
#endif | ||
|
||
#if __has_feature(ptrauth_calls) | ||
#include <ptrauth.h> | ||
#endif | ||
|
||
ldionne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
template<typename T> | ||
static inline | ||
T * | ||
ldionne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
get_vtable(T *vtable) { | ||
#if __has_feature(ptrauth_calls) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please give this a more descriptive name than Maybe a name that ties it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, it may be possible for __builtin_get_vtable() to be used as instead, but I'm not sure what the considerations were when this code was written (or if it predates that builtin?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dynamic_cast machinery had to strip but |
||
vtable = ptrauth_strip(vtable, ptrauth_key_cxx_vtable_pointer); | ||
#endif | ||
return vtable; | ||
} | ||
|
||
static inline | ||
bool | ||
is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp) | ||
|
@@ -103,6 +118,7 @@ void dyn_cast_get_derived_info(derived_object_info* info, const void* static_ptr | |
info->dynamic_type = *(reinterpret_cast<const __class_type_info* const*>(ptr_to_ti_proxy)); | ||
#else | ||
void **vtable = *static_cast<void ** const *>(static_ptr); | ||
vtable = get_vtable(vtable); | ||
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]); | ||
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived; | ||
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]); | ||
|
@@ -561,6 +577,7 @@ __base_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info, | |
offset_to_base = __offset_flags >> __offset_shift; | ||
if (is_virtual) { | ||
const char* vtable = *static_cast<const char* const*>(adjustedPtr); | ||
vtable = get_vtable(vtable); | ||
offset_to_base = update_offset_to_base(vtable, offset_to_base); | ||
} | ||
} else if (!is_virtual) { | ||
|
@@ -1501,6 +1518,7 @@ __base_class_type_info::search_above_dst(__dynamic_cast_info* info, | |
if (__offset_flags & __virtual_mask) | ||
{ | ||
const char* vtable = *static_cast<const char*const*>(current_ptr); | ||
vtable = get_vtable(vtable); | ||
offset_to_base = update_offset_to_base(vtable, offset_to_base); | ||
} | ||
__base_type->search_above_dst(info, dst_ptr, | ||
|
@@ -1521,6 +1539,7 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info, | |
if (__offset_flags & __virtual_mask) | ||
{ | ||
const char* vtable = *static_cast<const char*const*>(current_ptr); | ||
vtable = get_vtable(vtable); | ||
offset_to_base = update_offset_to_base(vtable, offset_to_base); | ||
} | ||
__base_type->search_below_dst(info, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like configuration that might be better suited for a config header?
type_info is weird magic though, so I understand if you disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separately, to support ELF platforms that don't define
__arm64__
we ended up rewriting the feature check as: