vbox: alloc memory of RTMem*Alloc within 2G window

Fixes #2116
This commit is contained in:
Alexander Boettcher 2016-10-04 11:07:59 +02:00 committed by Christian Helmuth
parent aeb76b9c3c
commit 07b994c8bd
8 changed files with 23 additions and 145 deletions

View File

@ -6,7 +6,7 @@ INC_DIR += $(call select_from_repositories,src/lib/libc)
INC_DIR += $(call select_from_repositories,src/lib/pthread)
INC_DIR += $(VBOX_DIR)/VMM/include
INC_DIR += $(REP_DIR)/src/virtualbox5
INC_DIR += $(REP_DIR)/src/virtualbox
vpath sup.cc $(REP_DIR)/src/virtualbox5/spec/nova/
vpath pgm.cc $(REP_DIR)/src/virtualbox5/spec/nova/

View File

@ -32,55 +32,7 @@
#include <libc_mem_alloc.h>
#include "util.h"
/**
* Sub rm_session as backend for the Libc::Mem_alloc implementation.
* Purpose is that memory allocation by vbox of a specific type (MMTYP) are
* all located within a 2G virtual window. Reason is that virtualbox converts
* internally pointers at several places in base + offset, whereby offset is
* a int32_t type.
*/
class Sub_rm_connection : private Genode::Rm_connection,
public Genode::Region_map_client
{
private:
Genode::addr_t const _offset;
Genode::size_t const _size;
public:
Sub_rm_connection(Genode::size_t size)
:
Genode::Region_map_client(Rm_connection::create(size)),
_offset(Genode::env()->rm_session()->attach(dataspace())),
_size(size)
{ }
Local_addr attach(Genode::Dataspace_capability ds,
Genode::size_t size = 0, Genode::off_t offset = 0,
bool use_local_addr = false,
Local_addr local_addr = (void *)0,
bool executable = false)
{
Local_addr addr = Region_map_client::attach(ds, size, offset,
use_local_addr, local_addr,
executable);
Genode::addr_t new_addr = addr;
new_addr += _offset;
return Local_addr(new_addr);
}
bool contains(void * ptr)
{
Genode::addr_t addr = reinterpret_cast<Genode::addr_t>(ptr);
return (_offset <= addr && addr < _offset + _size);
}
};
#include "mm.h"
static struct {

View File

@ -26,6 +26,16 @@
#include <iprt/time.h>
#include <internal/iprt.h>
#include "mm.h"
enum {
MEMORY_MAX = 64 * 1024 * 1024,
MEMORY_CACHED = 16 * 1024 * 1024,
};
/* using managed dataspace to have all addresses within a 1 << 31 bit range */
static Sub_rm_connection rt_memory(2 * MEMORY_MAX);
class Avl_ds : public Genode::Avl_node<Avl_ds>
{
private:
@ -129,12 +139,6 @@ class Avl_ds : public Genode::Avl_node<Avl_ds>
static void memory_freeup(Genode::addr_t const cb)
{
/* free up memory if we hit some chosen limits */
enum {
MEMORY_MAX = 64 * 1024 * 1024,
MEMORY_CACHED = 16 * 1024 * 1024,
};
::size_t cbx = cb * 4;
while (_unused_ds.first() && cbx &&
(_mem_allocated + cb > MEMORY_MAX ||
@ -219,9 +223,9 @@ static void *alloc_mem(size_t cb, const char *pszTag, bool executable = false)
bool const any_addr = false;
void * any_local_addr = nullptr;
void * local_addr = env()->rm_session()->attach(ds, whole_size, offset,
any_addr, any_local_addr,
executable);
void * local_addr = rt_memory.attach(ds, whole_size, offset,
any_addr, any_local_addr,
executable);
Assert(local_addr);

View File

@ -23,7 +23,12 @@
#include <VBox/com/ptr.h>
#include <iprt/param.h>
#if VBOX_VERSION_MAJOR == 4
#include "MachineImpl.h"
HRESULT genode_setup_machine(ComObjPtr<Machine> machine);
HRESULT genode_check_memory_config(ComObjPtr<Machine> machine);
#endif
/**
* Returns true if a vCPU could be started. If false we run without
@ -46,8 +51,4 @@ Genode::Cpu_session * get_vcpu_cpu_session();
void genode_VMMR0_DO_GVMM_CREATE_VM(PSUPVMMR0REQHDR pReqHdr);
void genode_VMMR0_DO_GVMM_REGISTER_VMCPU(PVMR0 pVMR0, VMCPUID idCpu);
HRESULT genode_setup_machine(ComObjPtr<Machine> machine);
HRESULT genode_check_memory_config(ComObjPtr<Machine> machine);
#endif /* _SUP_H_ */

View File

@ -1,46 +0,0 @@
/*
* \brief Common VirtualBox SUPLib supplements
* \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.
*/
#ifndef _SUP_H_
#define _SUP_H_
/* Genode includes */
#include <cpu_session/cpu_session.h>
/* VirtualBox includes */
#include <VBox/vmm/vm.h>
#include <VBox/vmm/gvmm.h>
#include <iprt/param.h>
/**
* Returns true if a vCPU could be started. If false we run without
* hardware acceleration support.
*/
bool create_emt_vcpu(pthread_t * pthread, ::size_t stack,
const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg,
Genode::Cpu_session * cpu_session,
Genode::Affinity::Location location,
unsigned int cpu_id,
const char * name);
uint64_t genode_cpu_hz();
void genode_update_tsc(void (*update_func)(void), unsigned long update_us);
Genode::Cpu_session * get_vcpu_cpu_session();
void genode_VMMR0_DO_GVMM_CREATE_VM(PSUPVMMR0REQHDR pReqHdr);
void genode_VMMR0_DO_GVMM_REGISTER_VMCPU(PVMR0 pVMR0, VMCPUID idCpu);
#endif /* _SUP_H_ */

View File

@ -55,6 +55,9 @@ SRC_CC += frontend/dummy/errorinfo.cc frontend/dummy/virtualboxbase.cc
SRC_CC += frontend/dummy/autostart.cc frontend/dummy/rest.cc
SRC_CC += frontend/dummy/host.cc
#vbox 4 include
INC_DIR += $(REP_DIR)/src/virtualbox
INC_DIR += $(VBOX_DIR)/Main/include
INC_DIR += $(VBOX_DIR)/VMM/include

View File

@ -1,36 +0,0 @@
/*
* \brief VirtualBox utilities
* \author Christian Helmuth
* \date 2013-08-28
*/
/*
* Copyright (C) 2013-2014 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
#ifndef _UTIL_H_
#define _UTIL_H_
/* VirtualBox includes */
#include <iprt/types.h>
/**
* 64bit-aware cast of pointer to RTRCPTR (uint32_t)
*/
template <typename T>
RTRCPTR to_rtrcptr(T* ptr)
{
unsigned long long u64 = reinterpret_cast<unsigned long long>(ptr);
RTRCPTR rtrcptr = u64 & 0xFFFFFFFFULL;
AssertMsg((u64 == rtrcptr) || (u64 >> 32) == 0xFFFFFFFFULL,
("pointer transformation - %llx != %x", u64, rtrcptr));
return rtrcptr;
}
#endif /* _UTIL_H_ */