| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/io_buffer.h" | 6 #include "bin/io_buffer.h" |
| 7 #include "bin/process.h" | 7 #include "bin/process.h" |
| 8 #include "bin/socket.h" | 8 #include "bin/socket.h" |
| 9 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| 11 | 11 |
| 12 | 12 |
| 13 static const int kProcessIdNativeField = 0; | 13 static const int kProcessIdNativeField = 0; |
| 14 | 14 |
| 15 int Process::global_exit_code_ = 0; |
| 16 dart::Mutex Process::global_exit_code_mutex_; |
| 15 | 17 |
| 16 // Extract an array of C strings from a list of Dart strings. | 18 // Extract an array of C strings from a list of Dart strings. |
| 17 static char** ExtractCStringList(Dart_Handle strings, | 19 static char** ExtractCStringList(Dart_Handle strings, |
| 18 Dart_Handle status_handle, | 20 Dart_Handle status_handle, |
| 19 const char* error_msg, | 21 const char* error_msg, |
| 20 intptr_t* length) { | 22 intptr_t* length) { |
| 21 static const intptr_t kMaxArgumentListLength = 1024 * 1024; | 23 static const intptr_t kMaxArgumentListLength = 1024 * 1024; |
| 22 ASSERT(Dart_IsList(strings)); | 24 ASSERT(Dart_IsList(strings)); |
| 23 intptr_t len = 0; | 25 intptr_t len = 0; |
| 24 Dart_Handle result = Dart_ListLength(strings, &len); | 26 Dart_Handle result = Dart_ListLength(strings, &len); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 Dart_Handle process = Dart_GetNativeArgument(args, 1); | 163 Dart_Handle process = Dart_GetNativeArgument(args, 1); |
| 162 intptr_t pid = -1; | 164 intptr_t pid = -1; |
| 163 Process::GetProcessIdNativeField(process, &pid); | 165 Process::GetProcessIdNativeField(process, &pid); |
| 164 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 166 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 165 bool success = Process::Kill(pid, signal); | 167 bool success = Process::Kill(pid, signal); |
| 166 Dart_SetReturnValue(args, Dart_NewBoolean(success)); | 168 Dart_SetReturnValue(args, Dart_NewBoolean(success)); |
| 167 Dart_ExitScope(); | 169 Dart_ExitScope(); |
| 168 } | 170 } |
| 169 | 171 |
| 170 | 172 |
| 173 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { |
| 174 Dart_EnterScope(); |
| 175 int64_t status = 0; |
| 176 // Ignore result if passing invalid argument and just exit 0. |
| 177 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
| 178 Dart_ExitScope(); |
| 179 exit(static_cast<int>(status)); |
| 180 } |
| 181 |
| 182 |
| 183 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { |
| 184 Dart_EnterScope(); |
| 185 int64_t status = 0; |
| 186 // Ignore result if passing invalid argument and just set exit code to 0. |
| 187 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
| 188 Process::SetGlobalExitCode(status); |
| 189 Dart_ExitScope(); |
| 190 } |
| 191 |
| 192 |
| 171 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 193 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
| 172 intptr_t* pid) { | 194 intptr_t* pid) { |
| 173 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); | 195 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 174 } | 196 } |
| 175 | 197 |
| 176 | 198 |
| 177 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 199 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
| 178 intptr_t pid) { | 200 intptr_t pid) { |
| 179 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 201 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 180 } | 202 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 207 const char* utf8 = DartUtils::GetStringValue(str); | 229 const char* utf8 = DartUtils::GetStringValue(str); |
| 208 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); | 230 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); |
| 209 int external_length = strlen(system_string); | 231 int external_length = strlen(system_string); |
| 210 uint8_t* buffer = NULL; | 232 uint8_t* buffer = NULL; |
| 211 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | 233 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); |
| 212 memmove(buffer, system_string, external_length); | 234 memmove(buffer, system_string, external_length); |
| 213 if (utf8 != system_string) free(const_cast<char*>(system_string)); | 235 if (utf8 != system_string) free(const_cast<char*>(system_string)); |
| 214 Dart_SetReturnValue(args, external_array); | 236 Dart_SetReturnValue(args, external_array); |
| 215 Dart_ExitScope(); | 237 Dart_ExitScope(); |
| 216 } | 238 } |
| OLD | NEW |