linux-um archives
 help / color / mirror / Atom feed
From: Blaisorblade <blaisorblade@yahoo.it>
To: ashwin tanugula <ashwin.tanugula@gmail.com>
Cc: user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [uml-devel] ptrace_test.c program on PPC
Date: Tue, 22 Mar 2005 20:26:57 +0100	[thread overview]
Message-ID: <200503222026.58074.blaisorblade@yahoo.it> (raw)
In-Reply-To: <838f7c5005032011255f738335@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]

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

[-- Attachment #2: ptrace_test.c --]
[-- Type: text/x-csrc, Size: 1331 bytes --]

#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);
  }
}

      parent reply	other threads:[~2005-03-22 19:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-18  0:15 [uml-devel] ptrace_test.c program on PPC ashwin tanugula
2005-03-20 10:36 ` Blaisorblade
     [not found]   ` <838f7c5005032011255f738335@mail.gmail.com>
2005-03-22 19:26     ` Blaisorblade [this message]

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=200503222026.58074.blaisorblade@yahoo.it \
    --to=blaisorblade@yahoo.it \
    --cc=ashwin.tanugula@gmail.com \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox