Commit b20390c0 authored by Albert Mingkun Yang's avatar Albert Mingkun Yang Committed by Commit Bot

[Fix] Allow LazyInstance to support classes with virtual members

Change the signature of `Construct` so that no casting is required on
calling it. The casting would fire control flow integrity check if the
class contains virtual members.

Bug: chromium:758925
Change-Id: Iefc711c634b36efd051e245e2df13b28d5563f45
Reviewed-on: https://chromium-review.googlesource.com/635563Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Albert Mingkun Yang <albertnetymk@google.com>
Cr-Commit-Position: refs/heads/master@{#47608}
parent f048b4b1
...@@ -15,7 +15,8 @@ namespace internal { ...@@ -15,7 +15,8 @@ namespace internal {
namespace { namespace {
struct PerThreadAssertKeyConstructTrait final { struct PerThreadAssertKeyConstructTrait final {
static void Construct(base::Thread::LocalStorageKey* key) { static void Construct(void* key_arg) {
auto key = reinterpret_cast<base::Thread::LocalStorageKey*>(key_arg);
*key = base::Thread::CreateThreadLocalKey(); *key = base::Thread::CreateThreadLocalKey();
} }
}; };
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
// providing your own trait: // providing your own trait:
// Example usage: // Example usage:
// struct MyCreateTrait { // struct MyCreateTrait {
// static void Construct(MyClass* allocated_ptr) { // static void Construct(void* allocated_ptr) {
// new (allocated_ptr) MyClass(/* extra parameters... */); // new (allocated_ptr) MyClass(/* extra parameters... */);
// } // }
// }; // };
...@@ -105,7 +105,7 @@ struct StaticallyAllocatedInstanceTrait { ...@@ -105,7 +105,7 @@ struct StaticallyAllocatedInstanceTrait {
template <typename ConstructTrait> template <typename ConstructTrait>
static void InitStorageUsingTrait(StorageType* storage) { static void InitStorageUsingTrait(StorageType* storage) {
ConstructTrait::Construct(MutableInstance(storage)); ConstructTrait::Construct(storage);
} }
}; };
...@@ -128,9 +128,7 @@ struct DynamicallyAllocatedInstanceTrait { ...@@ -128,9 +128,7 @@ struct DynamicallyAllocatedInstanceTrait {
template <typename T> template <typename T>
struct DefaultConstructTrait { struct DefaultConstructTrait {
// Constructs the provided object which was already allocated. // Constructs the provided object which was already allocated.
static void Construct(T* allocated_ptr) { static void Construct(void* allocated_ptr) { new (allocated_ptr) T(); }
new(allocated_ptr) T();
}
}; };
......
...@@ -66,8 +66,9 @@ const char* ElementsKindToString(ElementsKind kind) { ...@@ -66,8 +66,9 @@ const char* ElementsKindToString(ElementsKind kind) {
struct InitializeFastElementsKindSequence { struct InitializeFastElementsKindSequence {
static void Construct( static void Construct(void* fast_elements_kind_sequence_ptr_arg) {
ElementsKind** fast_elements_kind_sequence_ptr) { auto fast_elements_kind_sequence_ptr =
reinterpret_cast<ElementsKind**>(fast_elements_kind_sequence_ptr_arg);
ElementsKind* fast_elements_kind_sequence = ElementsKind* fast_elements_kind_sequence =
new ElementsKind[kFastElementsKindCount]; new ElementsKind[kFastElementsKindCount];
*fast_elements_kind_sequence_ptr = fast_elements_kind_sequence; *fast_elements_kind_sequence_ptr = fast_elements_kind_sequence;
......
...@@ -136,7 +136,7 @@ class ArchDefaultRegisterConfiguration : public RegisterConfiguration { ...@@ -136,7 +136,7 @@ class ArchDefaultRegisterConfiguration : public RegisterConfiguration {
}; };
struct RegisterConfigurationInitializer { struct RegisterConfigurationInitializer {
static void Construct(ArchDefaultRegisterConfiguration* config) { static void Construct(void* config) {
new (config) ArchDefaultRegisterConfiguration(); new (config) ArchDefaultRegisterConfiguration();
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment