base-linux: do not copy dataspace components
Dataspace components inherit from RPC objects which are non-copyable from now on. Therefore, the Rom_session_component's constructor had to be modified to not construct a dataspace component on the stack and assign it in the following. Ref #1704
This commit is contained in:
parent
c1492da15b
commit
bb4ee67357
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* \brief Linux-specific core implementation of the dataspace component
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2015-09-25
|
||||
*
|
||||
* 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) 2015 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 "dataspace_component.h"
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
Linux_dataspace::Filename Dataspace_component::_file_name(const char *args)
|
||||
{
|
||||
Filename fname;
|
||||
Arg_string::find_arg(args, "filename").string(fname.buf,
|
||||
sizeof(fname.buf), "");
|
||||
|
||||
/* only files inside the current working directory are allowed */
|
||||
for (const char *c = fname.buf; *c; c++)
|
||||
if (*c == '/') throw Root::Invalid_args();
|
||||
|
||||
return fname;
|
||||
}
|
||||
|
||||
|
||||
Genode::size_t Dataspace_component::_file_size()
|
||||
{
|
||||
struct stat64 s;
|
||||
if (lx_stat(_fname.buf, &s) < 0) throw Root::Invalid_args();
|
||||
|
||||
return s.st_size;
|
||||
}
|
||||
|
||||
|
||||
Dataspace_component::Dataspace_component(const char *args)
|
||||
: _fname(_file_name(args)),
|
||||
_size(_file_size()),
|
||||
_addr(0),
|
||||
_fd(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR)),
|
||||
_writable(false),
|
||||
_owner(0) { }
|
|
@ -36,9 +36,9 @@ namespace Genode {
|
|||
{
|
||||
private:
|
||||
|
||||
Filename _fname; /* filename for mmap */
|
||||
size_t _size; /* size of dataspace in bytes */
|
||||
addr_t _addr; /* meaningless on linux */
|
||||
Filename _fname; /* filename for mmap */
|
||||
int _fd; /* file descriptor */
|
||||
bool _writable; /* false if read-only */
|
||||
|
||||
|
@ -46,6 +46,9 @@ namespace Genode {
|
|||
* others is necessary on the dataspace, otherwise it is 0 */
|
||||
Dataspace_owner * _owner;
|
||||
|
||||
static Filename _file_name(const char *args);
|
||||
size_t _file_size();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -78,12 +81,11 @@ namespace Genode {
|
|||
}
|
||||
|
||||
/**
|
||||
* Define corresponding filename of dataspace
|
||||
* This constructor is especially used for ROM dataspaces
|
||||
*
|
||||
* The file name is only relevant for ROM dataspaces that should
|
||||
* be executed via execve.
|
||||
* \param args session parameters containing 'filename' key/value
|
||||
*/
|
||||
void fname(const char *fname) { strncpy(_fname.buf, fname, sizeof(_fname.buf)); }
|
||||
Dataspace_component(const char *args);
|
||||
|
||||
/**
|
||||
* Assign file descriptor to dataspace
|
||||
|
|
|
@ -30,45 +30,11 @@
|
|||
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)
|
||||
: _ds(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, CACHED, 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);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ SRC_CC = main.cc \
|
|||
cpu_session_component.cc \
|
||||
cpu_session_extension.cc \
|
||||
cpu_session_support.cc \
|
||||
dataspace_component.cc \
|
||||
pd_session_component.cc \
|
||||
io_mem_session_component.cc \
|
||||
signal_session_component.cc \
|
||||
|
|
Loading…
Reference in New Issue