genode/base-linux/src/base/env/platform_env.cc
Norman Feske aee0a2061b Create entrypoint sockets in core only
This patch alleviates the need for any non-core process to create Unix
domain sockets locally. All sockets used for RPC communication are
created by core and subsequently passed to the other processes via RPC
or the parent interface. The immediate benefit is that no process other
than core needs to access the 'rpath' directory in order to communicate.
However, access to 'rpath' is still needed for accessing dataspaces.

Core creates one socket pair per thread on demand on the first call of
the 'Linux_cpu_session::server_sd()' or 'Linux_cpu_session::client_sd()'
functions. 'Linux_cpu_session' is a Linux-specific extension to the CPU
session interface. In addition to the socket accessors, the extension
provides a mechanism to register the PID/TID of a thread. Those
information were formerly propagated into core along with the thread
name as argument to 'create_thread()'.

Because core creates socket pairs for entrypoints, it needs to know all
threads that are potential entrypoints. For lx_hybrid programs, we
hadn't had propagated any thread information into core, yet. Hence, this
patch also contains the code for registering threads of hybrid
applications at core.
2012-11-05 17:31:04 +01:00

132 lines
2.9 KiB
C++

/*
* \brief Support for the Linux-specific environment
* \author Norman Feske
* \date 2008-12-12
*/
/*
* Copyright (C) 2008-2012 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 <util/arg_string.h>
#include <base/platform_env.h>
#include <base/thread.h>
using namespace Genode;
/********************************
** Platform_env::Local_parent **
********************************/
Session_capability
Platform_env::Local_parent::session(Service_name const &service_name,
Session_args const &args)
{
if (strcmp(service_name.string(),
Rm_session::service_name()) == 0)
{
size_t size =
Arg_string::find_arg(args.string(),"size")
.ulong_value(~0);
if (size == 0)
return Parent_client::session(service_name, args);
Rm_session_mmap *rm = new (env()->heap())
Rm_session_mmap(true, size);
return Local_interface::capability(rm);
}
return Parent_client::session(service_name, args);
}
void Platform_env::Local_parent::close(Session_capability session)
{
/*
* Handle non-local capabilities
*/
if (session.valid()) {
Parent_client::close(session);
return;
}
/*
* Detect capability to local RM session
*/
try {
Capability<Rm_session_mmap> rm =
static_cap_cast<Rm_session_mmap>(session);
destroy(env()->heap(), Local_interface::deref(rm));
} catch (Local_interface::Non_local_capability) { }
}
Platform_env::Local_parent::Local_parent(Parent_capability parent_cap)
: Parent_client(parent_cap) { }
/******************
** Platform_env **
******************/
/**
* List of Unix environment variables, initialized by the startup code
*/
extern char **lx_environ;
/**
* Read environment variable as long value
*/
unsigned long Platform_env::_get_env_ulong(const char *key)
{
for (char **curr = lx_environ; curr && *curr; curr++) {
Arg arg = Arg_string::find_arg(*curr, key);
if (arg.valid())
return arg.ulong_value(0);
}
return 0;
}
/*****************************
** Support for IPC library **
*****************************/
namespace Genode {
Native_connection_state server_socket_pair()
{
/*
* Obtain access to Linux-specific extension of the CPU session
* interface. We can cast to the specific type because the Linux
* version of 'Platform_env' is hosting a 'Linux_cpu_client' object.
*/
Linux_cpu_session *cpu = dynamic_cast<Linux_cpu_session *>(env()->cpu_session());
if (!cpu) {
PERR("could not obtain Linux extension to CPU session interface");
struct Could_not_access_linux_cpu_session { };
throw Could_not_access_linux_cpu_session();
}
Native_connection_state ncs;
Thread_base *thread = Thread_base::myself();
if (thread) {
ncs.server_sd = cpu->server_sd(thread->cap()).dst().socket;
ncs.client_sd = cpu->client_sd(thread->cap()).dst().socket;
}
return ncs;
}
}