1 /* |
1 /* |
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
5248 // Run the specified command in a separate process. Return its exit value, |
5248 // Run the specified command in a separate process. Return its exit value, |
5249 // or -1 on failure (e.g. can't create a new process). |
5249 // or -1 on failure (e.g. can't create a new process). |
5250 int os::fork_and_exec(char* cmd) { |
5250 int os::fork_and_exec(char* cmd) { |
5251 STARTUPINFO si; |
5251 STARTUPINFO si; |
5252 PROCESS_INFORMATION pi; |
5252 PROCESS_INFORMATION pi; |
5253 |
5253 DWORD exit_code; |
|
5254 |
|
5255 char * cmd_string; |
|
5256 char * cmd_prefix = "cmd /C "; |
|
5257 size_t len = strlen(cmd) + strlen(cmd_prefix) + 1; |
|
5258 cmd_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtInternal); |
|
5259 if (cmd_string == NULL) { |
|
5260 return -1; |
|
5261 } |
|
5262 cmd_string[0] = '\0'; |
|
5263 strcat(cmd_string, cmd_prefix); |
|
5264 strcat(cmd_string, cmd); |
|
5265 |
|
5266 // now replace all '\n' with '&' |
|
5267 char * substring = cmd_string; |
|
5268 while ((substring = strchr(substring, '\n')) != NULL) { |
|
5269 substring[0] = '&'; |
|
5270 substring++; |
|
5271 } |
5254 memset(&si, 0, sizeof(si)); |
5272 memset(&si, 0, sizeof(si)); |
5255 si.cb = sizeof(si); |
5273 si.cb = sizeof(si); |
5256 memset(&pi, 0, sizeof(pi)); |
5274 memset(&pi, 0, sizeof(pi)); |
5257 BOOL rslt = CreateProcess(NULL, // executable name - use command line |
5275 BOOL rslt = CreateProcess(NULL, // executable name - use command line |
5258 cmd, // command line |
5276 cmd_string, // command line |
5259 NULL, // process security attribute |
5277 NULL, // process security attribute |
5260 NULL, // thread security attribute |
5278 NULL, // thread security attribute |
5261 TRUE, // inherits system handles |
5279 TRUE, // inherits system handles |
5262 0, // no creation flags |
5280 0, // no creation flags |
5263 NULL, // use parent's environment block |
5281 NULL, // use parent's environment block |
5267 |
5285 |
5268 if (rslt) { |
5286 if (rslt) { |
5269 // Wait until child process exits. |
5287 // Wait until child process exits. |
5270 WaitForSingleObject(pi.hProcess, INFINITE); |
5288 WaitForSingleObject(pi.hProcess, INFINITE); |
5271 |
5289 |
5272 DWORD exit_code; |
|
5273 GetExitCodeProcess(pi.hProcess, &exit_code); |
5290 GetExitCodeProcess(pi.hProcess, &exit_code); |
5274 |
5291 |
5275 // Close process and thread handles. |
5292 // Close process and thread handles. |
5276 CloseHandle(pi.hProcess); |
5293 CloseHandle(pi.hProcess); |
5277 CloseHandle(pi.hThread); |
5294 CloseHandle(pi.hThread); |
5278 |
|
5279 return (int)exit_code; |
|
5280 } else { |
5295 } else { |
5281 return -1; |
5296 exit_code = -1; |
5282 } |
5297 } |
|
5298 |
|
5299 FREE_C_HEAP_ARRAY(char, cmd_string); |
|
5300 return (int)exit_code; |
5283 } |
5301 } |
5284 |
5302 |
5285 bool os::find(address addr, outputStream* st) { |
5303 bool os::find(address addr, outputStream* st) { |
5286 int offset = -1; |
5304 int offset = -1; |
5287 bool result = false; |
5305 bool result = false; |