syscall_aix_ppc.go 1.7 KB

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