0

Looking for a list of libraries which can be called from a custom Kernel Module.

I understand that there are restrictions compared to user space and libraries like <stdio.h> and <string.h> can't be used.

Which are the most popular ones which can be used, or even better is there a rule of thumb to help me distinguish when a library can be called inside a Kernel Module.

I am currently looking to map memory using mmap(), which is part of sys/mman.h library, but i am pretty sure this won't be the only thing i will need.

So :

  • linux/<MANY_DIFFERENT_NAME> is available
  • i have seen including asm/uaccess.h in kernel code
  • is sys/<ANY> also available for Kernel Modules?
  • any other?

migrated from raspberrypi.stackexchange.com Sep 29 '18 at 15:24

This question came from our site for users and developers of hardware and software for Raspberry Pi.

1

None of the standard user space libraries are available from kernel code. There are some functions in the kernel that behave similar to the corresponding user space functions, but you should always verify that there are no differences.

Concerning the mmap function, this function is just a system call to the kernel. It doesn't make sense to have a call to the kernel inside the kernel. Instead, there is the function that implements mmap. Unless you want to map anonymous memory, which would be easier to achieve with memory allocation, you need a file descriptor. Processes have file descriptors, kernel modules don't.

In general, programming a kernel module is different from user space programming. A good approach would be to look for kernel modules doing something similar to what you intend and use that as a starting point.

  • the truth is that i was looking for a more generic list of common used kernel mode libraries, just like many user mode libraries listed and explained in dozens of sites (e.g. stdio.h, string.h et al , along with functions defined in and usage). After searching online, i didn't find anything well structured, so i took your advice and looked for other kernel implementation. Now i mostly go to linux repos to find out libraries and function for kernel mode, like linux/module.h – Gr3at Sep 30 '18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.