Linking shared library in linux kernel

后端 未结 1 2036
闹比i
闹比i 2020-12-19 21:42

I would like to modify the linux kernel.

I would like to use functions from a shared library (an .so file) in file kernel/panic.c.

相关标签:
1条回答
  • 2020-12-19 22:12

    It is not possible to link shared library into kernel code (ELF shared objects are a user-space thing, using ld-linux(8)...) You should consider making a kernel module (and use modprobe(8) to load it). Read Loadable Kernel Module HowTo.

    kernel modules *.ko are conceptually similar to shared objects *.so but the linking mechanism is different.

    BTW, you generally should avoid writing kernel code and should prefer coding application code. In other words, modifying the kernel is generally a bad idea and is frowned upon.

    Also, the API available in kernel space is not the same as user space API (which extends the C standard library and POSIX functions). For example, kernel modules (and kernel code) don't have (so cannot call) fopen or fprintf or fork; the kernel is a freestanding C application. Also, kernel code cannot use any floating point operation!

    Userland applications are interacting with the kernel using system calls listed in syscalls(2) (and the libc is using them, e.g. for printf or system(3)). Kernel code (including kernel modules) cannot use directly syscalls (since they are provided by the kernel, see syscalls(2)).

    Read also Advanced Linux Programming (mostly about application programming) and Operating Systems: Three Easy Pieces (to get a broader view about OSes).

    0 讨论(0)
提交回复
热议问题