2015-09-25 10:50:08 +02:00
|
|
|
/*
|
|
|
|
* \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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-09-25 10:50:08 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-09-25 10:50:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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>
|
2016-05-12 14:58:51 +02:00
|
|
|
#include <base/session_label.h>
|
2015-09-25 10:50:08 +02:00
|
|
|
|
|
|
|
/* local includes */
|
|
|
|
#include "dataspace_component.h"
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
Linux_dataspace::Filename Dataspace_component::_file_name(const char *args)
|
|
|
|
{
|
2016-05-12 14:58:51 +02:00
|
|
|
Session_label const label = label_from_args(args);
|
|
|
|
Linux_dataspace::Filename fname;
|
|
|
|
strncpy(fname.buf, label.last_element().string(), sizeof(fname.buf));
|
|
|
|
|
2015-09-25 10:50:08 +02:00
|
|
|
/* only files inside the current working directory are allowed */
|
2016-05-12 14:58:51 +02:00
|
|
|
for (const char *c = fname.buf; *c; ++c)
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
if (*c == '/') throw Service_denied();
|
2015-09-25 10:50:08 +02:00
|
|
|
|
|
|
|
return fname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Genode::size_t Dataspace_component::_file_size()
|
|
|
|
{
|
|
|
|
struct stat64 s;
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
if (lx_stat(_fname.buf, &s) < 0) throw Service_denied();
|
2015-09-25 10:50:08 +02:00
|
|
|
|
|
|
|
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) { }
|