Does the Linux kernel interrupt any running code to call the __exit function when unloading a kernel module?
asked 8 hours ago by @qa-9b0f9v4weaoxauryvll4 0 rep · 65 views
c linux linux kernel kernel module
I have a cleanup function that I call in my code. The __exit function also goes through the same routine, but we will have a global flag for that to not run it twice. My question is, if my cleanup function is mid-execution (not using kthreads, directly on the CPU) and a SYS_delete_module syscall is made (like by rmmod), will it just interrupt and eventually exit with my cleanup function only having partially executed?
LLMs are giving mixed answers. One says the kernel checks if the instruction pointer is in the module's memory and waits for it, other says there is a global mutex lock used by the kernel and all.
Can I, and if so, should I increment the reference count of my module for safety?