GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: split out async stack corruption detection from inline fn · nodejs/node@337ebfc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • env-inl.h
    • env.cc
    • env.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/env-inl.h‎

Copy file name to clipboardExpand all lines: src/env-inl.h
+4-14Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,15 @@ inline void AsyncHooks::push_async_context(double async_id,
166166
inline bool AsyncHooks::pop_async_context(double async_id) {
167167
// In case of an exception then this may have already been reset, if the
168168
// stack was multiple MakeCallback()'s deep.
169-
if (fields_[kStackLength] == 0) return false;
169+
if (UNLIKELY(fields_[kStackLength] == 0)) return false;
170170

171171
// Ask for the async_id to be restored as a check that the stack
172172
// hasn't been corrupted.
173173
// Since async_hooks is experimental, do only perform the check
174174
// when async_hooks is enabled.
175-
if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) {
176-
fprintf(stderr,
177-
"Error: async hook stack has become corrupted ("
178-
"actual: %.f, expected: %.f)\n",
179-
async_id_fields_.GetValue(kExecutionAsyncId),
180-
async_id);
181-
DumpBacktrace(stderr);
182-
fflush(stderr);
183-
if (!env()->abort_on_uncaught_exception())
184-
exit(1);
185-
fprintf(stderr, "\n");
186-
fflush(stderr);
187-
ABORT_NO_BACKTRACE();
175+
if (UNLIKELY(fields_[kCheck] > 0 &&
176+
async_id_fields_[kExecutionAsyncId] != async_id)) {
177+
FailWithCorruptedAsyncStack(async_id);
188178
}
189179

190180
uint32_t offset = fields_[kStackLength] - 1;
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,21 @@ void AsyncHooks::grow_async_ids_stack() {
11961196
async_ids_stack_.GetJSArray()).Check();
11971197
}
11981198

1199+
void AsyncHooks::FailWithCorruptedAsyncStack(double expected_async_id) {
1200+
fprintf(stderr,
1201+
"Error: async hook stack has become corrupted ("
1202+
"actual: %.f, expected: %.f)\n",
1203+
async_id_fields_.GetValue(kExecutionAsyncId),
1204+
expected_async_id);
1205+
DumpBacktrace(stderr);
1206+
fflush(stderr);
1207+
if (!env()->abort_on_uncaught_exception())
1208+
exit(1);
1209+
fprintf(stderr, "\n");
1210+
fflush(stderr);
1211+
ABORT_NO_BACKTRACE();
1212+
}
1213+
11991214
void Environment::Exit(int exit_code) {
12001215
if (options()->trace_exit) {
12011216
HandleScope handle_scope(isolate());
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ class AsyncHooks : public MemoryRetainer {
774774
friend class Environment; // So we can call the constructor.
775775
explicit AsyncHooks(v8::Isolate* isolate, const SerializeInfo* info);
776776

777+
[[noreturn]] void FailWithCorruptedAsyncStack(double expected_async_id);
778+
777779
// Stores the ids of the current execution context stack.
778780
AliasedFloat64Array async_ids_stack_;
779781
// Attached to a Uint32Array that tracks the number of active hooks for

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.