Skip to contentSkip to conversation

i386: fix singlestepping though a syscall

PATCH Chuck Ebbert 2 participants 2 messages Feb 17, 2006

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines · Linus Torvalds
Quoted 3 lines · Chuck Ebbert

Singlestep through a syscall using vsyscall-sysenter had two bugs:

Quoted 8 lines
Quoted 3 lines

1. Setting TIF_SINGLESTEP is not enough to force do_notify_resume() to be run on return to user; TIF_IRET must also be set.

Interesting, but I think you pinpointed the _real_ bug.
...
Oh, actually, I think you should just remove the clearing of _TIF_SINGLESTEP from _TIF_WORK_MASK. Does that fix the bug.

Yes, that works. I was afraid to try it because of unknown side-effects but one of those may be that it fixes Paolo's debugger problem. The C program I was testing with is enclosed and I can even (with care) debug it with gdb passing through SIGTRAP and step through the signal handler.

Paolo, can you try this patch for your debugger problem?

Do not mask TIF_SINGLESTEP bit in _TIF_WORK_MASK. Masking this stopped do_notify_resume() from being called when it should have been.

include/asm-i386/thread_info.h +2 -2
@@ -158,8 +158,8 @@ register unsigned long current_stack_poi
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK \
-  (0x0000FFFF & ~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP|\
-		  _TIF_SECCOMP|_TIF_SYSCALL_EMU))
+  (0x0000FFFF & ~(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
+		  _TIF_SECCOMP | _TIF_SYSCALL_EMU))
 /* work to do on any return to u-space */
 #define _TIF_ALLWORK_MASK	(0x0000FFFF & ~_TIF_SECCOMP)

_

#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>

#define TRAP_FLAG 0x100

#ifdef INT80

# define ENTER_KERNEL	"int $0x80\n\t"
#else
# define ENTER_KERNEL	"call *vsyscall\n\t"
#endif

static struct sigaction sa;
static void * const vsyscall = (void *)0xffffe400;

static void handler(int nr, siginfo_t *si, void *vuc)

{
	struct ucontext *uc = (struct ucontext *)vuc;
	struct sigcontext *sc = (struct sigcontext *)&uc->uc_mcontext;

	printf("handler: signo = %d, errno = %d, code = %d\n",
		si->si_signo, si->si_errno, si->si_code);
	printf("handler: addr = 0x%08x, inst = 0x%02x, flags=0x%08x\n\n",
		si->si_addr, *(unsigned char *)si->si_addr, sc->eflags);
}

int main(int argc, char * const argv[])

{
	sa.sa_sigaction = handler;
	sa.sa_flags     = SA_SIGINFO;
	sigaction(SIGTRAP, &sa, NULL);

	asm volatile ("pushf ; orl %0,(%%esp) ; popf" : : "i" (TRAP_FLAG));
	asm volatile (ENTER_KERNEL : : "a" (20) /* getpid() */);
	asm volatile ("pushf ; andl %0,(%%esp) ; popf" : : "i" (~TRAP_FLAG));
	asm volatile (ENTER_KERNEL : : "a" (20) /* getpid() */);

	return 0;
}
Signature · 2 lines
Chuck
"Equations are the Devil's sentences."  --Stephen Colbert
#1 lore raw
Quoted 7 lines · Chuck Ebbert

[...]
Yes, that works. I was afraid to try it because of unknown side-effects but one of those may be that it fixes Paolo's debugger problem. The C program I was testing with is enclosed and I can even (with care) debug it with gdb passing through SIGTRAP and step through the signal handler.

Paolo, can you try this patch for your debugger problem?

    ^

Paulo, please ;)

Humm.... I've already found a way to make the debugger work (see th other thread) and at a first glance it seems unrelated to this. So I suspect I wouldn't gain much by testing it.

If you think it is worth doing it anyway, it won't be that much trouble to test yet another kernel, so I can certainly do it tonight...

Signature · 4 lines
Paulo Marques - www.grupopie.com

Pointy-Haired Boss: I don't see anything that could stand in our way.
           Dilbert: Sanity? Reality? The laws of physics?