libc: make 'mmap()' address alignment configurable

With this commit, the alignment of anonymous 'mmap()' allocations can be
configured like this:

<config>
  <libc>
    <mmap align_log2="21"/>
  </libc>
</config>

Fixes #3907
This commit is contained in:
Christian Prochaska 2020-10-08 14:14:56 +02:00 committed by Christian Helmuth
parent 7d21335ac9
commit 058f2e687c
3 changed files with 15 additions and 5 deletions

View File

@ -63,11 +63,20 @@ Libc::Mmap_registry *Libc::mmap_registry()
} }
static Cwd *_cwd_ptr; static Cwd *_cwd_ptr;
static unsigned int _mmap_align_log2 { PAGE_SHIFT };
void Libc::init_file_operations(Cwd &cwd) void Libc::init_file_operations(Cwd &cwd,
Config_accessor const &config_accessor)
{ {
_cwd_ptr = &cwd; _cwd_ptr = &cwd;
config_accessor.config().with_sub_node("libc", [&] (Xml_node libc) {
libc.with_sub_node("mmap", [&] (Xml_node mmap) {
_mmap_align_log2 = mmap.attribute_value("align_log2",
(unsigned int)PAGE_SHIFT);
});
});
} }
@ -423,7 +432,7 @@ __SYS_(void *, mmap, (void *addr, ::size_t length,
} }
bool const executable = prot & PROT_EXEC; bool const executable = prot & PROT_EXEC;
void *start = mem_alloc(executable)->alloc(length, PAGE_SHIFT); void *start = mem_alloc(executable)->alloc(length, _mmap_align_log2);
if (!start) { if (!start) {
errno = ENOMEM; errno = ENOMEM;
return MAP_FAILED; return MAP_FAILED;

View File

@ -41,6 +41,7 @@ namespace Libc {
struct Timer_accessor; struct Timer_accessor;
struct Cwd; struct Cwd;
struct Atexit; struct Atexit;
struct Config_accessor;
/** /**
* Support for shared libraries * Support for shared libraries
@ -66,7 +67,7 @@ namespace Libc {
* Virtual file system * Virtual file system
*/ */
void init_vfs_plugin(Monitor &, Genode::Region_map &); void init_vfs_plugin(Monitor &, Genode::Region_map &);
void init_file_operations(Cwd &); void init_file_operations(Cwd &, Config_accessor const &);
/** /**
* Select support * Select support

View File

@ -474,7 +474,7 @@ Libc::Kernel::Kernel(Genode::Env &env, Genode::Allocator &heap)
init_plugin(*this); init_plugin(*this);
init_sleep(*this); init_sleep(*this);
init_vfs_plugin(*this, _env.rm()); init_vfs_plugin(*this, _env.rm());
init_file_operations(*this); init_file_operations(*this, _libc_env);
init_time(*this, *this); init_time(*this, *this);
init_select(*this, _signal, *this); init_select(*this, _signal, *this);
init_socket_fs(*this); init_socket_fs(*this);