Skip to content

Commit

Permalink
Kernel: Use SharedInodeVMObject for executables after all
Browse files Browse the repository at this point in the history
I had the wrong idea about this. Thanks to Sergey for pointing it out!

Here's what he says (reproduced for posterity):

> Private mappings protect the underlying file from the changes made by
> you, not the other way around. To quote POSIX, "If MAP_PRIVATE is
> specified, modifications to the mapped data by the calling process
> shall be visible only to the calling process and shall not change the
> underlying object. It is unspecified whether modifications to the
> underlying object done after the MAP_PRIVATE mapping is established
> are visible through the MAP_PRIVATE mapping." In practice that means
> that the pages that were already paged in don't get updated when the
> underlying file changes, and the pages that weren't paged in yet will
> load the latest data at that moment.
> The only thing MAP_FILE | MAP_PRIVATE is really useful for is mapping
> a library and performing relocations; it's definitely useless (and
> actively harmful for the system memory usage) if you only read from
> the file.

This effectively reverts e2697c2.
  • Loading branch information
awesomekling committed Mar 1, 2020
1 parent bb7dd63 commit ecfde59
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,12 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
return -ENOENT;

auto& inode = interpreter_description ? *interpreter_description->inode() : *main_program_description->inode();
auto vmobject = PrivateInodeVMObject::create_with_inode(inode);
auto vmobject = SharedInodeVMObject::create_with_inode(inode);

if (static_cast<const SharedInodeVMObject&>(*vmobject).writable_mappings()) {
dbg() << "Refusing to execute a write-mapped program";
return -ETXTBSY;
}

// Disable profiling temporarily in case it's running on this process.
bool was_profiling = is_profiling();
Expand Down

0 comments on commit ecfde59

Please sign in to comment.