mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
libc: Use Hamstraaja for malloc on EalánOS.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
LIBC_PORT_DIR := $(call select_from_ports,libc)
|
LIBC_PORT_DIR := $(call select_from_ports,libc)
|
||||||
LIBC_DIR := $(LIBC_PORT_DIR)/src/lib/libc
|
LIBC_DIR := $(LIBC_PORT_DIR)/src/lib/libc
|
||||||
LIBC_REP_DIR := $(realpath $(call select_from_repositories,include/libc-genode)/../..)
|
LIBC_REP_DIR := $(realpath $(call select_from_repositories,include/libc-genode)/../..)
|
||||||
|
EALAN_REP_DIR := $(realpath $(call select_from_repositories,ealanos))
|
||||||
|
|
||||||
# local libc includes
|
# local libc includes
|
||||||
INC_DIR += $(LIBC_DIR)/lib/libc/locale
|
INC_DIR += $(LIBC_DIR)/lib/libc/locale
|
||||||
@@ -14,6 +15,7 @@ INC_DIR += $(LIBC_DIR)/lib/libc/include
|
|||||||
INC_DIR += $(LIBC_DIR)/lib/libc/stdio
|
INC_DIR += $(LIBC_DIR)/lib/libc/stdio
|
||||||
INC_DIR += $(LIBC_DIR)/lib/libc/net
|
INC_DIR += $(LIBC_DIR)/lib/libc/net
|
||||||
INC_DIR += $(LIBC_DIR)/contrib/gdtoa
|
INC_DIR += $(LIBC_DIR)/contrib/gdtoa
|
||||||
|
INC_DIR += $(EALAN_REP_DIR)/include
|
||||||
|
|
||||||
#CC_OPT += -DGENODE_RELEASE
|
#CC_OPT += -DGENODE_RELEASE
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
#define _LIBC__INTERNAL__INIT_H_
|
#define _LIBC__INTERNAL__INIT_H_
|
||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
|
#include "pd_session/pd_session.h"
|
||||||
|
#include "region_map/region_map.h"
|
||||||
#include <base/env.h>
|
#include <base/env.h>
|
||||||
#include <base/heap.h>
|
#include <base/heap.h>
|
||||||
#include <util/xml_node.h>
|
#include <util/xml_node.h>
|
||||||
@@ -98,7 +100,7 @@ namespace Libc {
|
|||||||
/**
|
/**
|
||||||
* Malloc allocator
|
* Malloc allocator
|
||||||
*/
|
*/
|
||||||
void init_malloc(Genode::Allocator &);
|
void init_malloc(Genode::Pd_session &pd , Genode::Region_map &rm);
|
||||||
void init_malloc_cloned(Clone_connection &);
|
void init_malloc_cloned(Clone_connection &);
|
||||||
void reinit_malloc(Genode::Allocator &);
|
void reinit_malloc(Genode::Allocator &);
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include <internal/atexit.h>
|
#include <internal/atexit.h>
|
||||||
#include <internal/rtc.h>
|
#include <internal/rtc.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Libc {
|
namespace Libc {
|
||||||
class Kernel;
|
class Kernel;
|
||||||
class Main_blockade;
|
class Main_blockade;
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ Libc::Kernel::Kernel(Genode::Env &env, Genode::Allocator &heap)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
_malloc_heap.construct(*_malloc_ram, _env.rm());
|
_malloc_heap.construct(*_malloc_ram, _env.rm());
|
||||||
init_malloc(*_malloc_heap);
|
init_malloc(_env.pd(), _env.rm());
|
||||||
}
|
}
|
||||||
|
|
||||||
init_fork(_env, _fd_alloc, _libc_env, _heap, *_malloc_heap, _pid, *this,
|
init_fork(_env, _fd_alloc, _libc_env, _heap, *_malloc_heap, _pid, *this,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
|
#include "pd_session/pd_session.h"
|
||||||
|
#include "region_map/region_map.h"
|
||||||
#include <base/env.h>
|
#include <base/env.h>
|
||||||
#include <base/log.h>
|
#include <base/log.h>
|
||||||
#include <base/slab.h>
|
#include <base/slab.h>
|
||||||
@@ -30,6 +32,7 @@ extern "C" {
|
|||||||
#include <internal/init.h>
|
#include <internal/init.h>
|
||||||
#include <internal/clone_session.h>
|
#include <internal/clone_session.h>
|
||||||
#include <internal/errno.h>
|
#include <internal/errno.h>
|
||||||
|
#include <ealanos/memory/hamstraaja.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Libc {
|
namespace Libc {
|
||||||
@@ -83,7 +86,7 @@ class Libc::Malloc
|
|||||||
SLAB_START = 5, /* 32 bytes (log2) */
|
SLAB_START = 5, /* 32 bytes (log2) */
|
||||||
SLAB_STOP = 11, /* 2048 bytes (log2) */
|
SLAB_STOP = 11, /* 2048 bytes (log2) */
|
||||||
NUM_SLABS = (SLAB_STOP - SLAB_START) + 1,
|
NUM_SLABS = (SLAB_STOP - SLAB_START) + 1,
|
||||||
DEFAULT_ALIGN = 16
|
DEFAULT_ALIGN = 64
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Metadata
|
struct Metadata
|
||||||
@@ -232,10 +235,11 @@ class Libc::Malloc
|
|||||||
|
|
||||||
|
|
||||||
using namespace Libc;
|
using namespace Libc;
|
||||||
|
using Hamsterer = Ealan::Memory::Hamstraaja<32, 2048>;
|
||||||
|
|
||||||
|
//static Malloc *mallocator;
|
||||||
|
|
||||||
static Malloc *mallocator;
|
static Hamsterer *mallocator;
|
||||||
|
|
||||||
|
|
||||||
extern "C" void *malloc(size_t size)
|
extern "C" void *malloc(size_t size)
|
||||||
{
|
{
|
||||||
@@ -267,13 +271,21 @@ extern "C" void *realloc(void *ptr, size_t size)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mallocator->realloc(ptr, size);
|
void *new_addr = mallocator->alloc(size);
|
||||||
|
|
||||||
|
if (new_addr) {
|
||||||
|
::memcpy(new_addr, ptr, size);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_addr;
|
||||||
|
//return mallocator->realloc(ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int posix_memalign(void **memptr, size_t alignment, size_t size)
|
int posix_memalign(void **memptr, size_t alignment, size_t size)
|
||||||
{
|
{
|
||||||
*memptr = mallocator->alloc(size, alignment);
|
*memptr = mallocator->aligned_alloc(size, alignment);
|
||||||
|
|
||||||
if (!*memptr)
|
if (!*memptr)
|
||||||
return Errno(ENOMEM);
|
return Errno(ENOMEM);
|
||||||
@@ -283,19 +295,19 @@ int posix_memalign(void **memptr, size_t alignment, size_t size)
|
|||||||
|
|
||||||
|
|
||||||
/* space for singleton object w/o destructor */
|
/* space for singleton object w/o destructor */
|
||||||
static long _malloc_obj[(sizeof(Malloc) + sizeof(long))/sizeof(long)];
|
static long _malloc_obj[(sizeof(Hamsterer) + sizeof(long))/sizeof(long)];
|
||||||
|
|
||||||
|
|
||||||
void Libc::init_malloc(Genode::Allocator &heap)
|
void Libc::init_malloc(Genode::Pd_session &pd, Genode::Region_map &rm)
|
||||||
{
|
{
|
||||||
mallocator = construct_at<Malloc>(_malloc_obj, heap);
|
mallocator = construct_at<Hamsterer>(_malloc_obj, pd, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Libc::init_malloc_cloned(Clone_connection &clone_connection)
|
void Libc::init_malloc_cloned(Clone_connection &clone_connection)
|
||||||
{
|
{
|
||||||
clone_connection.object_content(_malloc_obj);
|
clone_connection.object_content(_malloc_obj);
|
||||||
mallocator = (Malloc *)_malloc_obj;
|
mallocator = (Hamsterer *)_malloc_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user