Skip to contentSkip to conversation

ptrace_test.c program on PPC

uml-devel ashwin tanugula 2 participants 3 messages Mar 18, 2005 – Mar 22, 2005 1 message not in the archive User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

Hi!
I tried running ptrace_test.c on my ppc. Initially i initialized ORIG_EAX to 20 which is the system call number for getpid on my ppc, but it gave out two different pids.
Then i started playing with the numbers
Finally i got same pids when i put ORIG_EAX to 0 , which is the system call number for restart_syscall.
Can somebody tell me if my machine is able to run UML? Thanks,
Ashwin.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw
Quoted 8 lines · ashwin tanugula

Hi!
I tried running ptrace_test.c on my ppc. Initially i initialized ORIG_EAX to 20 which is the system call number for getpid on my ppc, but it gave out two different pids.
Then i started playing with the numbers
Finally i got same pids when i put ORIG_EAX to 0 , which is the system call number for restart_syscall.
Can somebody tell me if my machine is able to run UML?

Not lookign at the above results, UML used to run on PPC, but there is not a current version of UML working... there is some work towards a port (see
http://www.usermodelinux.org/ news). However nothing for users at the moment.

Quoted 2 lines

Thanks,
Ashwin.

Signature · 17 lines
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade





-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#3 lore raw
In reply to a message not in the archive
Quoted 5 lines · ashwin tanugula

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.

Quoted 1 line

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.

Quoted 3 lines

Thanks,
Ashwin.

Signature · 3 lines
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);

}
}