This patch integrates three region maps into each PD session to reduce the session overhead and to simplify the PD creation procedure. Please refer to the issue cited below for an elaborative discussion. Note the API change: With this patch, the semantics of core's RM service have changed. Now, the service is merely a tool for creating and destroying managed dataspaces, which are rarely needed. Regular components no longer need a RM session. For this reason, the corresponding argument for the 'Process' and 'Child' constructors has been removed. The former interface of the 'Rm_session' is not named 'Region_map'. As a minor refinement, the 'Fault_type' enum values are now part of the 'Region_map::State' struct. Issue #1938
108 lines
2.6 KiB
C++
108 lines
2.6 KiB
C++
/*
|
|
* \brief Linux region-map test
|
|
* \author Christian Helmuth
|
|
* \date 2013-09-06
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2006-2013 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.
|
|
*/
|
|
|
|
/* Genode includes */
|
|
#include <base/printf.h>
|
|
#include <base/env.h>
|
|
#include <base/sleep.h>
|
|
#include <base/thread.h>
|
|
#include <util/misc_math.h>
|
|
#include <rm_session/connection.h>
|
|
#include <region_map/client.h>
|
|
|
|
|
|
static void blob() __attribute__((used));
|
|
static void blob()
|
|
{
|
|
asm volatile (
|
|
".balign 4096, -1\n"
|
|
"blob_beg:\n"
|
|
".space 16*4096, -2\n"
|
|
"blob_end:\n"
|
|
".global blob_beg\n"
|
|
".global blob_end\n"
|
|
: : : );
|
|
}
|
|
|
|
|
|
extern unsigned long blob_beg;
|
|
extern unsigned long blob_end;
|
|
|
|
|
|
int main()
|
|
{
|
|
using namespace Genode;
|
|
|
|
/* activate for early printf in Rm_session_mmap::attach() etc. */
|
|
if (0) Thread_base::trace("FOO");
|
|
|
|
/* induce initial heap expansion to remove RM noise */
|
|
if (1) {
|
|
void *addr(env()->heap()->alloc(0x100000));
|
|
env()->heap()->free(addr, 0);
|
|
}
|
|
|
|
addr_t beg((addr_t)&blob_beg);
|
|
addr_t end(align_addr((addr_t)&blob_end, 12));
|
|
|
|
size_t size(end - beg);
|
|
|
|
PLOG("blob region region [%016lx,%016lx) size=%zx", beg, end, size);
|
|
|
|
/* RAM dataspace attachment overlapping binary */
|
|
try {
|
|
Ram_dataspace_capability ds(env()->ram_session()->alloc(size));
|
|
|
|
PLOG("before RAM dataspace attach");
|
|
env()->rm_session()->attach_at(ds, beg);
|
|
PERR("after RAM dataspace attach -- ERROR");
|
|
sleep_forever();
|
|
} catch (Region_map::Region_conflict) {
|
|
PLOG("OK caught Region_conflict exception");
|
|
}
|
|
|
|
/* empty managed dataspace overlapping binary */
|
|
try {
|
|
Rm_connection rm_connection;
|
|
Region_map_client rm(rm_connection.create(size));
|
|
Dataspace_capability ds(rm.dataspace());
|
|
|
|
PLOG("before sub-RM dataspace attach");
|
|
env()->rm_session()->attach_at(ds, beg);
|
|
PERR("after sub-RM dataspace attach -- ERROR");
|
|
sleep_forever();
|
|
} catch (Region_map::Region_conflict) {
|
|
PLOG("OK caught Region_conflict exception");
|
|
}
|
|
|
|
/* sparsely populated managed dataspace in free VM area */
|
|
try {
|
|
Rm_connection rm_connection;
|
|
Region_map_client rm(rm_connection.create(0x100000));
|
|
|
|
rm.attach_at(env()->ram_session()->alloc(0x1000), 0x1000);
|
|
|
|
Dataspace_capability ds(rm.dataspace());
|
|
|
|
PLOG("before populated sub-RM dataspace attach");
|
|
char *addr = (char *)env()->rm_session()->attach(ds) + 0x1000;
|
|
PLOG("after populated sub-RM dataspace attach / before touch");
|
|
char const val = *addr;
|
|
*addr = 0x55;
|
|
PLOG("after touch (%x/%x)", val, *addr);
|
|
} catch (Region_map::Region_conflict) {
|
|
PERR("Caught Region_conflict exception -- ERROR");
|
|
sleep_forever();
|
|
}
|
|
}
|