From bb4ee6735753f4ed68ff2849304d5608dbc71eff Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Fri, 25 Sep 2015 10:50:08 +0200 Subject: [PATCH] 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 --- .../src/core/dataspace_component.cc | 62 +++++++++++++++++++ .../src/core/include/dataspace_component.h | 12 ++-- .../src/core/rom_session_component.cc | 36 +---------- repos/base-linux/src/core/target.mk | 1 + 4 files changed, 71 insertions(+), 40 deletions(-) create mode 100644 repos/base-linux/src/core/dataspace_component.cc diff --git a/repos/base-linux/src/core/dataspace_component.cc b/repos/base-linux/src/core/dataspace_component.cc new file mode 100644 index 000000000..b03390c86 --- /dev/null +++ b/repos/base-linux/src/core/dataspace_component.cc @@ -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 +#include + +/* Genode includes */ +#include +#include +#include + +/* 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) { } diff --git a/repos/base-linux/src/core/include/dataspace_component.h b/repos/base-linux/src/core/include/dataspace_component.h index 95e73f032..41cc18146 100644 --- a/repos/base-linux/src/core/include/dataspace_component.h +++ b/repos/base-linux/src/core/include/dataspace_component.h @@ -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 diff --git a/repos/base-linux/src/core/rom_session_component.cc b/repos/base-linux/src/core/rom_session_component.cc index f07009d0e..47ec3ec76 100644 --- a/repos/base-linux/src/core/rom_session_component.cc +++ b/repos/base-linux/src/core/rom_session_component.cc @@ -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(ds_cap); } diff --git a/repos/base-linux/src/core/target.mk b/repos/base-linux/src/core/target.mk index a3a9b95fb..7d7e4a741 100644 --- a/repos/base-linux/src/core/target.mk +++ b/repos/base-linux/src/core/target.mk @@ -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 \