Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > Re: XNU sys_for...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 3729 of 3882
Post > Topic >>

Re: XNU sys_fork syscall (0x02). Differences between linux and XNU

by Ben Artin <macdev@[EMAIL PROTECTED] > Apr 30, 2008 at 02:58 AM

In article
<dfd380e6-6c6b-40d2-81c8-31805120704f@[EMAIL PROTECTED]
>,
 Robert Spykerman <robert.spykerman@[EMAIL PROTECTED]
> wrote:

> I am fairly new to OS X having just got a penryn/leopard. I'm trying
> to ****t some IA-32 asm code over to the XNU kernel from linux, and I'm
> just having a bit of trouble understanding what actually is going on
> when I call a sys_fork.
> 
> on the man 2 pages it gives me this:
> 
> pid_t fork (void) where pid_t is an unsigned 32 bit.
> 
> Much the same as linux, fine, good. No worries, should be a piece of
> cake right? I know the different calling conventions..  I've already
> fixed the bit of code dealing with lseek, I should be grand right?

Are you sure you know the calling conventions? They are do***ented at 
<http://developer.apple.com/do***entation/DeveloperTools/Conceptual/LowLevelABI/A
rticles/IA32.html#//apple_ref/doc/uid/TP40002492> for IA-32 and 
<http://developer.apple.com/do***entation/DeveloperTools/Conceptual/LowLevelABI/A
rticles/x86_64.html#//apple_ref/doc/uid/TP40005035> for x86-64

I am unclear on why you are referring to BSD do***entation, when Apple's 
do***entation is available (and possibly different -- Mac OS X does not
use the 
BSD kernel).

> What gives?

The source for the fork syscall is in 
<http://www.opensource.apple.com/darwinsource/10.5.2/xnu-1228.3.13/bsd/kern/kern_
fork.c>. One notable aspect of it is:

   retval[0] = child->p_pid;
   retval[1] = 0;       /* flag parent */

which does, indeed indicate that the return value of the fork syscall on
Mach 
consists of two parts; if you look in the calling convention do***ents I 
mentioned above, I believe that you will find that those two parts are
returned 
in EAX and EDX, respectively.

> BUT still I have NO idea what EDX actually represents actually and
> where I should be expecting to get my error code, ie in EAX or EDX.

I am not sure either, off-hand; spelunking in the source and reading the 
do***entation should provide the answer. 

> I could not find the source to syscall fork (0x02) - to find out what
> the heck all this EDX business is... I mean, from the prototype, one
> would imagine you'd only get one 32 bit value returned..

That prototype is for the C library fork() call, not for the fork syscall.
I am 
wondering whether you'd be better off calling the C library, which has a
sane 
calling convention.

hth

Ben

-- 
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>
 




 6 Posts in Topic:
XNU sys_fork syscall (0x02). Differences between linux and XNU
Robert Spykerman <robe  2008-04-29 19:01:42 
Re: XNU sys_fork syscall (0x02). Differences between linux and X
Ben Artin <macdev@[EMA  2008-04-30 02:58:53 
Re: XNU sys_fork syscall (0x02). Differences between linux and X
Robert Spykerman <robe  2008-04-30 04:48:38 
Re: XNU sys_fork syscall (0x02). Differences between linux and X
Ben Artin <macdev@[EMA  2008-04-30 12:11:24 
Re: XNU sys_fork syscall (0x02). Differences between linux and X
Robert Spykerman <robe  2008-04-30 17:16:19 
Re: XNU sys_fork syscall (0x02). Differences between linux and X
Ben Artin <macdev@[EMA  2008-05-01 11:55:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 11:30:25 CST 2008.