2013-08-21 09:37:21 +00:00
|
|
|
/*
|
|
|
|
* \brief VirtualBox runtime (RT)
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is distributed under the terms of the GNU General Public License
|
|
|
|
* version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <base/env.h>
|
2016-06-08 18:15:27 +00:00
|
|
|
#include <base/allocator_avl.h>
|
2013-08-21 09:37:21 +00:00
|
|
|
|
|
|
|
/* VirtualBox includes */
|
|
|
|
#include <iprt/initterm.h>
|
|
|
|
#include <iprt/mem.h>
|
|
|
|
#include <iprt/err.h>
|
2014-09-23 11:01:47 +00:00
|
|
|
#include <iprt/assert.h>
|
2013-08-21 09:37:21 +00:00
|
|
|
#include <iprt/semaphore.h>
|
|
|
|
#include <iprt/time.h>
|
|
|
|
#include <internal/iprt.h>
|
|
|
|
|
2016-06-08 18:15:27 +00:00
|
|
|
class Avl_ds : public Genode::Avl_node<Avl_ds>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Genode::Ram_dataspace_capability _ds;
|
|
|
|
Genode::addr_t _virt;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Avl_ds(Genode::Ram_dataspace_capability ds, void * virt)
|
|
|
|
: _ds(ds), _virt(reinterpret_cast<Genode::addr_t>(virt))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Avl_ds() {
|
|
|
|
Genode::env()->ram_session()->free(_ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool higher(Avl_ds *e) { return e->_virt > _virt; }
|
|
|
|
|
|
|
|
Avl_ds *find(Genode::addr_t virt)
|
|
|
|
{
|
|
|
|
if (virt == _virt) return this;
|
|
|
|
Avl_ds *obj = this->child(virt > _virt);
|
|
|
|
return obj ? obj->find(virt) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static Genode::Avl_tree<Avl_ds> runtime_ds;
|
2013-08-21 09:37:21 +00:00
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
static void *alloc_mem(size_t cb, const char *pszTag, bool executable = false)
|
2013-08-21 09:37:21 +00:00
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
try {
|
|
|
|
Ram_dataspace_capability ds = env()->ram_session()->alloc(cb);
|
|
|
|
Assert(ds.valid());
|
|
|
|
|
|
|
|
size_t const whole_size = 0;
|
|
|
|
Genode::off_t const offset = 0;
|
|
|
|
bool const any_addr = false;
|
|
|
|
void * any_local_addr = nullptr;
|
2013-08-21 09:37:21 +00:00
|
|
|
|
2016-06-08 18:15:27 +00:00
|
|
|
void * local_addr = env()->rm_session()->attach(ds, whole_size, offset,
|
|
|
|
any_addr, any_local_addr,
|
|
|
|
executable);
|
2014-09-23 11:01:47 +00:00
|
|
|
|
|
|
|
if (!local_addr)
|
2016-06-08 18:15:27 +00:00
|
|
|
PERR("%s size=0x%zx, tag=%s -> %p", __func__, cb, pszTag, local_addr);
|
2014-09-23 11:01:47 +00:00
|
|
|
Assert(local_addr);
|
|
|
|
|
2016-06-08 18:15:27 +00:00
|
|
|
runtime_ds.insert(new (env()->heap()) Avl_ds(ds, local_addr));
|
|
|
|
|
|
|
|
return local_addr;
|
2014-09-23 11:01:47 +00:00
|
|
|
} catch (...) {
|
|
|
|
Assert(!"Could not allocate RTMem* memory ");
|
2016-06-08 18:15:27 +00:00
|
|
|
return nullptr;
|
2014-09-23 11:01:47 +00:00
|
|
|
}
|
2013-08-21 09:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
/*
|
|
|
|
* Called by the recompiler to allocate executable RAM
|
|
|
|
*/
|
|
|
|
void *RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
|
|
|
|
{
|
|
|
|
return alloc_mem(cb, pszTag, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-21 09:37:21 +00:00
|
|
|
void *RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The RAM dataspace freshly allocated by 'RTMemExecAllocTag' is zeroed
|
|
|
|
* already.
|
|
|
|
*/
|
2014-09-23 11:01:47 +00:00
|
|
|
return alloc_mem(cb, pszTag);
|
2013-08-21 09:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
|
|
|
|
{
|
2014-09-23 11:01:47 +00:00
|
|
|
return alloc_mem(cb, pszTag);
|
2013-08-21 09:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
void RTMemPageFree(void *pv, size_t cb) RT_NO_THROW
|
|
|
|
{
|
2016-06-08 18:15:27 +00:00
|
|
|
Avl_ds * ds_obj = runtime_ds.first();
|
|
|
|
if (ds_obj)
|
|
|
|
ds_obj = ds_obj->find(reinterpret_cast<Genode::addr_t>(pv));
|
|
|
|
|
|
|
|
if (ds_obj) {
|
|
|
|
runtime_ds.remove(ds_obj);
|
|
|
|
destroy(Genode::env()->heap(), ds_obj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PERR("%s unknown memory region %p+%zx", __func__, pv, cb);
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 09:37:21 +00:00
|
|
|
#include <iprt/buildconfig.h>
|
|
|
|
|
|
|
|
uint32_t RTBldCfgVersionMajor(void) { return VBOX_VERSION_MAJOR; }
|
|
|
|
uint32_t RTBldCfgVersionMinor(void) { return VBOX_VERSION_MINOR; }
|
|
|
|
uint32_t RTBldCfgVersionBuild(void) { return VBOX_VERSION_BUILD; }
|
|
|
|
uint32_t RTBldCfgRevision(void) { return ~0; }
|
|
|
|
|
|
|
|
|
2014-05-23 07:26:57 +00:00
|
|
|
extern "C" DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath)
|
2013-08-21 09:37:21 +00:00
|
|
|
{
|
2014-05-23 07:26:57 +00:00
|
|
|
Genode::strncpy(pszPath, "/virtualbox", cchPath);
|
2013-08-21 09:37:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|