mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-24 07:46:42 +00:00
lx_kit: optional global env + internal allocator
* make Lx::Malloc a real Genode allocator, so it can be used with 'new' and 'destroy; * add optional Lx_kit::Env class issue #2019
This commit is contained in:
parent
a145e6ad70
commit
58ef6e3695
@ -165,7 +165,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
|
|||||||
* XXX SLAB_LX_DMA is never used anywhere else, remove it?
|
* XXX SLAB_LX_DMA is never used anywhere else, remove it?
|
||||||
*/
|
*/
|
||||||
enum { SLAB_LX_DMA = 0x80000000ul, };
|
enum { SLAB_LX_DMA = 0x80000000ul, };
|
||||||
return new (Genode::env()->heap()) kmem_cache(size, flags & SLAB_LX_DMA, ctor);
|
return new (Lx::Malloc::mem()) kmem_cache(size, flags & SLAB_LX_DMA, ctor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void kmem_cache_destroy(struct kmem_cache *cache)
|
||||||
|
{
|
||||||
|
destroy(Lx::Malloc::mem(), cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
47
repos/dde_linux/src/include/lx_kit/env.h
Normal file
47
repos/dde_linux/src/include/lx_kit/env.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* \brief Helper class to make the Genode Env globally available
|
||||||
|
* \author Sebastian Sumpf
|
||||||
|
* \date 2016-06-21
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LX_KIT__ENV_H_
|
||||||
|
#define _LX_KIT__ENV_H_
|
||||||
|
|
||||||
|
#include <base/attached_rom_dataspace.h>
|
||||||
|
#include <base/env.h>
|
||||||
|
#include <base/heap.h>
|
||||||
|
#include <util/volatile_object.h>
|
||||||
|
|
||||||
|
namespace Lx_kit {
|
||||||
|
class Env;
|
||||||
|
|
||||||
|
Env &env();
|
||||||
|
|
||||||
|
void construct_env(Genode::Env &env);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Lx_kit::Env
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
Genode::Env &_env;
|
||||||
|
Genode::Heap _heap { _env.ram(), _env.rm() };
|
||||||
|
Genode::Attached_rom_dataspace _config { _env, "config" };
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Env(Genode::Env &env) : _env(env) { }
|
||||||
|
|
||||||
|
Genode::Env &env() { return _env; }
|
||||||
|
Genode::Heap &heap() { return _heap; }
|
||||||
|
Genode::Attached_rom_dataspace &config_rom() { return _config; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _LX_KIT__ENV_H_ */
|
@ -28,7 +28,7 @@ namespace Lx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Lx::Malloc
|
class Lx::Malloc : public Genode::Allocator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -56,11 +56,23 @@ class Lx::Malloc
|
|||||||
*/
|
*/
|
||||||
virtual bool inside(addr_t const addr) const = 0;
|
virtual bool inside(addr_t const addr) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Genode alllocator interface
|
||||||
|
*/
|
||||||
|
bool need_size_for_free() const override { return false; }
|
||||||
|
|
||||||
|
size_t overhead(size_t size) const override { return 0; }
|
||||||
|
|
||||||
|
bool alloc(size_t size, void **out_addr) override
|
||||||
|
{
|
||||||
|
*out_addr = alloc(size);
|
||||||
|
return *out_addr ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free(void *addr, size_t size) override { free(addr); }
|
||||||
|
|
||||||
static Malloc &mem();
|
static Malloc &mem();
|
||||||
static Malloc &dma();
|
static Malloc &dma();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void *operator new (Genode::size_t, Lx::Malloc &);
|
|
||||||
|
|
||||||
#endif /* _LX_KIT__MALLOC_H_ */
|
#endif /* _LX_KIT__MALLOC_H_ */
|
||||||
|
31
repos/dde_linux/src/lx_kit/env.cc
Normal file
31
repos/dde_linux/src/lx_kit/env.cc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* \brief Usb::Env initialization
|
||||||
|
* \author Sebastian Sumpf
|
||||||
|
* \date 2016-06-23
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <lx_kit/env.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lx_kit enviroment instance
|
||||||
|
*/
|
||||||
|
static Genode::Lazy_volatile_object<Lx_kit::Env> _env;
|
||||||
|
|
||||||
|
|
||||||
|
Lx_kit::Env &Lx_kit::env()
|
||||||
|
{
|
||||||
|
return *_env;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Lx_kit::construct_env(Genode::Env &env)
|
||||||
|
{
|
||||||
|
_env.construct(env);
|
||||||
|
}
|
@ -382,7 +382,3 @@ Lx::Malloc &Lx::Malloc::mem() {
|
|||||||
Lx::Malloc &Lx::Malloc::dma() {
|
Lx::Malloc &Lx::Malloc::dma() {
|
||||||
return Lx_kit::Malloc::dma(); }
|
return Lx_kit::Malloc::dma(); }
|
||||||
|
|
||||||
/**
|
|
||||||
* Placement new for Malloc allocator
|
|
||||||
*/
|
|
||||||
void *operator new (Genode::size_t s, Lx::Malloc &a) { return a.alloc(s); }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user