<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/node-new.git/src/js_native_api_v8.cc, branch docs-fix</title>
<subtitle>github.com: nodejs/node.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/'/>
<entry>
<title>n-api: handle weak no-finalizer refs correctly</title>
<updated>2020-08-21T13:16:18+00:00</updated>
<author>
<name>Gabriel Schulhof</name>
<email>gabriel.schulhof@intel.com</email>
</author>
<published>2020-08-19T06:00:37+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=acd423b45edad27427a6c4faa5bbed624983ae51'/>
<id>acd423b45edad27427a6c4faa5bbed624983ae51</id>
<content type='text'>
When deleting a weak reference that has no finalizer we must not defer
deletion until the non-existent finalizer gets called.

Fixes: https://github.com/nodejs/node/issues/34731
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;

PR-URL: https://github.com/nodejs/node/pull/34839
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Gus Caplan &lt;me@gus.host&gt;
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Rich Trott &lt;rtrott@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When deleting a weak reference that has no finalizer we must not defer
deletion until the non-existent finalizer gets called.

Fixes: https://github.com/nodejs/node/issues/34731
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;

PR-URL: https://github.com/nodejs/node/pull/34839
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Gus Caplan &lt;me@gus.host&gt;
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Rich Trott &lt;rtrott@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>n-api: support type-tagging objects</title>
<updated>2020-08-01T01:30:30+00:00</updated>
<author>
<name>Gabriel Schulhof</name>
<email>gabriel.schulhof@intel.com</email>
</author>
<published>2019-06-14T23:44:18+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=cc7ec889e863433c248bc4b5c8e33f61ccc40f29'/>
<id>cc7ec889e863433c248bc4b5c8e33f61ccc40f29</id>
<content type='text'>
`napi_instanceof()` is insufficient for reliably establishing the data
type to which a pointer stored with `napi_wrap()` or
`napi_create_external()` inside a JavaScript object points. Thus, we
need a way to "mark" an object with a value that, when later retrieved,
can unambiguously tell us whether it is safe to cast the pointer stored
inside it to a certain structure.

Such a check must survive loading/unloading/multiple instances of an
addon, so we use UUIDs chosen *a priori*.

Fixes: https://github.com/nodejs/node/issues/28164
Co-authored-by: Anna Henningsen &lt;github@addaleax.net&gt;
PR-URL: https://github.com/nodejs/node/pull/28237
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Colin Ihrig &lt;cjihrig@gmail.com&gt;
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
`napi_instanceof()` is insufficient for reliably establishing the data
type to which a pointer stored with `napi_wrap()` or
`napi_create_external()` inside a JavaScript object points. Thus, we
need a way to "mark" an object with a value that, when later retrieved,
can unambiguously tell us whether it is safe to cast the pointer stored
inside it to a certain structure.

Such a check must survive loading/unloading/multiple instances of an
addon, so we use UUIDs chosen *a priori*.

Fixes: https://github.com/nodejs/node/issues/28164
Co-authored-by: Anna Henningsen &lt;github@addaleax.net&gt;
PR-URL: https://github.com/nodejs/node/pull/28237
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Colin Ihrig &lt;cjihrig@gmail.com&gt;
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>n-api: simplify bigint-from-word creation</title>
<updated>2020-07-31T20:45:25+00:00</updated>
<author>
<name>Gabriel Schulhof</name>
<email>gabriel.schulhof@intel.com</email>
</author>
<published>2020-07-29T17:48:00+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=0cc2a54a53831968d5c955cb6cc09a2c46bd75ea'/>
<id>0cc2a54a53831968d5c955cb6cc09a2c46bd75ea</id>
<content type='text'>
Macro `CHECK_MAYBE_EMPTY_WITH_PREAMBLE()` does the work of checking
the `TryCatch` and returning `napi_pending_exception` so this change
reuses it for `napi_create_bigint_words()`.

Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
PR-URL: https://github.com/nodejs/node/pull/34554
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Macro `CHECK_MAYBE_EMPTY_WITH_PREAMBLE()` does the work of checking
the `TryCatch` and returning `napi_pending_exception` so this change
reuses it for `napi_create_bigint_words()`.

Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
PR-URL: https://github.com/nodejs/node/pull/34554
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>n-api: run all finalizers via SetImmediate()</title>
<updated>2020-07-24T06:28:09+00:00</updated>
<author>
<name>Gabriel Schulhof</name>
<email>gabriel.schulhof@intel.com</email>
</author>
<published>2020-07-15T22:45:53+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=a74a6e3ba131752225a527d915593d7e413b1594'/>
<id>a74a6e3ba131752225a527d915593d7e413b1594</id>
<content type='text'>
Throwing an exception from a finalizer can cause the following fatal
error:

