Skip to content

Commit

Permalink
initial mmap desc/file now trace-serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs committed Sep 11, 2017
1 parent 3ad32b0 commit df9a2d5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go/models/mmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
type Mmap struct {
Addr, Size uint64
Prot int
File *FileDesc
Desc string
File *FileDesc
}

func (m *Mmap) Contains(addr uint64) bool {
Expand Down
14 changes: 9 additions & 5 deletions go/models/trace/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ type OpMemMap struct {
Size uint64
Prot uint8

New uint8
New bool
Desc string
File string
Off uint64
Expand All @@ -273,13 +273,17 @@ func (o *OpMemMap) Pack(w io.Writer) (int, error) {
order.PutUint64(tmp[1:], o.Addr)
order.PutUint64(tmp[9:], o.Size)
tmp[17] = o.Prot
tmp[18] = o.New
if o.New {
tmp[18] = 1
} else {
tmp[18] = 0
}
n, err := w.Write(tmp[:])
if err != nil {
return n, err
}
total := n
if o.New > 0 {
if o.New {
desc, file := []byte(o.Desc), []byte(o.File)
tmp := make([]byte, 2+2+8+len(desc)+len(file))

Expand All @@ -302,8 +306,8 @@ func (o *OpMemMap) Unpack(r io.Reader) (int, error) {
o.Addr = order.Uint64(tmp[:])
o.Size = order.Uint64(tmp[8:])
o.Prot = tmp[16]
o.New = tmp[17]
if o.New > 0 {
o.New = tmp[17] > 0
if o.New {
tmp := make([]byte, 2+2+8)
n, err := io.ReadFull(r, tmp[:])
total += n
Expand Down
6 changes: 3 additions & 3 deletions go/models/trace/ops_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (o *OpMemWrite) MarshalJSON() ([]byte, error) {

func (o *OpMemMap) MarshalJSON() ([]byte, error) {
extra := ""
if o.New > 0 {
if o.New {
desc, err := json.Marshal(o.Desc)
if err != nil {
return nil, err
Expand All @@ -57,9 +57,9 @@ func (o *OpMemMap) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
extra = fmt.Sprintf(`,"desc":%s,"name":%s,"off":%d`, desc, file, o.Off)
extra = fmt.Sprintf(`,"desc":%s,"file":%s,"off":%d`, desc, file, o.Off)
}
return bprintf(`{"op":%d,"addr":%d,"size":%d,"prot":%d,"new":%d%s}`, OP_MEM_MAP, o.Addr, o.Size, o.Prot, o.New, extra), nil
return bprintf(`{"op":%d,"addr":%d,"size":%d,"prot":%d,"new":%v%s}`, OP_MEM_MAP, o.Addr, o.Size, o.Prot, o.New, extra), nil
}

func (o *OpMemUnmap) MarshalJSON() ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions go/models/trace/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
// these OPs are ordered to be semi-valid, so not by number
var allButSyscall = []models.Op{
&OpNop{},
&OpMemMap{0x1000, 0x1000, 7, 0, "", "", 0},
&OpMemMap{0x1000, 0x1000, 7, 1, "desc", "filename", 1234},
&OpMemMap{0x1000, 0x1000, 7, false, "", "", 0},
&OpMemMap{0x1000, 0x1000, 7, true, "desc", "filename", 1234},
&OpMemWrite{0x1000, []byte{0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00}}, // mov rax, 1
&OpJmp{0x1000, 0x7},
&OpStep{0x7},
Expand Down
2 changes: 1 addition & 1 deletion go/models/trace/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *Replay) update(op models.Op) {

case *OpMemMap: // memory
r.Mem.MemMap(o.Addr, uint64(o.Size), int(o.Prot))
if o.New != 0 {
if o.New {
r.Mem.MemZero(o.Addr, o.Size)
// TODO: update desc and file here
}
Expand Down
12 changes: 6 additions & 6 deletions go/models/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (t *Trace) Attach() error {
kf := &OpKeyframe{Ops: t.frame.Ops}
t.frame = nil
for _, m := range t.u.Mappings() {
mo := &OpMemMap{Addr: m.Addr, Size: m.Size, Prot: uint8(m.Prot)}
mo := &OpMemMap{Addr: m.Addr, Size: m.Size, Prot: uint8(m.Prot), New: true, Desc: m.Desc}
if m.File != nil {
mo.File = m.File.Name
mo.Off = m.File.Off
}
kf.Ops = append(kf.Ops, mo)
data, err := t.u.MemRead(m.Addr, m.Size)
if err != nil {
Expand Down Expand Up @@ -309,16 +313,12 @@ func (t *Trace) OnMemWrite(addr uint64, data []byte) {
}

func (t *Trace) OnMemMap(addr, size uint64, prot int, new bool, desc string, file *models.FileDesc) {
nint := 0
if new {
nint = 1
}
var name string
var off uint64
if file != nil {
name, off = file.Name, file.Off
}
t.Append(&OpMemMap{addr, size, uint8(prot), uint8(nint), desc, name, off}, false)
t.Append(&OpMemMap{addr, size, uint8(prot), new, desc, name, off}, false)
}

func (t *Trace) OnMemUnmap(addr, size uint64) {
Expand Down
2 changes: 2 additions & 0 deletions go/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func (t *Task) Mmap(addr, size uint64, prot int, fixed bool, desc string, file *
if err != nil {
return 0, err
}
mmap.Desc = desc
mmap.File = file
err = t.Cpu.MemMap(mmap.Addr, mmap.Size, prot)
if err == nil {
for _, v := range t.mapHooks {
Expand Down

0 comments on commit df9a2d5

Please sign in to comment.