mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-22 10:21:04 +00:00
parent
25bcc2dfa6
commit
d1df1dbd87
@ -1,19 +1,23 @@
|
|||||||
/**
|
/*
|
||||||
* \brief DL interface bindings
|
* \brief Dynamic linker interface bindings
|
||||||
* \author Sebastian Sumpf
|
* \author Sebastian Sumpf
|
||||||
* \date 2014-10-24
|
* \date 2014-10-24
|
||||||
*
|
*
|
||||||
* Wrap Genode's shared library interface onto libc semantics.
|
* Wrap Genode's shared library interface onto libc semantics.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <base/env.h>
|
/* Genode includes */
|
||||||
#include <base/log.h>
|
#include <base/log.h>
|
||||||
#include <base/shared_object.h>
|
#include <base/shared_object.h>
|
||||||
#include <base/snprintf.h>
|
#include <base/snprintf.h>
|
||||||
|
|
||||||
|
/* Genode-specific libc includes */
|
||||||
|
#include <libc/allocator.h>
|
||||||
|
|
||||||
/* libc-internal includes */
|
/* libc-internal includes */
|
||||||
#include <libc_init.h>
|
#include <libc_init.h>
|
||||||
|
|
||||||
|
/* libc includes */
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
}
|
}
|
||||||
@ -71,8 +75,9 @@ void *dlopen(const char *name, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new (env()->heap())
|
static Libc::Allocator global_alloc;
|
||||||
Shared_object(*genode_env, *env()->heap(), name, bind, keep);
|
return new (global_alloc)
|
||||||
|
Shared_object(*genode_env, global_alloc, name, bind, keep);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
snprintf(err_str, MAX_ERR, "Unable to open file %s\n", name);
|
snprintf(err_str, MAX_ERR, "Unable to open file %s\n", name);
|
||||||
}
|
}
|
||||||
@ -117,7 +122,7 @@ int dladdr(const void *addr, Dl_info *dlip)
|
|||||||
|
|
||||||
int dlclose(void *handle)
|
int dlclose(void *handle)
|
||||||
{
|
{
|
||||||
destroy(env()->heap(), to_object(handle));
|
destroy(Libc::Allocator(), to_object(handle));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,11 @@ namespace Libc {
|
|||||||
* Support for shared libraries
|
* Support for shared libraries
|
||||||
*/
|
*/
|
||||||
void init_dl(Genode::Env &env);
|
void init_dl(Genode::Env &env);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global memory allocator
|
||||||
|
*/
|
||||||
|
void init_mem_alloc(Genode::Env &env);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _LIBC_INIT_H_ */
|
#endif /* _LIBC_INIT_H_ */
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
#include <base/env.h>
|
#include <base/env.h>
|
||||||
#include <base/allocator_avl.h>
|
#include <base/allocator_avl.h>
|
||||||
#include <base/printf.h>
|
#include <base/sleep.h>
|
||||||
|
|
||||||
/* local includes */
|
/* local includes */
|
||||||
#include "libc_mem_alloc.h"
|
#include "libc_mem_alloc.h"
|
||||||
|
#include "libc_init.h"
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ int Libc::Mem_alloc_impl::Dataspace_pool::expand(size_t size, Range_allocator *a
|
|||||||
|
|
||||||
/* now that we have new backing store, allocate Dataspace structure */
|
/* now that we have new backing store, allocate Dataspace structure */
|
||||||
if (alloc->alloc_aligned(sizeof(Dataspace), &ds_addr, 2).error()) {
|
if (alloc->alloc_aligned(sizeof(Dataspace), &ds_addr, 2).error()) {
|
||||||
PWRN("could not allocate meta data - this should never happen");
|
Genode::warning("libc: could not allocate meta data - this should never happen");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ void *Libc::Mem_alloc_impl::alloc(size_t size, size_t align_log2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_ds_pool.expand(align_addr(request_size, 12), &_alloc) < 0) {
|
if (_ds_pool.expand(align_addr(request_size, 12), &_alloc) < 0) {
|
||||||
PWRN("could not expand dataspace pool");
|
Genode::warning("libc: could not expand dataspace pool");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,10 +137,26 @@ Genode::size_t Libc::Mem_alloc_impl::size_at(void const *addr) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Libc::Mem_alloc *Libc::mem_alloc()
|
static Libc::Mem_alloc *_libc_mem_alloc;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Libc {
|
||||||
|
|
||||||
|
void init_mem_alloc(Genode::Env &env)
|
||||||
{
|
{
|
||||||
static Libc::Mem_alloc_impl inst;
|
static Libc::Mem_alloc_impl inst(env.rm(), env.ram());
|
||||||
return &inst;
|
_libc_mem_alloc = &inst;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Libc::Mem_alloc *Libc::mem_alloc()
|
||||||
|
{
|
||||||
|
if (!_libc_mem_alloc) {
|
||||||
|
error("attempt to use 'Libc::mem_alloc' before call of 'init_mem_alloc'");
|
||||||
|
Genode::sleep_forever();
|
||||||
|
}
|
||||||
|
return _libc_mem_alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,10 +108,9 @@ namespace Libc {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Mem_alloc_impl(Genode::Region_map * rm = Genode::env()->rm_session(),
|
Mem_alloc_impl(Genode::Region_map &rm, Genode::Ram_session &ram)
|
||||||
Genode::Ram_session * ram = Genode::env()->ram_session())
|
|
||||||
:
|
:
|
||||||
_ds_pool(ram, rm),
|
_ds_pool(&ram, &rm),
|
||||||
_alloc(0),
|
_alloc(0),
|
||||||
_chunk_size(MIN_CHUNK_SIZE)
|
_chunk_size(MIN_CHUNK_SIZE)
|
||||||
{ }
|
{ }
|
||||||
|
@ -641,6 +641,7 @@ Genode::size_t Component::stack_size() { return Libc::Component::stack_size(); }
|
|||||||
void Component::construct(Genode::Env &env)
|
void Component::construct(Genode::Env &env)
|
||||||
{
|
{
|
||||||
/* pass Genode::Env to libc subsystems that depend on it */
|
/* pass Genode::Env to libc subsystems that depend on it */
|
||||||
|
Libc::init_mem_alloc(env);
|
||||||
Libc::init_dl(env);
|
Libc::init_dl(env);
|
||||||
|
|
||||||
kernel = unmanaged_singleton<Libc::Kernel>(env);
|
kernel = unmanaged_singleton<Libc::Kernel>(env);
|
||||||
|
@ -57,7 +57,8 @@ static Libc::Mem_alloc * heap_by_mmtag(MMTAG enmTag)
|
|||||||
return memory_regions[enmTag].heap;
|
return memory_regions[enmTag].heap;
|
||||||
|
|
||||||
memory_regions[enmTag].conn = new Sub_rm_connection(genode_env(), REGION_SIZE);
|
memory_regions[enmTag].conn = new Sub_rm_connection(genode_env(), REGION_SIZE);
|
||||||
memory_regions[enmTag].heap = new Libc::Mem_alloc_impl(memory_regions[enmTag].conn);
|
memory_regions[enmTag].heap = new Libc::Mem_alloc_impl(*memory_regions[enmTag].conn,
|
||||||
|
genode_env().ram());
|
||||||
|
|
||||||
return memory_regions[enmTag].heap;
|
return memory_regions[enmTag].heap;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ extern "C" void pthread_yield(void)
|
|||||||
|
|
||||||
void *operator new (__SIZE_TYPE__ size, int log2_align)
|
void *operator new (__SIZE_TYPE__ size, int log2_align)
|
||||||
{
|
{
|
||||||
static Libc::Mem_alloc_impl heap(&genode_env().rm());
|
static Libc::Mem_alloc_impl heap(genode_env().rm(), genode_env().ram());
|
||||||
return heap.alloc(size, log2_align);
|
return heap.alloc(size, log2_align);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ static Libc::Mem_alloc * heap_by_mmtag(MMTAG enmTag)
|
|||||||
return memory_regions[enmTag].heap;
|
return memory_regions[enmTag].heap;
|
||||||
|
|
||||||
memory_regions[enmTag].conn = new Sub_rm_connection(genode_env(), REGION_SIZE);
|
memory_regions[enmTag].conn = new Sub_rm_connection(genode_env(), REGION_SIZE);
|
||||||
memory_regions[enmTag].heap = new Libc::Mem_alloc_impl(memory_regions[enmTag].conn);
|
memory_regions[enmTag].heap = new Libc::Mem_alloc_impl(*memory_regions[enmTag].conn,
|
||||||
|
genode_env().ram());
|
||||||
|
|
||||||
return memory_regions[enmTag].heap;
|
return memory_regions[enmTag].heap;
|
||||||
}
|
}
|
||||||
|
@ -544,7 +544,7 @@ extern "C" void pthread_yield(void)
|
|||||||
|
|
||||||
void *operator new (__SIZE_TYPE__ size, int log2_align)
|
void *operator new (__SIZE_TYPE__ size, int log2_align)
|
||||||
{
|
{
|
||||||
static Libc::Mem_alloc_impl heap(&genode_env().rm());
|
static Libc::Mem_alloc_impl heap(genode_env().rm(), genode_env().ram());
|
||||||
return heap.alloc(size, log2_align);
|
return heap.alloc(size, log2_align);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user