Skip to content

Commit 3b81b64

Browse files
committed
Add Readable and ReadableN functions so callers can avoid panics
from Read* methods if the address is questionable.
1 parent 49d52fe commit 3b81b64

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

core/types.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,28 @@ func (p *Process) Mappings() []*Mapping {
7777
return p.maps
7878
}
7979

80-
// Writeable reports whether the address is writeable (by the inferior at the time of the core dump).
80+
// Readable reports whether the address a is readable.
81+
func (p *Process) Readable(a Address) bool {
82+
return p.findMapping(a) != nil
83+
}
84+
85+
// ReadableN reports whether the n bytes starting at address a are readable.
86+
func (p *Process) ReadableN(a Address, n int64) bool {
87+
for {
88+
m := p.findMapping(a)
89+
if m == nil || m.perm&Read == 0 {
90+
return false
91+
}
92+
c := m.max.Sub(a)
93+
if n <= c {
94+
return true
95+
}
96+
n -= c
97+
a = a.Add(c)
98+
}
99+
}
100+
101+
// Writeable reports whether the address a was writeable (by the inferior at the time of the core dump).
81102
func (p *Process) Writeable(a Address) bool {
82103
m := p.findMapping(a)
83104
if m == nil {

0 commit comments

Comments
 (0)