why we can't use whichever library...
hi
why we can't use whichever library when we code a linux driver? we can use strcpy but we can't use printf whey? thanks |
Try printk?
Because kernel drivers run in a completely different execution context than user code.
One alternative is to use "printk()" instead of "printf()". I'd definitely consider getting a good book. For example, "Linux Device Drivers, 2nd Ed", A. Rubini & J. Corbet. Hope that helps .. PSM |
Re: Try printk?
Quote:
i don't find your answer very clear and complete |
The standard C library in general, and printf() in particular, require considerable runtime support - runtime support you more or less take for granted in the user environment - and that simply doesn't exist in kernel mode.
If you have the Rubini/Corbet text, please re-read Chap 2, especially the section "Doing It in User Space". Bear in mind that even a simple "malloc()" (which the "printf()" implementation makes liberal use of!) cannot be done in kernel mode (although there is, to be sure, an anologous "kmalloc()"). Please let me know specifically what you're unclear about - I'd be happy to help clarify. Your .. PSM |
Re: why we can't use whichever library...
Quote:
[quote]Unlike a user-space application, the kernel is not linked against the standard C library (or any other library, for that matter). There are multiple reasons for this, including some chicken and egg situations, but the primary reason is speed and size.[quote] |
Hi, Hko -
Your book is correct that the kernel is not linked against the standard C library ... and, in fact, *cannot* be linked against it. I'm not sure I completely agree with the "speed and size" arguments (although obviously both are an important consideration in *any* code - especially in systems code). The "chicken and egg" argument is absolutely correct: the kernel is there to provide exactly that infrastructure that the standard library needs (like the ability to "malloc()" paged memory, for example). It cannot easily provide that infrastructure and at the same time use it. But, IMHO, the main point is that kernel code (in the executive context) and non-kernel code (in user context) are simply two very different, in many ways incompatible environments. Another good (albeit totally non-Linux ;-)) book that os2 might find useful is: "Inside Windows 2000", Solomon/Russinovich, Chap 1, pp 9-13, "Kernel mode vs. user mode". Hope that helps .. PSM |
thank
|
All times are GMT -5. The time now is 03:57 AM. |