Skip to content

Commit

Permalink
Handle misaligned pages in the core dump.
Browse files Browse the repository at this point in the history
  • Loading branch information
randall77 committed Nov 8, 2017
1 parent e2c03d6 commit 96a8494
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions core/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,33 @@ func Core(coreFile, base string) (*Process, error) {
}

// Memory map all the mappings.
pgsize := int64(syscall.Getpagesize())
for _, m := range maps {
size := m.max.Sub(m.min)
if m.f == nil {
// Pretend this is read-as-zero.
m.contents = make([]byte, m.max.Sub(m.min))
m.contents = make([]byte, size)
continue
}
// Data in core file might not be aligned. Expand memory range
// so we can mmap full pages.
minOff := m.off
maxOff := m.off + size
if minOff%pgsize != 0 {
minOff -= minOff % pgsize
}
if maxOff%pgsize != 0 {
maxOff += pgsize - maxOff%pgsize
}
var err error
m.contents, err = syscall.Mmap(int(m.f.Fd()), m.off, int(m.max.Sub(m.min)), syscall.PROT_READ, syscall.MAP_SHARED)
m.contents, err = syscall.Mmap(int(m.f.Fd()), minOff, int(maxOff-minOff), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return nil, fmt.Errorf("can't memory map %s at %d: %s\n", m.f, m.off, err)
return nil, fmt.Errorf("can't memory map %s at %x: %s\n", m.f, m.off, err)
}

// Trim any data we mapped but don't need.
m.contents = m.contents[m.off-minOff:]
m.contents = m.contents[:size]
}

// Build page table for mapping lookup.
Expand Down

0 comments on commit 96a8494

Please sign in to comment.