mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-24 15:56:41 +00:00
parent
e87b322616
commit
d18262da1f
@ -29,6 +29,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -427,7 +428,8 @@ extern "C" void *mmap(void *addr, ::size_t length, int prot, int flags,
|
||||
|
||||
/* handle requests for anonymous memory */
|
||||
if (!addr && libc_fd == -1) {
|
||||
void *start = Libc::mem_alloc()->alloc(length, PAGE_SHIFT);
|
||||
bool const executable = prot & PROT_EXEC;
|
||||
void *start = Libc::mem_alloc(executable)->alloc(length, PAGE_SHIFT);
|
||||
mmap_registry()->insert(start, length, 0);
|
||||
return start;
|
||||
}
|
||||
@ -464,8 +466,12 @@ extern "C" int munmap(void *start, ::size_t length)
|
||||
int ret = 0;
|
||||
if (plugin)
|
||||
ret = plugin->munmap(start, length);
|
||||
else
|
||||
Libc::mem_alloc()->free(start);
|
||||
else {
|
||||
bool const executable = true;
|
||||
/* XXX another metadata handling required to track anonymous memory */
|
||||
Libc::mem_alloc(!executable)->free(start);
|
||||
Libc::mem_alloc(executable)->free(start);
|
||||
}
|
||||
|
||||
mmap_registry()->remove(start);
|
||||
return ret;
|
||||
|
@ -16,7 +16,6 @@
|
||||
/* Genode includes */
|
||||
#include <base/env.h>
|
||||
#include <base/allocator_avl.h>
|
||||
#include <base/sleep.h>
|
||||
|
||||
/* local includes */
|
||||
#include "libc_mem_alloc.h"
|
||||
@ -143,13 +142,19 @@ Genode::size_t Libc::Mem_alloc_impl::size_at(void const *addr) const
|
||||
}
|
||||
|
||||
|
||||
static Libc::Mem_alloc *_libc_mem_alloc;
|
||||
static Libc::Mem_alloc *_libc_mem_alloc_rw = nullptr;
|
||||
static Libc::Mem_alloc *_libc_mem_alloc_rwx = nullptr;
|
||||
|
||||
|
||||
static void _init_mem_alloc(Genode::Region_map &rm, Genode::Ram_session &ram)
|
||||
{
|
||||
static Libc::Mem_alloc_impl inst(rm, ram);
|
||||
_libc_mem_alloc = &inst;
|
||||
enum { MEMORY_EXECUTABLE = true };
|
||||
|
||||
static Libc::Mem_alloc_impl inst_rw(rm, ram, !MEMORY_EXECUTABLE);
|
||||
static Libc::Mem_alloc_impl inst_rwx(rm, ram, MEMORY_EXECUTABLE);
|
||||
|
||||
_libc_mem_alloc_rw = &inst_rw;
|
||||
_libc_mem_alloc_rwx = &inst_rwx;
|
||||
}
|
||||
|
||||
|
||||
@ -162,12 +167,10 @@ namespace Libc {
|
||||
}
|
||||
|
||||
|
||||
Libc::Mem_alloc *Libc::mem_alloc()
|
||||
Libc::Mem_alloc *Libc::mem_alloc(bool executable)
|
||||
{
|
||||
if (!_libc_mem_alloc) {
|
||||
if (!_libc_mem_alloc_rw || !_libc_mem_alloc_rwx)
|
||||
error("attempt to use 'Libc::mem_alloc' before call of 'init_mem_alloc'");
|
||||
_init_mem_alloc(*env_deprecated()->rm_session(), *env_deprecated()->ram_session());
|
||||
}
|
||||
return _libc_mem_alloc;
|
||||
}
|
||||
|
||||
return executable ? _libc_mem_alloc_rwx : _libc_mem_alloc_rw;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace Libc {
|
||||
/**
|
||||
* Return singleton instance of the memory allocator
|
||||
*/
|
||||
Mem_alloc *mem_alloc();
|
||||
Mem_alloc *mem_alloc(bool executable = false);
|
||||
|
||||
class Mem_alloc_impl : public Mem_alloc
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user