2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Platform environment of Genode process
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2006-07-28
|
|
|
|
*
|
|
|
|
* This file is a generic variant of the platform environment, which is
|
|
|
|
* suitable for platforms such as L4ka::Pistachio and L4/Fiasco. On other
|
|
|
|
* platforms, it may be replaced by a platform-specific version residing
|
|
|
|
* in the corresponding 'base-<platform>' repository.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01: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.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-20 20:52:51 +01:00
|
|
|
#ifndef _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_
|
|
|
|
#define _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-09-25 15:36:23 +02:00
|
|
|
/* Genode includes */
|
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
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <base/env.h>
|
2016-01-19 20:24:22 +01:00
|
|
|
#include <base/heap.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-20 18:27:18 +01:00
|
|
|
/* base-internal includes */
|
2016-04-29 22:58:59 +02:00
|
|
|
#include <base/internal/globals.h>
|
|
|
|
#include <base/internal/parent_cap.h>
|
|
|
|
#include <base/internal/attached_stack_area.h>
|
|
|
|
#include <base/internal/expanding_cpu_session_client.h>
|
2017-05-11 20:03:28 +02:00
|
|
|
#include <base/internal/expanding_pd_session_client.h>
|
2016-04-29 22:58:59 +02:00
|
|
|
#include <base/internal/expanding_region_map_client.h>
|
|
|
|
#include <base/internal/expanding_parent_client.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2017-05-11 20:03:28 +02:00
|
|
|
namespace Genode {
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-05-11 20:03:28 +02:00
|
|
|
class Platform_env_base : public Env_deprecated { };
|
|
|
|
class Platform_env;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-05-11 20:03:28 +02:00
|
|
|
|
2017-06-13 13:18:11 +02:00
|
|
|
class Genode::Platform_env : public Platform_env_base
|
2013-09-25 15:36:23 +02:00
|
|
|
{
|
|
|
|
private:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-09-25 17:59:17 +02:00
|
|
|
Expanding_parent_client _parent_client;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-09-25 15:36:23 +02:00
|
|
|
struct Resources
|
2012-11-29 16:48:12 +01:00
|
|
|
{
|
2013-09-25 15:36:23 +02:00
|
|
|
template <typename T>
|
2016-11-06 14:26:34 +01:00
|
|
|
Capability<T> request(Parent &parent, Parent::Client::Id id)
|
2014-01-31 14:04:04 +01:00
|
|
|
{
|
2016-11-06 14:26:34 +01:00
|
|
|
return static_cap_cast<T>(parent.session_cap(id));
|
2014-01-31 14:04:04 +01:00
|
|
|
}
|
2013-09-25 15:36:23 +02:00
|
|
|
|
2017-05-11 20:03:28 +02:00
|
|
|
Expanding_pd_session_client pd;
|
2014-01-31 14:04:04 +01:00
|
|
|
Expanding_cpu_session_client cpu;
|
2016-04-15 15:19:22 +02:00
|
|
|
Expanding_region_map_client rm;
|
2013-09-25 15:36:23 +02:00
|
|
|
|
2014-01-31 14:04:04 +01:00
|
|
|
Resources(Parent &parent)
|
|
|
|
:
|
2017-05-11 20:03:28 +02:00
|
|
|
pd (request<Pd_session> (parent, Parent::Env::pd())),
|
2016-11-06 14:26:34 +01:00
|
|
|
cpu(request<Cpu_session>(parent, Parent::Env::cpu()),
|
|
|
|
Parent::Env::cpu()),
|
2017-05-11 20:03:28 +02:00
|
|
|
rm(pd, pd.address_space(), Parent::Env::pd())
|
2013-09-25 15:36:23 +02:00
|
|
|
{ }
|
|
|
|
};
|
2012-11-29 16:48:12 +01:00
|
|
|
|
2013-09-25 15:36:23 +02:00
|
|
|
Resources _resources;
|
2015-12-23 15:22:33 +01:00
|
|
|
|
|
|
|
Heap _heap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The '_heap' must be initialized before the '_stack_area'
|
|
|
|
* because the 'Local_parent' performs a dynamic memory allocation
|
|
|
|
* due to the creation of the stack area's sub-RM session.
|
|
|
|
*/
|
2016-04-15 15:19:22 +02:00
|
|
|
Attached_stack_area _stack_area { _parent_client, _resources.pd };
|
2012-11-29 16:48:12 +01:00
|
|
|
|
2013-09-25 15:36:23 +02:00
|
|
|
public:
|
2012-11-29 16:48:12 +01:00
|
|
|
|
2013-09-25 15:36:23 +02:00
|
|
|
/**
|
|
|
|
* Standard constructor
|
|
|
|
*/
|
|
|
|
Platform_env()
|
|
|
|
:
|
2017-06-13 13:18:11 +02:00
|
|
|
_parent_client(Genode::parent_cap()),
|
2013-09-25 15:36:23 +02:00
|
|
|
_resources(_parent_client),
|
2017-06-13 13:18:11 +02:00
|
|
|
_heap(&_resources.pd, &_resources.rm, Heap::UNLIMITED)
|
2015-12-23 15:22:33 +01:00
|
|
|
{
|
2017-05-11 20:03:28 +02:00
|
|
|
env_stack_area_ram_allocator = &_resources.pd;
|
2017-05-11 19:39:46 +02:00
|
|
|
env_stack_area_region_map = &_stack_area;
|
2015-12-23 15:22:33 +01:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-05-11 16:12:21 +02:00
|
|
|
/*
|
|
|
|
* Support functions for implementing fork on Noux.
|
2014-01-28 14:30:36 +01:00
|
|
|
*/
|
2016-06-13 15:14:32 +02:00
|
|
|
void reinit(Native_capability::Raw) override;
|
2016-04-15 15:19:22 +02:00
|
|
|
void reinit_main_thread(Capability<Region_map> &) override;
|
2012-02-15 19:14:37 +01:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-04-27 22:11:38 +02:00
|
|
|
/******************************
|
|
|
|
** Env_deprecated interface **
|
|
|
|
******************************/
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-19 20:24:22 +01:00
|
|
|
Parent *parent() override { return &_parent_client; }
|
2017-05-11 20:03:28 +02:00
|
|
|
Ram_session *ram_session() override { return &_resources.pd; }
|
|
|
|
Ram_session_capability ram_session_cap() override { return _resources.pd; }
|
2016-01-19 20:24:22 +01:00
|
|
|
Cpu_session *cpu_session() override { return &_resources.cpu; }
|
|
|
|
Cpu_session_capability cpu_session_cap() override { return _resources.cpu; }
|
2016-04-15 15:19:22 +02:00
|
|
|
Region_map *rm_session() override { return &_resources.rm; }
|
2016-01-19 20:24:22 +01:00
|
|
|
Pd_session *pd_session() override { return &_resources.pd; }
|
|
|
|
Pd_session_capability pd_session_cap() override { return _resources.pd; }
|
|
|
|
Allocator *heap() override { return &_heap; }
|
2013-09-25 15:36:23 +02:00
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-20 20:52:51 +01:00
|
|
|
#endif /* _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_ */
|