genode/base-linux/src/core/include/cpu_session_component.h
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

153 lines
4.5 KiB
C++

/*
* \brief Core-specific instance of the CPU session/thread interfaces
* \author Christian Helmuth
* \author Norman Feske
* \date 2006-07-17
*/
/*
* Copyright (C) 2006-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.
*/
#ifndef _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_
#define _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_
/* Genode includes */
#include <util/list.h>
#include <base/allocator_guard.h>
#include <base/lock.h>
#include <base/pager.h>
#include <base/rpc_server.h>
#include <linux_cpu_session/linux_cpu_session.h>
/* core includes */
#include <cpu_thread_allocator.h>
#include <platform_thread.h>
namespace Genode {
/**
* RPC interface of CPU thread
*
* We make 'Cpu_thread' a RPC object only to be able to lookup CPU threads
* from thread capabilities supplied as arguments to CPU-session functions.
* A CPU thread does not provide an actual RPC interface.
*/
struct Cpu_thread
{
GENODE_RPC_INTERFACE();
};
class Cpu_thread_component : public Rpc_object<Cpu_thread>,
public List<Cpu_thread_component>::Element
{
private:
Platform_thread _platform_thread;
bool _bound; /* pd binding flag */
public:
Cpu_thread_component(const char *name, unsigned priority,
addr_t utcb)
: _platform_thread(name, priority, utcb), _bound(false) { }
/************************
** Accessor functions **
************************/
inline Platform_thread * platform_thread() { return &_platform_thread; }
inline bool bound() const { return _bound; }
inline void bound(bool b) { _bound = b; }
};
class Cpu_session_component : public Rpc_object<Linux_cpu_session>
{
private:
Rpc_entrypoint *_thread_ep;
Pager_entrypoint *_pager_ep;
Allocator_guard _md_alloc; /* guarded meta-data allocator */
Cpu_thread_allocator _thread_alloc; /* meta-data allocator */
Lock _thread_alloc_lock; /* protect allocator access */
List<Cpu_thread_component> _thread_list;
Lock _thread_list_lock; /* protect thread list */
unsigned _priority; /* priority of threads
created with this
session */
/**
* Lookup thread in CPU session by its capability
*
* \retval NULL thread capability is invalid or
* does not belong to the CPU session
*/
Cpu_thread_component *_lookup_thread(Thread_capability thread) {
return dynamic_cast<Cpu_thread_component *>
(_thread_ep->obj_by_cap(thread)); }
/**
* Raw thread-killing functionality
*
* This function is called from the 'kill_thread' function and
* the destructor. Each these functions grab the list lock
* by themselves and call this function to perform the actual
* killing.
*/
void _unsynchronized_kill_thread(Cpu_thread_component *thread);
public:
/**
* Constructor
*/
Cpu_session_component(Rpc_entrypoint *thread_ep,
Pager_entrypoint *pager_ep,
Allocator *md_alloc, const char *args);
/**
* Destructor
*/
~Cpu_session_component();
/***************************
** CPU session interface **
***************************/
Thread_capability create_thread(Name const &, addr_t utcb);
Ram_dataspace_capability utcb(Thread_capability thread);
void kill_thread(Thread_capability);
Thread_capability first();
Thread_capability next(Thread_capability);
int set_pager(Thread_capability, Pager_capability);
int start(Thread_capability, addr_t, addr_t);
void pause(Thread_capability thread_cap);
void resume(Thread_capability thread_cap);
void cancel_blocking(Thread_capability);
int name(Thread_capability, char *, size_t);
int state(Thread_capability, Thread_state *);
void exception_handler(Thread_capability, Signal_context_capability);
unsigned num_cpus() const;
void affinity(Thread_capability, unsigned);
/*******************************
** Linux-specific extensions **
*******************************/
void thread_id(Thread_capability, int, int);
Untyped_capability server_sd(Thread_capability);
Untyped_capability client_sd(Thread_capability);
};
}
#endif /* _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ */