Files
genode/base-linux/src/core/rom_session_component.cc
Norman Feske de69ee2e66 Linux: cleanup system-call bindings
This patch simplifies the system call bindings. The common syscall
bindings in 'src/platform/' have been reduced to the syscalls needed by
non-core programs. The additional syscalls that are needed solely by
core have been moved to 'src/core/include/core_linux_syscalls.h'.
Furthermore, the resource path is not used outside of core anymore.
Hence, we could get rid of the rpath library. The resource-path code has
been moved to 'src/core/include/resource_path.h'. The IPC-related parts
of 'src/platform' have been moved to the IPC library. So there is now a
clean separation between low-level syscall bindings (in 'src/platform')
and higher-level code.

The code for the socket-descriptor registry is now located in the
'src/base/ipc/socket_descriptor_registry.h' header. The interface is
separated from 'ipc.cc' because core needs to access the registry from
outside the ipc library.
2012-11-05 17:31:04 +01:00

85 lines
2.0 KiB
C++

/*
* \brief Linux-specific core implementation of the ROM session interface
* \author Norman Feske
* \date 2006-07-06
*
* The Linux version of ROM session component does not use the
* Rom_fs as provided as constructor argument. Instead, we map
* rom modules directly to files of the host file system.
*/
/*
* 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.
*/
/* Linux includes */
#include <core_linux_syscalls.h>
#include <sys/fcntl.h>
/* Genode includes */
#include <linux_dataspace/linux_dataspace.h>
#include <util/arg_string.h>
#include <root/root.h>
/* local includes */
#include "rom_session_component.h"
using namespace Genode;
static Genode::size_t file_size(const char *path)
{
struct stat64 s;
if (lx_stat(path, &s) < 0)
return 0;
else
return s.st_size;
}
Rom_session_component::Rom_session_component(Rom_fs *rom_fs,
Rpc_entrypoint *ds_ep,
const char *args)
: _ds_ep(ds_ep)
{
/* extract filename from session arguments */
char fname[Linux_dataspace::FNAME_LEN];
Arg_string::find_arg(args, "filename").string(fname, sizeof(fname), "");
/* only files inside the current working directory are allowed */
for (const char *c = fname; *c; c++)
if (*c == '/')
throw Root::Invalid_args();
Genode::size_t const fsize = file_size(fname);
/* use invalid capability as default value */
_ds_cap = Rom_dataspace_capability();
/* ROM module not found */
if (fsize == 0)
throw Root::Invalid_args();
int const fd = lx_open(fname, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR);
_ds = Dataspace_component(fsize, 0, false, false, 0);
_ds.fd(fd);
_ds.fname(fname);
Dataspace_capability ds_cap = _ds_ep->manage(&_ds);
_ds_cap = static_cap_cast<Rom_dataspace>(ds_cap);
}
Rom_session_component::~Rom_session_component()
{
_ds_ep->dissolve(&_ds);
int const fd = _ds.fd().dst().socket;
if (fd != -1)
lx_close(fd);
}