ptrace.c 4.5 KB

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