| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/nacl/nacl_main_platform_delegate.h" | 5 #include "chrome/nacl/nacl_main_platform_delegate.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/native_library.h" | 11 #include "base/native_library.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "content/common/sandbox_mac.h" | 13 #include "content/common/sandbox_mac.h" |
| 14 #include "content/public/common/sandbox_init.h" |
| 14 | 15 |
| 15 NaClMainPlatformDelegate::NaClMainPlatformDelegate( | 16 NaClMainPlatformDelegate::NaClMainPlatformDelegate( |
| 16 const MainFunctionParams& parameters) | 17 const MainFunctionParams& parameters) |
| 17 : parameters_(parameters), sandbox_test_module_(NULL) { | 18 : parameters_(parameters), sandbox_test_module_(NULL) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 NaClMainPlatformDelegate::~NaClMainPlatformDelegate() { | 21 NaClMainPlatformDelegate::~NaClMainPlatformDelegate() { |
| 21 } | 22 } |
| 22 | 23 |
| 23 // TODO(jvoung): see if this old comment (from renderer_main_platform...) | 24 // TODO(jvoung): see if this old comment (from renderer_main_platform...) |
| 24 // is relevant to the nacl loader. | 25 // is relevant to the nacl loader. |
| 25 // TODO(mac-port): Any code needed to initialize a process for purposes of | 26 // TODO(mac-port): Any code needed to initialize a process for purposes of |
| 26 // running a NaClLoader needs to also be reflected in chrome_main.cc for | 27 // running a NaClLoader needs to also be reflected in chrome_main.cc for |
| 27 // --single-process support. | 28 // --single-process support. |
| 28 void NaClMainPlatformDelegate::PlatformInitialize() { | 29 void NaClMainPlatformDelegate::PlatformInitialize() { |
| 29 } | 30 } |
| 30 | 31 |
| 31 void NaClMainPlatformDelegate::PlatformUninitialize() { | 32 void NaClMainPlatformDelegate::PlatformUninitialize() { |
| 32 } | 33 } |
| 33 | 34 |
| 34 void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { | 35 void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { |
| 35 const CommandLine& command_line = parameters_.command_line_; | 36 const CommandLine& command_line = parameters_.command_line; |
| 36 | 37 |
| 37 DVLOG(1) << "Started NaClLdr with "; | 38 DVLOG(1) << "Started NaClLdr with "; |
| 38 const std::vector<std::string>& argstrings = command_line.argv(); | 39 const std::vector<std::string>& argstrings = command_line.argv(); |
| 39 for (std::vector<std::string>::const_iterator ii = argstrings.begin(); | 40 for (std::vector<std::string>::const_iterator ii = argstrings.begin(); |
| 40 ii != argstrings.end(); ++ii) | 41 ii != argstrings.end(); ++ii) |
| 41 DVLOG(1) << *ii; | 42 DVLOG(1) << *ii; |
| 42 | 43 |
| 43 // Be sure not to load the sandbox test DLL if the sandbox isn't on. | 44 // Be sure not to load the sandbox test DLL if the sandbox isn't on. |
| 44 // Comment-out guard and recompile if you REALLY want to test w/out the SB. | 45 // Comment-out guard and recompile if you REALLY want to test w/out the SB. |
| 45 // TODO(jvoung): allow testing without sandbox, but change expected ret vals. | 46 // TODO(jvoung): allow testing without sandbox, but change expected ret vals. |
| 46 if (!no_sandbox) { | 47 if (!no_sandbox) { |
| 47 FilePath test_dll_name = | 48 FilePath test_dll_name = |
| 48 command_line.GetSwitchValuePath(switches::kTestNaClSandbox); | 49 command_line.GetSwitchValuePath(switches::kTestNaClSandbox); |
| 49 if (!test_dll_name.empty()) { | 50 if (!test_dll_name.empty()) { |
| 50 sandbox_test_module_ = base::LoadNativeLibrary(test_dll_name, NULL); | 51 sandbox_test_module_ = base::LoadNativeLibrary(test_dll_name, NULL); |
| 51 CHECK(sandbox_test_module_); | 52 CHECK(sandbox_test_module_); |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 | 56 |
| 56 void NaClMainPlatformDelegate::EnableSandbox() { | 57 void NaClMainPlatformDelegate::EnableSandbox() { |
| 57 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess(); | 58 CHECK(content::InitializeSandbox()) << "Error initializing sandbox for " |
| 58 SandboxInitWrapper sandbox_wrapper; | 59 << switches::kNaClLoaderProcess; |
| 59 bool sandbox_initialized_ok = | |
| 60 sandbox_wrapper.InitializeSandbox(*parsed_command_line, | |
| 61 switches::kNaClLoaderProcess); | |
| 62 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " | |
| 63 << switches::kNaClLoaderProcess; | |
| 64 } | 60 } |
| 65 | 61 |
| 66 bool NaClMainPlatformDelegate::RunSandboxTests() { | 62 bool NaClMainPlatformDelegate::RunSandboxTests() { |
| 67 // TODO(jvoung): Win and mac should share this identical code. | 63 // TODO(jvoung): Win and mac should share this identical code. |
| 68 bool result = true; | 64 bool result = true; |
| 69 if (sandbox_test_module_) { | 65 if (sandbox_test_module_) { |
| 70 RunNaClLoaderTests run_security_tests = | 66 RunNaClLoaderTests run_security_tests = |
| 71 reinterpret_cast<RunNaClLoaderTests>( | 67 reinterpret_cast<RunNaClLoaderTests>( |
| 72 base::GetFunctionPointerFromNativeLibrary(sandbox_test_module_, | 68 base::GetFunctionPointerFromNativeLibrary(sandbox_test_module_, |
| 73 kNaClLoaderTestCall)); | 69 kNaClLoaderTestCall)); |
| 74 if (run_security_tests) { | 70 if (run_security_tests) { |
| 75 DVLOG(1) << "Running NaCl Loader security tests"; | 71 DVLOG(1) << "Running NaCl Loader security tests"; |
| 76 result = (*run_security_tests)(); | 72 result = (*run_security_tests)(); |
| 77 } else { | 73 } else { |
| 78 VLOG(1) << "Failed to get NaCl sandbox test function"; | 74 VLOG(1) << "Failed to get NaCl sandbox test function"; |
| 79 result = false; | 75 result = false; |
| 80 } | 76 } |
| 81 base::UnloadNativeLibrary(sandbox_test_module_); | 77 base::UnloadNativeLibrary(sandbox_test_module_); |
| 82 sandbox_test_module_ = NULL; | 78 sandbox_test_module_ = NULL; |
| 83 } | 79 } |
| 84 return result; | 80 return result; |
| 85 } | 81 } |
| OLD | NEW |