-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrace.go
76 lines (66 loc) · 1.49 KB
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
syscall "golang.org/x/sys/unix"
)
/*
* This file contains struct declarations and helper functions
* for the feedback/coverage functionality used by the harness.
*/
/*
* Basic unit of code coverage which forms an execution trace.
* Generated for every syscall trap.
* rax: syscall number
*/
type regSet struct {
rax uint64
}
/*
* Trace of a single program execution.
* trace: list of regSet structs generated through a program run.
*/
type execTrace struct {
trace []regSet
}
/*
* Grabs registers of interest from a register set.
* Returns a newly created regSet struct.
*/
func getInterestingRegs(regs *syscall.PtraceRegs) regSet {
r := regSet{rax: regs.Orig_rax}
return r
}
/*
* Compares two regSet structs.
* Returns whether they contain the same elements.
*/
func sameRegs(r1, r2 regSet) bool {
return r1.rax == r2.rax
}
/*
* Compares two execTrace structs.
* Returns whether they contain the same elements.
*/
func sameTrace(t1, t2 execTrace) bool {
// Fastpath: length mismatch.
if len(t1.trace) != len(t2.trace) {
return false
}
for i := 0; i < len(t1.trace); i++ {
if sameRegs(t1.trace[i], t2.trace[i]) == false {
return false
}
}
return true
}
/*
* Checks whether a given execTrace is unique in a slice of execTraces.
* Returns true if it is unique.
*/
func isUniqueTrace(curExecTrace execTrace, listExecTrace []execTrace) bool {
for _, t := range listExecTrace {
if sameTrace(curExecTrace, t) {
return false
}
}
return true
}