| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/dbg_connection.h" | 6 #include "bin/dbg_connection.h" |
| 7 #include "bin/eventhandler.h" | 7 #include "bin/eventhandler.h" |
| 8 #include "bin/io_buffer.h" | 8 #include "bin/io_buffer.h" |
| 9 #include "bin/log.h" | 9 #include "bin/log.h" |
| 10 #include "bin/platform.h" | 10 #include "bin/platform.h" |
| 11 #include "bin/process.h" | 11 #include "bin/process.h" |
| 12 #include "bin/socket.h" | 12 #include "bin/socket.h" |
| 13 #include "bin/utils.h" | 13 #include "bin/utils.h" |
| 14 | 14 |
| 15 #include "include/dart_api.h" | 15 #include "include/dart_api.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 namespace bin { | 18 namespace bin { |
| 19 | 19 |
| 20 // Global flag that is used to indicate that the VM should do a clean | |
| 21 // shutdown. | |
| 22 bool do_vm_shutdown = false; | |
| 23 | |
| 24 static const int kProcessIdNativeField = 0; | 20 static const int kProcessIdNativeField = 0; |
| 25 | 21 |
| 26 int Process::global_exit_code_ = 0; | 22 int Process::global_exit_code_ = 0; |
| 27 Mutex* Process::global_exit_code_mutex_ = new Mutex(); | 23 Mutex* Process::global_exit_code_mutex_ = new Mutex(); |
| 28 | 24 |
| 29 // Extract an array of C strings from a list of Dart strings. | 25 // Extract an array of C strings from a list of Dart strings. |
| 30 static char** ExtractCStringList(Dart_Handle strings, | 26 static char** ExtractCStringList(Dart_Handle strings, |
| 31 Dart_Handle status_handle, | 27 Dart_Handle status_handle, |
| 32 const char* error_msg, | 28 const char* error_msg, |
| 33 intptr_t* length) { | 29 intptr_t* length) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); | 243 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 248 bool success = Process::Kill(pid, signal); | 244 bool success = Process::Kill(pid, signal); |
| 249 Dart_SetReturnValue(args, Dart_NewBoolean(success)); | 245 Dart_SetReturnValue(args, Dart_NewBoolean(success)); |
| 250 } | 246 } |
| 251 | 247 |
| 252 | 248 |
| 253 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { | 249 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { |
| 254 int64_t status = 0; | 250 int64_t status = 0; |
| 255 // Ignore result if passing invalid argument and just exit 0. | 251 // Ignore result if passing invalid argument and just exit 0. |
| 256 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 252 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
| 257 Dart_ShutdownIsolate(); | 253 Dart_ExitIsolate(); |
| 258 Process::TerminateExitCodeHandler(); | |
| 259 char* error = Dart_Cleanup(); | |
| 260 if (error != NULL) { | |
| 261 Log::PrintErr("VM cleanup failed: %s\n", error); | |
| 262 free(error); | |
| 263 } | |
| 264 if (do_vm_shutdown) { | |
| 265 #ifdef LEGACY_DEBUG_PROTOCOL_ENABLED | |
| 266 // Note that this dependency crosses logical project boundaries by making | |
| 267 // the dart:io implementation depend upon the standalone VM's legacy debug | |
| 268 // protocol. This breaks projects which want to use our dart:io | |
| 269 // implementation. Because the protocol is going away shortly, it's | |
| 270 // reasonable to leave it behind a #ifdef that is only enabled for the | |
| 271 // standalone VM for now. | |
| 272 DebuggerConnectionHandler::StopHandler(); | |
| 273 #endif | |
| 274 EventHandler::Stop(); | |
| 275 } | |
| 276 Platform::Exit(static_cast<int>(status)); | 254 Platform::Exit(static_cast<int>(status)); |
| 277 } | 255 } |
| 278 | 256 |
| 279 | 257 |
| 280 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { | 258 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { |
| 281 int64_t status = 0; | 259 int64_t status = 0; |
| 282 // Ignore result if passing invalid argument and just set exit code to 0. | 260 // Ignore result if passing invalid argument and just set exit code to 0. |
| 283 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 261 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
| 284 Process::SetGlobalExitCode(status); | 262 Process::SetGlobalExitCode(status); |
| 285 } | 263 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 free(const_cast<char*>(system_string)); | 369 free(const_cast<char*>(system_string)); |
| 392 Dart_PropagateError(result); | 370 Dart_PropagateError(result); |
| 393 } | 371 } |
| 394 memmove(buffer, system_string, system_len); | 372 memmove(buffer, system_string, system_len); |
| 395 free(const_cast<char*>(system_string)); | 373 free(const_cast<char*>(system_string)); |
| 396 Dart_SetReturnValue(args, external_array); | 374 Dart_SetReturnValue(args, external_array); |
| 397 } | 375 } |
| 398 | 376 |
| 399 } // namespace bin | 377 } // namespace bin |
| 400 } // namespace dart | 378 } // namespace dart |
| OLD | NEW |