OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/nacl/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (result < sizeof(info)) | 89 if (result < sizeof(info)) |
90 break; | 90 break; |
91 if (info.State == MEM_FREE && info.RegionSize > *out_size) { | 91 if (info.State == MEM_FREE && info.RegionSize > *out_size) { |
92 *out_addr = addr; | 92 *out_addr = addr; |
93 *out_size = info.RegionSize; | 93 *out_size = info.RegionSize; |
94 } | 94 } |
95 addr += info.RegionSize; | 95 addr += info.RegionSize; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
| 99 #ifdef _DLL |
| 100 |
| 101 bool IsInPath(const std::string& path_env_var, const std::string& dir) { |
| 102 std::vector<std::string> split; |
| 103 base::SplitString(path_env_var, ';', &split); |
| 104 for (std::vector<std::string>::const_iterator i(split.begin()); |
| 105 i != split.end(); |
| 106 ++i) { |
| 107 if (*i == dir) |
| 108 return true; |
| 109 } |
| 110 return false; |
| 111 } |
| 112 |
| 113 #endif // _DLL |
| 114 |
99 } // namespace | 115 } // namespace |
100 | 116 |
101 namespace nacl { | 117 namespace nacl { |
102 | 118 |
103 // Allocates |size| bytes of address space in the given process at a | 119 // Allocates |size| bytes of address space in the given process at a |
104 // randomised address. | 120 // randomised address. |
105 void* AllocateAddressSpaceASLR(base::ProcessHandle process, size_t size) { | 121 void* AllocateAddressSpaceASLR(base::ProcessHandle process, size_t size) { |
106 char* addr; | 122 char* addr; |
107 size_t avail_size; | 123 size_t avail_size; |
108 FindAddressSpace(process, &addr, &avail_size); | 124 FindAddressSpace(process, &addr, &avail_size); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 if (exe_path.empty()) | 521 if (exe_path.empty()) |
506 return false; | 522 return false; |
507 | 523 |
508 #if defined(OS_WIN) | 524 #if defined(OS_WIN) |
509 // On Windows 64-bit NaCl loader is called nacl64.exe instead of chrome.exe | 525 // On Windows 64-bit NaCl loader is called nacl64.exe instead of chrome.exe |
510 if (RunningOnWOW64()) { | 526 if (RunningOnWOW64()) { |
511 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&exe_path)) { | 527 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&exe_path)) { |
512 SendErrorToRenderer("could not get path to nacl64.exe"); | 528 SendErrorToRenderer("could not get path to nacl64.exe"); |
513 return false; | 529 return false; |
514 } | 530 } |
| 531 |
| 532 #ifdef _DLL |
| 533 // When using the DLL CRT on Windows, we need to amend the PATH to include |
| 534 // the location of the x64 CRT DLLs. This is only the case when using a |
| 535 // component=shared_library build (i.e. generally dev debug builds). The |
| 536 // x86 CRT DLLs are in e.g. out\Debug for chrome.exe etc., so the x64 ones |
| 537 // are put in out\Debug\x64 which we add to the PATH here so that loader |
| 538 // can find them. See http://crbug.com/346034. |
| 539 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 540 static const char kPath[] = "PATH"; |
| 541 std::string old_path; |
| 542 base::FilePath module_path; |
| 543 if (!PathService::Get(base::FILE_MODULE, &module_path)) { |
| 544 SendErrorToRenderer("could not get path to current module"); |
| 545 return false; |
| 546 } |
| 547 std::string x64_crt_path = |
| 548 base::WideToUTF8(module_path.DirName().Append(L"x64").value()); |
| 549 if (!env->GetVar(kPath, &old_path)) { |
| 550 env->SetVar(kPath, x64_crt_path); |
| 551 } else if (!IsInPath(old_path, x64_crt_path)) { |
| 552 std::string new_path(old_path); |
| 553 new_path.append(";"); |
| 554 new_path.append(x64_crt_path); |
| 555 env->SetVar(kPath, new_path); |
| 556 } |
| 557 #endif // _DLL |
515 } | 558 } |
516 #endif | 559 #endif |
517 | 560 |
518 scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path)); | 561 scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path)); |
519 CopyNaClCommandLineArguments(cmd_line.get()); | 562 CopyNaClCommandLineArguments(cmd_line.get()); |
520 | 563 |
521 cmd_line->AppendSwitchASCII(switches::kProcessType, | 564 cmd_line->AppendSwitchASCII(switches::kProcessType, |
522 switches::kNaClLoaderProcess); | 565 switches::kNaClLoaderProcess); |
523 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 566 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
524 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) | 567 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 process_handle.Take(), info, | 1048 process_handle.Take(), info, |
1006 base::MessageLoopProxy::current(), | 1049 base::MessageLoopProxy::current(), |
1007 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1050 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
1008 weak_factory_.GetWeakPtr())); | 1051 weak_factory_.GetWeakPtr())); |
1009 return true; | 1052 return true; |
1010 } | 1053 } |
1011 } | 1054 } |
1012 #endif | 1055 #endif |
1013 | 1056 |
1014 } // namespace nacl | 1057 } // namespace nacl |
OLD | NEW |