[PATCH x86/mm 06/11] x86 ptrace arch merge

From: Roland McGrath
Date: Thu Nov 29 2007 - 07:01:42 EST



This adds 64-bit support to arch_ptrace in arch/x86/kernel/ptrace.c,
so this function can be used for native ptrace on both 32 and 64.

Signed-off-by: Roland McGrath <roland@xxxxxxxxxx>
---
arch/x86/kernel/ptrace.c | 65 ++++++++++++++++++++++++---------------------
1 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index f42f8d2..f4355f3 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -461,12 +461,13 @@ static int ptrace_set_debugreg(struct task_struct *child,
void ptrace_disable(struct task_struct *child)
{
user_disable_single_step(child);
+#ifdef TIF_SYSCALL_EMU
clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
+#endif
}

long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{
- struct user * dummy = NULL;
int i, ret;
unsigned long __user *datap = (unsigned long __user *)data;

@@ -482,18 +483,17 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
unsigned long tmp;

ret = -EIO;
- if ((addr & 3) || addr < 0 ||
- addr > sizeof(struct user) - 3)
+ if ((addr & (sizeof(data) - 1)) || addr < 0 ||
+ addr >= sizeof(struct user))
break;

tmp = 0; /* Default return condition */
- if(addr < FRAME_SIZE*sizeof(long))
+ if (addr < sizeof(struct user_regs_struct))
tmp = getreg(child, addr);
- if(addr >= (long) &dummy->u_debugreg[0] &&
- addr <= (long) &dummy->u_debugreg[7]){
- addr -= (long) &dummy->u_debugreg[0];
- addr = addr >> 2;
- tmp = ptrace_get_debugreg(child, addr);
+ else if (addr >= offsetof(struct user, u_debugreg[0]) &&
+ addr <= offsetof(struct user, u_debugreg[7])) {
+ addr -= offsetof(struct user, u_debugreg[0]);
+ tmp = ptrace_get_debugreg(child, addr / sizeof(data));
}
ret = put_user(tmp, datap);
break;
@@ -507,34 +507,26 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)

case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
ret = -EIO;
- if ((addr & 3) || addr < 0 ||
- addr > sizeof(struct user) - 3)
+ if ((addr & (sizeof(data) - 1)) || addr < 0 ||
+ addr >= sizeof(struct user))
break;

- if (addr < FRAME_SIZE*sizeof(long)) {
+ if (addr < sizeof(struct user_regs_struct))
ret = putreg(child, addr, data);
- break;
+ else if (addr >= offsetof(struct user, u_debugreg[0]) &&
+ addr <= offsetof(struct user, u_debugreg[7])) {
+ addr -= offsetof(struct user, u_debugreg[0]);
+ ret = ptrace_set_debugreg(child,
+ addr / sizeof(data), data);
}
- /* We need to be very careful here. We implicitly
- want to modify a portion of the task_struct, and we
- have to be selective about what portions we allow someone
- to modify. */
-
- ret = -EIO;
- if(addr >= (long) &dummy->u_debugreg[0] &&
- addr <= (long) &dummy->u_debugreg[7]){
- addr -= (long) &dummy->u_debugreg;
- addr = addr >> 2;
- ret = ptrace_set_debugreg(child, addr, data);
- }
- break;
+ break;

case PTRACE_GETREGS: { /* Get all gp regs from the child. */
- if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) {
+ if (!access_ok(VERIFY_WRITE, datap, sizeof(struct user_regs_struct))) {
ret = -EIO;
break;
}
- for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
+ for (i = 0; i < sizeof(struct user_regs_struct); i += sizeof(long)) {
__put_user(getreg(child, i), datap);
datap++;
}
@@ -544,11 +536,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)

case PTRACE_SETREGS: { /* Set all gp regs in the child. */
unsigned long tmp;
- if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) {
+ if (!access_ok(VERIFY_READ, datap, sizeof(struct user_regs_struct))) {
ret = -EIO;
break;
}
- for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
+ for (i = 0; i < sizeof(struct user_regs_struct); i += sizeof(long)) {
__get_user(tmp, datap);
putreg(child, i, tmp);
datap++;
@@ -582,6 +574,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
break;
}

+#ifdef CONFIG_X86_32
case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */
if (!access_ok(VERIFY_WRITE, datap,
sizeof(struct user_fxsr_struct))) {
@@ -604,7 +597,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
break;
}
+#endif

+#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
case PTRACE_GET_THREAD_AREA:
if (addr < 0)
return -EIO;
@@ -618,6 +613,16 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
ret = do_set_thread_area(child, addr,
(struct user_desc __user *) data, 0);
break;
+#endif
+
+#ifdef CONFIG_X86_64
+ /* normal 64bit interface to access TLS data.
+ Works just like arch_prctl, except that the arguments
+ are reversed. */
+ case PTRACE_ARCH_PRCTL:
+ ret = do_arch_prctl(child, data, addr);
+ break;
+#endif

default:
ret = ptrace_request(child, request, addr, data);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/