Linux: remove 'some_mem' array in core

The Linux version of core used a part of the BSS to simulate access to
physical memory. All dataspaces would refer to a portion of 'some_mem'.
So every time when core would access the dataspace content, it would
access its local BSS. For all processes outside of core, dataspaces were
represented as files. This patch removes the distinction between core
and non-core processes. Now, core uses the same 'Rm_session_mmap'
implementation as regular processes. This way, the 'some_mem' could be
abandoned. We still use BSS variable for allocating core-local meta
data through.
This commit is contained in:
Norman Feske
2012-12-04 16:51:24 +01:00
parent 8930ce765d
commit f081733f4b
10 changed files with 486 additions and 85 deletions

View File

@ -14,11 +14,39 @@
#include <util/arg_string.h>
#include <base/platform_env.h>
#include <base/thread.h>
#include <linux_dataspace/client.h>
#include <linux_syscalls.h>
using namespace Genode;
/****************************************************
** Support for Platform_env_base::Rm_session_mmap **
****************************************************/
Genode::size_t
Platform_env_base::Rm_session_mmap::_dataspace_size(Dataspace_capability ds)
{
if (ds.valid())
return Dataspace_client(ds).size();
return Dataspace_capability::deref(ds)->size();
}
int Platform_env_base::Rm_session_mmap::_dataspace_fd(Dataspace_capability ds)
{
return Linux_dataspace_client(ds).fd().dst().socket;
}
bool
Platform_env_base::Rm_session_mmap::_dataspace_writable(Dataspace_capability ds)
{
return Dataspace_client(ds).writable();
}
/********************************
** Platform_env::Local_parent **
********************************/
@ -83,7 +111,7 @@ extern char **lx_environ;
/**
* Read environment variable as long value
*/
unsigned long Platform_env::_get_env_ulong(const char *key)
static unsigned long get_env_ulong(const char *key)
{
for (char **curr = lx_environ; curr && *curr; curr++) {
@ -96,6 +124,24 @@ unsigned long Platform_env::_get_env_ulong(const char *key)
}
static Parent_capability obtain_parent_cap()
{
long local_name = get_env_ulong("parent_local_name");
/* produce typed capability manually */
typedef Native_capability::Dst Dst;
Dst const dst(PARENT_SOCKET_HANDLE);
return reinterpret_cap_cast<Parent>(Native_capability(dst, local_name));
}
Platform_env::Local_parent &Platform_env::_parent()
{
static Local_parent local_parent(obtain_parent_cap());
return local_parent;
}
/*****************************
** Support for IPC library **
*****************************/

View File

@ -19,15 +19,6 @@
using namespace Genode;
static Genode::size_t dataspace_size(Dataspace_capability ds)
{
if (ds.valid())
return Dataspace_client(ds).size();
return Dataspace_capability::deref(ds)->size();
}
static bool is_sub_rm_session(Dataspace_capability ds)
{
if (ds.valid())
@ -37,12 +28,16 @@ static bool is_sub_rm_session(Dataspace_capability ds)
}
static void *map_local(Dataspace_capability ds, Genode::size_t size,
addr_t offset, bool use_local_addr, addr_t local_addr,
bool executable)
void *
Platform_env_base::Rm_session_mmap::_map_local(Dataspace_capability ds,
Genode::size_t size,
addr_t offset,
bool use_local_addr,
addr_t local_addr,
bool executable)
{
int const fd = Linux_dataspace_client(ds).fd().dst().socket;
bool const writable = Dataspace_client(ds).writable();
int const fd = _dataspace_fd(ds);
bool const writable = _dataspace_writable(ds);
int const flags = MAP_SHARED | (use_local_addr ? MAP_FIXED : 0);
int const prot = PROT_READ
@ -60,7 +55,7 @@ static void *map_local(Dataspace_capability ds, Genode::size_t size,
lx_close(fd);
if (((long)addr_out < 0) && ((long)addr_out > -4095)) {
PERR("map_local: return value of mmap is %ld", (long)addr_out);
PERR("_map_local: return value of mmap is %ld", (long)addr_out);
throw Rm_session::Region_conflict();
}
@ -97,8 +92,8 @@ Platform_env::Rm_session_mmap::attach(Dataspace_capability ds,
throw Region_conflict();
}
size_t const remaining_ds_size = dataspace_size(ds) > (addr_t)offset
? dataspace_size(ds) - (addr_t)offset : 0;
size_t const remaining_ds_size = _dataspace_size(ds) > (addr_t)offset
? _dataspace_size(ds) - (addr_t)offset : 0;
/* determine size of virtual address region */
size_t const region_size = size ? min(remaining_ds_size, size)
@ -148,7 +143,7 @@ Platform_env::Rm_session_mmap::attach(Dataspace_capability ds,
* and map it.
*/
if (_is_attached())
map_local(ds, region_size, offset, true, _base + (addr_t)local_addr, executable);
_map_local(ds, region_size, offset, true, _base + (addr_t)local_addr, executable);
return (void *)local_addr;
@ -194,9 +189,9 @@ Platform_env::Rm_session_mmap::attach(Dataspace_capability ds,
if (!region.used())
continue;
map_local(region.dataspace(), region.size(), region.offset(),
true, rm->_base + region.start() + region.offset(),
executable);
_map_local(region.dataspace(), region.size(), region.offset(),
true, rm->_base + region.start() + region.offset(),
executable);
}
return rm->_base;
@ -208,8 +203,8 @@ Platform_env::Rm_session_mmap::attach(Dataspace_capability ds,
*
* Boring, a plain dataspace is attached to a root RM session.
*/
void *addr = map_local(ds, region_size, offset, use_local_addr,
local_addr, executable);
void *addr = _map_local(ds, region_size, offset, use_local_addr,
local_addr, executable);
_add_to_rmap(Region((addr_t)addr, offset, ds, region_size));