On Sunday 20 March 2005 20:25, ashwin tanugula wrote:
> Hi,
> I know that UML has to be ported to PPC. I want to resume that work. I
> just wanted to make sure that my PPC box can run uml.(because the
> first step in porting uml is to check that the ptrace_test.c file
> outputs two same pids).
Since there have been working versions of the PPC port, it should be working
well.
> I have set ORIG_EAX to 0. Is that correct or wrong?
Hmm, actually this is wrong... by reading ptrace_test.c, which I just found on
my HD, it should work almost "out of the box".
However, if you look at the source, what it puts inside the ORIG_EAX is the
number of getppid(), not of getpid(), i.e. 64. You don't need to change the
value IMHO.
If you write 20 there it is perfectly expectable that the pids you get are
different (as an exercise, try to understand why: if the child executes
getpid() it gets its own PID, if it executes getppid() it gets the father's
pid).
That said, the problem you should get is that I don't expect ORIG_EAX to be
accepted. From reading include/asm-ppc/unistd.h, it seems that the register
to be changed is r0 (so the macro is PT_R0).
Also, the ptrace_test.c requirement has been reduced a lot by SYSEMU
introduction. Basically, ptrace_test.c uses a hack to avoid that the syscall
is executed on the host, i.e. changing the syscall number to getpid.
PTRACE_SYSEMU is a ptrace() option that says that the syscall invoked by the
debugged thread must not be executed: we write the result from the UML
execution of the syscall to the result register.
> Thanks,
> Ashwin.
>
--
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade
#include <stdio.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <asm/ptrace.h>
#include <asm/unistd.h>
static char stack[65536];
int child(void *arg)
{
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
perror("ptrace");
exit(1);
}
kill(getpid(), SIGSTOP);
while(1){
printf("getpid() returned %d\n", getpid());
sleep(3);
}
return(0);
}
int main(int argc, char **argv)
{
int pid, status, syscall;
printf("Parent pid = %d\n", getpid());
if((pid = clone(child, &stack[65532], SIGCHLD, NULL)) < 0){
perror("clone");
exit(1);
}
if((pid = waitpid(pid, &status, WUNTRACED)) < 0){
perror("Waiting for stop");
exit(1);
}
if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0){
perror("continuing");
exit(1);
}
while(1){
if((pid = waitpid(-1, &status, WUNTRACED)) <= 0){
perror("wait");
exit(1);
}
if(WIFSTOPPED(status) && (WSTOPSIG(status) == SIGTRAP)){
syscall = ptrace(PTRACE_PEEKUSER, pid, 4 * ORIG_EAX, 0);
if(syscall == __NR_getpid){
if(ptrace(PTRACE_POKEUSER, pid, 4 * ORIG_EAX, __NR_getppid) < 0){
perror("ptrace");
exit(1);
}
}
if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0){
perror("continuing");
exit(1);
}
}
else printf("wait failed - pid = %d, status = %d\n", pid, status);
}
}