| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bfc5236 commit 004b9ea
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | namespace node { | |
| 10 | 10 | ||
| 11 | - typedef size_t AliasedBufferIndex; | ||
| 11 | + typedef uint64_t AliasedBufferIndex; | ||
| 12 | 12 | ||
| 13 | 13 | template <typename NativeT, typename V8T> | |
| 14 | 14 | AliasedBufferBase<NativeT, V8T>::AliasedBufferBase( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | 10 | namespace node { | |
| 11 | 11 | ||
| 12 | - typedef size_t AliasedBufferIndex; | ||
| 12 | + typedef uint64_t AliasedBufferIndex; | ||
| 13 | 13 | ||
| 14 | 14 | /** | |
| 15 | 15 | * Do not use this class directly when creating instances of it - use the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,10 +42,13 @@ namespace node { | |||
| 42 | 42 | SERIALIZABLE_NON_BINDING_TYPES(V) | |
| 43 | 43 | ||
| 44 | 44 | #define V(TypeId, NativeType) k_##TypeId, | |
| 45 | - enum class BindingDataType : uint8_t { BINDING_TYPES(V) kBindingDataTypeCount }; | ||
| 45 | + // To avoid padding, the enums are uint64_t. | ||
| 46 | + enum class BindingDataType : uint64_t { | ||
| 47 | + BINDING_TYPES(V) kBindingDataTypeCount | ||
| 48 | + }; | ||
| 46 | 49 | // Make sure that we put the bindings first so that we can also use the enums | |
| 47 | 50 | // for the bindings as index to the binding data store. | |
| 48 | - enum class EmbedderObjectType : uint8_t { | ||
| 51 | + enum class EmbedderObjectType : uint64_t { | ||
| 49 | 52 | BINDING_TYPES(V) SERIALIZABLE_NON_BINDING_TYPES(V) | |
| 50 | 53 | // We do not need to know about all the unserializable non-binding types for | |
| 51 | 54 | // now so we do not list them. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,12 @@ class BindingData : public SnapshotableObject { | |||
| 18 | 18 | AliasedBufferIndex encode_into_results_buffer; | |
| 19 | 19 | }; | |
| 20 | 20 | ||
| 21 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 22 | + // them into the snapshot blob and they need to be reproducible. | ||
| 23 | + static_assert(sizeof(InternalFieldInfo) == | ||
| 24 | + sizeof(InternalFieldInfoBase) + sizeof(AliasedBufferIndex), | ||
| 25 | + "InternalFieldInfo should have no padding"); | ||
| 26 | + | ||
| 21 | 27 | BindingData(Realm* realm, | |
| 22 | 28 | v8::Local<v8::Object> obj, | |
| 23 | 29 | InternalFieldInfo* info = nullptr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,6 +64,12 @@ class BindingData : public SnapshotableObject { | |||
| 64 | 64 | AliasedBufferIndex statfs_field_bigint_array; | |
| 65 | 65 | }; | |
| 66 | 66 | ||
| 67 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 68 | + // them into the snapshot blob and they need to be reproducible. | ||
| 69 | + static_assert(sizeof(InternalFieldInfo) == sizeof(InternalFieldInfoBase) + | ||
| 70 | + sizeof(AliasedBufferIndex) * 4, | ||
| 71 | + "InternalFieldInfo should have no padding"); | ||
| 72 | + | ||
| 67 | 73 | enum class FilePathIsFileReturnType { | |
| 68 | 74 | kIsFile = 0, | |
| 69 | 75 | kIsNotFile, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,12 @@ class BindingData : public SnapshotableObject { | |||
| 54 | 54 | AliasedBufferIndex hrtime_buffer; | |
| 55 | 55 | }; | |
| 56 | 56 | ||
| 57 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 58 | + // them into the snapshot blob and they need to be reproducible. | ||
| 59 | + static_assert(sizeof(InternalFieldInfo) == | ||
| 60 | + sizeof(InternalFieldInfoBase) + sizeof(AliasedBufferIndex), | ||
| 61 | + "InternalFieldInfo should have no padding"); | ||
| 62 | + | ||
| 57 | 63 | static void AddMethods(v8::Isolate* isolate, | |
| 58 | 64 | v8::Local<v8::ObjectTemplate> target); | |
| 59 | 65 | static void RegisterExternalReferences(ExternalReferenceRegistry* registry); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -282,9 +282,9 @@ size_t SnapshotSerializer::Write(const PropInfo& data) { | |||
| 282 | 282 | } | |
| 283 | 283 | ||
| 284 | 284 | // Layout of AsyncHooks::SerializeInfo | |
| 285 | - // [ 4/8 bytes ] snapshot index of async_ids_stack | ||
| 286 | - // [ 4/8 bytes ] snapshot index of fields | ||
| 287 | - // [ 4/8 bytes ] snapshot index of async_id_fields | ||
| 285 | + // [ 8 bytes ] snapshot index of async_ids_stack | ||
| 286 | + // [ 8 bytes ] snapshot index of fields | ||
| 287 | + // [ 8 bytes ] snapshot index of async_id_fields | ||
| 288 | 288 | // [ 4/8 bytes ] snapshot index of js_execution_async_resources | |
| 289 | 289 | // [ 4/8 bytes ] length of native_execution_async_resources | |
| 290 | 290 | // [ ... ] snapshot indices of each element in | |
@@ -387,9 +387,9 @@ size_t SnapshotSerializer::Write(const ImmediateInfo::SerializeInfo& data) { | |||
| 387 | 387 | } | |
| 388 | 388 | ||
| 389 | 389 | // Layout of PerformanceState::SerializeInfo | |
| 390 | - // [ 4/8 bytes ] snapshot index of root | ||
| 391 | - // [ 4/8 bytes ] snapshot index of milestones | ||
| 392 | - // [ 4/8 bytes ] snapshot index of observers | ||
| 390 | + // [ 8 bytes ] snapshot index of root | ||
| 391 | + // [ 8 bytes ] snapshot index of milestones | ||
| 392 | + // [ 8 bytes ] snapshot index of observers | ||
| 393 | 393 | template <> | |
| 394 | 394 | performance::PerformanceState::SerializeInfo SnapshotDeserializer::Read() { | |
| 395 | 395 | Debug("Read<PerformanceState::SerializeInfo>()\n"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 6 | 6 | ||
| 7 | + #include <cassert> // For static_assert | ||
| 8 | + #include <cstddef> // For offsetof | ||
| 7 | 9 | #include "aliased_buffer.h" | |
| 8 | 10 | #include "base_object.h" | |
| 9 | 11 | #include "util.h" | |
@@ -33,13 +35,13 @@ bool WithoutCodeCache(const SnapshotConfig& config); | |||
| 33 | 35 | // and pass it into the V8 callback as the payload of StartupData. | |
| 34 | 36 | // The memory chunk looks like this: | |
| 35 | 37 | // | |
| 36 | - // [ type ] - EmbedderObjectType (a uint8_t) | ||
| 37 | - // [ length ] - a size_t | ||
| 38 | + // [ type ] - EmbedderObjectType (a uint64_t) | ||
| 39 | + // [ length ] - a uint64_t | ||
| 38 | 40 | // [ ... ] - custom bytes of size |length - header size| | |
| 39 | 41 | struct InternalFieldInfoBase { | |
| 40 | 42 | public: | |
| 41 | 43 | EmbedderObjectType type; | |
| 42 | - size_t length; | ||
| 44 | + uint64_t length; | ||
| 43 | 45 | ||
| 44 | 46 | template <typename T> | |
| 45 | 47 | static T* New(EmbedderObjectType type) { | |
@@ -71,14 +73,35 @@ struct InternalFieldInfoBase { | |||
| 71 | 73 | InternalFieldInfoBase() = default; | |
| 72 | 74 | }; | |
| 73 | 75 | ||
| 76 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 77 | + // them into the snapshot blob and they need to be reproducible. | ||
| 78 | + static_assert(offsetof(InternalFieldInfoBase, type) == 0, | ||
| 79 | + "InternalFieldInfoBase::type should start from offset 0"); | ||
| 80 | + static_assert(offsetof(InternalFieldInfoBase, length) == | ||
| 81 | + sizeof(EmbedderObjectType), | ||
| 82 | + "InternalFieldInfoBase::type should have no padding"); | ||
| 83 | + | ||
| 74 | 84 | struct EmbedderTypeInfo { | |
| 75 | - enum class MemoryMode : uint8_t { kBaseObject, kCppGC }; | ||
| 85 | + // To avoid padding, the enum is uint64_t. | ||
| 86 | + enum class MemoryMode : uint64_t { kBaseObject = 0, kCppGC }; | ||
| 76 | 87 | EmbedderTypeInfo(EmbedderObjectType t, MemoryMode m) : type(t), mode(m) {} | |
| 77 | 88 | EmbedderTypeInfo() = default; | |
| 89 | + | ||
| 78 | 90 | EmbedderObjectType type; | |
| 79 | 91 | MemoryMode mode; | |
| 80 | 92 | }; | |
| 81 | 93 | ||
| 94 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 95 | + // them into the snapshot blob and they need to be reproducible. | ||
| 96 | + static_assert(offsetof(EmbedderTypeInfo, type) == 0, | ||
| 97 | + "EmbedderTypeInfo::type should start from offset 0"); | ||
| 98 | + static_assert(offsetof(EmbedderTypeInfo, mode) == sizeof(EmbedderObjectType), | ||
| 99 | + "EmbedderTypeInfo::type should have no padding"); | ||
| 100 | + static_assert(sizeof(EmbedderTypeInfo) == | ||
| 101 | + sizeof(EmbedderObjectType) + | ||
| 102 | + sizeof(EmbedderTypeInfo::MemoryMode), | ||
| 103 | + "EmbedderTypeInfo::mode should have no padding"); | ||
| 104 | + | ||
| 82 | 105 | // An interface for snapshotable native objects to inherit from. | |
| 83 | 106 | // Use the SERIALIZABLE_OBJECT_METHODS() macro in the class to define | |
| 84 | 107 | // the following methods to implement: | |
@@ -150,6 +173,12 @@ class BindingData : public SnapshotableObject { | |||
| 150 | 173 | AliasedBufferIndex is_building_snapshot_buffer; | |
| 151 | 174 | }; | |
| 152 | 175 | ||
| 176 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 177 | + // them into the snapshot blob and they need to be reproducible. | ||
| 178 | + static_assert(sizeof(InternalFieldInfo) == | ||
| 179 | + sizeof(InternalFieldInfoBase) + sizeof(AliasedBufferIndex), | ||
| 180 | + "InternalFieldInfo should have no padding"); | ||
| 181 | + | ||
| 153 | 182 | BindingData(Realm* realm, | |
| 154 | 183 | v8::Local<v8::Object> obj, | |
| 155 | 184 | InternalFieldInfo* info = nullptr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,13 @@ class BindingData : public SnapshotableObject { | |||
| 23 | 23 | AliasedBufferIndex heap_space_statistics_buffer; | |
| 24 | 24 | AliasedBufferIndex heap_code_statistics_buffer; | |
| 25 | 25 | }; | |
| 26 | + | ||
| 27 | + // Make sure that there's no padding in the struct since we will memcpy | ||
| 28 | + // them into the snapshot blob and they need to be reproducible. | ||
| 29 | + static_assert(sizeof(InternalFieldInfo) == sizeof(InternalFieldInfoBase) + | ||
| 30 | + sizeof(AliasedBufferIndex) * 3, | ||
| 31 | + "InternalFieldInfo should have no padding"); | ||
| 32 | + | ||
| 26 | 33 | BindingData(Realm* realm, | |
| 27 | 34 | v8::Local<v8::Object> obj, | |
| 28 | 35 | InternalFieldInfo* info = nullptr); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments