All times are UTC-06:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
 Post subject: ORIG_EAX and ptrace
PostPosted: Tue Mar 29, 2005 8:12 am 
Offline

Joined: Tue Mar 29, 2005 8:07 am
Posts: 2
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.


Top
   
 Post subject: Re: ORIG_EAX and ptrace
PostPosted: Tue Mar 29, 2005 11:03 pm 
Offline

Joined: Fri Sep 24, 2004 1:39 am
Posts: 103
Location: Gothenburg, Sweden
eax is an x86-specific register, it does not exist on ppc.


Top
   
 Post subject: Re: ORIG_EAX and ptrace
PostPosted: Wed Mar 30, 2005 11:56 am 
Offline

Joined: Tue Mar 29, 2005 8:07 am
Posts: 2
Hi,
I know that eax is not ppc register. Anyhow I got the answer for my question.
ORIG_EAX references have to be set to register 0 and the macro is PT_R0. I have made ORIG_EAX as PT_R0 and I got two same pids .

root@slemieux:/home/ashwin # gcc ptrace_test.c
root@slemieux:/home/ashwin # ./a.out
Parent pid = 18676
getpid() returned 18676
getpid() returned 18676

-Ashwin :wink:


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
PowerDeveloper.org: Copyright © 2004-2012, Genesi USA, Inc. The Power Architecture and Power.org wordmarks and the Power and Power.org logos and related marks are trademarks and service marks licensed by Power.org.
All other names and trademarks used are property of their respective owners. Privacy Policy
Powered by phpBB® Forum Software © phpBB Group