ptrace.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright 2003 PathScale, Inc.
  3. *
  4. * Licensed under the GPL
  5. */
  6. #define __FRAME_OFFSETS
  7. #include <asm/ptrace.h>
  8. #include <linux/sched.h>
  9. #include <linux/errno.h>
  10. #include <asm/uaccess.h>
  11. #include <asm/elf.h>
  12. /* XXX x86_64 */
  13. unsigned long not_ss;
  14. unsigned long not_ds;
  15. unsigned long not_es;
  16. #define SC_SS(r) (not_ss)
  17. #define SC_DS(r) (not_ds)
  18. #define SC_ES(r) (not_es)
  19. /* determines which flags the user has access to. */
  20. /* 1 = access 0 = no access */
  21. #define FLAG_MASK 0x44dd5UL
  22. int putreg(struct task_struct *child, int regno, unsigned long value)
  23. {
  24. unsigned long tmp;
  25. #ifdef TIF_IA32
  26. /* Some code in the 64bit emulation may not be 64bit clean.
  27. Don't take any chances. */
  28. if (test_tsk_thread_flag(child, TIF_IA32))
  29. value &= 0xffffffff;
  30. #endif
  31. switch (regno){
  32. case FS:
  33. case GS:
  34. case DS:
  35. case ES:
  36. case SS:
  37. case CS:
  38. if (value && (value & 3) != 3)
  39. return -EIO;
  40. value &= 0xffff;
  41. break;
  42. case FS_BASE:
  43. case GS_BASE:
  44. if (!((value >> 48) == 0 || (value >> 48) == 0xffff))
  45. return -EIO;
  46. break;
  47. case EFLAGS:
  48. value &= FLAG_MASK;
  49. tmp = PT_REGS_EFLAGS(&child->thread.regs) & ~FLAG_MASK;
  50. value |= tmp;
  51. break;
  52. }
  53. PT_REGS_SET(&child->thread.regs, regno, value);
  54. return 0;
  55. }
  56. int poke_user(struct task_struct *child, long addr, long data)
  57. {
  58. if ((addr & 3) || addr < 0)
  59. return -EIO;
  60. if (addr < MAX_REG_OFFSET)
  61. return putreg(child, addr, data);
  62. #if 0 /* Need x86_64 debugregs handling */
  63. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  64. (addr <= offsetof(struct user, u_debugreg[7]))){
  65. addr -= offsetof(struct user, u_debugreg[0]);
  66. addr = addr >> 2;
  67. if((addr == 4) || (addr == 5)) return -EIO;
  68. child->thread.arch.debugregs[addr] = data;
  69. return 0;
  70. }
  71. #endif
  72. return -EIO;
  73. }
  74. unsigned long getreg(struct task_struct *child, int regno)
  75. {
  76. unsigned long retval = ~0UL;
  77. switch (regno) {
  78. case FS:
  79. case GS:
  80. case DS:
  81. case ES:
  82. case SS:
  83. case CS:
  84. retval = 0xffff;
  85. /* fall through */
  86. default:
  87. retval &= PT_REG(&child->thread.regs, regno);
  88. #ifdef TIF_IA32
  89. if (test_tsk_thread_flag(child, TIF_IA32))
  90. retval &= 0xffffffff;
  91. #endif
  92. }
  93. return retval;
  94. }
  95. int peek_user(struct task_struct *child, long addr, long data)
  96. {
  97. /* read the word at location addr in the USER area. */
  98. unsigned long tmp;
  99. if ((addr & 3) || addr < 0)
  100. return -EIO;
  101. tmp = 0; /* Default return condition */
  102. if(addr < MAX_REG_OFFSET){
  103. tmp = getreg(child, addr);
  104. }
  105. #if 0 /* Need x86_64 debugregs handling */
  106. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  107. (addr <= offsetof(struct user, u_debugreg[7]))){
  108. addr -= offsetof(struct user, u_debugreg[0]);
  109. addr = addr >> 2;
  110. tmp = child->thread.arch.debugregs[addr];
  111. }
  112. #endif
  113. return put_user(tmp, (unsigned long *) data);
  114. }
  115. void arch_switch(void)
  116. {
  117. /* XXX
  118. printk("arch_switch\n");
  119. */
  120. }
  121. int is_syscall(unsigned long addr)
  122. {
  123. panic("is_syscall");
  124. }
  125. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
  126. {
  127. panic("dump_fpu");
  128. return(1);
  129. }
  130. int get_fpregs(unsigned long buf, struct task_struct *child)
  131. {
  132. panic("get_fpregs");
  133. return(0);
  134. }
  135. int set_fpregs(unsigned long buf, struct task_struct *child)
  136. {
  137. panic("set_fpregs");
  138. return(0);
  139. }
  140. int get_fpxregs(unsigned long buf, struct task_struct *tsk)
  141. {
  142. panic("get_fpxregs");
  143. return(0);
  144. }
  145. int set_fpxregs(unsigned long buf, struct task_struct *tsk)
  146. {
  147. panic("set_fxpregs");
  148. return(0);
  149. }
  150. /*
  151. * Overrides for Emacs so that we follow Linus's tabbing style.
  152. * Emacs will notice this stuff at the end of the file and automatically
  153. * adjust the settings for this buffer only. This must remain at the end
  154. * of the file.
  155. * ---------------------------------------------------------------------------
  156. * Local variables:
  157. * c-file-style: "linux"
  158. * End:
  159. */