Skip to contentSkip to conversation

powerpc: Allow ptrace write to pt_regs trap

PATCH In review Benjamin Herrenschmidt 2 participants 5 messages May 29, 2007 – May 30, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 5/5 powerpc: Allow ptrace write to pt_regs trap

This patch allows a ptracer to write to the "trap" word of the pt_regs. This, along with the previous patch, should enable gdb to properly handle syscall restarting after executing a separate function (at least when there's no restart block).

 arch/powerpc/kernel/ptrace-common.h |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/kernel/ptrace-common.h +6 -1
Index: linux-cell/arch/powerpc/kernel/ptrace-common.h
===================================================================
@@ -41,10 +41,15 @@ static inline int put_reg(struct task_st
 	if (task->thread.regs == NULL)
 		return -EIO;
 
-	if (regno <= PT_MAX_PUT_REG) {
+	if (regno <= PT_MAX_PUT_REG || regno == PT_TRAP) {
 		if (regno == PT_MSR)
 			data = (data & MSR_DEBUGCHANGE)
 				| (task->thread.regs->msr & ~MSR_DEBUGCHANGE);
+		/* We prevent mucking around with the reserved area of trap
+		 * which are used internally by the kernel
+		 */
+		if (regno == PT_TRAP)
+			data &= 0xff00;
 		((unsigned long *)task->thread.regs)[regno] = data;
 		return 0;
 	}
#1 lore raw

Benjamin Herrenschmidt <[email protected]> wrote on 05/29/2007 08:45:24 AM:

Quoted 4 lines

This patch allows a ptracer to write to the "trap" word of the pt_regs. This, along with the previous patch, should enable gdb to properly handle syscall restarting after executing a separate function (at least when there's no restart block).

This doesn't look sufficient. If you want GDB to use the save/ restore style means of handling interrupted calls (like i386), at the very least we also need the capability to *write* the orig_gpr3 field, which is currently prohibited. (I don't know why this is case, though.)

Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

Signature · 7 lines
  Dr. Ulrich Weigand | Phone: +49-7031/16-3727
  GNU compiler/toolchain for Linux on System z and Cell BE
  IBM Deutschland Entwicklung GmbH
  Vorsitzender des Aufsichtsrats: Martin Jetter | Geschäftsführung: 
Herbert Kircher
  Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht 
Stuttgart, HRB 243294
#2 lore raw
Quoted 5 lines · Ulrich Weigand

This doesn't look sufficient. If you want GDB to use the save/ restore style means of handling interrupted calls (like i386), at the very least we also need the capability to *write* the orig_gpr3 field, which is currently prohibited. (I don't know why this is case, though.)

It's not prohibited afaik ... we allow writing to everything <= MQ (39) on 32 bits and <= CCR (38) on 64 bits and ORIG_R3 qualifies (34)

Ben.

#3 lore raw

Benjamin Herrenschmidt <[email protected]> wrote on 05/29/2007 11:41:40 PM:

Quoted 9 lines · Ulrich Weigand
Quoted 5 lines

This doesn't look sufficient. If you want GDB to use the save/ restore style means of handling interrupted calls (like i386), at the very least we also need the capability to *write* the orig_gpr3 field, which is currently prohibited. (I don't know why this is case, though.)

It's not prohibited afaik ... we allow writing to everything <= MQ (39) on 32 bits and <= CCR (38) on 64 bits and ORIG_R3 qualifies (34)

Um? I see this in the PTRACE_POKEUSR case in arch_ptrace:

                if (index == PT_ORIG_R3)
                        break;

Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

Signature · 7 lines
  Dr. Ulrich Weigand | Phone: +49-7031/16-3727
  GNU compiler/toolchain for Linux on System z and Cell BE
  IBM Deutschland Entwicklung GmbH
  Vorsitzender des Aufsichtsrats: Martin Jetter | Geschäftsführung: 
Herbert Kircher
  Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht 
Stuttgart, HRB 243294
#4 lore raw
In reply to Ulrich Weigand
Quoted 6 lines

This doesn't look sufficient. If you want GDB to use the save/ restore style means of handling interrupted calls (like i386), at the very least we also need the capability to *write* the orig_gpr3 field, which is currently prohibited. (I don't know why this is case, though.)

Ok, I found it... put_reg doesn't filter it out but the caller does. Fixing that too.

Ben.