0
votes

My question is not limited to mmap(), but all the functions (when called from userspace - a systemcall) which are used in both kernel space code and user space code. An example if I call mmap() from user space , that include a context switch (SYSENTER / INT 80H), however that would not be needed if I call the mmap from kernel. My question is, is the mmap() function same in kernel or userspace. If it is same, is the mmap implementation manage to not execute SYSENTER / INT 80H if it is been called from kernel?

1
There's no such function in the Linux kernel.0andriy

1 Answers

0
votes

mmap(2) implementation is not as illustrative because it has compatibility artefacts, but here's an example with truncate(2):

  1. Userspace calls into kernel space, which starts with a specially linked function.
  2. That function calls an internal function.
  3. The internal function e.g. do_sys_truncate() calls into an actual kernel API.
  4. The kernel API e.g. vfs_truncate() does the heavy lifting.
  5. That kernel API is what's being exported to the rest of the kernel code.

So, essentially, the userspace mmap() is just another, more complex path, to an internal kernel API that is accessible to the rest of the kernel via other, simpler path.