2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Linux platform interface implementation
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-06-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-01-03 15:35:05 +01:00
|
|
|
* Copyright (C) 2006-2012 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* 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/lock.h>
|
|
|
|
|
|
|
|
/* local includes */
|
|
|
|
#include "platform.h"
|
|
|
|
#include "core_env.h"
|
2012-08-10 16:35:57 +02:00
|
|
|
#include "server_socket_pair.h"
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* Linux includes */
|
2012-08-10 16:35:57 +02:00
|
|
|
#include <core_linux_syscalls.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
static char _some_mem[80*1024*1024];
|
|
|
|
static Lock _wait_for_exit_lock(Lock::LOCKED); /* exit() sync */
|
|
|
|
|
|
|
|
|
|
|
|
static void signal_handler(int signum)
|
|
|
|
{
|
|
|
|
_wait_for_exit_lock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Platform::Platform()
|
|
|
|
: _ram_alloc(0)
|
|
|
|
{
|
|
|
|
/* catch control-c */
|
|
|
|
lx_sigaction(2, signal_handler);
|
|
|
|
|
|
|
|
/* create resource directory under /tmp */
|
2012-08-10 16:35:57 +02:00
|
|
|
lx_mkdir(resource_path(), S_IRWXU);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
_ram_alloc.add_range((addr_t)_some_mem, sizeof(_some_mem));
|
2012-11-26 20:30:35 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Occupy the socket handle that will be used to propagate the parent
|
|
|
|
* capability new processes. Otherwise, there may be the chance that the
|
|
|
|
* parent capability as supplied by the process creator will be assigned to
|
|
|
|
* this handle, which would result in a 'dup2' syscall taking
|
|
|
|
* PARENT_SOCKET_HANDLE as both source and target descriptor.
|
|
|
|
*/
|
|
|
|
lx_dup2(0, PARENT_SOCKET_HANDLE);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Platform::wait_for_exit()
|
|
|
|
{
|
|
|
|
/* block until exit condition is satisfied */
|
|
|
|
try { _wait_for_exit_lock.lock(); }
|
|
|
|
catch (Blocking_canceled) { };
|
|
|
|
}
|
|
|
|
|
2012-08-10 16:35:57 +02:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
void Core_parent::exit(int exit_value)
|
|
|
|
{
|
|
|
|
lx_exit_group(exit_value);
|
|
|
|
}
|
2012-08-09 16:52:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
** Support for IPC library **
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
Native_connection_state server_socket_pair()
|
|
|
|
{
|
2012-08-10 16:35:57 +02:00
|
|
|
return create_server_socket_pair(Thread_base::myself()->tid().tid);
|
2012-08-09 16:52:47 +02:00
|
|
|
}
|
2012-11-15 12:53:32 +01:00
|
|
|
|
|
|
|
void destroy_server_socket_pair(Native_connection_state const &ncs)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* As entrypoints in core are never destructed, this function is only
|
|
|
|
* called on IPC-client destruction. In this case, it's a no-op in core
|
|
|
|
* as well as in Genode processes.
|
|
|
|
*/
|
|
|
|
if (ncs.server_sd != -1 || ncs.client_sd != -1)
|
|
|
|
PERR("%s called for IPC server which should never happen", __func__);
|
|
|
|
}
|
2012-08-09 16:52:47 +02:00
|
|
|
}
|
|
|
|
|