diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index b31c18af..8d331fc0 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -235,29 +235,6 @@ static_library("snapshot") { } } -if (crashpad_is_win) { - static_library("snapshot_api") { - sources = [ - "api/module_annotations_win.cc", - "api/module_annotations_win.h", - ] - - public_configs = [ "..:crashpad_config" ] - - cflags = [ "/wd4201" ] - - deps = [ - ":snapshot", - "../compat", - "../third_party/mini_chromium:base", - "../util", - ] - } -} else { - group("snapshot_api") { - } -} - fuzzer_test("elf_image_reader_fuzzer") { sources = [ "elf/elf_image_reader_fuzzer.cc", @@ -367,7 +344,6 @@ source_set("snapshot_test") { if (crashpad_is_win) { sources += [ - "api/module_annotations_win_test.cc", "win/cpu_context_win_test.cc", "win/exception_snapshot_win_test.cc", "win/extra_memory_ranges_test.cc", @@ -399,7 +375,6 @@ source_set("snapshot_test") { public_configs = [ ":snapshot_test_link" ] deps = [ - ":snapshot_api", ":test_support", "../client", "../compat", diff --git a/snapshot/api/module_annotations_win.cc b/snapshot/api/module_annotations_win.cc deleted file mode 100644 index fd468703..00000000 --- a/snapshot/api/module_annotations_win.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2016 The Crashpad Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "snapshot/api/module_annotations_win.h" - -#include "snapshot/win/pe_image_annotations_reader.h" -#include "snapshot/win/pe_image_reader.h" -#include "snapshot/win/process_reader_win.h" -#include "util/misc/from_pointer_cast.h" -#include "util/win/get_module_information.h" - -namespace crashpad { - -bool ReadModuleAnnotations(HANDLE process, - HMODULE module, - std::map* annotations) { - ProcessReaderWin process_reader; - if (!process_reader.Initialize(process, ProcessSuspensionState::kRunning)) - return false; - - MODULEINFO module_info; - if (!CrashpadGetModuleInformation( - process, module, &module_info, sizeof(module_info))) { - PLOG(ERROR) << "CrashpadGetModuleInformation"; - return false; - } - - PEImageReader image_reader; - if (!image_reader.Initialize( - &process_reader, - FromPointerCast(module_info.lpBaseOfDll), - module_info.SizeOfImage, - "")) - return false; - - PEImageAnnotationsReader annotations_reader( - &process_reader, &image_reader, L""); - - *annotations = annotations_reader.SimpleMap(); - return true; -} - -} // namespace crashpad diff --git a/snapshot/api/module_annotations_win.h b/snapshot/api/module_annotations_win.h deleted file mode 100644 index e0240310..00000000 --- a/snapshot/api/module_annotations_win.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2016 The Crashpad Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef CRASHPAD_SNAPSHOT_API_MODULE_ANNOTATIONS_WIN_H_ -#define CRASHPAD_SNAPSHOT_API_MODULE_ANNOTATIONS_WIN_H_ - -#include - -#include -#include - -namespace crashpad { - -//! \brief Reads the module annotations from another process. -//! -//! \param[in] process The handle to the process that hosts the \a module. -//! Requires PROCESS_QUERY_INFORMATION and PROCESS_VM_READ accesses. -//! \param[in] module The handle to the module from which the \a annotations -//! will be read. This module should be loaded in the target process. -//! \param[out] annotations The map that will be filled with the annotations. -//! Remains unchanged if the function returns 'false'. -//! -//! \return `true` if the annotations could be read succesfully, even if the -//! module doesn't contain any annotations. -bool ReadModuleAnnotations(HANDLE process, - HMODULE module, - std::map* annotations); - -} // namespace crashpad - -#endif // CRASHPAD_SNAPSHOT_API_MODULE_ANNOTATIONS_WIN_H_ diff --git a/snapshot/api/module_annotations_win_test.cc b/snapshot/api/module_annotations_win_test.cc deleted file mode 100644 index ecfa4659..00000000 --- a/snapshot/api/module_annotations_win_test.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2016 The Crashpad Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "snapshot/api/module_annotations_win.h" - -#include "client/crashpad_info.h" -#include "gtest/gtest.h" -#include "test/win/win_multiprocess.h" -#include "util/file/file_io.h" - -namespace crashpad { -namespace test { -namespace { - -class ModuleAnnotationsMultiprocessTest final : public WinMultiprocess { - private: - void WinMultiprocessParent() override { - // Read the child executable module. - HMODULE module = nullptr; - CheckedReadFileExactly(ReadPipeHandle(), &module, sizeof(module)); - - // Reopen the child process with necessary access. - HANDLE process_handle = - OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, - FALSE, - GetProcessId(ChildProcess())); - EXPECT_TRUE(process_handle); - - // Read the module annotations in the child process and verify them. - std::map annotations; - ASSERT_TRUE(ReadModuleAnnotations(process_handle, module, &annotations)); - - EXPECT_GE(annotations.size(), 3u); - EXPECT_EQ(annotations["#APITEST# key"], "value"); - EXPECT_EQ(annotations["#APITEST# x"], "y"); - EXPECT_EQ(annotations["#APITEST# empty_value"], ""); - - // Signal the child process to terminate. - char c = ' '; - CheckedWriteFile(WritePipeHandle(), &c, sizeof(c)); - } - - void WinMultiprocessChild() override { - // Set some test annotations. - crashpad::CrashpadInfo* crashpad_info = - crashpad::CrashpadInfo::GetCrashpadInfo(); - - crashpad::SimpleStringDictionary* simple_annotations = - new crashpad::SimpleStringDictionary(); - simple_annotations->SetKeyValue("#APITEST# key", "value"); - simple_annotations->SetKeyValue("#APITEST# x", "y"); - simple_annotations->SetKeyValue("#APITEST# empty_value", ""); - - crashpad_info->set_simple_annotations(simple_annotations); - - // Send the executable module. - HMODULE module = GetModuleHandle(nullptr); - CheckedWriteFile(WritePipeHandle(), &module, sizeof(module)); - - // Wait until a signal from the parent process to terminate. - char c; - CheckedReadFileExactly(ReadPipeHandle(), &c, sizeof(c)); - } -}; - -TEST(ModuleAnnotationsWin, ReadAnnotations) { - WinMultiprocess::Run(); -} - -} // namespace -} // namespace test -} // namespace crashpad diff --git a/snapshot/snapshot.gyp b/snapshot/snapshot.gyp index ac7de298..8c563f52 100644 --- a/snapshot/snapshot.gyp +++ b/snapshot/snapshot.gyp @@ -210,32 +210,5 @@ }], ], }, - { - 'variables': { - 'conditions': [ - ['OS == "win"', { - 'snapshot_api_target_type%': 'static_library', - }, { - # There are no source files except on Windows. - 'snapshot_api_target_type%': 'none', - }], - ], - }, - 'target_name': 'crashpad_snapshot_api', - 'type': '<(snapshot_api_target_type)', - 'dependencies': [ - 'crashpad_snapshot', - '../compat/compat.gyp:crashpad_compat', - '../third_party/mini_chromium/mini_chromium.gyp:base', - '../util/util.gyp:crashpad_util', - ], - 'include_dirs': [ - '..', - ], - 'sources': [ - 'api/module_annotations_win.cc', - 'api/module_annotations_win.h', - ], - }, ], } diff --git a/snapshot/snapshot_test.gyp b/snapshot/snapshot_test.gyp index 396be345..cf7b8aec 100644 --- a/snapshot/snapshot_test.gyp +++ b/snapshot/snapshot_test.gyp @@ -57,7 +57,6 @@ 'crashpad_snapshot_test_module_large', 'crashpad_snapshot_test_module_small', 'snapshot.gyp:crashpad_snapshot', - 'snapshot.gyp:crashpad_snapshot_api', '../client/client.gyp:crashpad_client', '../compat/compat.gyp:crashpad_compat', '../test/test.gyp:crashpad_gtest_main', @@ -70,7 +69,6 @@ '..', ], 'sources': [ - 'api/module_annotations_win_test.cc', 'cpu_context_test.cc', 'memory_snapshot_test.cc', 'crashpad_info_client_options_test.cc',