Error: async hook stack has become corrupted (actual: 2, expected: 0)
 1: 0x970b5a node::InternalCallbackScope::~InternalCallbackScope()
    [./node]
 2: 0x99dda0 node::Environment::RunTimers(uv_timer_s*) [./node]
 3: 0x13d8b22  [./node]
 4: 0x13dbe42 uv_run [./node]
 5: 0xa57974 node::NodeMainInstance::Run() [./node]
 6: 0x9dbc17 node::Start(int, char**) [./node]
 7: 0x7f4965417f43 __libc_start_main [/lib64/libc.so.6]
 8: 0x96f4ae _start [./node]

By https://github.com/nodejs/node/issues/34341#issuecomment-658426281,
calling into JS from a finalizer and/or throwing exceptions from there
is not advised, because the stack may or may not be set up for JS
execution. The best solution is to run the user's finalizer from a
`SetImmediate()` callback.

Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Fixes: https://github.com/nodejs/node/issues/34341
PR-URL: https://github.com/nodejs/node/pull/34386
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Juan José Arboleda &lt;soyjuanarbol@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Throwing an exception from a finalizer can cause the following fatal
error:

Error: async hook stack has become corrupted (actual: 2, expected: 0)
 1: 0x970b5a node::InternalCallbackScope::~InternalCallbackScope()
    [./node]
 2: 0x99dda0 node::Environment::RunTimers(uv_timer_s*) [./node]
 3: 0x13d8b22  [./node]
 4: 0x13dbe42 uv_run [./node]
 5: 0xa57974 node::NodeMainInstance::Run() [./node]
 6: 0x9dbc17 node::Start(int, char**) [./node]
 7: 0x7f4965417f43 __libc_start_main [/lib64/libc.so.6]
 8: 0x96f4ae _start [./node]

By https://github.com/nodejs/node/issues/34341#issuecomment-658426281,
calling into JS from a finalizer and/or throwing exceptions from there
is not advised, because the stack may or may not be set up for JS
execution. The best solution is to run the user's finalizer from a
`SetImmediate()` callback.

Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Fixes: https://github.com/nodejs/node/issues/34341
PR-URL: https://github.com/nodejs/node/pull/34386
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Juan José Arboleda &lt;soyjuanarbol@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>n-api: ensure scope present for finalization</title>
<updated>2020-06-09T23:17:49+00:00</updated>
<author>
<name>Michael Dawson</name>
<email>michael_dawson@ca.ibm.com</email>
</author>
<published>2020-05-22T02:05:16+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=362e4a1aec46f386b7bc5a1b3493c690976d9105'/>
<id>362e4a1aec46f386b7bc5a1b3493c690976d9105</id>
<content type='text'>
Refs: https://github.com/nodejs/node-addon-api/issues/722

Ensure a scope is on stack during finalization
as finalization functions can create JS Objects

Signed-off-by: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;

PR-URL: https://github.com/nodejs/node/pull/33508
Reviewed-By: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Refs: https://github.com/nodejs/node-addon-api/issues/722

Ensure a scope is on stack during finalization
as finalization functions can create JS Objects

Signed-off-by: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;

PR-URL: https://github.com/nodejs/node/pull/33508
Reviewed-By: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>napi: fix memory corruption vulnerability</title>
<updated>2020-06-02T18:35:51+00:00</updated>
<author>
<name>Tobias Nießen</name>
<email>tniessen@tnie.de</email>
</author>
<published>2020-01-27T17:38:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=656260b4b65fec3b10f6da3fdc9f11fb941aafb5'/>
<id>656260b4b65fec3b10f6da3fdc9f11fb941aafb5</id>
<content type='text'>
Fixes: https://hackerone.com/reports/784186
CVE-ID: CVE-2020-8174
PR-URL: https://github.com/nodejs-private/node-private/pull/195
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Colin Ihrig &lt;cjihrig@gmail.com&gt;
Reviewed-By: Rich Trott &lt;rtrott@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fixes: https://hackerone.com/reports/784186
CVE-ID: CVE-2020-8174
PR-URL: https://github.com/nodejs-private/node-private/pull/195
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Colin Ihrig &lt;cjihrig@gmail.com&gt;
Reviewed-By: Rich Trott &lt;rtrott@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>n-api: remove `napi_env::CallIntoModuleThrow`</title>
<updated>2020-05-28T20:28:56+00:00</updated>
<author>
<name>Gabriel Schulhof</name>
<email>gabriel.schulhof@intel.com</email>
</author>
<published>2020-05-26T15:32:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=6a1df3b5afc92f438cf84621abd8cda79d9b1b17'/>
<id>6a1df3b5afc92f438cf84621abd8cda79d9b1b17</id>
<content type='text'>
Give `napi_env::CallIntoModule` the thrower used by
`CallIntoModuleThrow` as its default second argument. That way we do
not need two different methods on `napi_env` for calling into the
addon.

PR-URL: https://github.com/nodejs/node/pull/33570
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Chengzhong Wu &lt;legendecas@gmail.com&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Give `napi_env::CallIntoModule` the thrower used by
`CallIntoModuleThrow` as its default second argument. That way we do
not need two different methods on `napi_env` for calling into the
addon.

PR-URL: https://github.com/nodejs/node/pull/33570
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt;
Reviewed-By: Chengzhong Wu &lt;legendecas@gmail.com&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>buffer,n-api: release external buffers from BackingStore callback</title>
<updated>2020-05-16T10:15:07+00:00</updated>
<author>
<name>Anna Henningsen</name>
<email>anna@addaleax.net</email>
</author>
<published>2020-05-09T04:41:58+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=c1ee70ec168eedc3f9d193473d141b9c03e2df88'/>
<id>c1ee70ec168eedc3f9d193473d141b9c03e2df88</id>
<content type='text'>
Release `Buffer` and `ArrayBuffer` instances that were created through
our addon APIs and have finalizers attached to them only after V8 has
called the deleter callback passed to the `BackingStore`, instead of
relying on our own GC callback(s).

This fixes the following race condition:

1. Addon code allocates pointer P via `malloc`.
2. P is passed into `napi_create_external_buffer` with a finalization
   callback which calls `free(P)`. P is inserted into V8’s global array
   buffer table for tracking.
3. The finalization callback is executed on GC. P is freed and returned
   to the allocator. P is not yet removed from V8’s global array
   buffer table. (!)
4. Addon code attempts to allocate memory once again. The allocator
   returns P, as it is now available.
5. P is passed into `napi_create_external_buffer`. P still has not been
   removed from the v8 global array buffer table.
6. The world ends with `Check failed: result.second`.

Since our API contract is to call the finalizer on the JS thread on
which the `ArrayBuffer` was created, but V8 may call the `BackingStore`
deleter callback on another thread, fixing this requires posting
a task back to the JS thread.

Refs: https://github.com/nodejs/node/issues/32463#issuecomment-625877175
Fixes: https://github.com/nodejs/node/issues/32463

PR-URL: https://github.com/nodejs/node/pull/33321
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Release `Buffer` and `ArrayBuffer` instances that were created through
our addon APIs and have finalizers attached to them only after V8 has
called the deleter callback passed to the `BackingStore`, instead of
relying on our own GC callback(s).

This fixes the following race condition:

1. Addon code allocates pointer P via `malloc`.
2. P is passed into `napi_create_external_buffer` with a finalization
   callback which calls `free(P)`. P is inserted into V8’s global array
   buffer table for tracking.
