Debian Codegraph @

libgo/go/syscall/syscall_aix_ppc.go

raw
1 // syscall_aix_ppc.go -- AIX 32-bit specific support
2
3 // Copyright 2017 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package syscall
8
9 import "unsafe"
10
11 //sys ptrace(request int, id int, addr uintptr, data int, buff uintptr) (val int)
12 //ptrace(request _C_int, id int, addr uintptr, data _C_int, buff *byte) _C_int
13
14 // AIX does not define a specific structure but instead uses separate
15 // ptrace calls for the different registers.
16 type PtraceRegs struct {
17 Gpr [32]uint32
18 Iar uint32
19 Msr uint32
20 Cr uint32
21 Lr uint32
22 Ctr uint32
23 Xer uint32
24 }
25
26 func (r *PtraceRegs) PC() uint64 { return uint64(r.Iar) }
27
28 func (r *PtraceRegs) SetPC(pc uint64) { r.Iar = uint32(pc) }
29
30 func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
31 ptrace(_PT_REGSET, pid, uintptr(unsafe.Pointer(&regsout.Gpr[0])), 0, 0)
32 regsout.Iar = uint32(ptrace(_PT_READ_GPR, pid, 128, 0, 0))
33 regsout.Msr = uint32(ptrace(_PT_READ_GPR, pid, 129, 0, 0))
34 regsout.Cr = uint32(ptrace(_PT_READ_GPR, pid, 130, 0, 0))
35 regsout.Lr = uint32(ptrace(_PT_READ_GPR, pid, 131, 0, 0))
36 regsout.Ctr = uint32(ptrace(_PT_READ_GPR, pid, 132, 0, 0))
37 regsout.Xer = uint32(ptrace(_PT_READ_GPR, pid, 133, 0, 0))
38 return nil
39 }
40
41 func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) {
42 for i := 0; i < len(regs.Gpr); i++ {
43 ptrace(_PT_WRITE_GPR, pid, uintptr(i), int(regs.Gpr[i]), 0)
44 }
45 ptrace(_PT_WRITE_GPR, pid, 128, int(regs.Iar), 0)
46 ptrace(_PT_WRITE_GPR, pid, 129, int(regs.Msr), 0)
47 ptrace(_PT_WRITE_GPR, pid, 130, int(regs.Cr), 0)
48 ptrace(_PT_WRITE_GPR, pid, 131, int(regs.Lr), 0)
49 ptrace(_PT_WRITE_GPR, pid, 132, int(regs.Ctr), 0)
50 ptrace(_PT_WRITE_GPR, pid, 133, int(regs.Xer), 0)
51 return nil
52 }