Bug 206804 - Introduce a getVTablePointer() utility function.
Summary: Introduce a getVTablePointer() utility function.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-25 13:10 PST by Mark Lam
Modified: 2020-01-26 21:21 PST (History)
17 users (show)

See Also:


Attachments
proposed patch. (74.85 KB, patch)
2020-01-25 13:26 PST, Mark Lam
ysuzuki: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2020-01-25 13:10:38 PST
With getVTablePointer(), we can abstract away how we get a vtable function pointer without assuming the way it is signed for ARM64E.  With this, we can remove the WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION macro which assumes how a vtable function pointer is signed.

<rdar://problem/58872290>
Comment 1 Mark Lam 2020-01-25 13:26:17 PST
Created attachment 388787 [details]
proposed patch.
Comment 2 Oliver Hunt 2020-01-25 13:50:45 PST
Comment on attachment 388787 [details]
proposed patch.

LGTM, though I am no longer a reviewer :D
Comment 3 Yusuke Suzuki 2020-01-25 14:05:16 PST
Comment on attachment 388787 [details]
proposed patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=388787&action=review

> Source/WTF/wtf/PointerPreparations.h:40
> +#if __has_builtin(__builtin_get_vtable_pointer)
> +#define getVTablePointer(o) __builtin_get_vtable_pointer(o)
> +#else
> +#define getVTablePointer(o) __builtin_ptrauth_auth(*(reinterpret_cast<void**>(o)), ptrauth_key_cxx_vtable_pointer, 0)
> +#endif

Is it supported in newer clang? This is out of this patch's scope, but I was considering that whether we can just use `__builtin_get_vtable_pointer` to determine a lot of C++ WebCore class types.
Comment 4 Oliver Hunt 2020-01-25 14:26:20 PST
Comment on attachment 388787 [details]
proposed patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=388787&action=review

>> Source/WTF/wtf/PointerPreparations.h:40
>> +#endif
> 
> Is it supported in newer clang? This is out of this patch's scope, but I was considering that whether we can just use `__builtin_get_vtable_pointer` to determine a lot of C++ WebCore class types.

You can't get metadata - so no sub typing checks, you could theoretically use it for exact matching but that doesn't work for MI (you only get the primary vtable), but the joy of linking could mean duplicate vtable definitions for some classes so it could only ever be a speculative optimization.

You *could* do a comparison to the destructor - e.g.

vtable[0] == &Class::~Class
Comment 5 Mark Lam 2020-01-25 14:35:19 PST
Thanks for the reviews.  Landed in r255126: <https://trac.webkit.org/r255126>.
Comment 6 Darin Adler 2020-01-26 14:16:46 PST
Comment on attachment 388787 [details]
proposed patch.

I think this patch goes against our WebKit coding style tradition of using normal casing for functions including inline functions, but using ALL_CAPS for macros, even function-like macros. But maybe we agreed on something different a while back? The most dangerous macros are the non-function-style ones, so maybe those are the ones we are strongly encouraging ALL_CAPS for?
Comment 7 Mark Lam 2020-01-26 19:50:16 PST
(In reply to Darin Adler from comment #6)
> Comment on attachment 388787 [details]
> proposed patch.
> 
> I think this patch goes against our WebKit coding style tradition of using
> normal casing for functions including inline functions, but using ALL_CAPS
> for macros, even function-like macros. But maybe we agreed on something
> different a while back? The most dangerous macros are the non-function-style
> ones, so maybe those are the ones we are strongly encouraging ALL_CAPS for?

You are right.  This totally slipped my mind.  Sorry about that.

I'll fix this by making getVTablePointer() into an inlined function.
Comment 8 Mark Lam 2020-01-26 21:21:21 PST
(In reply to Mark Lam from comment #7)
> I'll fix this by making getVTablePointer() into an inlined function.

Will address this in https://bugs.webkit.org/show_bug.cgi?id=206816.