3. The finalization callback is executed on GC. P is freed and returned
   to the allocator. P is not yet removed from V8’s global array
   buffer table. (!)
4. Addon code attempts to allocate memory once again. The allocator
   returns P, as it is now available.
5. P is passed into `napi_create_external_buffer`. P still has not been
   removed from the v8 global array buffer table.
6. The world ends with `Check failed: result.second`.

Since our API contract is to call the finalizer on the JS thread on
which the `ArrayBuffer` was created, but V8 may call the `BackingStore`
deleter callback on another thread, fixing this requires posting
a task back to the JS thread.

Refs: https://github.com/nodejs/node/issues/32463#issuecomment-625877175
Fixes: https://github.com/nodejs/node/issues/32463

PR-URL: https://github.com/nodejs/node/pull/33321
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>buffer,n-api: fix double ArrayBuffer::Detach() during cleanup</title>
<updated>2020-04-27T09:16:51+00:00</updated>
<author>
<name>Anna Henningsen</name>
<email>anna@addaleax.net</email>
</author>
<published>2020-04-24T13:45:51+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=36993c05667bbfda66d84329278b82887771cc94'/>
<id>36993c05667bbfda66d84329278b82887771cc94</id>
<content type='text'>
These calls could fail if the `ArrayBuffer` had already been explicitly
detached at some point in the past.

The necessary test changes already came with 4f523c2c1a1c and could
be ported back to v12.x with a backport of this PR.

Fixes: https://github.com/nodejs/node/issues/33022
Refs: https://github.com/nodejs/node/pull/30551

PR-URL: https://github.com/nodejs/node/pull/33039
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Chengzhong Wu &lt;legendecas@gmail.com&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Gerhard Stöbich &lt;deb2001-github@yahoo.de&gt;
Reviewed-By: David Carlier &lt;devnexen@gmail.com&gt;
Reviewed-By: Juan José Arboleda &lt;soyjuanarbol@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
These calls could fail if the `ArrayBuffer` had already been explicitly
detached at some point in the past.

The necessary test changes already came with 4f523c2c1a1c and could
be ported back to v12.x with a backport of this PR.

Fixes: https://github.com/nodejs/node/issues/33022
Refs: https://github.com/nodejs/node/pull/30551

PR-URL: https://github.com/nodejs/node/pull/33039
Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
Reviewed-By: Chengzhong Wu &lt;legendecas@gmail.com&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Gerhard Stöbich &lt;deb2001-github@yahoo.de&gt;
Reviewed-By: David Carlier &lt;devnexen@gmail.com&gt;
Reviewed-By: Juan José Arboleda &lt;soyjuanarbol@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>n-api: detect deadlocks in thread-safe function</title>
<updated>2020-04-19T17:07:00+00:00</updated>
<author>
<name>Gabriel Schulhof</name>
<email>gabriel.schulhof@intel.com</email>
</author>
<published>2020-04-06T17:16:15+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/node-new.git/commit/?id=d26ca06c16f497ffa5ac4845a27922d5058a9318'/>
<id>d26ca06c16f497ffa5ac4845a27922d5058a9318</id>
<content type='text'>
We introduce status `napi_would_deadlock` to be used as a return status
by `napi_call_threadsafe_function` if the call is made with
`napi_tsfn_blocking` on the main thread and the queue is full.

Fixes: https://github.com/nodejs/node/issues/32615
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
PR-URL: https://github.com/nodejs/node/pull/32860
Reviewed-By: Ben Noordhuis &lt;info@bnoordhuis.nl&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Zeyu Yang &lt;himself65@outlook.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We introduce status `napi_would_deadlock` to be used as a return status
by `napi_call_threadsafe_function` if the call is made with
`napi_tsfn_blocking` on the main thread and the queue is full.

Fixes: https://github.com/nodejs/node/issues/32615
Signed-off-by: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt;
PR-URL: https://github.com/nodejs/node/pull/32860
Reviewed-By: Ben Noordhuis &lt;info@bnoordhuis.nl&gt;
Reviewed-By: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt;
Reviewed-By: Zeyu Yang &lt;himself65@outlook.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
