Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: runtime/bin/process.cc

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/process.h ('k') | runtime/bin/process_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(namespc,
155 path, string_args, args_length, working_directory, string_environment, 157 path, string_args, args_length, working_directory, string_environment,
156 environment_length, static_cast<ProcessStartMode>(mode), &process_stdout, 158 environment_length, static_cast<ProcessStartMode>(mode), &process_stdout,
157 &process_stdin, &process_stderr, &pid, &exit_event, &os_error_message); 159 &process_stdin, &process_stderr, &pid, &exit_event, &os_error_message);
158 if (error_code == 0) { 160 if (error_code == 0) {
159 if (mode != kDetached) { 161 if (mode != kDetached) {
160 Socket::SetSocketIdNativeField(stdin_handle, process_stdin, 162 Socket::SetSocketIdNativeField(stdin_handle, process_stdin,
161 Socket::kFinalizerNormal); 163 Socket::kFinalizerNormal);
162 Socket::SetSocketIdNativeField(stdout_handle, process_stdout, 164 Socket::SetSocketIdNativeField(stdout_handle, process_stdout,
163 Socket::kFinalizerNormal); 165 Socket::kFinalizerNormal);
164 Socket::SetSocketIdNativeField(stderr_handle, process_stderr, 166 Socket::SetSocketIdNativeField(stderr_handle, process_stderr,
(...skipping 11 matching lines...) Expand all
176 Dart_PropagateError(result); 178 Dart_PropagateError(result);
177 } 179 }
178 result = DartUtils::SetStringField(status_handle, "_errorMessage", 180 result = DartUtils::SetStringField(status_handle, "_errorMessage",
179 os_error_message != NULL 181 os_error_message != NULL
180 ? os_error_message 182 ? os_error_message
181 : "Cannot get error message"); 183 : "Cannot get error message");
182 if (Dart_IsError(result)) { 184 if (Dart_IsError(result)) {
183 Dart_PropagateError(result); 185 Dart_PropagateError(result);
184 } 186 }
185 } 187 }
186 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); 188 Dart_SetBooleanReturnValue(args, error_code == 0);
187 } 189 }
188 190
189 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { 191 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) {
190 Dart_Handle process = Dart_GetNativeArgument(args, 0); 192 Dart_Handle process = Dart_GetNativeArgument(args, 0);
191 Socket* process_stdin = 193 Socket* process_stdin =
192 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); 194 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1));
193 Socket* process_stdout = 195 Socket* process_stdout =
194 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); 196 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2));
195 Socket* process_stderr = 197 Socket* process_stderr =
196 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); 198 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3));
(...skipping 29 matching lines...) Expand all
226 Dart_Handle error = DartUtils::NewDartOSError(); 228 Dart_Handle error = DartUtils::NewDartOSError();
227 Process::Kill(pid, 9); 229 Process::Kill(pid, 9);
228 Dart_ThrowException(error); 230 Dart_ThrowException(error);
229 } 231 }
230 } 232 }
231 233
232 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { 234 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) {
233 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); 235 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0));
234 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); 236 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
235 bool success = Process::Kill(pid, signal); 237 bool success = Process::Kill(pid, signal);
236 Dart_SetReturnValue(args, Dart_NewBoolean(success)); 238 Dart_SetBooleanReturnValue(args, success);
237 } 239 }
238 240
239 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { 241 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) {
240 int64_t status = 0; 242 int64_t status = 0;
241 // Ignore result if passing invalid argument and just exit 0. 243 // Ignore result if passing invalid argument and just exit 0.
242 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 244 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
243 Process::RunExitHook(status); 245 Process::RunExitHook(status);
244 Dart_ExitIsolate(); 246 Dart_ExitIsolate();
245 Platform::Exit(static_cast<int>(status)); 247 Platform::Exit(static_cast<int>(status));
246 } 248 }
247 249
248 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { 250 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) {
249 int64_t status = 0; 251 int64_t status = 0;
250 // 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.
251 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 253 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
252 Process::SetGlobalExitCode(status); 254 Process::SetGlobalExitCode(status);
253 } 255 }
254 256
255 void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) { 257 void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) {
256 Dart_SetReturnValue(args, Dart_NewInteger(Process::GlobalExitCode())); 258 Dart_SetIntegerReturnValue(args, Process::GlobalExitCode());
257 } 259 }
258 260
259 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { 261 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) {
260 ScopedBlockingCall blocker; 262 ScopedBlockingCall blocker;
261 int64_t milliseconds = 0; 263 int64_t milliseconds = 0;
262 // 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.
263 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); 265 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds);
264 TimerUtils::Sleep(milliseconds); 266 TimerUtils::Sleep(milliseconds);
265 } 267 }
266 268
267 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { 269 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) {
268 // 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.
269 intptr_t pid = -1; 271 intptr_t pid = -1;
270 Dart_Handle process = Dart_GetNativeArgument(args, 0); 272 Dart_Handle process = Dart_GetNativeArgument(args, 0);
271 if (Dart_IsNull(process)) { 273 if (Dart_IsNull(process)) {
272 pid = Process::CurrentProcessId(); 274 pid = Process::CurrentProcessId();
273 } else { 275 } else {
274 Process::GetProcessIdNativeField(process, &pid); 276 Process::GetProcessIdNativeField(process, &pid);
275 } 277 }
276 Dart_SetReturnValue(args, Dart_NewInteger(pid)); 278 Dart_SetIntegerReturnValue(args, pid);
277 } 279 }
278 280
279 void FUNCTION_NAME(Process_SetSignalHandler)(Dart_NativeArguments args) { 281 void FUNCTION_NAME(Process_SetSignalHandler)(Dart_NativeArguments args) {
280 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); 282 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0));
281 intptr_t id = Process::SetSignalHandler(signal); 283 intptr_t id = Process::SetSignalHandler(signal);
282 if (id == -1) { 284 if (id == -1) {
283 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 285 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
284 } else { 286 } else {
285 Dart_SetReturnValue(args, Dart_NewInteger(id)); 287 Dart_SetIntegerReturnValue(args, id);
286 } 288 }
287 } 289 }
288 290
289 void FUNCTION_NAME(Process_ClearSignalHandler)(Dart_NativeArguments args) { 291 void FUNCTION_NAME(Process_ClearSignalHandler)(Dart_NativeArguments args) {
290 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); 292 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0));
291 Process::ClearSignalHandler(signal, Dart_GetMainPortId()); 293 Process::ClearSignalHandler(signal, Dart_GetMainPortId());
292 } 294 }
293 295
294 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, 296 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process,
295 intptr_t* pid) { 297 intptr_t* pid) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 371
370 void Process::GetRSSInformation(int64_t* max_rss, int64_t* current_rss) { 372 void Process::GetRSSInformation(int64_t* max_rss, int64_t* current_rss) {
371 ASSERT(max_rss != NULL); 373 ASSERT(max_rss != NULL);
372 ASSERT(current_rss != NULL); 374 ASSERT(current_rss != NULL);
373 *max_rss = Process::MaxRSS(); 375 *max_rss = Process::MaxRSS();
374 *current_rss = Process::CurrentRSS(); 376 *current_rss = Process::CurrentRSS();
375 } 377 }
376 378
377 } // namespace bin 379 } // namespace bin
378 } // namespace dart 380 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/process.h ('k') | runtime/bin/process_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698