ptrace.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. 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. return -EIO;
  72. }
  73. unsigned long getreg(struct task_struct *child, int regno)
  74. {
  75. unsigned long retval = ~0UL;
  76. switch (regno) {
  77. case FS:
  78. case GS:
  79. case DS:
  80. case ES:
  81. case SS:
  82. case CS:
  83. retval = 0xffff;
  84. /* fall through */
  85. default:
  86. retval &= PT_REG(&child->thread.regs, regno);
  87. #ifdef TIF_IA32
  88. if (test_tsk_thread_flag(child, TIF_IA32))
  89. retval &= 0xffffffff;
  90. #endif
  91. }
  92. return retval;
  93. }
  94. int peek_user(struct task_struct *child, long addr, long data)
  95. {
  96. /* read the word at location addr in the USER area. */
  97. unsigned long tmp;
  98. if ((addr & 3) || addr < 0)
  99. return -EIO;
  100. tmp = 0; /* Default return condition */
  101. if(addr < MAX_REG_OFFSET){
  102. tmp = getreg(child, addr);
  103. }
  104. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  105. (addr <= offsetof(struct user, u_debugreg[7]))){
  106. addr -= offsetof(struct user, u_debugreg[0]);
  107. addr = addr >> 2;
  108. tmp = child->thread.arch.debugregs[addr];
  109. }
  110. return put_user(tmp, (unsigned long *) data);
  111. }
  112. void arch_switch(void)
  113. {
  114. /* XXX
  115. printk("arch_switch\n");
  116. */
  117. }
  118. /* XXX Mostly copied from sys-i386 */
  119. int is_syscall(unsigned long addr)
  120. {
  121. unsigned short instr;
  122. int n;
  123. n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
  124. if(n){
  125. /* access_process_vm() grants access to vsyscall and stub,
  126. * while copy_from_user doesn't. Maybe access_process_vm is
  127. * slow, but that doesn't matter, since it will be called only
  128. * in case of singlestepping, if copy_from_user failed.
  129. */
  130. n = access_process_vm(current, addr, &instr, sizeof(instr), 0);
  131. if(n != sizeof(instr)) {
  132. printk("is_syscall : failed to read instruction from "
  133. "0x%lx\n", addr);
  134. return(1);
  135. }
  136. }
  137. /* sysenter */
  138. return(instr == 0x050f);
  139. }
  140. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
  141. {
  142. panic("dump_fpu");
  143. return(1);
  144. }
  145. int get_fpregs(unsigned long buf, struct task_struct *child)
  146. {
  147. panic("get_fpregs");
  148. return(0);
  149. }
  150. int set_fpregs(unsigned long buf, struct task_struct *child)
  151. {
  152. panic("set_fpregs");
  153. return(0);
  154. }
  155. int get_fpxregs(unsigned long buf, struct task_struct *tsk)
  156. {
  157. panic("get_fpxregs");
  158. return(0);
  159. }
  160. int set_fpxregs(unsigned long buf, struct task_struct *tsk)
  161. {
  162. panic("set_fxpregs");
  163. return(0);
  164. }
  165. /*
  166. * Overrides for Emacs so that we follow Linus's tabbing style.
  167. * Emacs will notice this stuff at the end of the file and automatically
  168. * adjust the settings for this buffer only. This must remain at the end
  169. * of the file.
  170. * ---------------------------------------------------------------------------
  171. * Local variables:
  172. * c-file-style: "linux"
  173. * End:
  174. */