LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-06-2004, 07:03 PM   #1
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Rep: Reputation: 30
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
 
Old 06-06-2004, 07:23 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 06-06-2004, 07:34 PM   #3
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Original Poster
Rep: Reputation: 30
Re: Try printk?

Quote:
Originally posted by paulsm4
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
i have read this book

i don't find your answer very clear and complete
 
Old 06-06-2004, 08:55 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 06-07-2004, 11:57 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: why we can't use whichever library...

Quote:
why we can't use whichever library when we code a linux driver?
we can use strcpy but we can't use printf[/B]
A quote from Robert Love's book: "Linux Kernel Development" (Sams publishing):
[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]
 
Old 06-07-2004, 11:43 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 06-09-2004, 03:35 PM   #7
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Original Poster
Rep: Reputation: 30
thank
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
library help... Slackeriz Slackware 1 04-17-2005 06:19 AM
Which library ? wood@addanc Programming 3 02-20-2005 02:14 PM
adding a bulit in library to my library lg3 Linux - Software 1 10-17-2004 08:19 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
what is the function library of the basic graphics library in rethat9.0? zerwolve Red Hat 0 04-29-2004 09:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration