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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "bin/process.h" | 7 #include "bin/process.h" |
8 | 8 |
9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
10 #include "bin/io_buffer.h" | 10 #include "bin/io_buffer.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if (Dart_IsError(result)) { | 65 if (Dart_IsError(result)) { |
66 Dart_PropagateError(result); | 66 Dart_PropagateError(result); |
67 } | 67 } |
68 return NULL; | 68 return NULL; |
69 } | 69 } |
70 string_args[i] = const_cast<char*>(DartUtils::GetStringValue(arg)); | 70 string_args[i] = const_cast<char*>(DartUtils::GetStringValue(arg)); |
71 } | 71 } |
72 return string_args; | 72 return string_args; |
73 } | 73 } |
74 | 74 |
75 | |
76 void Process::ClearAllSignalHandlers() { | 75 void Process::ClearAllSignalHandlers() { |
77 for (intptr_t i = 1; i <= kLastSignal; i++) { | 76 for (intptr_t i = 1; i <= kLastSignal; i++) { |
78 ClearSignalHandler(i, ILLEGAL_PORT); | 77 ClearSignalHandler(i, ILLEGAL_PORT); |
79 } | 78 } |
80 } | 79 } |
81 | 80 |
82 | |
83 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { | 81 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { |
84 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 82 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
85 intptr_t process_stdin; | 83 intptr_t process_stdin; |
86 intptr_t process_stdout; | 84 intptr_t process_stdout; |
87 intptr_t process_stderr; | 85 intptr_t process_stderr; |
88 intptr_t exit_event; | 86 intptr_t exit_event; |
89 Dart_Handle result; | 87 Dart_Handle result; |
90 Dart_Handle status_handle = Dart_GetNativeArgument(args, 10); | 88 Dart_Handle status_handle = Dart_GetNativeArgument(args, 10); |
91 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); | 89 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); |
92 // The Dart code verifies that the path implements the String | 90 // The Dart code verifies that the path implements the String |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 os_error_message != NULL | 181 os_error_message != NULL |
184 ? os_error_message | 182 ? os_error_message |
185 : "Cannot get error message"); | 183 : "Cannot get error message"); |
186 if (Dart_IsError(result)) { | 184 if (Dart_IsError(result)) { |
187 Dart_PropagateError(result); | 185 Dart_PropagateError(result); |
188 } | 186 } |
189 } | 187 } |
190 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); | 188 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); |
191 } | 189 } |
192 | 190 |
193 | |
194 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { | 191 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { |
195 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 192 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
196 Socket* process_stdin = | 193 Socket* process_stdin = |
197 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); | 194 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); |
198 Socket* process_stdout = | 195 Socket* process_stdout = |
199 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); | 196 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); |
200 Socket* process_stderr = | 197 Socket* process_stderr = |
201 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); | 198 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); |
202 Socket* exit_event = | 199 Socket* exit_event = |
203 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 4)); | 200 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 4)); |
(...skipping 23 matching lines...) Expand all Loading... |
227 Dart_ListSetAt(list, 2, out); | 224 Dart_ListSetAt(list, 2, out); |
228 Dart_ListSetAt(list, 3, err); | 225 Dart_ListSetAt(list, 3, err); |
229 Dart_SetReturnValue(args, list); | 226 Dart_SetReturnValue(args, list); |
230 } else { | 227 } else { |
231 Dart_Handle error = DartUtils::NewDartOSError(); | 228 Dart_Handle error = DartUtils::NewDartOSError(); |
232 Process::Kill(pid, 9); | 229 Process::Kill(pid, 9); |
233 Dart_ThrowException(error); | 230 Dart_ThrowException(error); |
234 } | 231 } |
235 } | 232 } |
236 | 233 |
237 | |
238 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { | 234 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { |
239 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 235 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
240 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); | 236 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
241 bool success = Process::Kill(pid, signal); | 237 bool success = Process::Kill(pid, signal); |
242 Dart_SetReturnValue(args, Dart_NewBoolean(success)); | 238 Dart_SetReturnValue(args, Dart_NewBoolean(success)); |
243 } | 239 } |
244 | 240 |
245 | |
246 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { | 241 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { |
247 int64_t status = 0; | 242 int64_t status = 0; |
248 // Ignore result if passing invalid argument and just exit 0. | 243 // Ignore result if passing invalid argument and just exit 0. |
249 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 244 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
250 Process::RunExitHook(status); | 245 Process::RunExitHook(status); |
251 Dart_ExitIsolate(); | 246 Dart_ExitIsolate(); |
252 Platform::Exit(static_cast<int>(status)); | 247 Platform::Exit(static_cast<int>(status)); |
253 } | 248 } |
254 | 249 |
255 | |
256 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { | 250 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { |
257 int64_t status = 0; | 251 int64_t status = 0; |
258 // Ignore result if passing invalid argument and just set exit code to 0. | 252 // Ignore result if passing invalid argument and just set exit code to 0. |
259 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 253 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
260 Process::SetGlobalExitCode(status); | 254 Process::SetGlobalExitCode(status); |
261 } | 255 } |
262 | 256 |
263 | |
264 void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) { | 257 void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) { |
265 Dart_SetReturnValue(args, Dart_NewInteger(Process::GlobalExitCode())); | 258 Dart_SetReturnValue(args, Dart_NewInteger(Process::GlobalExitCode())); |
266 } | 259 } |
267 | 260 |
268 | |
269 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { | 261 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { |
270 ScopedBlockingCall blocker; | 262 ScopedBlockingCall blocker; |
271 int64_t milliseconds = 0; | 263 int64_t milliseconds = 0; |
272 // Ignore result if passing invalid argument and just set exit code to 0. | 264 // Ignore result if passing invalid argument and just set exit code to 0. |
273 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); | 265 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); |
274 TimerUtils::Sleep(milliseconds); | 266 TimerUtils::Sleep(milliseconds); |
275 } | 267 } |
276 | 268 |
277 | |
278 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { | 269 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { |
279 // Ignore result if passing invalid argument and just set exit code to 0. | 270 // Ignore result if passing invalid argument and just set exit code to 0. |
280 intptr_t pid = -1; | 271 intptr_t pid = -1; |
281 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 272 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
282 if (Dart_IsNull(process)) { | 273 if (Dart_IsNull(process)) { |
283 pid = Process::CurrentProcessId(); | 274 pid = Process::CurrentProcessId(); |
284 } else { | 275 } else { |
285 Process::GetProcessIdNativeField(process, &pid); | 276 Process::GetProcessIdNativeField(process, &pid); |
286 } | 277 } |
287 Dart_SetReturnValue(args, Dart_NewInteger(pid)); | 278 Dart_SetReturnValue(args, Dart_NewInteger(pid)); |
288 } | 279 } |
289 | 280 |
290 | |
291 void FUNCTION_NAME(Process_SetSignalHandler)(Dart_NativeArguments args) { | 281 void FUNCTION_NAME(Process_SetSignalHandler)(Dart_NativeArguments args) { |
292 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 282 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
293 intptr_t id = Process::SetSignalHandler(signal); | 283 intptr_t id = Process::SetSignalHandler(signal); |
294 if (id == -1) { | 284 if (id == -1) { |
295 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 285 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
296 } else { | 286 } else { |
297 Dart_SetReturnValue(args, Dart_NewInteger(id)); | 287 Dart_SetReturnValue(args, Dart_NewInteger(id)); |
298 } | 288 } |
299 } | 289 } |
300 | 290 |
301 | |
302 void FUNCTION_NAME(Process_ClearSignalHandler)(Dart_NativeArguments args) { | 291 void FUNCTION_NAME(Process_ClearSignalHandler)(Dart_NativeArguments args) { |
303 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 292 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
304 Process::ClearSignalHandler(signal, Dart_GetMainPortId()); | 293 Process::ClearSignalHandler(signal, Dart_GetMainPortId()); |
305 } | 294 } |
306 | 295 |
307 | |
308 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 296 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
309 intptr_t* pid) { | 297 intptr_t* pid) { |
310 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); | 298 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
311 } | 299 } |
312 | 300 |
313 | |
314 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 301 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
315 intptr_t pid) { | 302 intptr_t pid) { |
316 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 303 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
317 } | 304 } |
318 | 305 |
319 | |
320 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) { | 306 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) { |
321 Dart_Handle bytes = Dart_GetNativeArgument(args, 0); | 307 Dart_Handle bytes = Dart_GetNativeArgument(args, 0); |
322 intptr_t bytes_length = 0; | 308 intptr_t bytes_length = 0; |
323 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); | 309 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); |
324 if (Dart_IsError(result)) { | 310 if (Dart_IsError(result)) { |
325 Dart_PropagateError(result); | 311 Dart_PropagateError(result); |
326 } | 312 } |
327 uint8_t* buffer = Dart_ScopeAllocate(bytes_length + 1); | 313 uint8_t* buffer = Dart_ScopeAllocate(bytes_length + 1); |
328 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); | 314 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); |
329 buffer[bytes_length] = '\0'; | 315 buffer[bytes_length] = '\0'; |
330 if (Dart_IsError(result)) { | 316 if (Dart_IsError(result)) { |
331 Dart_PropagateError(result); | 317 Dart_PropagateError(result); |
332 } | 318 } |
333 intptr_t len; | 319 intptr_t len; |
334 char* str = StringUtils::ConsoleStringToUtf8(reinterpret_cast<char*>(buffer), | 320 char* str = StringUtils::ConsoleStringToUtf8(reinterpret_cast<char*>(buffer), |
335 bytes_length, &len); | 321 bytes_length, &len); |
336 if (str == NULL) { | 322 if (str == NULL) { |
337 Dart_ThrowException( | 323 Dart_ThrowException( |
338 DartUtils::NewInternalError("SystemEncodingToString failed")); | 324 DartUtils::NewInternalError("SystemEncodingToString failed")); |
339 } | 325 } |
340 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len); | 326 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len); |
341 Dart_SetReturnValue(args, result); | 327 Dart_SetReturnValue(args, result); |
342 } | 328 } |
343 | 329 |
344 | |
345 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { | 330 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { |
346 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 331 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
347 char* utf8; | 332 char* utf8; |
348 intptr_t utf8_len; | 333 intptr_t utf8_len; |
349 Dart_Handle result = | 334 Dart_Handle result = |
350 Dart_StringToUTF8(str, reinterpret_cast<uint8_t**>(&utf8), &utf8_len); | 335 Dart_StringToUTF8(str, reinterpret_cast<uint8_t**>(&utf8), &utf8_len); |
351 if (Dart_IsError(result)) { | 336 if (Dart_IsError(result)) { |
352 Dart_PropagateError(result); | 337 Dart_PropagateError(result); |
353 } | 338 } |
354 intptr_t system_len; | 339 intptr_t system_len; |
355 const char* system_string = | 340 const char* system_string = |
356 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len); | 341 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len); |
357 if (system_string == NULL) { | 342 if (system_string == NULL) { |
358 Dart_ThrowException( | 343 Dart_ThrowException( |
359 DartUtils::NewInternalError("StringToSystemEncoding failed")); | 344 DartUtils::NewInternalError("StringToSystemEncoding failed")); |
360 } | 345 } |
361 uint8_t* buffer = NULL; | 346 uint8_t* buffer = NULL; |
362 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer); | 347 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer); |
363 if (!Dart_IsError(external_array)) { | 348 if (!Dart_IsError(external_array)) { |
364 memmove(buffer, system_string, system_len); | 349 memmove(buffer, system_string, system_len); |
365 } | 350 } |
366 Dart_SetReturnValue(args, external_array); | 351 Dart_SetReturnValue(args, external_array); |
367 } | 352 } |
368 | 353 |
369 | |
370 void FUNCTION_NAME(ProcessInfo_CurrentRSS)(Dart_NativeArguments args) { | 354 void FUNCTION_NAME(ProcessInfo_CurrentRSS)(Dart_NativeArguments args) { |
371 int64_t current_rss = Process::CurrentRSS(); | 355 int64_t current_rss = Process::CurrentRSS(); |
372 if (current_rss < 0) { | 356 if (current_rss < 0) { |
373 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 357 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
374 return; | 358 return; |
375 } | 359 } |
376 Dart_SetIntegerReturnValue(args, current_rss); | 360 Dart_SetIntegerReturnValue(args, current_rss); |
377 } | 361 } |
378 | 362 |
379 | |
380 void FUNCTION_NAME(ProcessInfo_MaxRSS)(Dart_NativeArguments args) { | 363 void FUNCTION_NAME(ProcessInfo_MaxRSS)(Dart_NativeArguments args) { |
381 int64_t max_rss = Process::MaxRSS(); | 364 int64_t max_rss = Process::MaxRSS(); |
382 if (max_rss < 0) { | 365 if (max_rss < 0) { |
383 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 366 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
384 return; | 367 return; |
385 } | 368 } |
386 Dart_SetIntegerReturnValue(args, max_rss); | 369 Dart_SetIntegerReturnValue(args, max_rss); |
387 } | 370 } |
388 | 371 |
389 } // namespace bin | 372 } // namespace bin |
390 } // namespace dart | 373 } // namespace dart |
391 | 374 |
392 #endif // !defined(DART_IO_DISABLED) | 375 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |