Commit 1047dd4a authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove using directives ("using namespace x") from chrome/chrome_elf/.

Also shortens/cleans up some existing code (no functional change).

Bug: 82078
Change-Id: I4d3ee878d6c4f6e301dcaaa19e5fc7877bb1b5e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881696
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarCait Phillips <caitkp@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709961}
parent ffc6c925
...@@ -501,12 +501,10 @@ bool GetDataFromImageForTesting(PVOID mapped_image, ...@@ -501,12 +501,10 @@ bool GetDataFromImageForTesting(PVOID mapped_image,
} // namespace third_party_dlls } // namespace third_party_dlls
using namespace third_party_dlls;
void DisableHook() { void DisableHook() {
g_hook_disabled.store(true, std::memory_order_relaxed); third_party_dlls::g_hook_disabled.store(true, std::memory_order_relaxed);
} }
int32_t GetApplyHookResult() { int32_t GetApplyHookResult() {
return g_apply_hook_result.load(std::memory_order_relaxed); return third_party_dlls::g_apply_hook_result.load(std::memory_order_relaxed);
} }
...@@ -273,17 +273,17 @@ void DeinitLogs() { ...@@ -273,17 +273,17 @@ void DeinitLogs() {
// - Function definition in logging_api.h // - Function definition in logging_api.h
// - Export declared in chrome_elf_[x64|x86].def // - Export declared in chrome_elf_[x64|x86].def
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using namespace third_party_dlls;
uint32_t DrainLog(uint8_t* buffer, uint32_t DrainLog(uint8_t* buffer,
uint32_t buffer_size, uint32_t buffer_size,
uint32_t* log_remaining) { uint32_t* log_remaining) {
if (!g_log_mutex || if (!third_party_dlls::g_log_mutex ||
::WaitForSingleObject(g_log_mutex, kMaxMutexWaitMs) != WAIT_OBJECT_0) ::WaitForSingleObject(third_party_dlls::g_log_mutex,
third_party_dlls::kMaxMutexWaitMs) != WAIT_OBJECT_0)
return 0; return 0;
Log& blocked = GetBlockedLog(); third_party_dlls::Log& blocked = third_party_dlls::GetBlockedLog();
Log& allowed = GetAllowedLog(); third_party_dlls::Log& allowed = third_party_dlls::GetAllowedLog();
uint32_t bytes_written = blocked.Drain(buffer, buffer_size); uint32_t bytes_written = blocked.Drain(buffer, buffer_size);
bytes_written += bytes_written +=
...@@ -299,13 +299,13 @@ uint32_t DrainLog(uint8_t* buffer, ...@@ -299,13 +299,13 @@ uint32_t DrainLog(uint8_t* buffer,
*log_remaining = static_cast<uint32_t>(full_size); *log_remaining = static_cast<uint32_t>(full_size);
} }
::ReleaseMutex(g_log_mutex); ::ReleaseMutex(third_party_dlls::g_log_mutex);
return bytes_written; return bytes_written;
} }
bool RegisterLogNotification(HANDLE event_handle) { bool RegisterLogNotification(HANDLE event_handle) {
if (!g_log_mutex) if (!third_party_dlls::g_log_mutex)
return false; return false;
// Duplicate the new handle, if not clearing with nullptr. // Duplicate the new handle, if not clearing with nullptr.
...@@ -317,18 +317,20 @@ bool RegisterLogNotification(HANDLE event_handle) { ...@@ -317,18 +317,20 @@ bool RegisterLogNotification(HANDLE event_handle) {
} }
// Close any existing registered handle. // Close any existing registered handle.
if (g_notification_event) if (third_party_dlls::g_notification_event)
::CloseHandle(g_notification_event); ::CloseHandle(third_party_dlls::g_notification_event);
g_notification_event = temp; third_party_dlls::g_notification_event = temp;
return true; return true;
} }
uint32_t GetBlockedModulesCount() { uint32_t GetBlockedModulesCount() {
return g_blocked_modules_count.load(std::memory_order_relaxed); return third_party_dlls::g_blocked_modules_count.load(
std::memory_order_relaxed);
} }
uint32_t GetUniqueBlockedModulesCount() { uint32_t GetUniqueBlockedModulesCount() {
return g_unique_blocked_modules_count.load(std::memory_order_relaxed); return third_party_dlls::g_unique_blocked_modules_count.load(
std::memory_order_relaxed);
} }
...@@ -152,8 +152,6 @@ void AddStatusCodeForTesting(ThirdPartyStatus code) { ...@@ -152,8 +152,6 @@ void AddStatusCodeForTesting(ThirdPartyStatus code) {
} // namespace third_party_dlls } // namespace third_party_dlls
using namespace third_party_dlls;
bool IsThirdPartyInitialized() { bool IsThirdPartyInitialized() {
return g_third_party_initialized; return third_party_dlls::g_third_party_initialized;
} }
...@@ -260,23 +260,21 @@ TEST_F(ThirdPartyTest, MAYBE_Base) { ...@@ -260,23 +260,21 @@ TEST_F(ThirdPartyTest, MAYBE_Base) {
// initialization. // initialization.
base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename);
cmd_line1.AppendArgNative(GetBlTestFilePath()); cmd_line1.AppendArgNative(GetBlTestFilePath());
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(base::NumberToString16(kTestOnlyInitialization));
base::NumberToString16(main_unittest_exe::kTestOnlyInitialization));
int exit_code = 0; int exit_code = 0;
LaunchChildAndWait(cmd_line1, &exit_code); LaunchChildAndWait(cmd_line1, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadSuccess, exit_code); ASSERT_EQ(kDllLoadSuccess, exit_code);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// 2. Spawn the test process with NO blacklist. Expect successful DLL load. // 2. Spawn the test process with NO blacklist. Expect successful DLL load.
base::CommandLine cmd_line2 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line2 = base::CommandLine::FromString(kTestExeFilename);
cmd_line2.AppendArgNative(GetBlTestFilePath()); cmd_line2.AppendArgNative(GetBlTestFilePath());
cmd_line2.AppendArgNative( cmd_line2.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line2.AppendArgNative(MakePath(GetExeDir(), kTestDllName1)); cmd_line2.AppendArgNative(MakePath(GetExeDir(), kTestDllName1));
LaunchChildAndWait(cmd_line2, &exit_code); LaunchChildAndWait(cmd_line2, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadSuccess, exit_code); ASSERT_EQ(kDllLoadSuccess, exit_code);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// 3. Spawn the test process with blacklist. Expect failed DLL load. // 3. Spawn the test process with blacklist. Expect failed DLL load.
...@@ -295,12 +293,11 @@ TEST_F(ThirdPartyTest, MAYBE_Base) { ...@@ -295,12 +293,11 @@ TEST_F(ThirdPartyTest, MAYBE_Base) {
base::CommandLine cmd_line3 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line3 = base::CommandLine::FromString(kTestExeFilename);
cmd_line3.AppendArgNative(GetBlTestFilePath()); cmd_line3.AppendArgNative(GetBlTestFilePath());
cmd_line3.AppendArgNative( cmd_line3.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line3.AppendArgNative(MakePath(GetExeDir(), kTestDllName1)); cmd_line3.AppendArgNative(MakePath(GetExeDir(), kTestDllName1));
LaunchChildAndWait(cmd_line3, &exit_code); LaunchChildAndWait(cmd_line3, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadFailed, exit_code); ASSERT_EQ(kDllLoadFailed, exit_code);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// 4. Spawn the test process with blacklist. Expect failed DLL load. // 4. Spawn the test process with blacklist. Expect failed DLL load.
...@@ -315,13 +312,12 @@ TEST_F(ThirdPartyTest, MAYBE_Base) { ...@@ -315,13 +312,12 @@ TEST_F(ThirdPartyTest, MAYBE_Base) {
base::CommandLine cmd_line4 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line4 = base::CommandLine::FromString(kTestExeFilename);
cmd_line4.AppendArgNative(GetBlTestFilePath()); cmd_line4.AppendArgNative(GetBlTestFilePath());
cmd_line4.AppendArgNative( cmd_line4.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line4.AppendArgNative( cmd_line4.AppendArgNative(
MakePath(GetScopedTempDirValue(), kTestDllName1MixedCase)); MakePath(GetScopedTempDirValue(), kTestDllName1MixedCase));
LaunchChildAndWait(cmd_line4, &exit_code); LaunchChildAndWait(cmd_line4, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadFailed, exit_code); ASSERT_EQ(kDllLoadFailed, exit_code);
} }
// Note: The test module used in this unittest has no export table. // Note: The test module used in this unittest has no export table.
...@@ -334,13 +330,12 @@ TEST_F(ThirdPartyTest, WideCharEncoding) { ...@@ -334,13 +330,12 @@ TEST_F(ThirdPartyTest, WideCharEncoding) {
// 1) Test a successful DLL load with no blacklist. // 1) Test a successful DLL load with no blacklist.
base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename);
cmd_line1.AppendArgNative(GetBlTestFilePath()); cmd_line1.AppendArgNative(GetBlTestFilePath());
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line1.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode)); cmd_line1.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode));
int exit_code = 0; int exit_code = 0;
LaunchChildAndWait(cmd_line1, &exit_code); LaunchChildAndWait(cmd_line1, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadSuccess, exit_code); ASSERT_EQ(kDllLoadSuccess, exit_code);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// 2) Test a failed DLL load with blacklist. // 2) Test a failed DLL load with blacklist.
...@@ -360,12 +355,11 @@ TEST_F(ThirdPartyTest, WideCharEncoding) { ...@@ -360,12 +355,11 @@ TEST_F(ThirdPartyTest, WideCharEncoding) {
base::CommandLine cmd_line2 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line2 = base::CommandLine::FromString(kTestExeFilename);
cmd_line2.AppendArgNative(GetBlTestFilePath()); cmd_line2.AppendArgNative(GetBlTestFilePath());
cmd_line2.AppendArgNative( cmd_line2.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line2.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode)); cmd_line2.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode));
LaunchChildAndWait(cmd_line2, &exit_code); LaunchChildAndWait(cmd_line2, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadFailed, exit_code); ASSERT_EQ(kDllLoadFailed, exit_code);
} }
// Note: The test module used in this unittest has an export table. // Note: The test module used in this unittest has an export table.
...@@ -378,13 +372,12 @@ TEST_F(ThirdPartyTest, WideCharEncodingWithExportDir) { ...@@ -378,13 +372,12 @@ TEST_F(ThirdPartyTest, WideCharEncodingWithExportDir) {
// 1) Test a successful DLL load with no blacklist. // 1) Test a successful DLL load with no blacklist.
base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename);
cmd_line1.AppendArgNative(GetBlTestFilePath()); cmd_line1.AppendArgNative(GetBlTestFilePath());
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line1.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode)); cmd_line1.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode));
int exit_code = 0; int exit_code = 0;
LaunchChildAndWait(cmd_line1, &exit_code); LaunchChildAndWait(cmd_line1, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadSuccess, exit_code); ASSERT_EQ(kDllLoadSuccess, exit_code);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// 2) Test a failed DLL load with blacklist. // 2) Test a failed DLL load with blacklist.
...@@ -409,12 +402,11 @@ TEST_F(ThirdPartyTest, WideCharEncodingWithExportDir) { ...@@ -409,12 +402,11 @@ TEST_F(ThirdPartyTest, WideCharEncodingWithExportDir) {
base::CommandLine cmd_line2 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line2 = base::CommandLine::FromString(kTestExeFilename);
cmd_line2.AppendArgNative(GetBlTestFilePath()); cmd_line2.AppendArgNative(GetBlTestFilePath());
cmd_line2.AppendArgNative( cmd_line2.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line2.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode)); cmd_line2.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode));
LaunchChildAndWait(cmd_line2, &exit_code); LaunchChildAndWait(cmd_line2, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadFailed, exit_code); ASSERT_EQ(kDllLoadFailed, exit_code);
// 2b) Only blacklist the new DLL file name, which should be mined out of the // 2b) Only blacklist the new DLL file name, which should be mined out of the
// section by the hook, and the load should be blocked. // section by the hook, and the load should be blocked.
...@@ -426,12 +418,11 @@ TEST_F(ThirdPartyTest, WideCharEncodingWithExportDir) { ...@@ -426,12 +418,11 @@ TEST_F(ThirdPartyTest, WideCharEncodingWithExportDir) {
base::CommandLine cmd_line3 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line3 = base::CommandLine::FromString(kTestExeFilename);
cmd_line3.AppendArgNative(GetBlTestFilePath()); cmd_line3.AppendArgNative(GetBlTestFilePath());
cmd_line3.AppendArgNative( cmd_line3.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line3.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode)); cmd_line3.AppendArgNative(MakePath(GetScopedTempDirValue(), kChineseUnicode));
LaunchChildAndWait(cmd_line3, &exit_code); LaunchChildAndWait(cmd_line3, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadFailed, exit_code); ASSERT_EQ(kDllLoadFailed, exit_code);
} }
// Note: The test module used in this unittest has no export table. // Note: The test module used in this unittest has no export table.
...@@ -444,14 +435,13 @@ TEST_F(ThirdPartyTest, DeprecatedBlacklistSanityCheck) { ...@@ -444,14 +435,13 @@ TEST_F(ThirdPartyTest, DeprecatedBlacklistSanityCheck) {
// should trigger a block). // should trigger a block).
base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename);
cmd_line1.AppendArgNative(GetBlTestFilePath()); cmd_line1.AppendArgNative(GetBlTestFilePath());
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(
MakePath(GetScopedTempDirValue(), kOldBlacklistDllName)); MakePath(GetScopedTempDirValue(), kOldBlacklistDllName));
int exit_code = 0; int exit_code = 0;
LaunchChildAndWait(cmd_line1, &exit_code); LaunchChildAndWait(cmd_line1, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadFailed, exit_code); ASSERT_EQ(kDllLoadFailed, exit_code);
} }
// Note: This test only sanity checks the two SHA1 libraries used on either side // Note: This test only sanity checks the two SHA1 libraries used on either side
...@@ -523,14 +513,13 @@ TEST_F(ThirdPartyTest, MAYBE_PathCaseSensitive) { ...@@ -523,14 +513,13 @@ TEST_F(ThirdPartyTest, MAYBE_PathCaseSensitive) {
// for this test. // for this test.
base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename); base::CommandLine cmd_line1 = base::CommandLine::FromString(kTestExeFilename);
cmd_line1.AppendArgNative(GetBlTestFilePath()); cmd_line1.AppendArgNative(GetBlTestFilePath());
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(base::NumberToString16(kTestSingleDllLoad));
base::NumberToString16(main_unittest_exe::kTestSingleDllLoad));
cmd_line1.AppendArgNative( cmd_line1.AppendArgNative(
MakePath(GetScopedTempDirValue(), kTestDllName1MixedCase)); MakePath(GetScopedTempDirValue(), kTestDllName1MixedCase));
int exit_code = 0; int exit_code = 0;
LaunchChildAndWait(cmd_line1, &exit_code); LaunchChildAndWait(cmd_line1, &exit_code);
ASSERT_EQ(main_unittest_exe::kDllLoadSuccess, exit_code); ASSERT_EQ(kDllLoadSuccess, exit_code);
} }
// Test the status-code passing in registry. // Test the status-code passing in registry.
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include "chrome/install_static/install_util.h" #include "chrome/install_static/install_util.h"
#include "chrome/install_static/product_install_details.h" #include "chrome/install_static/product_install_details.h"
using namespace third_party_dlls::main_unittest_exe;
namespace { namespace {
// Function object which invokes LocalFree on its parameter, which must be // Function object which invokes LocalFree on its parameter, which must be
...@@ -33,13 +31,11 @@ struct LocalFreeDeleter { ...@@ -33,13 +31,11 @@ struct LocalFreeDeleter {
}; };
// Attempt to load a given DLL. // Attempt to load a given DLL.
ExitCode LoadDll(std::wstring name) { third_party_dlls::ExitCode LoadDll(std::wstring name) {
base::FilePath dll_path(name); base::FilePath dll_path(name);
base::ScopedNativeLibrary dll(dll_path); base::ScopedNativeLibrary dll(dll_path);
if (!dll.is_valid()) return dll.is_valid() ? third_party_dlls::kDllLoadSuccess
return kDllLoadFailed; : third_party_dlls::kDllLoadFailed;
return kDllLoadSuccess;
} }
// Utility function to protect the local registry. // Utility function to protect the local registry.
...@@ -60,10 +56,7 @@ bool MatchPath(const wchar_t* arg_path, const third_party_dlls::LogEntry& log) { ...@@ -60,10 +56,7 @@ bool MatchPath(const wchar_t* arg_path, const third_party_dlls::LogEntry& log) {
return false; return false;
} }
if (drive_path.value().compare(arg_path) != 0) return drive_path.value().compare(arg_path) == 0;
return false;
return true;
} }
} // namespace } // namespace
...@@ -91,27 +84,26 @@ int main() { ...@@ -91,27 +84,26 @@ int main() {
std::unique_ptr<wchar_t*[], LocalFreeDeleter> argv( std::unique_ptr<wchar_t*[], LocalFreeDeleter> argv(
::CommandLineToArgvW(::GetCommandLineW(), &argument_count)); ::CommandLineToArgvW(::GetCommandLineW(), &argument_count));
if (!argv) if (!argv)
return kBadCommandLine; return third_party_dlls::kBadCommandLine;
if (IsThirdPartyInitialized()) if (IsThirdPartyInitialized())
return kThirdPartyAlreadyInitialized; return third_party_dlls::kThirdPartyAlreadyInitialized;
install_static::InitializeProductDetailsForPrimaryModule(); install_static::InitializeProductDetailsForPrimaryModule();
install_static::InitializeProcessType(); install_static::InitializeProcessType();
// Get the required arguments, path to blacklist file and test id to run. // Get the required arguments, path to blacklist file and test id to run.
if (argument_count < 3) if (argument_count < 3)
return kMissingArgument; return third_party_dlls::kMissingArgument;
const wchar_t* blacklist_path = argv[1]; const wchar_t* blacklist_path = argv[1];
if (!blacklist_path || ::wcslen(blacklist_path) == 0) { if (!blacklist_path || ::wcslen(blacklist_path) == 0)
return kBadBlacklistPath; return third_party_dlls::kBadBlacklistPath;
}
const wchar_t* arg2 = argv[2]; const wchar_t* arg2 = argv[2];
int test_id = ::_wtoi(arg2); int test_id = ::_wtoi(arg2);
if (!test_id) if (!test_id)
return kUnsupportedTestId; return third_party_dlls::kUnsupportedTestId;
// Override blacklist path before initializing. // Override blacklist path before initializing.
third_party_dlls::OverrideFilePathForTesting(blacklist_path); third_party_dlls::OverrideFilePathForTesting(blacklist_path);
...@@ -121,51 +113,49 @@ int main() { ...@@ -121,51 +113,49 @@ int main() {
RegRedirect(&rom); RegRedirect(&rom);
if (!third_party_dlls::Init()) if (!third_party_dlls::Init())
return kThirdPartyInitFailure; return third_party_dlls::kThirdPartyInitFailure;
// Switch on test id.
switch (test_id) { switch (test_id) {
// Just initialization. case third_party_dlls::kTestOnlyInitialization:
case kTestOnlyInitialization:
break; break;
// Single DLL load.
case kTestSingleDllLoad: case third_party_dlls::kTestSingleDllLoad:
// Single DLL load with log path scrutiny. case third_party_dlls::kTestLogPath: {
case kTestLogPath: {
if (argument_count < 4) if (argument_count < 4)
return kMissingArgument; return third_party_dlls::kMissingArgument;
const wchar_t* dll_name = argv[3]; const wchar_t* dll_name = argv[3];
if (!dll_name || ::wcslen(dll_name) == 0) if (!dll_name || ::wcslen(dll_name) == 0)
return kBadArgument; return third_party_dlls::kBadArgument;
ExitCode code = LoadDll(dll_name); third_party_dlls::ExitCode code = LoadDll(dll_name);
// Get logging. Ensure the log is as expected. // Get logging. Ensure the log is as expected.
uint32_t bytes = 0; uint32_t bytes = 0;
DrainLog(nullptr, 0, &bytes); DrainLog(nullptr, 0, &bytes);
if (!bytes) if (!bytes)
return kEmptyLog; return third_party_dlls::kEmptyLog;
auto buffer = std::unique_ptr<uint8_t[]>(new uint8_t[bytes]); auto buffer = std::make_unique<uint8_t[]>(bytes);
bytes = DrainLog(&buffer[0], bytes, nullptr); bytes = DrainLog(&buffer[0], bytes, nullptr);
third_party_dlls::LogEntry* entry = third_party_dlls::LogEntry* entry =
reinterpret_cast<third_party_dlls::LogEntry*>(&buffer[0]); reinterpret_cast<third_party_dlls::LogEntry*>(&buffer[0]);
if (!bytes || bytes < third_party_dlls::GetLogEntrySize(entry->path_len)) if (!bytes || bytes < third_party_dlls::GetLogEntrySize(entry->path_len))
return kBadLogEntrySize; return third_party_dlls::kBadLogEntrySize;
if ((code == kDllLoadFailed && if ((code == third_party_dlls::kDllLoadFailed &&
entry->type != third_party_dlls::kBlocked) || entry->type != third_party_dlls::kBlocked) ||
(code == kDllLoadSuccess && (code == third_party_dlls::kDllLoadSuccess &&
entry->type != third_party_dlls::kAllowed)) { entry->type != third_party_dlls::kAllowed)) {
return kUnexpectedLog; return third_party_dlls::kUnexpectedLog;
} }
if (test_id == kTestLogPath && !MatchPath(dll_name, *entry)) if (test_id == third_party_dlls::kTestLogPath &&
return kUnexpectedSectionPath; !MatchPath(dll_name, *entry))
return third_party_dlls::kUnexpectedSectionPath;
return code; return code;
} }
// Unsupported argument.
default: default:
return kUnsupportedTestId; return third_party_dlls::kUnsupportedTestId;
} }
return 0; return 0;
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#define CHROME_CHROME_ELF_THIRD_PARTY_DLLS_MAIN_UNITTEST_EXE_H_ #define CHROME_CHROME_ELF_THIRD_PARTY_DLLS_MAIN_UNITTEST_EXE_H_
namespace third_party_dlls { namespace third_party_dlls {
namespace main_unittest_exe {
enum ExitCode { enum ExitCode {
kDllLoadSuccess = 0, kDllLoadSuccess = 0,
kDllLoadFailed = 1, kDllLoadFailed = 1,
// Unexpected failures are negative ints: // Unexpected failures are negative ints:
kBadCommandLine = -1, kBadCommandLine = -1,
kThirdPartyAlreadyInitialized = -2, kThirdPartyAlreadyInitialized = -2,
...@@ -26,12 +26,11 @@ enum ExitCode { ...@@ -26,12 +26,11 @@ enum ExitCode {
}; };
enum TestId { enum TestId {
kTestOnlyInitialization = 1, kTestOnlyInitialization = 1, // Just initialization.
kTestSingleDllLoad = 2, kTestSingleDllLoad = 2, // Single DLL load.
kTestLogPath = 3, kTestLogPath = 3, // Single DLL load with log path scrutiny.
}; };
} // namespace main_unittest_exe
} // namespace third_party_dlls } // namespace third_party_dlls
#endif // CHROME_CHROME_ELF_THIRD_PARTY_DLLS_MAIN_UNITTEST_EXE_H_ #endif // CHROME_CHROME_ELF_THIRD_PARTY_DLLS_MAIN_UNITTEST_EXE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment