Issue
I am writing a device driver in which I have the mmap system call refer to a function of my driver, which is registered as a file operation. Then I have the release system call refer to another function, registered as vm_operations_struct. When my user level program which uses those system calls exits or is killed while running I see that the release function is called automatically, with no code written. My question is whether the release system call is called actually automatically when the program returns or crashes and is there a way to call the release system call myself in the code?
Solution
Yes, whenever a process terminates, either normally (via the _exit
system call) or by the action of a signal, the kernel automatically releases all resources held by that process. For Linux I believe you can look at the code of do_exit
to see how this is done.
There is no "release" system call, but assuming you have wired everything up correctly, I would expect that your driver's release function will also be called when the program uses munmap
to tear down memory mappings backed by your driver, and/or when it uses close
to close file descriptors backed by your driver.
Answered By - zwol Answer Checked By - Pedro (WPSolving Volunteer)