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

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

Issue 11312242: Revised CL for customisable logging (replacing printfs). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 <process.h> 5 #include <process.h>
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/process.h" 8 #include "bin/process.h"
9 #include "bin/eventhandler.h" 9 #include "bin/eventhandler.h"
10 #include "bin/log.h"
10 #include "bin/thread.h" 11 #include "bin/thread.h"
11 #include "bin/utils.h" 12 #include "bin/utils.h"
12 #include "platform/globals.h" 13 #include "platform/globals.h"
13 14
14 static const int kReadHandle = 0; 15 static const int kReadHandle = 0;
15 static const int kWriteHandle = 1; 16 static const int kWriteHandle = 1;
16 17
17 18
18 // ProcessInfo is used to map a process id to the process handle, 19 // ProcessInfo is used to map a process id to the process handle,
19 // wait handle for registered exit code event and the pipe used to 20 // wait handle for registered exit code event and the pipe used to
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 CreateNamedPipe(pipe_name, 215 CreateNamedPipe(pipe_name,
215 PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, 216 PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
216 PIPE_TYPE_BYTE | PIPE_WAIT, 217 PIPE_TYPE_BYTE | PIPE_WAIT,
217 1, // Number of pipes 218 1, // Number of pipes
218 1024, // Out buffer size 219 1024, // Out buffer size
219 1024, // In buffer size 220 1024, // In buffer size
220 0, // Timeout in ms 221 0, // Timeout in ms
221 NULL); 222 NULL);
222 223
223 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) { 224 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) {
224 fprintf(stderr, "CreateNamedPipe failed %d\n", GetLastError()); 225 Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError());
225 return false; 226 return false;
226 } 227 }
227 228
228 handles[kReadHandle] = 229 handles[kReadHandle] =
229 CreateFile(pipe_name, 230 CreateFile(pipe_name,
230 GENERIC_READ, 231 GENERIC_READ,
231 0, 232 0,
232 &inherit_handle, 233 &inherit_handle,
233 OPEN_EXISTING, 234 OPEN_EXISTING,
234 FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED, 235 FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
235 NULL); 236 NULL);
236 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) { 237 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) {
237 fprintf(stderr, "CreateFile failed %d\n", GetLastError()); 238 Log::PrintErr("CreateFile failed %d\n", GetLastError());
238 return false; 239 return false;
239 } 240 }
240 } else { 241 } else {
241 ASSERT(type == kInheritWrite || type == kInheritNone); 242 ASSERT(type == kInheritWrite || type == kInheritNone);
242 handles[kReadHandle] = 243 handles[kReadHandle] =
243 CreateNamedPipe(pipe_name, 244 CreateNamedPipe(pipe_name,
244 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, 245 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
245 PIPE_TYPE_BYTE | PIPE_WAIT, 246 PIPE_TYPE_BYTE | PIPE_WAIT,
246 1, // Number of pipes 247 1, // Number of pipes
247 1024, // Out buffer size 248 1024, // Out buffer size
248 1024, // In buffer size 249 1024, // In buffer size
249 0, // Timeout in ms 250 0, // Timeout in ms
250 NULL); 251 NULL);
251 252
252 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) { 253 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) {
253 fprintf(stderr, "CreateNamedPipe failed %d\n", GetLastError()); 254 Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError());
254 return false; 255 return false;
255 } 256 }
256 257
257 handles[kWriteHandle] = 258 handles[kWriteHandle] =
258 CreateFile(pipe_name, 259 CreateFile(pipe_name,
259 GENERIC_WRITE, 260 GENERIC_WRITE,
260 0, 261 0,
261 (type == kInheritWrite) ? &inherit_handle : NULL, 262 (type == kInheritWrite) ? &inherit_handle : NULL,
262 OPEN_EXISTING, 263 OPEN_EXISTING,
263 FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED, 264 FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
264 NULL); 265 NULL);
265 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) { 266 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) {
266 fprintf(stderr, "CreateFile failed %d\n", GetLastError()); 267 Log::PrintErr("CreateFile failed %d\n", GetLastError());
267 return false; 268 return false;
268 } 269 }
269 } 270 }
270 return true; 271 return true;
271 } 272 }
272 273
273 274
274 static void CloseProcessPipe(HANDLE handles[2]) { 275 static void CloseProcessPipe(HANDLE handles[2]) {
275 for (int i = kReadHandle; i < kWriteHandle; i++) { 276 for (int i = kReadHandle; i < kWriteHandle; i++) {
276 if (handles[i] != INVALID_HANDLE_VALUE) { 277 if (handles[i] != INVALID_HANDLE_VALUE) {
277 if (!CloseHandle(handles[i])) { 278 if (!CloseHandle(handles[i])) {
278 fprintf(stderr, "CloseHandle failed %d\n", GetLastError()); 279 Log::PrintErr("CloseHandle failed %d\n", GetLastError());
279 } 280 }
280 handles[i] = INVALID_HANDLE_VALUE; 281 handles[i] = INVALID_HANDLE_VALUE;
281 } 282 }
282 } 283 }
283 } 284 }
284 285
285 286
286 static void CloseProcessPipes(HANDLE handles1[2], 287 static void CloseProcessPipes(HANDLE handles1[2],
287 HANDLE handles2[2], 288 HANDLE handles2[2],
288 HANDLE handles3[2], 289 HANDLE handles3[2],
(...skipping 10 matching lines...) Expand all
299 DWORD message_size = 300 DWORD message_size =
300 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 301 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
301 NULL, 302 NULL,
302 error_code, 303 error_code,
303 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 304 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
304 os_error_message, 305 os_error_message,
305 os_error_message_len, 306 os_error_message_len,
306 NULL); 307 NULL);
307 if (message_size == 0) { 308 if (message_size == 0) {
308 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { 309 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
309 fprintf(stderr, "FormatMessage failed %d\n", GetLastError()); 310 Log::PrintErr("FormatMessage failed %d\n", GetLastError());
310 } 311 }
311 snprintf(os_error_message, os_error_message_len, "OS Error %d", error_code); 312 snprintf(os_error_message, os_error_message_len, "OS Error %d", error_code);
312 } 313 }
313 os_error_message[os_error_message_len - 1] = '\0'; 314 os_error_message[os_error_message_len - 1] = '\0';
314 return error_code; 315 return error_code;
315 } 316 }
316 317
317 318
318 int Process::Start(const char* path, 319 int Process::Start(const char* path,
319 char* arguments[], 320 char* arguments[],
(...skipping 11 matching lines...) Expand all
331 HANDLE stdin_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 332 HANDLE stdin_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
332 HANDLE stdout_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 333 HANDLE stdout_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
333 HANDLE stderr_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 334 HANDLE stderr_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
334 HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 335 HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
335 336
336 // Generate unique pipe names for the four named pipes needed. 337 // Generate unique pipe names for the four named pipes needed.
337 char pipe_names[4][80]; 338 char pipe_names[4][80];
338 UUID uuid; 339 UUID uuid;
339 RPC_STATUS status = UuidCreateSequential(&uuid); 340 RPC_STATUS status = UuidCreateSequential(&uuid);
340 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { 341 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
341 fprintf(stderr, "UuidCreateSequential failed %d\n", status); 342 Log::PrintErr("UuidCreateSequential failed %d\n", status);
342 SetOsErrorMessage(os_error_message, os_error_message_len); 343 SetOsErrorMessage(os_error_message, os_error_message_len);
343 return status; 344 return status;
344 } 345 }
345 RPC_CSTR uuid_string; 346 RPC_CSTR uuid_string;
346 status = UuidToString(&uuid, &uuid_string); 347 status = UuidToString(&uuid, &uuid_string);
347 if (status != RPC_S_OK) { 348 if (status != RPC_S_OK) {
348 fprintf(stderr, "UuidToString failed %d\n", status); 349 Log::PrintErr("UuidToString failed %d\n", status);
349 SetOsErrorMessage(os_error_message, os_error_message_len); 350 SetOsErrorMessage(os_error_message, os_error_message_len);
350 return status; 351 return status;
351 } 352 }
352 for (int i = 0; i < 4; i++) { 353 for (int i = 0; i < 4; i++) {
353 static const char* prefix = "\\\\.\\Pipe\\dart"; 354 static const char* prefix = "\\\\.\\Pipe\\dart";
354 snprintf(pipe_names[i], 355 snprintf(pipe_names[i],
355 sizeof(pipe_names[i]), 356 sizeof(pipe_names[i]),
356 "%s_%s_%d", prefix, uuid_string, i + 1); 357 "%s_%s_%d", prefix, uuid_string, i + 1);
357 } 358 }
358 status = RpcStringFree(&uuid_string); 359 status = RpcStringFree(&uuid_string);
359 if (status != RPC_S_OK) { 360 if (status != RPC_S_OK) {
360 fprintf(stderr, "RpcStringFree failed %d\n", status); 361 Log::PrintErr("RpcStringFree failed %d\n", status);
361 SetOsErrorMessage(os_error_message, os_error_message_len); 362 SetOsErrorMessage(os_error_message, os_error_message_len);
362 return status; 363 return status;
363 } 364 }
364 365
365 if (!CreateProcessPipe(stdin_handles, pipe_names[0], kInheritRead)) { 366 if (!CreateProcessPipe(stdin_handles, pipe_names[0], kInheritRead)) {
366 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); 367 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
367 CloseProcessPipes( 368 CloseProcessPipes(
368 stdin_handles, stdout_handles, stderr_handles, exit_handles); 369 stdin_handles, stdout_handles, stderr_handles, exit_handles);
369 return error_code; 370 return error_code;
370 } 371 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 544
544 545
545 void Process::TerminateExitCodeHandler() { 546 void Process::TerminateExitCodeHandler() {
546 // Nothing needs to be done on Windows. 547 // Nothing needs to be done on Windows.
547 } 548 }
548 549
549 550
550 intptr_t Process::CurrentProcessId() { 551 intptr_t Process::CurrentProcessId() {
551 return static_cast<intptr_t>(GetCurrentProcessId()); 552 return static_cast<intptr_t>(GetCurrentProcessId());
552 } 553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698