2012-05-30 20:13:09 +02:00
|
|
|
/*
|
|
|
|
* \brief Protection-domain facility
|
|
|
|
* \author Martin Stein
|
2014-04-28 21:31:57 +02:00
|
|
|
* \author Stefan Kalkowski
|
2016-02-11 11:59:31 +01:00
|
|
|
* \author Sebastian Sumpf
|
2012-05-30 20:13:09 +02:00
|
|
|
* \date 2012-02-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
2012-05-30 20:13:09 +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.
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <root/root.h>
|
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
/* core includes */
|
2017-02-21 13:46:59 +01:00
|
|
|
#include <hw/assert.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <platform_pd.h>
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <platform_thread.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
using namespace Genode;
|
2017-02-21 13:46:59 +01:00
|
|
|
using Hw::Page_table;
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2015-04-28 14:07:51 +02:00
|
|
|
|
|
|
|
/**************************************
|
|
|
|
** Hw::Address_space implementation **
|
|
|
|
**************************************/
|
|
|
|
|
|
|
|
Core_mem_allocator * Hw::Address_space::_cma() {
|
|
|
|
return static_cast<Core_mem_allocator*>(platform()->core_mem_alloc()); }
|
|
|
|
|
|
|
|
|
2015-06-16 10:59:26 +02:00
|
|
|
void * Hw::Address_space::_table_alloc()
|
2015-04-10 12:35:30 +02:00
|
|
|
{
|
2015-04-28 14:07:51 +02:00
|
|
|
void * ret;
|
2017-02-21 13:46:59 +01:00
|
|
|
if (!_cma()->alloc_aligned(sizeof(Page_table), (void**)&ret,
|
|
|
|
Page_table::ALIGNM_LOG2).ok())
|
2015-04-28 14:07:51 +02:00
|
|
|
throw Root::Quota_exceeded();
|
|
|
|
return ret;
|
|
|
|
}
|
2015-04-10 12:35:30 +02:00
|
|
|
|
|
|
|
|
2015-04-28 14:07:51 +02:00
|
|
|
bool Hw::Address_space::insert_translation(addr_t virt, addr_t phys,
|
|
|
|
size_t size, Page_flags flags)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
for (;;) {
|
|
|
|
try {
|
|
|
|
Lock::Guard guard(_lock);
|
2017-02-21 13:46:59 +01:00
|
|
|
_tt.insert_translation(virt, phys, size, flags, _tt_alloc);
|
2015-04-28 14:07:51 +02:00
|
|
|
return true;
|
2017-02-21 13:46:59 +01:00
|
|
|
} catch(Hw::Out_of_tables &) {
|
2015-06-16 10:59:26 +02:00
|
|
|
flush(platform()->vm_start(), platform()->vm_size());
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(...) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("invalid mapping ", Hex(phys), " -> ", Hex(virt), " (", size, ")");
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|
|
|
|
return false;
|
2015-04-10 12:35:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-28 14:07:51 +02:00
|
|
|
void Hw::Address_space::flush(addr_t virt, size_t size)
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
try {
|
2017-02-21 13:46:59 +01:00
|
|
|
_tt.remove_translation(virt, size, _tt_alloc);
|
2015-04-28 14:07:51 +02:00
|
|
|
|
|
|
|
/* update translation caches */
|
2017-02-21 13:46:59 +01:00
|
|
|
Kernel::update_pd(&_kernel_pd);
|
2015-04-28 14:07:51 +02:00
|
|
|
} catch(...) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("tried to remove invalid region!");
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
Hw::Address_space::Address_space(Kernel::Pd & pd, Page_table & tt,
|
|
|
|
Page_table::Allocator & tt_alloc)
|
|
|
|
: _tt(tt), _tt_phys(Platform::core_phys_addr((addr_t)&tt)),
|
|
|
|
_tt_alloc(tt_alloc), _kernel_pd(pd) {
|
2016-11-07 18:00:24 +01:00
|
|
|
Kernel::mtc()->map(_tt, _tt_alloc); }
|
2015-04-28 14:07:51 +02:00
|
|
|
|
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
Hw::Address_space::Address_space(Kernel::Pd & pd)
|
|
|
|
: _tt(*construct_at<Page_table>(_table_alloc())),
|
|
|
|
_tt_phys((addr_t)_cma()->phys_addr(&_tt)),
|
|
|
|
_tt_array(new (_cma()) Array([this] (void * virt) {
|
|
|
|
return (addr_t)_cma()->phys_addr(virt);})),
|
|
|
|
_tt_alloc(_tt_array->alloc()),
|
2015-04-28 14:07:51 +02:00
|
|
|
_kernel_pd(pd)
|
2013-08-30 14:15:13 +02:00
|
|
|
{
|
2014-04-28 21:31:57 +02:00
|
|
|
Lock::Guard guard(_lock);
|
2015-06-16 10:59:26 +02:00
|
|
|
Kernel::mtc()->map(_tt, _tt_alloc);
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-21 15:00:03 +02:00
|
|
|
Hw::Address_space::~Address_space()
|
|
|
|
{
|
|
|
|
flush(platform()->vm_start(), platform()->vm_size());
|
2017-02-21 13:46:59 +01:00
|
|
|
destroy(_cma(), _tt_array);
|
|
|
|
destroy(_cma(), &_tt);
|
2015-05-21 15:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
/******************************
|
|
|
|
** Cap_space implementation **
|
|
|
|
******************************/
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
Cap_space::Cap_space() : _slab(nullptr, &_initial_sb) { }
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
void Cap_space::upgrade_slab(Allocator &alloc)
|
2015-05-19 14:18:40 +02:00
|
|
|
{
|
2017-05-08 11:25:11 +02:00
|
|
|
enum { NEEDED_AVAIL_ENTRIES_FOR_SUCCESSFUL_SYSCALL = 8 };
|
|
|
|
|
|
|
|
if (_slab.avail_entries() > NEEDED_AVAIL_ENTRIES_FOR_SUCCESSFUL_SYSCALL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *block = nullptr;
|
|
|
|
if (alloc.alloc(SLAB_SIZE, &block))
|
2015-05-19 14:18:40 +02:00
|
|
|
_slab.insert_sb(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-28 14:07:51 +02:00
|
|
|
/********************************
|
|
|
|
** Platform_pd implementation **
|
|
|
|
********************************/
|
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
bool Platform_pd::bind_thread(Platform_thread * t)
|
2015-04-28 14:07:51 +02:00
|
|
|
{
|
|
|
|
/* is this the first and therefore main thread in this PD? */
|
|
|
|
bool main_thread = !_thread_associated;
|
|
|
|
_thread_associated = true;
|
2016-04-14 16:29:07 +02:00
|
|
|
t->join_pd(this, main_thread, Address_space::weak_ptr());
|
2016-04-20 21:12:57 +02:00
|
|
|
return true;
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Platform_pd::unbind_thread(Platform_thread *t) {
|
|
|
|
t->join_pd(nullptr, false, Address_space::weak_ptr()); }
|
|
|
|
|
|
|
|
|
2016-04-14 16:29:07 +02:00
|
|
|
void Platform_pd::assign_parent(Native_capability parent)
|
2015-04-28 14:07:51 +02:00
|
|
|
{
|
2016-04-14 16:29:07 +02:00
|
|
|
if (!_parent.valid() && parent.valid())
|
|
|
|
_parent = parent;
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
Platform_pd::Platform_pd(Page_table & tt,
|
|
|
|
Page_table::Allocator & alloc)
|
|
|
|
: Hw::Address_space(*kernel_object(), tt, alloc),
|
|
|
|
Kernel_object<Kernel::Pd>(false, (Page_table*)translation_table_phys(), this),
|
2015-05-19 14:18:40 +02:00
|
|
|
_label("core") { }
|
2015-04-28 14:07:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
Platform_pd::Platform_pd(Allocator * md_alloc, char const *label)
|
2017-02-21 13:46:59 +01:00
|
|
|
: Hw::Address_space(*kernel_object()),
|
|
|
|
Kernel_object<Kernel::Pd>(true, (Page_table*)translation_table_phys(), this),
|
2015-04-28 14:07:51 +02:00
|
|
|
_label(label)
|
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
if (!_cap.valid()) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("failed to create kernel object");
|
2015-04-28 14:07:51 +02:00
|
|
|
throw Root::Unavailable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 08:59:33 +02:00
|
|
|
Platform_pd::~Platform_pd()
|
|
|
|
{
|
|
|
|
/* invalidate weak pointers to this object */
|
|
|
|
Address_space::lock_for_destruction();
|
|
|
|
}
|
|
|
|
|
2015-04-28 14:07:51 +02:00
|
|
|
|
|
|
|
/*************************************
|
|
|
|
** Core_platform_pd implementation **
|
|
|
|
*************************************/
|
|
|
|
|
2016-11-07 18:00:24 +01:00
|
|
|
extern int _mt_master_context_begin;
|
2015-04-28 14:07:51 +02:00
|
|
|
|
|
|
|
Core_platform_pd::Core_platform_pd()
|
2017-02-21 13:46:59 +01:00
|
|
|
: Platform_pd(Platform::core_page_table(),
|
|
|
|
Platform::core_page_table_allocator())
|
2015-04-28 14:07:51 +02:00
|
|
|
{
|
2016-11-07 18:00:24 +01:00
|
|
|
Genode::construct_at<Kernel::Cpu_context>(&_mt_master_context_begin,
|
2017-02-21 13:46:59 +01:00
|
|
|
(Page_table*)translation_table_phys());
|
2015-04-28 14:07:51 +02:00
|
|
|
}
|