user489152
user489152

Reputation: 907

How do I make standard library calls from the Linux kernel?

I am tweaking code residing in the /net directory of linux kernel.

I was trying things like printing but I see that there are no relevant headers (like stdlib.h, stdio.h etc). So how can I do this at the kernel level?

Upvotes: 2

Views: 1419

Answers (2)

rulingminds
rulingminds

Reputation:

You cannot use any user space library functions in kernel, You should use only functions exported by the kernel. So, there will not be stdio.h, stdlib.h, etc. If you want to print something in the kernel, you have the printk() function, this is equivalent to printf() in user space.

See also my blog posts Linux Module Programming Part1 and Part2.

Upvotes: 5

Kernel modules do not have access to the C standard library. There are a few functions available in the kernel; look in the lib directory in the kernel source or in your favorite Linux kernel programming book (if you don't have one, Linux Device Drivers is a good one, and it's available online). For printf debugging, there's printk, which emits messages to the kernel logs.

Upvotes: 2

Related Questions