2012-02-25 19:41:59 +00:00
|
|
|
/*
|
|
|
|
* \brief Noux child policy
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2012-02-25
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
2012-02-25 19:41:59 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NOUX__CHILD_POLICY_H_
|
|
|
|
#define _NOUX__CHILD_POLICY_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <init/child_policy.h>
|
|
|
|
|
|
|
|
/* Noux includes */
|
|
|
|
#include <family_member.h>
|
2014-01-23 16:21:35 +00:00
|
|
|
#include <parent_exit.h>
|
2012-09-14 14:46:51 +00:00
|
|
|
#include <file_descriptor_registry.h>
|
2012-02-25 19:41:59 +00:00
|
|
|
#include <local_noux_service.h>
|
|
|
|
#include <local_rm_service.h>
|
2013-07-18 14:27:42 +00:00
|
|
|
#include <local_rom_service.h>
|
2012-02-25 19:41:59 +00:00
|
|
|
|
|
|
|
namespace Noux {
|
|
|
|
|
|
|
|
class Child_policy : public Genode::Child_policy
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
char const *_name;
|
|
|
|
Init::Child_policy_enforce_labeling _labeling_policy;
|
|
|
|
Init::Child_policy_provide_rom_file _binary_policy;
|
|
|
|
Init::Child_policy_provide_rom_file _args_policy;
|
|
|
|
Init::Child_policy_provide_rom_file _env_policy;
|
|
|
|
Local_noux_service &_local_noux_service;
|
|
|
|
Local_rm_service &_local_rm_service;
|
2013-07-18 14:27:42 +00:00
|
|
|
Local_rom_service &_local_rom_service;
|
2012-02-25 19:41:59 +00:00
|
|
|
Service_registry &_parent_services;
|
|
|
|
Family_member &_family_member;
|
2014-01-23 16:21:35 +00:00
|
|
|
Parent_exit *_parent_exit;
|
2012-09-14 14:46:51 +00:00
|
|
|
File_descriptor_registry &_file_descriptor_registry;
|
2013-01-03 14:52:27 +00:00
|
|
|
Signal_context_capability _destruct_context_cap;
|
2012-02-25 19:41:59 +00:00
|
|
|
Ram_session &_ref_ram_session;
|
2013-08-22 12:36:15 +00:00
|
|
|
bool _verbose;
|
2012-02-25 19:41:59 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Child_policy(char const *name,
|
|
|
|
Dataspace_capability binary_ds,
|
|
|
|
Dataspace_capability args_ds,
|
|
|
|
Dataspace_capability env_ds,
|
|
|
|
Rpc_entrypoint &entrypoint,
|
|
|
|
Local_noux_service &local_noux_service,
|
|
|
|
Local_rm_service &local_rm_service,
|
2013-07-18 14:27:42 +00:00
|
|
|
Local_rom_service &local_rom_service,
|
2012-02-25 19:41:59 +00:00
|
|
|
Service_registry &parent_services,
|
|
|
|
Family_member &family_member,
|
2014-01-23 16:21:35 +00:00
|
|
|
Parent_exit *parent_exit,
|
2012-09-14 14:46:51 +00:00
|
|
|
File_descriptor_registry &file_descriptor_registry,
|
2013-01-03 14:52:27 +00:00
|
|
|
Signal_context_capability destruct_context_cap,
|
2013-08-22 12:36:15 +00:00
|
|
|
Ram_session &ref_ram_session,
|
|
|
|
bool verbose)
|
2012-02-25 19:41:59 +00:00
|
|
|
:
|
2013-09-17 08:44:33 +00:00
|
|
|
_name(name),
|
2012-02-25 19:41:59 +00:00
|
|
|
_labeling_policy(_name),
|
|
|
|
_binary_policy("binary", binary_ds, &entrypoint),
|
|
|
|
_args_policy( "args", args_ds, &entrypoint),
|
|
|
|
_env_policy( "env", env_ds, &entrypoint),
|
|
|
|
_local_noux_service(local_noux_service),
|
|
|
|
_local_rm_service(local_rm_service),
|
2013-07-18 14:27:42 +00:00
|
|
|
_local_rom_service(local_rom_service),
|
2012-02-25 19:41:59 +00:00
|
|
|
_parent_services(parent_services),
|
|
|
|
_family_member(family_member),
|
2014-01-23 16:21:35 +00:00
|
|
|
_parent_exit(parent_exit),
|
2012-09-14 14:46:51 +00:00
|
|
|
_file_descriptor_registry(file_descriptor_registry),
|
2013-01-03 14:52:27 +00:00
|
|
|
_destruct_context_cap(destruct_context_cap),
|
2013-08-22 12:36:15 +00:00
|
|
|
_ref_ram_session(ref_ram_session),
|
|
|
|
_verbose(verbose)
|
2012-02-25 19:41:59 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
const char *name() const { return _name; }
|
|
|
|
|
|
|
|
Service *resolve_session_request(const char *service_name,
|
|
|
|
const char *args)
|
|
|
|
{
|
|
|
|
Service *service = 0;
|
|
|
|
|
|
|
|
/* check for local ROM file requests */
|
|
|
|
if ((service = _args_policy.resolve_session_request(service_name, args))
|
|
|
|
|| (service = _env_policy.resolve_session_request(service_name, args))
|
|
|
|
|| (service = _binary_policy.resolve_session_request(service_name, args)))
|
|
|
|
return service;
|
|
|
|
|
|
|
|
/* check for locally implemented noux service */
|
|
|
|
if (strcmp(service_name, Session::service_name()) == 0)
|
|
|
|
return &_local_noux_service;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for the creation of an RM session, which is used by
|
|
|
|
* the dynamic linker to manually manage a part of the address
|
|
|
|
* space.
|
|
|
|
*/
|
|
|
|
if (strcmp(service_name, Rm_session::service_name()) == 0)
|
|
|
|
return &_local_rm_service;
|
|
|
|
|
2013-07-18 14:27:42 +00:00
|
|
|
/*
|
|
|
|
* Check for local ROM service
|
|
|
|
*/
|
|
|
|
if (strcmp(service_name, Rom_session::service_name()) == 0)
|
|
|
|
return &_local_rom_service;
|
|
|
|
|
2012-02-25 19:41:59 +00:00
|
|
|
return _parent_services.find(service_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void filter_session_args(const char *service,
|
|
|
|
char *args, size_t args_len)
|
|
|
|
{
|
|
|
|
_labeling_policy.filter_session_args(service, args, args_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void exit(int exit_value)
|
|
|
|
{
|
2013-08-22 12:36:15 +00:00
|
|
|
if (_verbose || (exit_value != 0))
|
|
|
|
PERR("child %s exited with exit value %d", _name, exit_value);
|
2012-02-25 19:41:59 +00:00
|
|
|
|
2012-09-14 14:46:51 +00:00
|
|
|
/*
|
|
|
|
* Close all open file descriptors. This is necessary to unblock
|
|
|
|
* the parent if it is trying to read from a pipe (connected to
|
|
|
|
* the child) before calling 'wait4()'.
|
|
|
|
*/
|
|
|
|
_file_descriptor_registry.flush();
|
|
|
|
|
2014-01-23 16:21:35 +00:00
|
|
|
_family_member.exit(exit_value);
|
2012-02-25 19:41:59 +00:00
|
|
|
|
2014-01-23 16:21:35 +00:00
|
|
|
/* notify the parent */
|
|
|
|
if (_parent_exit)
|
|
|
|
_parent_exit->exit_child();
|
|
|
|
else {
|
|
|
|
/* handle exit of the init process */
|
2013-01-03 14:52:27 +00:00
|
|
|
Signal_transmitter(_destruct_context_cap).submit();
|
2014-01-23 16:21:35 +00:00
|
|
|
}
|
2012-02-25 19:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ram_session *ref_ram_session()
|
|
|
|
{
|
|
|
|
return &_ref_ram_session;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _NOUX__CHILD_POLICY_H_ */
|
|
|
|
|