dart-sdk/runtime/bin/error_exit.cc
asiva e4f1a10431 [VM/Runtime] Ensure an isolate exists before calling Dart_ShutdownIsolate()
Fixes https://github.com/dart-lang/sdk/issues/52892
TEST=ci

Change-Id: I4f0aa64642d4ba8416ef353dfca7371adc7e6bba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313543
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2023-07-14 01:31:38 +00:00

46 lines
1.2 KiB
C++

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "bin/error_exit.h"
#include "bin/eventhandler.h"
#include "bin/platform.h"
#include "bin/process.h"
#include "include/dart_api.h"
#include "platform/assert.h"
#include "platform/globals.h"
#include "platform/syslog.h"
namespace dart {
namespace bin {
void ErrorExit(int exit_code, const char* format, ...) {
va_list arguments;
va_start(arguments, format);
Syslog::VPrintErr(format, arguments);
va_end(arguments);
// Sometimes ErrorExit is called even before we have entered an isolate.
// We need to shutdown the isolate only if one exists.
if (Dart_CurrentIsolate() != nullptr) {
Dart_ShutdownIsolate();
}
// Terminate process exit-code handler.
Process::TerminateExitCodeHandler();
char* error = Dart_Cleanup();
if (error != nullptr) {
Syslog::PrintErr("VM cleanup failed: %s\n", error);
free(error);
}
Process::ClearAllSignalHandlers();
EventHandler::Stop();
Platform::Exit(exit_code);
}
} // namespace bin
} // namespace dart