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


Programming > Forth > Re: Why is GFor...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 24 of 30 Topic 4030 of 4325
Post > Topic >>

Re: Why is GForth-ITC fast?

by Robert Spykerman <robert.spykerman@[EMAIL PROTECTED] > May 1, 2008 at 09:06 PM

On May 1, 10:45 pm, Thomas ****in <****...@[EMAIL PROTECTED]
> wrote:

> According to Robert Spykerman  <robert.spyker...@[EMAIL PROTECTED]
>:
>
> > I was wondering why linus was stuffing parameters in registers to make
> > linux syscalls, instead of pu****ng to the stack. I must ask a linux
> > kernel hacker.
>
> The kernel and the application code (so-called "userland") do not run
> with the same privilege levels (the kernel code is allowed to tinker
> with the hardware, not the userland). A system call is a jump between
> the two worlds, usually through a software interrupt or an equivalent
> mechanism. That jump entails a "stack switch", which means that the
> kernel code obtains its own stack (the stack pointer register value is
> saved, and the value for the kernel recovered during the switch; the
> reverse operation occurs when the system call returns). To access
> the userland stack, the kernel must first recover the userland stack
> pointer.
>
> Besides, the userland is not trusted by the kernel. The stack pointer
> could be bogus, or point to a part of the memory which the kernel can
> physically access (with its "kernel rights") but the userland cannot.
> Before accessing the user stack, the kernel would have to check whether
> that memory area is safe, which is doable (and actually done for system
> calls such as read() or write() which exchange data chunks with the
> userland) but somewhat complex and expensive. Besides, the kernel really
> needs a safe stack of its own (the userland stack could be concurrently
> modified from another thread, hence the kernel cannot safely store its
> own data in it).
>
> Hence it is safer and simpler to exchange data through registers when
> possible. As an added bonus, this means that the userland code needs not
> maintain a C-like stack, if it runs code written in a language which
> does not have that concept, or would like to reuse the stack pointer
> register for other usages (except for signals, but there is the
> sigaltstack() system call for that).
>
>         --Thomas ****in

Ok points taken, the only thing is I guess if you want to do syscalls
the linux way on an IA-32 you kind of are starved of registers and (I
guess depending on code) you may have to save them first,  then load
up EAX et al with the function call parameters then syscall...

This contrasts with OSX / BSD where you push the syscall parameters to
the  userland stack and the kernel picks them up. I have to admit,
this seems to me slightly more convenient way of doing it.

I don't really know how expensive PUSH immediates or PUSH addresses
actually are I admit, offhand but I expect given the convenience they
apparently offer, they must be expensive.

Whichever is actually more efficient I do not know... I suspect it
depends on coding style.

Do you have any opinion on this (I'm just bloody curious)?

As you probably realize Thomas, my interest in syscalls is all in the
setting of trying to ****t Albert's ciforth/lina.

By the way, I've been warned by at least one person in the know at
Apple not to use int 0x80 syscalls on OS X, which apparently have been
left in for 'legacy code'. Nevertheless I got some pointers to where
in the source to look.

Does this sort of taboo exist on other *nixes as well? (I ask because
I'm still very much a nix nub/scrub)

The apple guys have warned me, but some BSD guys apparently have no
qualms in direct syscalls...

http://www.int80h.org/bsdasm/

Anyway, if I am not making sense I need to go to bed to reboot and fix
the memory leak in my brain. Any ideas on how to keep my brain real
time and mission critical graciously accepted :P

Robert Spykerman
 




 30 Posts in Topic:
Why is GForth-ITC fast?
brian.fox@[EMAIL PROTECTE  2008-04-30 19:30:05 
Re: Why is GForth-ITC fast?
"winston19842005@[EM  2008-04-30 21:29:44 
Re: Why is GForth-ITC fast?
Robert Spykerman <robe  2008-05-01 01:42:28 
Re: Why is GForth-ITC fast?
anton@[EMAIL PROTECTED]   2008-05-01 10:54:45 
Re: Why is GForth-ITC fast?
Albert van der Horst <  2008-05-01 17:26:57 
Re: Why is GForth-ITC fast?
stephenXXX@[EMAIL PROTECT  2008-05-01 22:22:50 
Re: Why is GForth-ITC fast?
stephenXXX@[EMAIL PROTECT  2008-05-01 09:00:18 
Re: Why is GForth-ITC fast?
Robert Spykerman <robe  2008-05-01 04:43:05 
Re: Why is GForth-ITC fast?
Thomas Pornin <pornin@  2008-05-01 12:45:38 
Re: Why is GForth-ITC fast?
stephenXXX@[EMAIL PROTECT  2008-05-01 12:56:26 
Re: Why is GForth-ITC fast?
Andrew Haley <andrew29  2008-05-01 11:41:05 
Re: Why is GForth-ITC fast?
anton@[EMAIL PROTECTED]   2008-05-01 18:22:56 
Re: Why is GForth-ITC fast?
Bernd Paysan <bernd.pa  2008-05-01 22:01:54 
Re: Why is GForth-ITC fast?
stephenXXX@[EMAIL PROTECT  2008-05-01 22:45:04 
Re: Why is GForth-ITC fast?
Thomas Pornin <pornin@  2008-05-01 23:44:26 
Re: Why is GForth-ITC fast?
Andrew Haley <andrew29  2008-05-02 04:27:59 
Re: Why is GForth-ITC fast?
Thomas Pornin <pornin@  2008-05-01 12:31:12 
Re: Why is GForth-ITC fast?
Albert van der Horst <  2008-05-01 16:33:12 
Re: Why is GForth-ITC fast?
brian.fox@[EMAIL PROTECTE  2008-05-01 17:12:16 
Re: Why is GForth-ITC fast?
mhx@[EMAIL PROTECTED] (M  2008-05-02 02:53:47 
Re: Why is GForth-ITC fast?
brian.fox@[EMAIL PROTECTE  2008-05-01 19:44:40 
Re: Why is GForth-ITC fast?
brian.fox@[EMAIL PROTECTE  2008-05-01 17:16:42 
Re: Why is GForth-ITC fast?
Robert Spykerman <robe  2008-05-01 20:17:47 
Re: Why is GForth-ITC fast?
Robert Spykerman <robe  2008-05-01 21:06:05 
Re: Why is GForth-ITC fast?
Thomas Pornin <pornin@  2008-05-02 13:00:46 
Re: Why is GForth-ITC fast?
Albert van der Horst <  2008-05-02 16:46:32 
Re: Why is GForth-ITC fast?
Thomas Pornin <pornin@  2008-05-02 18:11:41 
Re: Why is GForth-ITC fast?
Robert Spykerman <robe  2008-05-02 06:12:42 
Re: Why is GForth-ITC fast?
Robert Spykerman <robe  2008-05-02 17:40:35 
Re: Why is GForth-ITC fast?
Albert van der Horst <  2008-05-03 10:12:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Nov 22 17:07:37 CST 2008.