|
|
Subscribe / Log in / New account

An in-kernel file loading interface

An in-kernel file loading interface

Posted Feb 18, 2016 8:25 UTC (Thu) by eru (subscriber, #2753)
Parent article: An in-kernel file loading interface

Hasn't the kernel always been able to read files for implementing exec? I never thought there is anything special in kernel reading files. (But then, I am not a kernel programmer).


to post comments

An in-kernel file loading interface

Posted Feb 21, 2016 0:20 UTC (Sun) by giraffedata (guest, #1954) [Link]

Hasn't the kernel always been able to read files for implementing exec? I never thought there is anything special in kernel reading files.

Yes, and the kernel has always been able to read files for implementing read, too :-)

Exec is essentially a file operation (it even has its own file permission bit). That puts it in a different class from kernel facilities that use files. The latter smells of a layering violation.

An in-kernel file loading interface

Posted Feb 21, 2016 2:09 UTC (Sun) by anselm (subscriber, #2796) [Link] (3 responses)

I was under the impression that what exec() does with files is more closely related to mmap() than to read().

An in-kernel file loading interface

Posted Feb 21, 2016 11:43 UTC (Sun) by PaXTeam (guest, #24616) [Link] (2 responses)

before the kernel can mmap files into the userland part of the address space it has to know what and where to map and for that it needs to read and parse the ELF program headers of the main executable (and the interpreter if needed). see fs/exec.c:kernel_read() and its uses for the gory details.

An in-kernel file loading interface

Posted Feb 21, 2016 11:54 UTC (Sun) by anselm (subscriber, #2796) [Link] (1 responses)

Makes sense to me (thank you for the clarification).

The important point as far as I'm concerned is that the kernel doesn't “read” a large executable into memory in its entirety before it is started, but maps it into memory and fetches pages from the file as required according to page faults arising from running the code.

An in-kernel file loading interface

Posted Feb 21, 2016 13:29 UTC (Sun) by PaXTeam (guest, #24616) [Link]

yes, that's how it works for userland maps however note that kernel_read has other uses such as the module loader which does read in the entire module file (finit_module->copy_module_from_fd->kernel_read).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds