Anonymous user
Library Calls: Difference between revisions
Jump to navigation
Jump to search
no edit summary
[unchecked revision] | [unchecked revision] |
No edit summary |
No edit summary |
||
Line 1:
{{Convert}}
<pre>
Line 9:
</pre>
We all know this construct from our userspace programming experiences. We never really thought about how it worked, at least for some time. You
For some, when starting their own OS project, there are some surprises. This page is meant to lessen the confusion, or to avoid it outright: How does a library call actually work, and what is different from kernel space?
close to what Linux actually does. Of course different approaches
can be devised.
Let us have a look at the above code fragment, again. You could just as well write:
Line 29:
</pre>
The header
The
It is defined in the
If you did follow the [[GCC Cross-Compiler]] how-to, your cross-compiler does not know about
Let us assume that, at the bottom of it, you already have some kernel-space function that accepts a
Well, the usual userspace process for a library call is already explained above, is it? Well, yes, but only at a high level. What actually
Your userland =printf()= does not have a string to print, yet - only a parameter that happens to be an integer, and a manual on how to make a string of it. It then proceeds to construct that very string, "The answer is 42!\n". In some way. Doesn't matter.
So let's say your standard library implementation of
An interrupt ends userspace processing, and wakes up the kernel - more specifically, the interrupt handler registered by the kernel. Since it was the interrupt reserved for
So the interrupt handler passes the
The interrupt handler ends,
If you are in kernel space anyway, you don't want that hassle with the registers and the interrupt. After all, you
So what do you do? The answer is easy. Just tell the linker that the _system libraries_ are to be found in a different directory than for userspace. (Your
So you provide a lightweight
<pre>
#ifdef __STDC_HOSTED__
// Userspace declarations
Line 83:
// Kernelspace declarations
#endif
</
|