2015-06-12 19:49:23 +00:00
|
|
|
package proc
|
2015-04-29 17:07:27 +00:00
|
|
|
|
2016-01-10 08:57:52 +00:00
|
|
|
// Arch defines an interface for representing a
|
|
|
|
// CPU architecture.
|
2015-04-29 17:07:27 +00:00
|
|
|
type Arch interface {
|
|
|
|
PtrSize() int
|
|
|
|
BreakpointInstruction() []byte
|
|
|
|
BreakpointSize() int
|
2017-02-15 13:41:03 +00:00
|
|
|
DerefTLS() bool
|
2015-04-29 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 11:47:54 +00:00
|
|
|
// AMD64 represents the AMD64 CPU architecture.
|
2015-04-29 17:07:27 +00:00
|
|
|
type AMD64 struct {
|
2015-06-17 18:09:55 +00:00
|
|
|
ptrSize int
|
|
|
|
breakInstruction []byte
|
|
|
|
breakInstructionLen int
|
2015-07-28 05:33:07 +00:00
|
|
|
gStructOffset uint64
|
2015-06-17 18:09:55 +00:00
|
|
|
hardwareBreakpointUsage []bool
|
2017-04-06 18:14:01 +00:00
|
|
|
goos string
|
2015-04-29 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 08:57:52 +00:00
|
|
|
// AMD64Arch returns an initialized AMD64
|
|
|
|
// struct.
|
2017-04-06 18:14:01 +00:00
|
|
|
func AMD64Arch(goos string) *AMD64 {
|
2015-07-23 17:08:28 +00:00
|
|
|
var breakInstr = []byte{0xCC}
|
|
|
|
|
|
|
|
return &AMD64{
|
|
|
|
ptrSize: 8,
|
|
|
|
breakInstruction: breakInstr,
|
|
|
|
breakInstructionLen: len(breakInstr),
|
|
|
|
hardwareBreakpointUsage: make([]bool, 4),
|
2017-04-06 18:14:01 +00:00
|
|
|
goos: goos,
|
2015-07-23 17:08:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 08:57:52 +00:00
|
|
|
// PtrSize returns the size of a pointer
|
|
|
|
// on this architecture.
|
2015-04-29 17:07:27 +00:00
|
|
|
func (a *AMD64) PtrSize() int {
|
|
|
|
return a.ptrSize
|
|
|
|
}
|
|
|
|
|
2016-01-10 08:57:52 +00:00
|
|
|
// BreakpointInstruction returns the Breakpoint
|
|
|
|
// instruction for this architecture.
|
2015-04-29 17:07:27 +00:00
|
|
|
func (a *AMD64) BreakpointInstruction() []byte {
|
|
|
|
return a.breakInstruction
|
|
|
|
}
|
|
|
|
|
2016-01-10 08:57:52 +00:00
|
|
|
// BreakpointSize returns the size of the
|
|
|
|
// breakpoint instruction on this architecture.
|
2015-04-29 17:07:27 +00:00
|
|
|
func (a *AMD64) BreakpointSize() int {
|
|
|
|
return a.breakInstructionLen
|
|
|
|
}
|
2015-06-11 20:17:56 +00:00
|
|
|
|
2017-02-15 13:41:03 +00:00
|
|
|
// If DerefTLS returns true the value of regs.TLS()+GStructOffset() is a
|
|
|
|
// pointer to the G struct
|
|
|
|
func (a *AMD64) DerefTLS() bool {
|
|
|
|
return a.goos == "windows"
|
|
|
|
}
|