mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
Adaptation to init refactoring
Since init no longer provides public headers, we have to adjust the existing users of this headers. The 'init/child_config.h' is used only by GDB monitor. So the patch moves the header there as an interim fix. The 'init/child_policy.h' is still used by a few components, so we have to keep a trimmed-down version of it for now.
This commit is contained in:
parent
1cf830497a
commit
b3e5357cf1
@ -19,12 +19,15 @@
|
||||
#ifndef _INCLUDE__LAUNCHPAD__LAUNCHPAD_H_
|
||||
#define _INCLUDE__LAUNCHPAD__LAUNCHPAD_H_
|
||||
|
||||
#include <util/xml_node.h>
|
||||
#include <base/allocator.h>
|
||||
#include <base/service.h>
|
||||
#include <base/lock.h>
|
||||
#include <base/child.h>
|
||||
#include <timer_session/timer_session.h>
|
||||
#include <pd_session/client.h>
|
||||
#include <init/child.h>
|
||||
#include <init/child_policy.h>
|
||||
#include <os/session_requester.h>
|
||||
|
||||
class Launchpad;
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
/*
|
||||
* \brief Policy applied to all children of the init process
|
||||
* \brief Child-policy helpers
|
||||
* \author Norman Feske
|
||||
* \date 2010-04-29
|
||||
*
|
||||
* \deprecated use os/dynamic_rom_session.h instead
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -15,104 +17,16 @@
|
||||
#define _INCLUDE__INIT__CHILD_POLICY_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/rpc_server.h>
|
||||
#include <base/service.h>
|
||||
#include <base/child.h>
|
||||
#include <base/session_label.h>
|
||||
#include <base/attached_ram_dataspace.h>
|
||||
#include <util/arg_string.h>
|
||||
#include <rom_session/connection.h>
|
||||
#include <base/session_label.h>
|
||||
#include <os/dynamic_rom_session.h>
|
||||
#include <rom_session/rom_session.h>
|
||||
|
||||
namespace Init {
|
||||
|
||||
class Child_policy_ram_phys;
|
||||
class Child_policy_handle_cpu_priorities;
|
||||
class Child_policy_provide_rom_file;
|
||||
class Child_policy_provide_dynamic_rom;
|
||||
class Child_policy_redirect_rom_file;
|
||||
class Traditional_child_policy;
|
||||
|
||||
using namespace Genode;
|
||||
using Genode::size_t;
|
||||
using Genode::strcmp;
|
||||
using Genode::snprintf;
|
||||
}
|
||||
|
||||
|
||||
class Init::Child_policy_ram_phys
|
||||
{
|
||||
private:
|
||||
|
||||
bool _constrain_phys;
|
||||
|
||||
public:
|
||||
|
||||
Child_policy_ram_phys(bool constrain_phys)
|
||||
: _constrain_phys(constrain_phys) { }
|
||||
|
||||
/**
|
||||
* Filter arguments of session request
|
||||
*
|
||||
* This method removes phys_start and phys_size ram_session
|
||||
* parameters if the child configuration does not explicitly
|
||||
* permits this.
|
||||
*/
|
||||
void filter_session_args(const char *service, char *args,
|
||||
size_t args_len)
|
||||
{
|
||||
/* intercept only RAM session requests */
|
||||
if (strcmp(service, "RAM"))
|
||||
return;
|
||||
|
||||
if (_constrain_phys)
|
||||
return;
|
||||
|
||||
Arg_string::remove_arg(args, "phys_start");
|
||||
Arg_string::remove_arg(args, "phys_size");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Init::Child_policy_handle_cpu_priorities
|
||||
{
|
||||
/* priority parameters */
|
||||
long _prio_levels_log2;
|
||||
long _priority;
|
||||
|
||||
public:
|
||||
|
||||
Child_policy_handle_cpu_priorities(long prio_levels_log2, long priority)
|
||||
: _prio_levels_log2(prio_levels_log2), _priority(priority) { }
|
||||
|
||||
void filter_session_args(const char *service, char *args, size_t args_len)
|
||||
{
|
||||
/* intercept only CPU session requests to scale priorities */
|
||||
if (strcmp(service, "CPU") || _prio_levels_log2 == 0)
|
||||
return;
|
||||
|
||||
unsigned long priority = Arg_string::find_arg(args, "priority").ulong_value(0);
|
||||
|
||||
/* clamp priority value to valid range */
|
||||
priority = min((unsigned)Cpu_session::PRIORITY_LIMIT - 1, priority);
|
||||
|
||||
long discarded_prio_lsb_bits_mask = (1 << _prio_levels_log2) - 1;
|
||||
if (priority & discarded_prio_lsb_bits_mask) {
|
||||
warning("priority band too small, losing least-significant priority bits");
|
||||
}
|
||||
priority >>= _prio_levels_log2;
|
||||
|
||||
/* assign child priority to the most significant priority bits */
|
||||
priority |= _priority*(Cpu_session::PRIORITY_LIMIT >> _prio_levels_log2);
|
||||
|
||||
/* override priority when delegating the session request to the parent */
|
||||
char value_buf[64];
|
||||
snprintf(value_buf, sizeof(value_buf), "0x%lx", priority);
|
||||
Arg_string::set_arg(args, args_len, "priority", value_buf);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Init::Child_policy_provide_rom_file
|
||||
{
|
||||
private:
|
||||
@ -177,46 +91,4 @@ class Init::Child_policy_provide_rom_file
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Init::Child_policy_redirect_rom_file
|
||||
{
|
||||
private:
|
||||
|
||||
char const *_from;
|
||||
char const *_to;
|
||||
|
||||
public:
|
||||
|
||||
Child_policy_redirect_rom_file(const char *from, const char *to)
|
||||
: _from(from), _to(to) { }
|
||||
|
||||
void filter_session_args(const char *service,
|
||||
char *args, size_t args_len)
|
||||
{
|
||||
if (!_from || !_to) return;
|
||||
|
||||
/* ignore session requests for non-ROM services */
|
||||
if (strcmp(service, "ROM")) return;
|
||||
|
||||
/* drop out if request refers to another module name */
|
||||
Session_label const label = label_from_args(args);
|
||||
Session_label const from(_from);
|
||||
if (from != label.last_element()) return;
|
||||
|
||||
/*
|
||||
* The module name corresponds to the last part of the label.
|
||||
* We have to replace this part with the 'to' module name.
|
||||
* If the label consists of only the module name but no prefix,
|
||||
* we replace the entire label with the 'to' module name.
|
||||
*/
|
||||
Session_label const prefix = label.prefix();
|
||||
Session_label const to(_to);
|
||||
|
||||
Session_label const prefixed_to =
|
||||
prefixed_label(prefix.valid() ? prefix : Session_label(), to);
|
||||
|
||||
Arg_string::set_arg_string(args, args_len, "label", prefixed_to.string());
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__INIT__CHILD_POLICY_H_ */
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <base/child.h>
|
||||
#include <base/service.h>
|
||||
|
||||
#include <init/child_config.h>
|
||||
#include <init/child_policy.h>
|
||||
|
||||
#include <util/arg_string.h>
|
||||
@ -28,6 +27,7 @@
|
||||
#include "cpu_session_component.h"
|
||||
#include "pd_session_component.h"
|
||||
#include "rom.h"
|
||||
#include "child_config.h"
|
||||
|
||||
namespace Gdb_monitor {
|
||||
using namespace Genode;
|
||||
|
138
repos/ports/src/app/gdb_monitor/child_config.h
Normal file
138
repos/ports/src/app/gdb_monitor/child_config.h
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* \brief Utility for handling child configuration
|
||||
* \author Norman Feske
|
||||
* \date 2008-03-22
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2008-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _CHILD_CONFIG_H_
|
||||
#define _CHILD_CONFIG_H_
|
||||
|
||||
#warning header is deprecated, used os/dynamic_rom_session.h instead
|
||||
|
||||
#include <util/xml_node.h>
|
||||
#include <base/attached_dataspace.h>
|
||||
#include <ram_session/ram_session.h>
|
||||
|
||||
namespace Init { class Child_config; }
|
||||
|
||||
|
||||
class Init::Child_config
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Ram_session &_ram;
|
||||
|
||||
typedef Genode::String<64> Rom_name;
|
||||
Rom_name const _rom_name;
|
||||
|
||||
Genode::Ram_dataspace_capability const _ram_ds;
|
||||
|
||||
Rom_name _rom_name_from_start_node(Genode::Xml_node start)
|
||||
{
|
||||
if (!start.has_sub_node("configfile"))
|
||||
return Rom_name();
|
||||
|
||||
return start.sub_node("configfile").attribute_value("name", Rom_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Buffer '<config>' sub node in a dedicated RAM dataspace
|
||||
*
|
||||
* \throw Ram_session::Alloc_failed
|
||||
* \throw Rm_session::Attach_failed
|
||||
*/
|
||||
Genode::Ram_dataspace_capability
|
||||
_ram_ds_from_start_node(Genode::Xml_node start,
|
||||
Genode::Ram_session &ram, Genode::Region_map &rm)
|
||||
{
|
||||
/*
|
||||
* If the start node contains a 'config' entry, we copy this entry
|
||||
* into a fresh dataspace to be provided to our child.
|
||||
*/
|
||||
Genode::Xml_node const config = start.has_sub_node("config")
|
||||
? start.sub_node("config")
|
||||
: Genode::Xml_node("<config/>");
|
||||
|
||||
Genode::Ram_dataspace_capability ram_ds;
|
||||
try {
|
||||
/*
|
||||
* Allocate RAM dataspace that is big enough to hold the
|
||||
* configuration and the null termination.
|
||||
*/
|
||||
ram_ds = ram.alloc(config.size() + 1);
|
||||
|
||||
/*
|
||||
* Make dataspace locally accessible, copy configuration into the
|
||||
* dataspace, and append a string-terminating zero.
|
||||
*/
|
||||
Genode::Attached_dataspace attached(rm, ram_ds);
|
||||
|
||||
Genode::memcpy(attached.local_addr<char>(),
|
||||
config.addr(), config.size());
|
||||
|
||||
attached.local_addr<char>()[config.size()] = 0;
|
||||
|
||||
return ram_ds;
|
||||
}
|
||||
catch (Genode::Region_map::Attach_failed) { ram.free(ram_ds); throw; }
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* The provided RAM session is used to obtain a dataspace for
|
||||
* holding the copy of the child's configuration data unless the
|
||||
* configuration is supplied via a config ROM module.
|
||||
*
|
||||
* \throw Ram_session::Alloc_failed failed to allocate the backing
|
||||
* store for holding config data
|
||||
*
|
||||
* \throw Region_map::Attach_failed failed to temporarily attach the
|
||||
* config dataspace to the local
|
||||
* address space
|
||||
*
|
||||
* If the start node contains a 'filename' entry, we only keep the
|
||||
* information about the ROM module name.
|
||||
*/
|
||||
Child_config(Genode::Ram_session &ram, Genode::Region_map &local_rm,
|
||||
Genode::Xml_node start)
|
||||
:
|
||||
_ram(ram),
|
||||
_rom_name(_rom_name_from_start_node(start)),
|
||||
_ram_ds(_rom_name.valid() ? Genode::Ram_dataspace_capability()
|
||||
: _ram_ds_from_start_node(start, ram, local_rm))
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~Child_config() { if (_ram_ds.valid()) _ram.free(_ram_ds); }
|
||||
|
||||
/**
|
||||
* Return file name if configuration comes from a file
|
||||
*
|
||||
* If the configuration is provided inline, the method returns 0.
|
||||
*/
|
||||
char const *filename() const {
|
||||
return _rom_name.valid() ? _rom_name.string() : nullptr; }
|
||||
|
||||
/**
|
||||
* Request dataspace holding the start node's configuration data
|
||||
*
|
||||
* This method returns a valid dataspace only when using an
|
||||
* inline configuration (if 'filename()' returns 0).
|
||||
*/
|
||||
Genode::Dataspace_capability dataspace() {
|
||||
return Genode::Dataspace_capability(_ram_ds); }
|
||||
};
|
||||
|
||||
#endif /* _CHILD_CONFIG_H_ */
|
Loading…
Reference in New Issue
Block a user