Skip to content

Commit 53fb57e

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, io] Restore global destructors for normal shutdown path.
Cf. ef49845. TEST=samples/hello_world Bug: dart-lang/samples#195 Change-Id: I05cac92500a912c5d3e0771f626878decac18a9b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324267 Reviewed-by: Brian Quinlan <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent b8ee3a9 commit 53fb57e

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

runtime/bin/platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class Platform {
9999
static void SetProcessName(const char* name);
100100

101101
DART_NORETURN static void Exit(int exit_code);
102+
DART_NORETURN static void _Exit(int exit_code);
102103

103104
static void SetCoreDumpResourceLimit(int value);
104105

runtime/bin/platform_android.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ void Platform::SetProcessName(const char* name) {
162162
void Platform::Exit(int exit_code) {
163163
Console::RestoreConfig();
164164
Dart_PrepareToAbort();
165-
// We're not doing a full VM shutdown with Dart_Cleanup, which might block,
166-
// and other VM threads may be accessing state with global destructors, so
167-
// we skip global destructors by using _exit instead of exit.
165+
exit(exit_code);
166+
}
167+
168+
void Platform::_Exit(int exit_code) {
169+
Console::RestoreConfig();
170+
Dart_PrepareToAbort();
168171
_exit(exit_code);
169172
}
170173

runtime/bin/platform_fuchsia.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,12 @@ void Platform::SetProcessName(const char* name) {
157157
void Platform::Exit(int exit_code) {
158158
Console::RestoreConfig();
159159
Dart_PrepareToAbort();
160-
// We're not doing a full VM shutdown with Dart_Cleanup, which might block,
161-
// and other VM threads may be accessing state with global destructors, so
162-
// we skip global destructors by using _exit instead of exit.
160+
exit(exit_code);
161+
}
162+
163+
void Platform::_Exit(int exit_code) {
164+
Console::RestoreConfig();
165+
Dart_PrepareToAbort();
163166
_exit(exit_code);
164167
}
165168

runtime/bin/platform_linux.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ void Platform::SetProcessName(const char* name) {
169169
void Platform::Exit(int exit_code) {
170170
Console::RestoreConfig();
171171
Dart_PrepareToAbort();
172-
// We're not doing a full VM shutdown with Dart_Cleanup, which might block,
173-
// and other VM threads may be accessing state with global destructors, so
174-
// we skip global destructors by using _exit instead of exit.
172+
exit(exit_code);
173+
}
174+
175+
void Platform::_Exit(int exit_code) {
176+
Console::RestoreConfig();
177+
Dart_PrepareToAbort();
175178
_exit(exit_code);
176179
}
177180

runtime/bin/platform_macos.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,12 @@ void Platform::SetProcessName(const char* name) {
342342
void Platform::Exit(int exit_code) {
343343
Console::RestoreConfig();
344344
Dart_PrepareToAbort();
345-
// We're not doing a full VM shutdown with Dart_Cleanup, which might block,
346-
// and other VM threads may be accessing state with global destructors, so
347-
// we skip global destructors by using _exit instead of exit.
345+
exit(exit_code);
346+
}
347+
348+
void Platform::_Exit(int exit_code) {
349+
Console::RestoreConfig();
350+
Dart_PrepareToAbort();
348351
_exit(exit_code);
349352
}
350353

runtime/bin/platform_win.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ void Platform::Exit(int exit_code) {
307307
::ExitProcess(exit_code);
308308
}
309309

310+
void Platform::_Exit(int exit_code) {
311+
// Restore the console's output code page
312+
Console::RestoreConfig();
313+
// On Windows we use ExitProcess so that threads can't clobber the exit_code.
314+
// See: https://code.google.com/p/nativeclient/issues/detail?id=2870
315+
Dart_PrepareToAbort();
316+
::ExitProcess(exit_code);
317+
}
318+
310319
void Platform::SetCoreDumpResourceLimit(int value) {
311320
// Not supported.
312321
}

runtime/bin/process.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) {
263263
DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
264264
Process::RunExitHook(status);
265265
Dart_ExitIsolate();
266-
Platform::Exit(static_cast<int>(status));
266+
// We're not doing a full VM shutdown with Dart_Cleanup, which might block,
267+
// and other VM threads may be accessing state with global destructors, so
268+
// we skip global destructors by using _exit instead of exit.
269+
Platform::_Exit(static_cast<int>(status));
267270
}
268271

269272
void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) {

0 commit comments

Comments
 (0)