Prev: Proxy site open your favoraite sites facebook myspace ...etc
Next: Shared Memory and mutex protection
From: Linny on 20 Jul 2010 05:43 Hi, I have a few queries about calling library functions in Linux Kernel(module) code. What are the disadvantages of using printf instead of printk in kernel code ? I have also heard that it is unwise to use standard library functions in the kernel but was unable to understand why. Can someone please explain the reason for the same ? Thanks Linny
From: Jens Thoms Toerring on 20 Jul 2010 07:36
Linny <linvin333(a)gmail.com> wrote: > I have a few queries about calling library functions in Linux > Kernel(module) code. > What are the disadvantages of using printf instead of printk in kernel > code ? The disadvantage is rather simple: you can't use libraries in the kernel or in modules code. The kernel isn't a normal program that would get loaded at some time, including libraries, instead it's what get used in the end to load other programs and libraries. Moreover, you really don't want to have potentially buggy or even malicious code from libraries getting loaded into the kernel indiscriminately - even a small bug might bring the whole system down instead of just one of hundreds of programs running at the same time! > I have also heard that it is unwise to use standard library functions > in the kernel but was unable to understand why. Again, the simple reason is that the standard library isn't available at all in the kernel. All you've got is what's in the kernel. You simply have to make do with the functions the kernel supplies, e.g. with printk() instead of printf(). They are normally somewhat restricted to what you get for normal user-land programs since most of the functionality isn't needede in th kernel and only would bloat its size. E.g. since there are no loating point numbers used in the kernel, what would having function for printing that can deal with floating point values be good for? What good would be functions for opening files for when the kernel itself is needed by these functions for doing the "opening" etc.? Regards, Jens -- \ Jens Thoms Toerring ___ jt(a)toerring.de \__________________________ http://toerring.de |