From: Jeff Dike <jdike@addtoit.com>
To: Roland McGrath <roland@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: Current utrace breaks UML
Date: Wed, 23 May 2007 08:19:02 -0400 [thread overview]
Message-ID: <20070523121902.GA4365@c2.user-mode-linux.org> (raw)
In-Reply-To: <20070523064611.3BD151F8510@magilla.localdomain>
On Tue, May 22, 2007 at 11:46:11PM -0700, Roland McGrath wrote:
> Do you have a test case for PTRACE_SYSEMU that does not work right?
UML, obviously. Below is a smaller test. orig_eax is wrong, so you
can't read the system call number from the process.
With kernel-2.6.20-1.2948, it prints out a bunch of -1's. On FC5
kernels, you get more reasonable numbers.
Jeff
--
Work email - jdike at linux dot intel dot com
#include <stdlib.h>
#include <stdio.h>
#include <asm/unistd.h>
#include <sys/mman.h>
#include <sys/ptrace.h>
#include <asm/ptrace.h>
#include <sys/wait.h>
#define PTRACE_SYSEMU 31
#define PAGE_SIZE 4096
static inline long stub_syscall0(long syscall)
{
long ret;
__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
return ret;
}
static void child(void)
{
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
perror("traceme");
exit(1);
}
kill(getpid(), SIGUSR1);
stub_syscall0(__NR_getpid);
}
int main(void)
{
void *stack;
unsigned long sp, regs[FRAME_SIZE];
int pid, n, status;
stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(stack == MAP_FAILED){
perror("mmap");
exit(1);
}
sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
pid = fork();
if(pid < 0)
perror("fork");
else if(pid == 0){
child();
}
else {
while(1){
n = waitpid(pid, &status, WUNTRACED);
if(n < 0){
perror("waitpid");
exit(1);
}
n = ptrace(PTRACE_GETREGS, pid, 0, regs);
if(n < 0){
perror("PTRACE_GETREGS");
exit(1);
}
printf("Status 0x%x orig_eax 0x%x\n", status,
regs[ORIG_EAX]);
if(ptrace(PTRACE_SYSEMU, pid, 0, 0)){
perror("PTRACE_SYSEMU");
exit(1);
}
}
}
return 0;
}
next prev parent reply other threads:[~2007-05-23 12:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-22 21:38 Current utrace breaks UML Jeff Dike
2007-05-23 6:46 ` Roland McGrath
2007-05-23 12:19 ` Jeff Dike [this message]
2007-05-26 1:35 ` Roland McGrath
2007-05-26 2:10 ` Jeff Dike
2007-05-23 12:20 ` Jeff Dike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070523121902.GA4365@c2.user-mode-linux.org \
--to=jdike@addtoit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.