RFC: Revise n32 ptrace interface
Subsystems (2)
Currently n32 uses the n64 ptrace interface. This means that it expects both of its arguments to be "long long" rather than "long", PTRACE_PEEKTEXT transfers eight bytes, et cetera. All of which has combined to cause no end of trouble for GDB.
Here's an alternative interface that I've just started testing. n32 uses the o32 ptrace interface instead, which transfers 32-bit quantities, as we'd expect from a system with 32-bit longs. There are only a couple of catches:
1. We need to get at the 64-bit registers. I considered a number of different approaches for this and decided to just implement a 64-bit PTRACE_GETREGS instead of messing with PTRACE_PEEKUSR. It's much simpler this way. I didn't add one for the DSP registers; that can be handled separately when someone's working on debug support for them...
2. While I'm fixing this interface, an n32 program ought to be able to debug an n64 program. This copies the clever trick that ppc64 uses, i.e. passing the 64-bit address via reference. Less efficient but hugely simpler.
3. PTRACE_{GET,SET}SIGINFO. I didn't even go there. N32 kernel and glibc don't even agree about the layout of struct siginfo at the moment. This should be investigated, but it's a problem for another day.
Any thoughts on the ABI change? Just for N32 of course; for o32/n64 this strictly adds new mechanisms.
NOTE: this patch is just for comments, I don't want it to go in as is. There ought to be a 32-bit GETREGS while I'm here, and I haven't written GDB support for the _3264 operations yet, so I haven't tested it much. I'll be back to work on this some more in a couple of days.
arch/mips/kernel/ptrace32.c +81 -0
@@ -35,6 +35,12 @@#include <asm/uaccess.h> #include <asm/bootinfo.h> +int ptrace_getregs64 (struct task_struct *child,__u64 __user *data); +int ptrace_setregs64 (struct task_struct *child,__u64 __user *data); + +int ptrace_getfpregs (struct task_struct *child,__u32 __user *data); +int ptrace_setfpregs (struct task_struct *child,__u32 __user *data); +/* * Tracing a 32-bit process with a 64-bit strace and vice versa will not * work. I don't know how to fix this.
@@ -99,6 +105,35 @@ asmlinkage int sys32_ptrace(int request,break ; } +/* +* Read 4 bytes of the other process' storage +* data is a pointer specifying where the user wants the +* 4 bytes copied into +* addr is a pointer in the user's storage that contains an 8 byte +* address in the other process of the 4 bytes that is to be read +* (this is run in a 32-bit process looking at a 64-bit process) +* when I and D space are separate, these will need to be fixed. +*/ +case PTRACE_PEEKTEXT_3264 : +case PTRACE_PEEKDATA_3264 : { +u32 tmp; +int copied; +u32 __user * addrOthers; + + ret = -EIO ; + +/* Get the addr in the other process that we want to read */ +if (get_user (addrOthers, (u32 __user *__user *) (unsigned long ) addr) !=0 ) +break ; + + copied =access_process_vm (child, (u64 )addrOthers, &tmp, +sizeof (tmp),0 ); +if (copied !=sizeof (tmp)) +break ; + ret =put_user (tmp, (u32 __user *) (unsigned long ) data); +break ; + } +/* Read the word at location addr in the USER area. */ case PTRACE_PEEKUSR : {struct pt_regs *regs;
@@ -202,6 +237,31 @@ asmlinkage int sys32_ptrace(int request, ret = -EIO ;break ; +/* +* Write 4 bytes into the other process' storage +* data is the 4 bytes that the user wants written +* addr is a pointer in the user's storage that contains an +* 8 byte address in the other process where the 4 bytes +* that is to be written +* (this is run in a 32-bit process looking at a 64-bit process) +* when I and D space are separate, these will need to be fixed. +*/ +case PTRACE_POKETEXT_3264 : +case PTRACE_POKEDATA_3264 : { +u32 __user * addrOthers; + +/* Get the addr in the other process that we want to write into */ + ret = -EIO ; +if (get_user (addrOthers, (u32 __user *__user *) (unsigned long ) addr) !=0 ) +break ; + ret =0 ; +if (access_process_vm (child, (u64 )addrOthers, &data, +sizeof (data),1 ) ==sizeof (data)) +break ; + ret = -EIO ; +break ; + } +case PTRACE_POKEUSR : {struct pt_regs *regs; ret =0 ;
@@ -276,6 +336,22 @@ asmlinkage int sys32_ptrace(int request,break ; } +case PTRACE_GETFPREGS : + ret =ptrace_getfpregs (child, (__u32 __user *) (__u64 ) data); +break ; + +case PTRACE_SETFPREGS : + ret =ptrace_setfpregs (child, (__u32 __user *) (__u64 ) data); +break ; + +case PTRACE_GETREGS64 : + ret =ptrace_getregs64 (child, (__u64 __user *) (__u64 ) data); +break ; + +case PTRACE_SETREGS64 : + ret =ptrace_setregs64 (child, (__u64 __user *) (__u64 ) data); +break ; +case PTRACE_SYSCALL :/* continue and stop at next (return from) syscall */ case PTRACE_CONT : {/* restart after signal. */ ret = -EIO ;
@@ -320,6 +396,11 @@ asmlinkage int sys32_ptrace(int request, (unsigned int __user *) (unsigned long) data);break ; +case PTRACE_GET_THREAD_AREA_3264 : + ret =put_user (child->thread_info->tp_value, + (unsigned long __user *) (unsigned long ) data); +break ; +default : ret =ptrace_request (child, request, addr, data);break ;
include/asm-mips/ptrace.h +13 -2
@@ -50,8 +50,8 @@ struct pt_regs {/* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ /* #define PTRACE_GETREGS 12 */ /* #define PTRACE_SETREGS 13 */ -/* #define PTRACE_GETFPREGS 14 */ -/* #define PTRACE_SETFPREGS 15 */ +#define PTRACE_GETFPREGS 14 +#define PTRACE_SETFPREGS 15/* #define PTRACE_GETFPXREGS 18 */ /* #define PTRACE_SETFPXREGS 19 */
@@ -60,6 +60,17 @@ struct pt_regs {#define PTRACE_GET_THREAD_AREA 25#define PTRACE_SET_THREAD_AREA 26 +/* Calls to trace a 64bit program from a 32bit program. */ +#define PTRACE_PEEKTEXT_3264 0xc0 +#define PTRACE_PEEKDATA_3264 0xc1 +#define PTRACE_POKETEXT_3264 0xc2 +#define PTRACE_POKEDATA_3264 0xc3 +#define PTRACE_GET_THREAD_AREA_3264 0xc4 + +/* Calls to fetch 64bit registers from an o32 or n32 program. */ +#define PTRACE_GETREGS64 0xd0 +#define PTRACE_SETREGS64 0xd1 +#ifdef __KERNEL__#include <linux/linkage.h>
arch/mips/kernel/scall64-n32.S +1 -1
@@ -216,7 +216,7 @@ EXPORT(sysn32_call_table) PTR compat_sys_getrusage PTR sys32_sysinfo PTR compat_sys_times - PTR sys_ptrace + PTR sys32_ptrace PTR sys_getuid /* 6100 */ PTR sys_syslog PTR sys_getgid
arch/mips/kernel/ptrace.c +123 -0
141 lines not on this page · raw message
Signature · 2 lines
Daniel Jacobowitz CodeSourcery, LLC
PATCH 1/1 Revise MIPS64 ptrace interface
Change the N32 debugging ABI to something more sane, and add support for o32 and n32 debuggers to trace n64 programs.
---
I've now tested everything except the actual _3264 operations, which were copied from PPC anyway and I have reasonable faith in. So here's a final patch. If this seems reasonable to everyone, I'd like for it to be merged, and then I can submit the glibc and gdb bits.
The patch itself is below. If you want to test it, at
http://return.false.org/~drow/mips/ you can find:
gdb-2005-09-28-HEAD-MIPS64-DEBUG.tar.gz
glibc-2005-09-28-HEAD-MIPS64-NPTL.tar.gz
linux-2005-09-28-sentosa-n32-ptrace.tar.gz
These are patches against linux-mips.org HEAD, glibc HEAD, and gdb HEAD (all last week) that allow n32 and n64 debugging. For n64 debugging you'll need to remove .debug_frame/.eh_frame first since I haven't looked at those bits of GDB / GCC yet.
arch/mips/kernel/ptrace32.c +81 -0
@@ -35,6 +35,12 @@#include <asm/uaccess.h> #include <asm/bootinfo.h> +int ptrace_getregs (struct task_struct *child,__s64 __user *data); +int ptrace_setregs (struct task_struct *child,__s64 __user *data); + +int ptrace_getfpregs (struct task_struct *child,__u32 __user *data); +int ptrace_setfpregs (struct task_struct *child,__u32 __user *data); +/* * Tracing a 32-bit process with a 64-bit strace and vice versa will not * work. I don't know how to fix this.
@@ -99,6 +105,35 @@ asmlinkage int sys32_ptrace(int request,break ; } +/* +* Read 4 bytes of the other process' storage +* data is a pointer specifying where the user wants the +* 4 bytes copied into +* addr is a pointer in the user's storage that contains an 8 byte +* address in the other process of the 4 bytes that is to be read +* (this is run in a 32-bit process looking at a 64-bit process) +* when I and D space are separate, these will need to be fixed. +*/ +case PTRACE_PEEKTEXT_3264 : +case PTRACE_PEEKDATA_3264 : { +u32 tmp; +int copied; +u32 __user * addrOthers; + + ret = -EIO ; + +/* Get the addr in the other process that we want to read */ +if (get_user (addrOthers, (u32 __user *__user *) (unsigned long ) addr) !=0 ) +break ; + + copied =access_process_vm (child, (u64 )addrOthers, &tmp, +sizeof (tmp),0 ); +if (copied !=sizeof (tmp)) +break ; + ret =put_user (tmp, (u32 __user *) (unsigned long ) data); +break ; + } +/* Read the word at location addr in the USER area. */ case PTRACE_PEEKUSR : {struct pt_regs *regs;
@@ -202,6 +237,31 @@ asmlinkage int sys32_ptrace(int request, ret = -EIO ;break ; +/* +* Write 4 bytes into the other process' storage +* data is the 4 bytes that the user wants written +* addr is a pointer in the user's storage that contains an +* 8 byte address in the other process where the 4 bytes +* that is to be written +* (this is run in a 32-bit process looking at a 64-bit process) +* when I and D space are separate, these will need to be fixed. +*/ +case PTRACE_POKETEXT_3264 : +case PTRACE_POKEDATA_3264 : { +u32 __user * addrOthers; + +/* Get the addr in the other process that we want to write into */ + ret = -EIO ; +if (get_user (addrOthers, (u32 __user *__user *) (unsigned long ) addr) !=0 ) +break ; + ret =0 ; +if (access_process_vm (child, (u64 )addrOthers, &data, +sizeof (data),1 ) ==sizeof (data)) +break ; + ret = -EIO ; +break ; + } +case PTRACE_POKEUSR : {struct pt_regs *regs; ret =0 ;
@@ -276,6 +336,22 @@ asmlinkage int sys32_ptrace(int request,break ; } +case PTRACE_GETREGS : + ret =ptrace_getregs (child, (__u64 __user *) (__u64 ) data); +break ; + +case PTRACE_SETREGS : + ret =ptrace_setregs (child, (__u64 __user *) (__u64 ) data); +break ; + +case PTRACE_GETFPREGS : + ret =ptrace_getfpregs (child, (__u32 __user *) (__u64 ) data); +break ; + +case PTRACE_SETFPREGS : + ret =ptrace_setfpregs (child, (__u32 __user *) (__u64 ) data); +break ; +case PTRACE_SYSCALL :/* continue and stop at next (return from) syscall */ case PTRACE_CONT : {/* restart after signal. */ ret = -EIO ;
@@ -320,6 +396,11 @@ asmlinkage int sys32_ptrace(int request, (unsigned int __user *) (unsigned long) data);break ; +case PTRACE_GET_THREAD_AREA_3264 : + ret =put_user (child->thread_info->tp_value, + (unsigned long __user *) (unsigned long ) data); +break ; +default : ret =ptrace_request (child, request, addr, data);break ;
include/asm-mips/ptrace.h +11 -4
@@ -48,10 +48,10 @@ struct pt_regs { };/* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ -/* #define PTRACE_GETREGS 12 */ -/* #define PTRACE_SETREGS 13 */ -/* #define PTRACE_GETFPREGS 14 */ -/* #define PTRACE_SETFPREGS 15 */ +#define PTRACE_GETREGS 12 +#define PTRACE_SETREGS 13 +#define PTRACE_GETFPREGS 14 +#define PTRACE_SETFPREGS 15/* #define PTRACE_GETFPXREGS 18 */ /* #define PTRACE_SETFPXREGS 19 */
@@ -60,6 +60,13 @@ struct pt_regs {#define PTRACE_GET_THREAD_AREA 25#define PTRACE_SET_THREAD_AREA 26 +/* Calls to trace a 64bit program from a 32bit program. */ +#define PTRACE_PEEKTEXT_3264 0xc0 +#define PTRACE_PEEKDATA_3264 0xc1 +#define PTRACE_POKETEXT_3264 0xc2 +#define PTRACE_POKEDATA_3264 0xc3 +#define PTRACE_GET_THREAD_AREA_3264 0xc4 +#ifdef __KERNEL__#include <linux/linkage.h>
arch/mips/kernel/scall64-n32.S +1 -1
@@ -216,7 +216,7 @@ EXPORT(sysn32_call_table) PTR compat_sys_getrusage PTR sys32_sysinfo PTR compat_sys_times - PTR sys_ptrace + PTR sys32_ptrace PTR sys_getuid /* 6100 */ PTR sys_syslog PTR sys_getgid
arch/mips/kernel/ptrace.c +129 -0
147 lines not on this page · raw message
Signature · 2 lines
Daniel Jacobowitz CodeSourcery, LLC
Re: [PATCH] Revise MIPS64 ptrace interface
Quoted 10 lines · Daniel Jacobowitz
Change the N32 debugging ABI to something more sane, and add support for o32 and n32 debuggers to trace n64 programs.
Signed-off-by Daniel Jacobowitz <[email protected]>---
I've now tested everything except the actual _3264 operations, which were copied from PPC anyway and I have reasonable faith in. So here's a final patch. If this seems reasonable to everyone, I'd like for it to be merged, and then I can submit the glibc and gdb bits.
I haven't heared any objections and I guess for an interface like ptrace such a somewhat trigger happy change is still ok, so I've applied your patch.
Ralf
Quoted 5 lines · Daniel Jacobowitz
1. We need to get at the 64-bit registers. I considered a number of different approaches for this and decided to just implement a 64-bit
PTRACE_GETREGSinstead of messing withPTRACE_PEEKUSR. It's much simpler this way. I didn't add one for the DSP registers; that can be handled separately when someone's working on debug support for them...
I quite deliberately did omit DSP support from 64-bit ptrace(2); there is currently no MIPS64 processor with DSP support that I know of.
Ralf
Quoted 2 lines · Ralf Baechle
I quite deliberately did omit DSP support from 64-bit ptrace(2); there is currently no MIPS64 processor with DSP support that I know of.
This is true so far.
But assuming that 64-bit processing becomes increasingly interesting (which seems certain) and that some kind of DSP support with extra registers remains attractive (which seems fairly likely)... well, I'd have said that any 64-bit MIPS CPU configured from now on is quite likely to have extra DSP registers.
So while "you aren't going to need it" for a while, anyone thinking of doing a non-compatible change to ptrace might want to reserve some space for these registers.
--
Dominic
Quoted 14 lines · Dominic Sweetman
Quoted 2 lines · Ralf Baechle
I quite deliberately did omit DSP support from 64-bit ptrace(2); there is currently no MIPS64 processor with DSP support that I know of.
This is true so far.
But assuming that 64-bit processing becomes increasingly interesting (which seems certain) and that some kind of DSP support with extra registers remains attractive (which seems fairly likely)... well, I'd have said that any 64-bit MIPS CPU configured from now on is quite likely to have extra DSP registers.
Quoted 3 lines
So while "you aren't going to need it" for a while, anyone thinking of doing a non-compatible change to ptrace might want to reserve some space for these registers.
In the future they should be added using PTRACE_GETDSPREGS, or something similar. No one's designed that yet, so the first person to need it gets to do it right.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery, LLC