ptrace.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/elf.h"
  11. /* XXX x86_64 */
  12. unsigned long not_ss;
  13. unsigned long not_ds;
  14. unsigned long not_es;
  15. #define SC_SS(r) (not_ss)
  16. #define SC_DS(r) (not_ds)
  17. #define SC_ES(r) (not_es)
  18. /* determines which flags the user has access to. */
  19. /* 1 = access 0 = no access */
  20. #define FLAG_MASK 0x44dd5UL
  21. int putreg(struct task_struct *child, int regno, unsigned long value)
  22. {
  23. unsigned long tmp;
  24. #ifdef TIF_IA32
  25. /* Some code in the 64bit emulation may not be 64bit clean.
  26. Don't take any chances. */
  27. if (test_tsk_thread_flag(child, TIF_IA32))
  28. value &= 0xffffffff;
  29. #endif
  30. switch (regno){
  31. case FS:
  32. case GS:
  33. case DS:
  34. case ES:
  35. case SS:
  36. case CS:
  37. if (value && (value & 3) != 3)
  38. return -EIO;
  39. value &= 0xffff;
  40. break;
  41. case FS_BASE:
  42. case GS_BASE:
  43. if (!((value >> 48) == 0 || (value >> 48) == 0xffff))
  44. return -EIO;
  45. break;
  46. case EFLAGS:
  47. value &= FLAG_MASK;
  48. tmp = PT_REGS_EFLAGS(&child->thread.regs) & ~FLAG_MASK;
  49. value |= tmp;
  50. break;
  51. }
  52. PT_REGS_SET(&child->thread.regs, regno, value);
  53. return 0;
  54. }
  55. int poke_user(struct task_struct *child, long addr, long data)
  56. {
  57. if ((addr & 3) || addr < 0)
  58. return -EIO;
  59. if (addr < MAX_REG_OFFSET)
  60. return putreg(child, addr, data);
  61. #if 0 /* Need x86_64 debugregs handling */
  62. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  63. (addr <= offsetof(struct user, u_debugreg[7]))){
  64. addr -= offsetof(struct user, u_debugreg[0]);
  65. addr = addr >> 2;
  66. if((addr == 4) || (addr == 5)) return -EIO;
  67. child->thread.arch.debugregs[addr] = data;
  68. return 0;
  69. }
  70. #endif
  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. #if 0 /* Need x86_64 debugregs handling */
  105. else if((addr >= offsetof(struct user, u_debugreg[0])) &&
  106. (addr <= offsetof(struct user, u_debugreg[7]))){
  107. addr -= offsetof(struct user, u_debugreg[0]);
  108. addr = addr >> 2;
  109. tmp = child->thread.arch.debugregs[addr];
  110. }
  111. #endif
  112. return put_user(tmp, (unsigned long *) data);
  113. }
  114. void arch_switch(void)
  115. {
  116. /* XXX
  117. printk("arch_switch\n");
  118. */
  119. }
  120. int is_syscall(unsigned long addr)
  121. {
  122. panic("is_syscall");
  123. }
  124. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
  125. {
  126. panic("dump_fpu");
  127. return(1);
  128. }
  129. int get_fpregs(unsigned long buf, struct task_struct *child)
  130. {
  131. panic("get_fpregs");
  132. return(0);
  133. }
  134. int set_fpregs(unsigned long buf, struct task_struct *child)
  135. {
  136. panic("set_fpregs");
  137. return(0);
  138. }
  139. int get_fpxregs(unsigned long buf, struct task_struct *tsk)
  140. {
  141. panic("get_fpxregs");
  142. return(0);
  143. }
  144. int set_fpxregs(unsigned long buf, struct task_struct *tsk)
  145. {
  146. panic("set_fxpregs");
  147. return(0);
  148. }
  149. /*
  150. * Overrides for Emacs so that we follow Linus's tabbing style.
  151. * Emacs will notice this stuff at the end of the file and automatically
  152. * adjust the settings for this buffer only. This must remain at the end
  153. * of the file.
  154. * ---------------------------------------------------------------------------
  155. * Local variables:
  156. * c-file-style: "linux"
  157. * End:
  158. */