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/process.h" | 5 #include "bin/process.h" |
6 | 6 |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.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/namespace.h" |
10 #include "bin/platform.h" | 11 #include "bin/platform.h" |
11 #include "bin/socket.h" | 12 #include "bin/socket.h" |
12 #include "bin/utils.h" | 13 #include "bin/utils.h" |
13 | 14 |
14 #include "include/dart_api.h" | 15 #include "include/dart_api.h" |
15 | 16 |
16 namespace dart { | 17 namespace dart { |
17 namespace bin { | 18 namespace bin { |
18 | 19 |
19 static const int kProcessIdNativeField = 0; | 20 static const int kProcessIdNativeField = 0; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 ClearSignalHandler(i, ILLEGAL_PORT); | 76 ClearSignalHandler(i, ILLEGAL_PORT); |
76 } | 77 } |
77 } | 78 } |
78 | 79 |
79 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { | 80 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { |
80 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 81 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
81 intptr_t process_stdin; | 82 intptr_t process_stdin; |
82 intptr_t process_stdout; | 83 intptr_t process_stdout; |
83 intptr_t process_stderr; | 84 intptr_t process_stderr; |
84 intptr_t exit_event; | 85 intptr_t exit_event; |
85 Dart_Handle result; | 86 Namespace* namespc = Namespace::GetNamespace(args, 1); |
86 Dart_Handle status_handle = Dart_GetNativeArgument(args, 10); | 87 Dart_Handle status_handle = Dart_GetNativeArgument(args, 11); |
87 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); | 88 Dart_Handle path_handle = Dart_GetNativeArgument(args, 2); |
88 // The Dart code verifies that the path implements the String | 89 // The Dart code verifies that the path implements the String |
89 // interface. However, only builtin Strings are handled by | 90 // interface. However, only builtin Strings are handled by |
90 // GetStringValue. | 91 // GetStringValue. |
| 92 Dart_Handle result; |
91 if (!Dart_IsString(path_handle)) { | 93 if (!Dart_IsString(path_handle)) { |
92 result = DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | 94 result = DartUtils::SetIntegerField(status_handle, "_errorCode", 0); |
93 if (Dart_IsError(result)) { | 95 if (Dart_IsError(result)) { |
94 Dart_PropagateError(result); | 96 Dart_PropagateError(result); |
95 } | 97 } |
96 result = DartUtils::SetStringField(status_handle, "_errorMessage", | 98 result = DartUtils::SetStringField(status_handle, "_errorMessage", |
97 "Path must be a builtin string"); | 99 "Path must be a builtin string"); |
98 if (Dart_IsError(result)) { | 100 if (Dart_IsError(result)) { |
99 Dart_PropagateError(result); | 101 Dart_PropagateError(result); |
100 } | 102 } |
101 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 103 Dart_SetBooleanReturnValue(args, false); |
102 return; | 104 return; |
103 } | 105 } |
104 const char* path = DartUtils::GetStringValue(path_handle); | 106 const char* path = DartUtils::GetStringValue(path_handle); |
105 Dart_Handle arguments = Dart_GetNativeArgument(args, 2); | 107 Dart_Handle arguments = Dart_GetNativeArgument(args, 3); |
106 intptr_t args_length = 0; | 108 intptr_t args_length = 0; |
107 char** string_args = | 109 char** string_args = |
108 ExtractCStringList(arguments, status_handle, | 110 ExtractCStringList(arguments, status_handle, |
109 "Arguments must be builtin strings", &args_length); | 111 "Arguments must be builtin strings", &args_length); |
110 if (string_args == NULL) { | 112 if (string_args == NULL) { |
111 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 113 Dart_SetBooleanReturnValue(args, false); |
112 return; | 114 return; |
113 } | 115 } |
114 Dart_Handle working_directory_handle = Dart_GetNativeArgument(args, 3); | 116 Dart_Handle working_directory_handle = Dart_GetNativeArgument(args, 4); |
115 // Defaults to the current working directoy. | 117 // Defaults to the current working directoy. |
116 const char* working_directory = NULL; | 118 const char* working_directory = NULL; |
117 if (Dart_IsString(working_directory_handle)) { | 119 if (Dart_IsString(working_directory_handle)) { |
118 working_directory = DartUtils::GetStringValue(working_directory_handle); | 120 working_directory = DartUtils::GetStringValue(working_directory_handle); |
119 } else if (!Dart_IsNull(working_directory_handle)) { | 121 } else if (!Dart_IsNull(working_directory_handle)) { |
120 result = DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | 122 result = DartUtils::SetIntegerField(status_handle, "_errorCode", 0); |
121 if (Dart_IsError(result)) { | 123 if (Dart_IsError(result)) { |
122 Dart_PropagateError(result); | 124 Dart_PropagateError(result); |
123 } | 125 } |
124 result = | 126 result = |
125 DartUtils::SetStringField(status_handle, "_errorMessage", | 127 DartUtils::SetStringField(status_handle, "_errorMessage", |
126 "WorkingDirectory must be a builtin string"); | 128 "WorkingDirectory must be a builtin string"); |
127 if (Dart_IsError(result)) { | 129 if (Dart_IsError(result)) { |
128 Dart_PropagateError(result); | 130 Dart_PropagateError(result); |
129 } | 131 } |
130 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 132 Dart_SetBooleanReturnValue(args, false); |
131 return; | 133 return; |
132 } | 134 } |
133 Dart_Handle environment = Dart_GetNativeArgument(args, 4); | 135 Dart_Handle environment = Dart_GetNativeArgument(args, 5); |
134 intptr_t environment_length = 0; | 136 intptr_t environment_length = 0; |
135 char** string_environment = NULL; | 137 char** string_environment = NULL; |
136 if (!Dart_IsNull(environment)) { | 138 if (!Dart_IsNull(environment)) { |
137 string_environment = ExtractCStringList( | 139 string_environment = ExtractCStringList( |
138 environment, status_handle, | 140 environment, status_handle, |
139 "Environment values must be builtin strings", &environment_length); | 141 "Environment values must be builtin strings", &environment_length); |
140 if (string_environment == NULL) { | 142 if (string_environment == NULL) { |
141 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 143 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
142 return; | 144 return; |
143 } | 145 } |
144 } | 146 } |
145 int64_t mode = | 147 int64_t mode = |
146 DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 5), 0, 2); | 148 DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 6), 0, 2); |
147 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 6); | 149 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 7); |
148 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 7); | 150 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 8); |
149 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 8); | 151 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 9); |
150 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 9); | 152 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 10); |
151 intptr_t pid = -1; | 153 intptr_t pid = -1; |
152 char* os_error_message = NULL; // Scope allocated by Process::Start. | 154 char* os_error_message = NULL; // Scope allocated by Process::Start. |
153 | 155 |
154 int error_code = Process::Start( | 156 int error_code = Process::Start( |
155 path, string_args, args_length, working_directory, string_environment, | 157 namespc, path, string_args, args_length, working_directory, |
156 environment_length, static_cast<ProcessStartMode>(mode), &process_stdout, | 158 string_environment, environment_length, |
157 &process_stdin, &process_stderr, &pid, &exit_event, &os_error_message); | 159 static_cast<ProcessStartMode>(mode), &process_stdout, &process_stdin, |
| 160 &process_stderr, &pid, &exit_event, &os_error_message); |
158 if (error_code == 0) { | 161 if (error_code == 0) { |
159 if (mode != kDetached) { | 162 if (mode != kDetached) { |
160 Socket::SetSocketIdNativeField(stdin_handle, process_stdin, | 163 Socket::SetSocketIdNativeField(stdin_handle, process_stdin, |
161 Socket::kFinalizerNormal); | 164 Socket::kFinalizerNormal); |
162 Socket::SetSocketIdNativeField(stdout_handle, process_stdout, | 165 Socket::SetSocketIdNativeField(stdout_handle, process_stdout, |
163 Socket::kFinalizerNormal); | 166 Socket::kFinalizerNormal); |
164 Socket::SetSocketIdNativeField(stderr_handle, process_stderr, | 167 Socket::SetSocketIdNativeField(stderr_handle, process_stderr, |
165 Socket::kFinalizerNormal); | 168 Socket::kFinalizerNormal); |
166 } | 169 } |
167 if (mode == kNormal) { | 170 if (mode == kNormal) { |
168 Socket::SetSocketIdNativeField(exit_handle, exit_event, | 171 Socket::SetSocketIdNativeField(exit_handle, exit_event, |
169 Socket::kFinalizerNormal); | 172 Socket::kFinalizerNormal); |
170 } | 173 } |
171 Process::SetProcessIdNativeField(process, pid); | 174 Process::SetProcessIdNativeField(process, pid); |
172 } else { | 175 } else { |
173 result = | 176 result = |
174 DartUtils::SetIntegerField(status_handle, "_errorCode", error_code); | 177 DartUtils::SetIntegerField(status_handle, "_errorCode", error_code); |
175 if (Dart_IsError(result)) { | 178 if (Dart_IsError(result)) { |
176 Dart_PropagateError(result); | 179 Dart_PropagateError(result); |
177 } | 180 } |
178 result = DartUtils::SetStringField(status_handle, "_errorMessage", | 181 result = DartUtils::SetStringField(status_handle, "_errorMessage", |
179 os_error_message != NULL | 182 os_error_message != NULL |
180 ? os_error_message | 183 ? os_error_message |
181 : "Cannot get error message"); | 184 : "Cannot get error message"); |
182 if (Dart_IsError(result)) { | 185 if (Dart_IsError(result)) { |
183 Dart_PropagateError(result); | 186 Dart_PropagateError(result); |
184 } | 187 } |
185 } | 188 } |
186 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); | 189 Dart_SetBooleanReturnValue(args, error_code == 0); |
187 } | 190 } |
188 | 191 |
189 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { | 192 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { |
190 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 193 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
191 Socket* process_stdin = | 194 Socket* process_stdin = |
192 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); | 195 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); |
193 Socket* process_stdout = | 196 Socket* process_stdout = |
194 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); | 197 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); |
195 Socket* process_stderr = | 198 Socket* process_stderr = |
196 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); | 199 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); |
(...skipping 29 matching lines...) Expand all Loading... |
226 Dart_Handle error = DartUtils::NewDartOSError(); | 229 Dart_Handle error = DartUtils::NewDartOSError(); |
227 Process::Kill(pid, 9); | 230 Process::Kill(pid, 9); |
228 Dart_ThrowException(error); | 231 Dart_ThrowException(error); |
229 } | 232 } |
230 } | 233 } |
231 | 234 |
232 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { | 235 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { |
233 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 236 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
234 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); | 237 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
235 bool success = Process::Kill(pid, signal); | 238 bool success = Process::Kill(pid, signal); |
236 Dart_SetReturnValue(args, Dart_NewBoolean(success)); | 239 Dart_SetBooleanReturnValue(args, success); |
237 } | 240 } |
238 | 241 |
239 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { | 242 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { |
240 int64_t status = 0; | 243 int64_t status = 0; |
241 // Ignore result if passing invalid argument and just exit 0. | 244 // Ignore result if passing invalid argument and just exit 0. |
242 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 245 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
243 Process::RunExitHook(status); | 246 Process::RunExitHook(status); |
244 Dart_ExitIsolate(); | 247 Dart_ExitIsolate(); |
245 Platform::Exit(static_cast<int>(status)); | 248 Platform::Exit(static_cast<int>(status)); |
246 } | 249 } |
247 | 250 |
248 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { | 251 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { |
249 int64_t status = 0; | 252 int64_t status = 0; |
250 // Ignore result if passing invalid argument and just set exit code to 0. | 253 // Ignore result if passing invalid argument and just set exit code to 0. |
251 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 254 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
252 Process::SetGlobalExitCode(status); | 255 Process::SetGlobalExitCode(status); |
253 } | 256 } |
254 | 257 |
255 void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) { | 258 void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) { |
256 Dart_SetReturnValue(args, Dart_NewInteger(Process::GlobalExitCode())); | 259 Dart_SetIntegerReturnValue(args, Process::GlobalExitCode()); |
257 } | 260 } |
258 | 261 |
259 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { | 262 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { |
260 ScopedBlockingCall blocker; | 263 ScopedBlockingCall blocker; |
261 int64_t milliseconds = 0; | 264 int64_t milliseconds = 0; |
262 // Ignore result if passing invalid argument and just set exit code to 0. | 265 // Ignore result if passing invalid argument and just set exit code to 0. |
263 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); | 266 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); |
264 TimerUtils::Sleep(milliseconds); | 267 TimerUtils::Sleep(milliseconds); |
265 } | 268 } |
266 | 269 |
267 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { | 270 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { |
268 // Ignore result if passing invalid argument and just set exit code to 0. | 271 // Ignore result if passing invalid argument and just set exit code to 0. |
269 intptr_t pid = -1; | 272 intptr_t pid = -1; |
270 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 273 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
271 if (Dart_IsNull(process)) { | 274 if (Dart_IsNull(process)) { |
272 pid = Process::CurrentProcessId(); | 275 pid = Process::CurrentProcessId(); |
273 } else { | 276 } else { |
274 Process::GetProcessIdNativeField(process, &pid); | 277 Process::GetProcessIdNativeField(process, &pid); |
275 } | 278 } |
276 Dart_SetReturnValue(args, Dart_NewInteger(pid)); | 279 Dart_SetIntegerReturnValue(args, pid); |
277 } | 280 } |
278 | 281 |
279 void FUNCTION_NAME(Process_SetSignalHandler)(Dart_NativeArguments args) { | 282 void FUNCTION_NAME(Process_SetSignalHandler)(Dart_NativeArguments args) { |
280 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 283 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
281 intptr_t id = Process::SetSignalHandler(signal); | 284 intptr_t id = Process::SetSignalHandler(signal); |
282 if (id == -1) { | 285 if (id == -1) { |
283 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 286 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
284 } else { | 287 } else { |
285 Dart_SetReturnValue(args, Dart_NewInteger(id)); | 288 Dart_SetIntegerReturnValue(args, id); |
286 } | 289 } |
287 } | 290 } |
288 | 291 |
289 void FUNCTION_NAME(Process_ClearSignalHandler)(Dart_NativeArguments args) { | 292 void FUNCTION_NAME(Process_ClearSignalHandler)(Dart_NativeArguments args) { |
290 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 293 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
291 Process::ClearSignalHandler(signal, Dart_GetMainPortId()); | 294 Process::ClearSignalHandler(signal, Dart_GetMainPortId()); |
292 } | 295 } |
293 | 296 |
294 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 297 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
295 intptr_t* pid) { | 298 intptr_t* pid) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 372 |
370 void Process::GetRSSInformation(int64_t* max_rss, int64_t* current_rss) { | 373 void Process::GetRSSInformation(int64_t* max_rss, int64_t* current_rss) { |
371 ASSERT(max_rss != NULL); | 374 ASSERT(max_rss != NULL); |
372 ASSERT(current_rss != NULL); | 375 ASSERT(current_rss != NULL); |
373 *max_rss = Process::MaxRSS(); | 376 *max_rss = Process::MaxRSS(); |
374 *current_rss = Process::CurrentRSS(); | 377 *current_rss = Process::CurrentRSS(); |
375 } | 378 } |
376 | 379 |
377 } // namespace bin | 380 } // namespace bin |
378 } // namespace dart | 381 } // namespace dart |
OLD | NEW |