Skip to content

Commit 9d46921

Browse files
joyeecheungaduh95
authored andcommitted
Revert "src: make sure that memcpy-ed structs in snapshot have no padding"
This reverts commit 4e58cde. PR-URL: #53563 Refs: #50983 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 878630a commit 9d46921

9 files changed

+14
-71
lines changed

src/aliased_buffer-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace node {
1010

11-
typedef uint64_t AliasedBufferIndex;
11+
typedef size_t AliasedBufferIndex;
1212

1313
template <typename NativeT, typename V8T>
1414
AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(

src/aliased_buffer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace node {
1111

12-
typedef uint64_t AliasedBufferIndex;
12+
typedef size_t AliasedBufferIndex;
1313

1414
/**
1515
* Do not use this class directly when creating instances of it - use the

src/base_object_types.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ namespace node {
4242
SERIALIZABLE_NON_BINDING_TYPES(V)
4343

4444
#define V(TypeId, NativeType) k_##TypeId,
45-
// To avoid padding, the enums are uint64_t.
46-
enum class BindingDataType : uint64_t {
47-
BINDING_TYPES(V) kBindingDataTypeCount
48-
};
45+
enum class BindingDataType : uint8_t { BINDING_TYPES(V) kBindingDataTypeCount };
4946
// Make sure that we put the bindings first so that we can also use the enums
5047
// for the bindings as index to the binding data store.
51-
enum class EmbedderObjectType : uint64_t {
48+
enum class EmbedderObjectType : uint8_t {
5249
BINDING_TYPES(V) SERIALIZABLE_NON_BINDING_TYPES(V)
5350
// We do not need to know about all the unserializable non-binding types for
5451
// now so we do not list them.

src/encoding_binding.h

-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ class BindingData : public SnapshotableObject {
1818
AliasedBufferIndex encode_into_results_buffer;
1919
};
2020

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-
2721
BindingData(Realm* realm,
2822
v8::Local<v8::Object> obj,
2923
InternalFieldInfo* info = nullptr);

src/node_file.h

-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ class BindingData : public SnapshotableObject {
6464
AliasedBufferIndex statfs_field_bigint_array;
6565
};
6666

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-
7367
enum class FilePathIsFileReturnType {
7468
kIsFile = 0,
7569
kIsNotFile,

src/node_process.h

-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ class BindingData : public SnapshotableObject {
5454
AliasedBufferIndex hrtime_buffer;
5555
};
5656

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-
6357
static void AddMethods(v8::Isolate* isolate,
6458
v8::Local<v8::ObjectTemplate> target);
6559
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

src/node_snapshotable.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ size_t SnapshotSerializer::Write(const PropInfo& data) {
282282
}
283283

284284
// Layout of AsyncHooks::SerializeInfo
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
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
288288
// [ 4/8 bytes ] snapshot index of js_execution_async_resources
289289
// [ 4/8 bytes ] length of native_execution_async_resources
290290
// [ ... ] snapshot indices of each element in
@@ -387,9 +387,9 @@ size_t SnapshotSerializer::Write(const ImmediateInfo::SerializeInfo& data) {
387387
}
388388

389389
// Layout of PerformanceState::SerializeInfo
390-
// [ 8 bytes ] snapshot index of root
391-
// [ 8 bytes ] snapshot index of milestones
392-
// [ 8 bytes ] snapshot index of observers
390+
// [ 4/8 bytes ] snapshot index of root
391+
// [ 4/8 bytes ] snapshot index of milestones
392+
// [ 4/8 bytes ] snapshot index of observers
393393
template <>
394394
performance::PerformanceState::SerializeInfo SnapshotDeserializer::Read() {
395395
Debug("Read<PerformanceState::SerializeInfo>()\n");

src/node_snapshotable.h

+4-33
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
66

7-
#include <cassert> // For static_assert
8-
#include <cstddef> // For offsetof
97
#include "aliased_buffer.h"
108
#include "base_object.h"
119
#include "util.h"
@@ -35,13 +33,13 @@ bool WithoutCodeCache(const SnapshotConfig& config);
3533
// and pass it into the V8 callback as the payload of StartupData.
3634
// The memory chunk looks like this:
3735
//
38-
// [ type ] - EmbedderObjectType (a uint64_t)
39-
// [ length ] - a uint64_t
36+
// [ type ] - EmbedderObjectType (a uint8_t)
37+
// [ length ] - a size_t
4038
// [ ... ] - custom bytes of size |length - header size|
4139
struct InternalFieldInfoBase {
4240
public:
4341
EmbedderObjectType type;
44-
uint64_t length;
42+
size_t length;
4543

4644
template <typename T>
4745
static T* New(EmbedderObjectType type) {
@@ -73,35 +71,14 @@ struct InternalFieldInfoBase {
7371
InternalFieldInfoBase() = default;
7472
};
7573

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-
8474
struct EmbedderTypeInfo {
85-
// To avoid padding, the enum is uint64_t.
86-
enum class MemoryMode : uint64_t { kBaseObject = 0, kCppGC };
75+
enum class MemoryMode : uint8_t { kBaseObject, kCppGC };
8776
EmbedderTypeInfo(EmbedderObjectType t, MemoryMode m) : type(t), mode(m) {}
8877
EmbedderTypeInfo() = default;
89-
9078
EmbedderObjectType type;
9179
MemoryMode mode;
9280
};
9381

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-
10582
// An interface for snapshotable native objects to inherit from.
10683
// Use the SERIALIZABLE_OBJECT_METHODS() macro in the class to define
10784
// the following methods to implement:
@@ -173,12 +150,6 @@ class BindingData : public SnapshotableObject {
173150
AliasedBufferIndex is_building_snapshot_buffer;
174151
};
175152

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-
182153
BindingData(Realm* realm,
183154
v8::Local<v8::Object> obj,
184155
InternalFieldInfo* info = nullptr);

src/node_v8.h

-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ class BindingData : public SnapshotableObject {
2323
AliasedBufferIndex heap_space_statistics_buffer;
2424
AliasedBufferIndex heap_code_statistics_buffer;
2525
};
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-
3326
BindingData(Realm* realm,
3427
v8::Local<v8::Object> obj,
3528
InternalFieldInfo* info = nullptr);

0 commit comments

Comments
 (0)