mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 15:43:56 +00:00
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.
This commit is contained in:
34
base-linux/src/base/env/platform_env.cc
vendored
34
base-linux/src/base/env/platform_env.cc
vendored
@ -13,6 +13,7 @@
|
||||
|
||||
#include <util/arg_string.h>
|
||||
#include <base/platform_env.h>
|
||||
#include <base/thread.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
@ -95,3 +96,36 @@ unsigned long Platform_env::_get_env_ulong(const char *key)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,10 @@
|
||||
#include <base/ipc.h>
|
||||
#include <base/thread.h>
|
||||
#include <base/blocking.h>
|
||||
#include <base/env.h>
|
||||
#include <linux_cpu_session/linux_cpu_session.h>
|
||||
|
||||
/* Linux includes */
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <linux_socket.h>
|
||||
#include <linux_syscalls.h>
|
||||
|
||||
@ -219,6 +216,20 @@ void Ipc_server::_reply_wait()
|
||||
}
|
||||
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/*
|
||||
* Helper for obtaining a bound and connected socket pair
|
||||
*
|
||||
* For core, the implementation is just a wrapper around
|
||||
* 'lx_server_socket_pair()'. For all other processes, the implementation
|
||||
* requests the socket pair from the Env::CPU session interface using a
|
||||
* Linux-specific interface extension.
|
||||
*/
|
||||
Native_connection_state server_socket_pair();
|
||||
}
|
||||
|
||||
|
||||
Ipc_server::Ipc_server(Msgbuf_base *snd_msg, Msgbuf_base *rcv_msg)
|
||||
:
|
||||
Ipc_istream(rcv_msg),
|
||||
@ -238,10 +249,10 @@ Ipc_server::Ipc_server(Msgbuf_base *snd_msg, Msgbuf_base *rcv_msg)
|
||||
throw Ipc_server_multiple_instance();
|
||||
}
|
||||
|
||||
_rcv_cs = lx_server_socket_pair(Thread_base::myself());
|
||||
|
||||
if (thread)
|
||||
if (thread) {
|
||||
_rcv_cs = server_socket_pair();
|
||||
thread->tid().is_ipc_server = true;
|
||||
}
|
||||
|
||||
/* override capability initialization performed by 'Ipc_istream' */
|
||||
*static_cast<Native_capability *>(this) =
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <base/thread.h>
|
||||
#include <base/snprintf.h>
|
||||
#include <base/sleep.h>
|
||||
#include <linux_cpu_session/linux_cpu_session.h>
|
||||
|
||||
/* Linux syscall bindings */
|
||||
#include <linux_syscalls.h>
|
||||
@ -50,7 +51,10 @@ static void thread_start(void *)
|
||||
}
|
||||
|
||||
|
||||
void Thread_base::_init_platform_thread() { }
|
||||
void Thread_base::_init_platform_thread()
|
||||
{
|
||||
_thread_cap = env()->cpu_session()->create_thread(_context->name);
|
||||
}
|
||||
|
||||
|
||||
void Thread_base::_deinit_platform_thread()
|
||||
@ -103,14 +107,10 @@ void Thread_base::start()
|
||||
_tid.tid = lx_create_thread(thread_start, thread_sp, this);
|
||||
_tid.pid = lx_getpid();
|
||||
|
||||
/*
|
||||
* Inform core about the new thread by calling create_thread and encoding
|
||||
* the thread's PID in the thread-name argument.
|
||||
*/
|
||||
char name_and_pid[Cpu_session::THREAD_NAME_LEN + 2*16];
|
||||
snprintf(name_and_pid, sizeof(name_and_pid), "%s:0x%x:0x%x",
|
||||
_context->name, _tid.tid, _tid.pid);
|
||||
_thread_cap = env()->cpu_session()->create_thread(name_and_pid);
|
||||
/* inform core about the new thread and process ID of the new thread */
|
||||
Linux_cpu_session *cpu = dynamic_cast<Linux_cpu_session *>(env()->cpu_session());
|
||||
if (cpu)
|
||||
cpu->thread_id(_thread_cap, _tid.pid, _tid.tid);
|
||||
}
|
||||
|
||||
|
||||
|
52
base-linux/src/core/cpu_session_extension.cc
Normal file
52
base-linux/src/core/cpu_session_extension.cc
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* \brief Linux-specific extension of the CPU session implementation
|
||||
* \author Norman Feske
|
||||
* \date 2012-08-09
|
||||
*/
|
||||
|
||||
/* core includes */
|
||||
#include <cpu_session_component.h>
|
||||
|
||||
/* Linux includes */
|
||||
#include <linux_socket.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
void Cpu_session_component::thread_id(Thread_capability thread_cap, int pid, int tid)
|
||||
{
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
|
||||
Cpu_thread_component *thread = _lookup_thread(thread_cap);
|
||||
if (!thread) return;
|
||||
|
||||
thread->platform_thread()->thread_id(pid, tid);
|
||||
}
|
||||
|
||||
|
||||
Untyped_capability Cpu_session_component::server_sd(Thread_capability thread_cap)
|
||||
{
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
|
||||
Cpu_thread_component *thread = _lookup_thread(thread_cap);
|
||||
if (!thread) return Untyped_capability();
|
||||
|
||||
enum { DUMMY_LOCAL_NAME = 0 };
|
||||
typedef Native_capability::Dst Dst;
|
||||
return Untyped_capability(Dst(thread->platform_thread()->server_sd()),
|
||||
DUMMY_LOCAL_NAME);
|
||||
}
|
||||
|
||||
|
||||
Untyped_capability Cpu_session_component::client_sd(Thread_capability thread_cap)
|
||||
{
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
|
||||
Cpu_thread_component *thread = _lookup_thread(thread_cap);
|
||||
if (!thread) return Untyped_capability();
|
||||
|
||||
enum { DUMMY_LOCAL_NAME = 0 };
|
||||
typedef Native_capability::Dst Dst;
|
||||
return Untyped_capability(Dst(thread->platform_thread()->client_sd()),
|
||||
DUMMY_LOCAL_NAME);
|
||||
}
|
152
base-linux/src/core/include/cpu_session_component.h
Normal file
152
base-linux/src/core/include/cpu_session_component.h
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* \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_ */
|
@ -29,6 +29,11 @@ namespace Genode {
|
||||
unsigned long _pid;
|
||||
char _name[32];
|
||||
|
||||
/**
|
||||
* Unix-domain socket pair bound to the thread
|
||||
*/
|
||||
Native_connection_state _ncs;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -60,6 +65,24 @@ namespace Genode {
|
||||
int state(Thread_state *state_dst) { return 0; }
|
||||
const char *name() { return _name; }
|
||||
void affinity(unsigned) { }
|
||||
|
||||
/**
|
||||
* Register process ID and thread ID of thread
|
||||
*/
|
||||
void thread_id(int pid, int tid) { _pid = pid, _tid = tid; }
|
||||
|
||||
/**
|
||||
* Return client-side socket descriptor
|
||||
*
|
||||
* For more information, please refer to the comments in
|
||||
* 'linux_cpu_session/linux_cpu_session.h'.
|
||||
*/
|
||||
int client_sd();
|
||||
|
||||
/**
|
||||
* Return server-side socket descriptor
|
||||
*/
|
||||
int server_sd();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "core_env.h"
|
||||
|
||||
/* Linux includes */
|
||||
#include <linux_socket.h>
|
||||
#include <linux_syscalls.h>
|
||||
#include <linux_rpath.h>
|
||||
|
||||
@ -60,3 +61,17 @@ void Core_parent::exit(int exit_value)
|
||||
{
|
||||
lx_exit_group(exit_value);
|
||||
}
|
||||
|
||||
|
||||
/*****************************
|
||||
** Support for IPC library **
|
||||
*****************************/
|
||||
|
||||
namespace Genode {
|
||||
|
||||
Native_connection_state server_socket_pair()
|
||||
{
|
||||
return lx_server_socket_pair(Thread_base::myself()->tid().tid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
/* Linux syscall helper */
|
||||
#include <linux_syscalls.h>
|
||||
#include <linux_socket.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
@ -29,41 +30,9 @@ typedef Token<Scanner_policy_identifier_with_underline> Tid_token;
|
||||
|
||||
|
||||
Platform_thread::Platform_thread(const char *name, unsigned, addr_t)
|
||||
: _tid(-1), _pid(-1)
|
||||
{
|
||||
/* search for thread-id portion of thread name */
|
||||
Tid_token tok(name);
|
||||
while (tok.type() != Tid_token::END && tok[0] != ':')
|
||||
tok = tok.next();
|
||||
|
||||
/* tok points at the colon separator, next token is the id */
|
||||
tok = tok.next();
|
||||
|
||||
if (tok.type() == Tid_token::END) {
|
||||
PWRN("Invalid format of thread name.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* convert string to thread id */
|
||||
ascii_to(tok.start(), &_tid);
|
||||
|
||||
/* search for process-id portion of thread name */
|
||||
while (tok.type() != Tid_token::END && tok[0] != ':')
|
||||
tok = tok.next();
|
||||
|
||||
/* tok points at the colon separator, next token is the id */
|
||||
tok = tok.next();
|
||||
|
||||
if (tok.type() == Tid_token::END) {
|
||||
PWRN("Invalid format of thread name.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* convert string to process id */
|
||||
ascii_to(tok.start(), &_pid);
|
||||
|
||||
/* initialize private members */
|
||||
size_t name_len = tok.start() - name;
|
||||
strncpy(_name, name, min(sizeof(_name), name_len));
|
||||
strncpy(_name, name, min(sizeof(_name), strlen(name)));
|
||||
}
|
||||
|
||||
|
||||
@ -84,3 +53,20 @@ void Platform_thread::resume()
|
||||
{
|
||||
PDBG("not implemented");
|
||||
}
|
||||
|
||||
|
||||
int Platform_thread::client_sd()
|
||||
{
|
||||
/* construct socket pair on first call */
|
||||
if (_ncs.client_sd == -1)
|
||||
_ncs = lx_server_socket_pair(_tid);
|
||||
|
||||
return _ncs.client_sd;
|
||||
}
|
||||
|
||||
|
||||
int Platform_thread::server_sd()
|
||||
{
|
||||
client_sd();
|
||||
return _ncs.server_sd;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ SRC_CC = main.cc \
|
||||
ram_session_support.cc \
|
||||
rom_session_component.cc \
|
||||
cpu_session_component.cc \
|
||||
cpu_session_extension.cc \
|
||||
cpu_session_support.cc \
|
||||
pd_session_component.cc \
|
||||
io_mem_session_component.cc \
|
||||
|
@ -24,6 +24,13 @@
|
||||
#include <base/blocking.h>
|
||||
#include <base/snprintf.h>
|
||||
|
||||
/* Linux includes */
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Genode bindings to Linux kernel */
|
||||
#include <linux_rpath.h>
|
||||
#include <linux_syscalls.h>
|
||||
|
||||
@ -342,7 +349,7 @@ class Connect_failed { };
|
||||
* \throw Bind_failed
|
||||
* \throw Connect_failed
|
||||
*/
|
||||
static Genode::Native_connection_state lx_server_socket_pair(Genode::Thread_base *thread)
|
||||
static inline Genode::Native_connection_state lx_server_socket_pair(long thread_id)
|
||||
{
|
||||
Genode::Native_connection_state ncs;
|
||||
|
||||
@ -350,10 +357,10 @@ static Genode::Native_connection_state lx_server_socket_pair(Genode::Thread_base
|
||||
* Main thread uses 'Ipc_server' for 'sleep_forever()' only. No need for
|
||||
* binding.
|
||||
*/
|
||||
if (!thread)
|
||||
if (thread_id == -1)
|
||||
return ncs;
|
||||
|
||||
Uds_addr addr(thread->tid().tid);
|
||||
Uds_addr addr(thread_id);
|
||||
|
||||
/*
|
||||
* Create server-side socket
|
||||
@ -391,6 +398,12 @@ static Genode::Native_connection_state lx_server_socket_pair(Genode::Thread_base
|
||||
int const tid = lookup_tid_by_client_socket(ncs.client_sd);
|
||||
Genode::ep_sd_registry()->associate(ncs.client_sd, tid);
|
||||
|
||||
/*
|
||||
* Wipe Unix domain socket from the file system. It will live as long as
|
||||
* there exist references to it in the form of file descriptors.
|
||||
*/
|
||||
lx_unlink(addr.sun_path);
|
||||
|
||||
return ncs;
|
||||
}
|
||||
|
||||
@ -398,9 +411,9 @@ static Genode::Native_connection_state lx_server_socket_pair(Genode::Thread_base
|
||||
/**
|
||||
* Utility: Send request to server and wait for reply
|
||||
*/
|
||||
static void lx_call(int dst_sd,
|
||||
Genode::Msgbuf_base &send_msgbuf, size_t send_msg_len,
|
||||
Genode::Msgbuf_base &recv_msgbuf)
|
||||
static inline void lx_call(int dst_sd,
|
||||
Genode::Msgbuf_base &send_msgbuf, size_t send_msg_len,
|
||||
Genode::Msgbuf_base &recv_msgbuf)
|
||||
{
|
||||
int ret;
|
||||
Message send_msg(send_msgbuf.buf, send_msg_len);
|
||||
@ -426,7 +439,8 @@ static void lx_call(int dst_sd,
|
||||
|
||||
ret = lx_sendmsg(dst_sd, send_msg.msg(), 0);
|
||||
if (ret < 0) {
|
||||
PRAW("lx_sendmsg failed with %d in lx_call()", ret);
|
||||
PRAW("[%d] lx_sendmsg to sd %d failed with %d in lx_call()",
|
||||
lx_getpid(), dst_sd, ret);
|
||||
throw Genode::Ipc_error();
|
||||
}
|
||||
|
||||
@ -437,7 +451,7 @@ static void lx_call(int dst_sd,
|
||||
|
||||
ret = lx_recvmsg(reply_channel[LOCAL_SOCKET], recv_msg.msg(), 0);
|
||||
if (ret < 0) {
|
||||
PRAW("lx_recvmsg failed with %d in lx_call()", ret);
|
||||
PRAW("[%d] lx_recvmsg failed with %d in lx_call()", lx_getpid(), ret);
|
||||
throw Genode::Ipc_error();
|
||||
}
|
||||
|
||||
@ -454,8 +468,8 @@ static void lx_call(int dst_sd,
|
||||
*
|
||||
* \return socket descriptor of reply capability
|
||||
*/
|
||||
static int lx_wait(Genode::Native_connection_state &cs,
|
||||
Genode::Msgbuf_base &recv_msgbuf)
|
||||
static inline int lx_wait(Genode::Native_connection_state &cs,
|
||||
Genode::Msgbuf_base &recv_msgbuf)
|
||||
{
|
||||
Message msg(recv_msgbuf.buf, recv_msgbuf.size());
|
||||
|
||||
@ -478,9 +492,9 @@ static int lx_wait(Genode::Native_connection_state &cs,
|
||||
/**
|
||||
* Utility: Send reply to client
|
||||
*/
|
||||
static void lx_reply(int reply_socket,
|
||||
Genode::Msgbuf_base &send_msgbuf,
|
||||
size_t msg_len)
|
||||
static inline void lx_reply(int reply_socket,
|
||||
Genode::Msgbuf_base &send_msgbuf,
|
||||
size_t msg_len)
|
||||
{
|
||||
Message msg(send_msgbuf.buf, msg_len);
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <base/crt0.h>
|
||||
#include <base/printf.h>
|
||||
#include <_main_helper.h>
|
||||
#include <linux_cpu_session/linux_cpu_session.h>
|
||||
|
||||
|
||||
extern "C" int raw_write_str(const char *str);
|
||||
@ -59,6 +60,7 @@ __attribute__((constructor(101))) void lx_hybrid_init()
|
||||
char **genode_argv = 0;
|
||||
int genode_argc = 1;
|
||||
|
||||
|
||||
/************
|
||||
** Thread **
|
||||
************/
|
||||
@ -159,6 +161,23 @@ namespace Genode {
|
||||
static void empty_signal_handler(int) { }
|
||||
|
||||
|
||||
/**
|
||||
* Return Linux-specific extension of the Env::CPU session interface
|
||||
*/
|
||||
Linux_cpu_session *cpu_session()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
return cpu;
|
||||
}
|
||||
|
||||
|
||||
static void adopt_thread(Thread_meta_data *meta_data)
|
||||
{
|
||||
/*
|
||||
@ -277,6 +296,17 @@ Thread_base::Thread_base(const char *name, size_t stack_size)
|
||||
}
|
||||
|
||||
_tid.meta_data->construct_lock.lock();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
_thread_cap = cpu_session()->create_thread(name);
|
||||
cpu_session()->thread_id(_thread_cap, _tid.pid, _tid.tid);
|
||||
}
|
||||
|
||||
|
||||
@ -305,4 +335,7 @@ Thread_base::~Thread_base()
|
||||
|
||||
destroy(env()->heap(), _tid.meta_data);
|
||||
_tid.meta_data = 0;
|
||||
|
||||
/* inform core about the killed thread */
|
||||
cpu_session()->kill_thread(_thread_cap);
|
||||
}
|
||||
|
Reference in New Issue
Block a user