aboutsummaryrefslogtreecommitdiff
path: root/src/client/linux/minidump_writer
diff options
context:
space:
mode:
authorbenchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2011-12-16 16:42:59 +0000
committerbenchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2011-12-16 16:42:59 +0000
commitf044345c23c0324942b7375e7a09558267651523 (patch)
tree55a0847ef9681e390bad9c97458c352cc1da75ed /src/client/linux/minidump_writer
parentFix ContextDeathTest.X86BadFlags unit test on Mac OS X. (diff)
downloadbreakpad-f044345c23c0324942b7375e7a09558267651523.tar.xz
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
Diffstat (limited to 'src/client/linux/minidump_writer')
-rw-r--r--src/client/linux/minidump_writer/linux_dumper.cc21
1 files changed, 5 insertions, 16 deletions
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';