2018-10-24 18:24:11 +00:00
|
|
|
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.
|
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/gin/array_buffer.cc b/gin/array_buffer.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index b94a71ef856f92404e16544e22ebbadf57cff363..b15685f6907bcafeb1acd62bfe76f0713dea27f3 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/gin/array_buffer.cc
|
|
|
|
+++ b/gin/array_buffer.cc
|
|
|
|
@@ -43,6 +43,10 @@ void* ArrayBufferAllocator::AllocateUninitialized(size_t length) {
|
|
|
|
return malloc(length);
|
|
|
|
}
|
2018-09-14 18:03:43 +00:00
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
+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
|
2018-10-24 18:24:11 +00:00
|
|
|
index 2aef366ac8194aa261cbca6abc051f7da8a988d3..3c7d66c81032636abcca4f1538ce9b7f4ddb2de2 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- 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;
|
2018-09-14 18:03:43 +00:00
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
GIN_EXPORT static ArrayBufferAllocator* SharedInstance();
|
2018-09-14 18:03:43 +00:00
|
|
|
diff --git a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index c69cfebccd7d7bff35d2292e61bf6008f0ca7940..2cb5f5d3f89f2af13221e66b2277a28532d53deb 100644
|
2018-09-14 18:03:43 +00:00
|
|
|
--- a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc
|
|
|
|
+++ b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -654,6 +654,10 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
2019-11-05 23:41:20 +00:00
|
|
|
size, ArrayBufferContents::kDontInitialize);
|
2018-09-14 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ void* Realloc(void* data, size_t size) override {
|
2019-11-05 23:41:20 +00:00
|
|
|
+ return ArrayBufferContents::Realloc(data, size);
|
2018-09-14 18:03:43 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
void Free(void* data, size_t size) override {
|
2019-11-05 23:41:20 +00:00
|
|
|
ArrayBufferContents::FreeMemory(data);
|
2018-09-14 18:03:43 +00:00
|
|
|
}
|
2019-11-05 23:41:20 +00:00
|
|
|
diff --git a/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.cc b/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index 095ca3db051362319611976b9052725ab16c1b3a..13e802a5732f0b04832d6dd8031ae43e1240b79a 100644
|
2019-11-05 23:41:20 +00:00
|
|
|
--- a/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.cc
|
|
|
|
@@ -126,6 +126,11 @@ void* ArrayBufferContents::AllocateMemoryOrNull(size_t size,
|
2018-09-14 05:02:16 +00:00
|
|
|
return AllocateMemoryWithFlags(size, policy, base::PartitionAllocReturnNull);
|
|
|
|
}
|
|
|
|
|
|
|
|
+void* ArrayBufferContents::Realloc(void* data, size_t size) {
|
2019-11-05 23:41:20 +00:00
|
|
|
+ return WTF::Partitions::ArrayBufferPartition()->Realloc(data, size,
|
2018-09-14 05:02:16 +00:00
|
|
|
+ WTF_HEAP_PROFILER_TYPE_NAME(ArrayBufferContents));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void ArrayBufferContents::FreeMemory(void* data) {
|
2019-11-05 23:41:20 +00:00
|
|
|
WTF::Partitions::ArrayBufferPartition()->Free(data);
|
2018-09-14 05:02:16 +00:00
|
|
|
}
|
2019-11-05 23:41:20 +00:00
|
|
|
diff --git a/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.h b/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.h
|
2019-12-11 00:22:35 +00:00
|
|
|
index 2e871b20c1e6fc3703178957fd03923f02ab1b47..8f2fd80130f1e7f957d642af4e5c22f9a5937ce4 100644
|
2019-11-05 23:41:20 +00:00
|
|
|
--- a/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.h
|
|
|
|
+++ b/third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.h
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -106,6 +106,7 @@ class CORE_EXPORT ArrayBufferContents {
|
2018-09-14 05:02:16 +00:00
|
|
|
void CopyTo(ArrayBufferContents& other);
|
|
|
|
|
|
|
|
static void* AllocateMemoryOrNull(size_t, InitializationPolicy);
|
|
|
|
+ static void* Realloc(void* data, size_t);
|
|
|
|
static void FreeMemory(void*);
|
2019-10-28 22:12:35 +00:00
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
private:
|