v8/include
Anna Henningsen 6b0a9535e6 [api] Add possibility for BackingStore to keep Allocator alive
Add an `array_buffer_allocator_shared` field to the
`Isolate::CreateParams` struct that allows embedders to share
ownership of the ArrayBuffer::Allocator with V8, and which in
particular means that when this method is used that the
BackingStore deleter will not perform an use-after-free access to the
Allocator under certain circumstances.

For Background:

tl;dr: This is necessary for Node.js to perform the transition to
V8 7.9, because of the way that ArrayBuffer::Allocators and their
lifetimes currently work there.

In Node.js, each Worker thread has its own ArrayBuffer::Allocator.
Changing that would currently be impractical, as each allocator
depends on per-Isolate state. However, now that backing stores
are managed globally and keep a pointer to the original
ArrayBuffer::Allocator, this means that when transferring an
ArrayBuffer (e.g. from one Worker to another through postMessage()),
the original Allocator has to be kept alive until the ArrayBuffer
no longer exists in the receiving Isolate (or until that Isolate
is disposed). See [1] for an example Node.js test that fails with
V8 7.9.

This problem also existed for SharedArrayBuffers, where Node.js
was broken by V8 earlier for the same reasons (see [2] for the bug
report on that and [3] for the resolution in Node.js).
For SharedArrayBuffers, we already had extensive tracking logic,
so adding a shared_ptr to keep alive the ArrayBuffer::Allocator
was not a significant amount of work. However, the mechanism for
transferring non-shared ArrayBuffers is quite different, and
it seems both easier for us and better for V8 from an API standpoint
to keep the Allocator alive from where it is being referenced.

By sharing memory with the custom deleter function/data pair,
this comes at no memory overhead.

[1]: https://github.com/nodejs/node/pull/30044
[2]: https://github.com/nodejs/node-v8/issues/115
[3]: https://github.com/nodejs/node/pull/29637

Bug: v8:9380
Change-Id: Ibc2c4fb6341b53653cbd637bd8cb3d4ac43809c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1874347
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64542}
2019-10-24 10:56:03 +00:00
..
libplatform [api] Use C++14 [[deprecated]] attribute 2019-10-09 07:31:28 +00:00
APIDesign.md Move inspector protocol definitions to include/ 2019-06-18 17:59:36 +00:00
DEPS [inspector] Build inspector under v8_enable_inspector build flag. 2016-09-06 23:26:35 +00:00
js_protocol-1.2.json Move inspector protocol definitions to include/ 2019-06-18 17:59:36 +00:00
js_protocol-1.3.json Move inspector protocol definitions to include/ 2019-06-18 17:59:36 +00:00
js_protocol.pdl Introduce 'replMode' flag for Runtime.evaluate 2019-10-22 13:42:12 +00:00
OWNERS Add verwaest as an API owner 2019-10-15 17:40:59 +00:00
v8-inspector-protocol.h [inspector] Build inspector under v8_enable_inspector build flag. 2016-09-06 23:26:35 +00:00
v8-inspector.h inspector: V8StackTraceId serialization/deserialization 2019-09-20 00:38:24 +00:00
v8-internal.h Reland^2 "[runtime] Move Context::native_context to the map" 2019-10-17 17:33:08 +00:00
v8-platform.h [api] Prepare removal of deprecated tasks API 2019-10-21 13:07:56 +00:00
v8-profiler.h [api] Use C++14 [[deprecated]] attribute 2019-10-09 07:31:28 +00:00
v8-testing.h Remove easy to remove calls to Isolate::Current() from api.cc 2015-11-30 08:16:59 +00:00
v8-util.h Reland "[api,heap] Remove deprecated Persistent APIs" 2019-04-24 09:34:27 +00:00
v8-value-serializer-version.h Expose the ValueSerializer data format version as a compile-time constant. 2017-04-27 15:14:41 +00:00
v8-version-string.h [build] Fix V8_VERSION_STRING with embedder string 2017-10-23 14:31:52 +00:00
v8-version.h Update V8 version to 8.0 2019-10-17 14:23:59 +00:00
v8-wasm-trap-handler-posix.h [api] Fix includes in trap handler API header files 2019-01-16 15:15:52 +00:00
v8-wasm-trap-handler-win.h [api] Fix includes in trap handler API header files 2019-01-16 15:15:52 +00:00
v8.h [api] Add possibility for BackingStore to keep Allocator alive 2019-10-24 10:56:03 +00:00
v8config.h Remove build support for gcc < 5 2019-10-21 11:20:09 +00:00