linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: ashwin tanugula <ashwin.tanugula@gmail.com>
To: linuxppc-dev@ozlabs.org
Subject: ptrace and ORIG_EAX on ppc
Date: Tue, 29 Mar 2005 20:01:06 -0500	[thread overview]
Message-ID: <838f7c50050329170146631318@mail.gmail.com> (raw)

Hi!
Can somebody tell me how to set references to ORIG_EAX in ppc kernel.
We know ORIG_EAX is defined in unistd.h of i386. How do i make the
following program print two same pids in ppc?

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

}

}



Note: References to ORIG_EAX have to be set here.
Thanks,
Ashwin.

             reply	other threads:[~2005-03-30  1:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-30  1:01 ashwin tanugula [this message]
2005-03-30  7:25 ` ptrace and ORIG_EAX on ppc Brad Boyer
2005-03-30 19:15   ` ashwin tanugula

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=838f7c50050329170146631318@mail.gmail.com \
    --to=ashwin.tanugula@gmail.com \
    --cc=linuxppc-dev@ozlabs.org \
    /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;
as well as URLs for NNTP newsgroup(s).