Re: Executable entry point
Re: Executable entry point
- Subject: Re: Executable entry point
- From: Geoffrey Lee <email@hidden>
- Date: Sun, 18 Mar 2007 23:20:21 +1100
On Sun, Mar 18, 2007 at 11:02:55AM +0000, Filipe Cabecinhas wrote:
> Thank you very much, now it runs :D
>
> I have now another problem.
>
> As far as I could see (by going through the source of Darwin, when I
> want to call a system call directly (I can't link the output of my
> compiler with the libc, I have to link it with my run-time library) I
> should do the following:
>
> push the arguments to the stack(for example (write): push nbytes,
> push str, push fd)
> set eax to the system call number (4)
> call __sysenter_trap
>
> sysenter_trap:
> put the esp in ecx
> sysenter
>
> I think I should call the trap so the system call has an address to
> return to, right?
>
No, you missed something:
sysenter_trap looks like this:
__sysenter_trap:
90110ac0 popl íx
90110ac1 movl %esp,ìx
90110ac3 sysenter
So, ìx contains the saved stack pointer and íx contains the return
address.
By the way, I am not quite sure if doing things directly is such a good
idea ... can you not go through libc?
- gl
> But my problem is, when I return from sysenter, it goes to a weird
> position instead of going to the address after the call __sysenter_trap.
>
> Am I doing anything wrong?
>
>
> Thanks for the help
>
> Filipe Cabecinhas
>
>
> On 18 Mar, 2007, at 07:50, Geoffrey Lee wrote:
>
> >>
> >>The question is: how does darwin know where is the entry point of the
> >>binary and how can I choose it?
> >>
> >
> >Use -e flag in ld(1). It is actually stored in the thread state,
> >the kernel loads this thread state when the binary is loaded, you can
> >see for yourself with otool -l, srr0 on ppc and eip on 32bit x86.
> >
> >
> > - gl
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden