ptrace.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "linux/sched.h"
  2. #include "asm/ptrace.h"
  3. int putreg(struct task_struct *child, unsigned long regno,
  4. unsigned long value)
  5. {
  6. child->thread.process_regs.regs[regno >> 2] = value;
  7. return 0;
  8. }
  9. int poke_user(struct task_struct *child, long addr, long data)
  10. {
  11. if ((addr & 3) || addr < 0)
  12. return -EIO;
  13. if (addr < MAX_REG_OFFSET)
  14. return putreg(child, addr, data);
  15. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  16. (addr <= offsetof(struct user, u_debugreg[7]))){
  17. addr -= offsetof(struct user, u_debugreg[0]);
  18. addr = addr >> 2;
  19. if((addr == 4) || (addr == 5)) return -EIO;
  20. child->thread.arch.debugregs[addr] = data;
  21. return 0;
  22. }
  23. return -EIO;
  24. }
  25. unsigned long getreg(struct task_struct *child, unsigned long regno)
  26. {
  27. unsigned long retval = ~0UL;
  28. retval &= child->thread.process_regs.regs[regno >> 2];
  29. return retval;
  30. }
  31. int peek_user(struct task_struct *child, long addr, long data)
  32. {
  33. /* read the word at location addr in the USER area. */
  34. unsigned long tmp;
  35. if ((addr & 3) || addr < 0)
  36. return -EIO;
  37. tmp = 0; /* Default return condition */
  38. if(addr < MAX_REG_OFFSET){
  39. tmp = getreg(child, addr);
  40. }
  41. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  42. (addr <= offsetof(struct user, u_debugreg[7]))){
  43. addr -= offsetof(struct user, u_debugreg[0]);
  44. addr = addr >> 2;
  45. tmp = child->thread.arch.debugregs[addr];
  46. }
  47. return put_user(tmp, (unsigned long *) data);
  48. }