electron/patches/common/chromium/add_realloc.patch

84 lines
4.1 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-09-21 00:30:26 +00:00
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Thu, 20 Sep 2018 17:44:26 -0700
Subject: add_realloc.patch
Blink overrides ArrayBuffer's allocator with its own one, while Node simply
uses malloc and free, so we need to use v8's allocator in Node. As part of the
10.6.0 upgrade, we needed to make SerializerDelegate accept an allocator
argument in its constructor, and override ReallocateBufferMemory and
FreeBufferMemory to use the allocator. We cannot simply allocate and then memcpy
when we override ReallocateBufferMemory, so we therefore need to implement
Realloc on the v8 side and correspondingly in gin.
diff --git a/gin/array_buffer.cc b/gin/array_buffer.cc
index f84934bfd712dbad0e85d908165a5a4033bff170..fc23fef68b6fb9a4cccdf99bc427078faed2f62e 100644
--- a/gin/array_buffer.cc
+++ b/gin/array_buffer.cc
@@ -43,6 +43,10 @@ void* ArrayBufferAllocator::AllocateUninitialized(size_t length) {
return malloc(length);
}
+void* ArrayBufferAllocator::Realloc(void* data, size_t length) {
+ return realloc(data, length);
+}
+
void ArrayBufferAllocator::Free(void* data, size_t length) {
free(data);
}
diff --git a/gin/array_buffer.h b/gin/array_buffer.h
index 2aef366ac8194aa261cbca6abc051f7da8a988d3..3c7d66c81032636abcca4f1538ce9b7f4ddb2de2 100644
--- a/gin/array_buffer.h
+++ b/gin/array_buffer.h
@@ -21,6 +21,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
public:
void* Allocate(size_t length) override;
void* AllocateUninitialized(size_t length) override;
+ void* Realloc(void* data, size_t length) override;
void Free(void* data, size_t length) override;
GIN_EXPORT static ArrayBufferAllocator* SharedInstance();
diff --git a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc
2018-10-24 23:25:48 +00:00
index de5c4b11829141913784fc3c7190ab86368cf675..f88a404c95c12ab5647bf88bd7be2504699b7ff7 100644
--- a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc
+++ b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc
2018-10-24 23:25:48 +00:00
@@ -671,6 +671,10 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
size, WTF::ArrayBufferContents::kDontInitialize);
}
+ void* Realloc(void* data, size_t size) override {
+ return WTF::ArrayBufferContents::Realloc(data, size);
+ }
+
void Free(void* data, size_t size) override {
WTF::ArrayBufferContents::FreeMemory(data);
}
diff --git a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.cc b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.cc
2018-10-24 23:25:48 +00:00
index 83133e1a836d0c3b25e931e0c19ebcdb987173cf..2c64bd4d5cf3ecd71ee0711cecd1c149e8795797 100644
--- a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.cc
+++ b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.cc
@@ -121,6 +121,11 @@ void* ArrayBufferContents::AllocateMemoryOrNull(size_t size,
return AllocateMemoryWithFlags(size, policy, base::PartitionAllocReturnNull);
}
+void* ArrayBufferContents::Realloc(void* data, size_t size) {
+ return Partitions::ArrayBufferPartition()->Realloc(data, size,
+ WTF_HEAP_PROFILER_TYPE_NAME(ArrayBufferContents));
+}
+
void ArrayBufferContents::FreeMemory(void* data) {
Partitions::ArrayBufferPartition()->Free(data);
}
diff --git a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.h b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.h
2018-10-24 23:25:48 +00:00
index a87a02bdaf4b7050752f05984ff1c0170f64a203..cf7f2940d48b03c51b997729fc7ea033dc0d1bfe 100644
--- a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.h
+++ b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.h
2018-10-24 23:25:48 +00:00
@@ -187,6 +187,7 @@ class WTF_EXPORT ArrayBufferContents {
void CopyTo(ArrayBufferContents& other);
static void* AllocateMemoryOrNull(size_t, InitializationPolicy);
+ static void* Realloc(void* data, size_t);
static void FreeMemory(void*);
static DataHandle CreateDataHandle(size_t, InitializationPolicy);
static void Initialize(