From f044345c23c0324942b7375e7a09558267651523 Mon Sep 17 00:00:00 2001 From: "benchan@chromium.org" Date: Fri, 16 Dec 2011 16:42:59 +0000 Subject: Refactor code in preparation of merging with the fork in Chromium OS. This patch is part of a bigger patch that helps merging the breakpad code with the modified version in Chromium OS. Specifically, this patch makes the following changes: 1. Add a MemoryRange class for encapsulating and checking read access to a contiguous range of memory. 2. Add a MemoryMappedFile class for mapping a file into memory for read-only access. 3. Refactor other source code to use MemoryMappedFile. BUG=455 TEST=Tested the following: 1. Build on 32-bit and 64-bit Linux with gcc 4.4.3 and gcc 4.6. 2. Build on Mac OS X 10.6.8 with gcc 4.2 and clang 3.0 (with latest gmock). 3. All unit tests pass. 4. Run minidump-2-core to covnert a minidump file to a core file. Review URL: http://breakpad.appspot.com/332001 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@895 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/linux/minidump_writer/linux_dumper.cc | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/client/linux/minidump_writer') diff --git a/src/client/linux/minidump_writer/linux_dumper.cc b/src/client/linux/minidump_writer/linux_dumper.cc index ab3a5ea5..f4ab5b1f 100644 --- a/src/client/linux/minidump_writer/linux_dumper.cc +++ b/src/client/linux/minidump_writer/linux_dumper.cc @@ -56,6 +56,7 @@ #include "client/linux/minidump_writer/line_reader.h" #include "common/linux/file_id.h" #include "common/linux/linux_libc_support.h" +#include "common/linux/memory_mapped_file.h" #include "third_party/lss/linux_syscall_support.h" static const char kMappedFileUnsafePrefix[] = "/dev/"; @@ -237,24 +238,12 @@ LinuxDumper::ElfFileIdentifierForMapping(const MappingInfo& mapping, filename[filename_len] = '\0'; bool filename_modified = HandleDeletedFileInMapping(filename); - int fd = sys_open(filename, O_RDONLY, 0); - if (fd < 0) - return false; - struct kernel_stat st; - if (sys_fstat(fd, &st) != 0) { - sys_close(fd); - return false; - } -#if defined(__x86_64) -#define sys_mmap2 sys_mmap -#endif - void* base = sys_mmap2(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - sys_close(fd); - if (base == MAP_FAILED) + MemoryMappedFile mapped_file(filename); + if (!mapped_file.data()) // Should probably check if size >= ElfW(Ehdr)? return false; - bool success = FileID::ElfFileIdentifierFromMappedFile(base, identifier); - sys_munmap(base, st.st_size); + bool success = + FileID::ElfFileIdentifierFromMappedFile(mapped_file.data(), identifier); if (success && member && filename_modified) { mappings_[mapping_id]->name[filename_len - sizeof(kDeletedSuffix) + 1] = '\0'; -- cgit v1.2.1