浏览代码

unix: use struct pt_regs for PtraceRegs on mips

On mips, "struct user" bears no relation to the actual structure used by
PTRACE_GETREGS. The real structure is "struct pt_regs" which is declared
in asm/ptrace.h

Fixes golang/go#20338.

Change-Id: I604d27bd2b0a0903784380cbd3fa2fd9b9811fa5
Reviewed-on: https://go-review.googlesource.com/43431
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
James Cowgill 8 年之前
父节点
当前提交
156c5a2da4

+ 1 - 3
unix/linux/types.go

@@ -163,10 +163,8 @@ struct my_sockaddr_un {
 typedef struct user_regs PtraceRegs;
 #elif defined(__aarch64__)
 typedef struct user_pt_regs PtraceRegs;
-#elif defined(__powerpc64__)
+#elif defined(__mips__) || defined(__powerpc64__)
 typedef struct pt_regs PtraceRegs;
-#elif defined(__mips__)
-typedef struct user PtraceRegs;
 #elif defined(__s390x__)
 typedef struct _user_regs_struct PtraceRegs;
 #elif defined(__sparc__)

+ 2 - 2
unix/syscall_linux_mips64x.go

@@ -183,9 +183,9 @@ func fillStat_t(s *Stat_t, st *stat_t) {
 	s.Blocks = st.Blocks
 }
 
-func (r *PtraceRegs) PC() uint64 { return r.Regs[64] }
+func (r *PtraceRegs) PC() uint64 { return r.Epc }
 
-func (r *PtraceRegs) SetPC(pc uint64) { r.Regs[64] = pc }
+func (r *PtraceRegs) SetPC(pc uint64) { r.Epc = pc }
 
 func (iov *Iovec) SetLen(length int) {
 	iov.Len = uint64(length)

+ 2 - 2
unix/syscall_linux_mipsx.go

@@ -211,9 +211,9 @@ func Setrlimit(resource int, rlim *Rlimit) (err error) {
 	return setrlimit(resource, &rl)
 }
 
-func (r *PtraceRegs) PC() uint64 { return uint64(r.Regs[64]) }
+func (r *PtraceRegs) PC() uint64 { return r.Epc }
 
-func (r *PtraceRegs) SetPC(pc uint64) { r.Regs[64] = uint32(pc) }
+func (r *PtraceRegs) SetPC(pc uint64) { r.Epc = pc }
 
 func (iov *Iovec) SetLen(length int) {
 	iov.Len = uint32(length)

+ 7 - 11
unix/ztypes_linux_mips.go

@@ -568,17 +568,13 @@ type InotifyEvent struct {
 const SizeofInotifyEvent = 0x10
 
 type PtraceRegs struct {
-	Regs        [109]uint32
-	U_tsize     uint32
-	U_dsize     uint32
-	U_ssize     uint32
-	Start_code  uint32
-	Start_data  uint32
-	Start_stack uint32
-	Signal      int32
-	U_ar0       *byte
-	Magic       uint32
-	U_comm      [32]int8
+	Regs     [32]uint64
+	Lo       uint64
+	Hi       uint64
+	Epc      uint64
+	Badvaddr uint64
+	Status   uint64
+	Cause    uint64
 }
 
 type FdSet struct {

+ 7 - 11
unix/ztypes_linux_mips64.go

@@ -570,17 +570,13 @@ type InotifyEvent struct {
 const SizeofInotifyEvent = 0x10
 
 type PtraceRegs struct {
-	Regs        [102]uint64
-	U_tsize     uint64
-	U_dsize     uint64
-	U_ssize     uint64
-	Start_code  uint64
-	Start_data  uint64
-	Start_stack uint64
-	Signal      int64
-	U_ar0       uint64
-	Magic       uint64
-	U_comm      [32]int8
+	Regs     [32]uint64
+	Lo       uint64
+	Hi       uint64
+	Epc      uint64
+	Badvaddr uint64
+	Status   uint64
+	Cause    uint64
 }
 
 type FdSet struct {

+ 7 - 11
unix/ztypes_linux_mips64le.go

@@ -570,17 +570,13 @@ type InotifyEvent struct {
 const SizeofInotifyEvent = 0x10
 
 type PtraceRegs struct {
-	Regs        [102]uint64
-	U_tsize     uint64
-	U_dsize     uint64
-	U_ssize     uint64
-	Start_code  uint64
-	Start_data  uint64
-	Start_stack uint64
-	Signal      int64
-	U_ar0       uint64
-	Magic       uint64
-	U_comm      [32]int8
+	Regs     [32]uint64
+	Lo       uint64
+	Hi       uint64
+	Epc      uint64
+	Badvaddr uint64
+	Status   uint64
+	Cause    uint64
 }
 
 type FdSet struct {

+ 7 - 11
unix/ztypes_linux_mipsle.go

@@ -568,17 +568,13 @@ type InotifyEvent struct {
 const SizeofInotifyEvent = 0x10
 
 type PtraceRegs struct {
-	Regs        [109]uint32
-	U_tsize     uint32
-	U_dsize     uint32
-	U_ssize     uint32
-	Start_code  uint32
-	Start_data  uint32
-	Start_stack uint32
-	Signal      int32
-	U_ar0       *byte
-	Magic       uint32
-	U_comm      [32]int8
+	Regs     [32]uint64
+	Lo       uint64
+	Hi       uint64
+	Epc      uint64
+	Badvaddr uint64
+	Status   uint64
+	Cause    uint64
 }
 
 type FdSet struct {