Skip to content

Commit

Permalink
Replace 'Env' interface with modern one
Browse files Browse the repository at this point in the history
The original 'Env' interface as returned by 'Genode::env()' has been
renamed to 'Env_deprecated' and moved to deprecated/env.h. The new version
of base/env.h contains the interface passed to modern components that
use the component API via base/component.h.

Issue #1832
  • Loading branch information
nfeske authored and chelmuth committed May 9, 2016
1 parent 7274ca9 commit 4f69772
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 181 deletions.
6 changes: 3 additions & 3 deletions repos/base-linux/src/core/include/core_env.h
Expand Up @@ -197,9 +197,9 @@ namespace Genode {
Entrypoint *entrypoint() { return &_entrypoint; }


/*******************
** Env interface **
*******************/
/******************************
** Env_deprecated interface **
******************************/

Parent *parent() override { return &_core_parent; }
Ram_session *ram_session() override { return &_ram_session; }
Expand Down
14 changes: 7 additions & 7 deletions repos/base-linux/src/include/base/internal/platform_env.h
Expand Up @@ -60,7 +60,7 @@ struct Genode::Expanding_cpu_session_client
* Common base class of the 'Platform_env' implementations for core and
* non-core processes.
*/
class Genode::Platform_env_base : public Env
class Genode::Platform_env_base : public Env_deprecated
{
private:

Expand Down Expand Up @@ -389,9 +389,9 @@ class Genode::Platform_env_base : public Env
{ }


/*******************
** Env interface **
*******************/
/******************************
** Env_deprecated interface **
******************************/

Ram_session *ram_session() override { return &_ram_session_client; }
Ram_session_capability ram_session_cap() override { return _ram_session_cap; }
Expand Down Expand Up @@ -499,9 +499,9 @@ class Genode::Platform_env : public Platform_env_base, public Emergency_ram_rese
void release() { ram_session()->free(_emergency_ram_ds); }


/*******************
** Env interface **
*******************/
/******************************
** Env_deprecated interface **
******************************/

Parent *parent() override { return &_parent(); }
Heap *heap() override { return &_heap; }
Expand Down
6 changes: 3 additions & 3 deletions repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc
Expand Up @@ -86,15 +86,15 @@ namespace Genode {
* component's entrypoint is activated.
*/

extern void (*call_component_construct)(Genode::Environment &) __attribute__((weak));
extern void (*call_component_construct)(Genode::Env &) __attribute__((weak));
}

static void lx_hybrid_component_construct(Genode::Environment &env)
static void lx_hybrid_component_construct(Genode::Env &env)
{
Component::construct(env);
}

void (*Genode::call_component_construct)(Genode::Environment &) = &lx_hybrid_component_construct;
void (*Genode::call_component_construct)(Genode::Env &) = &lx_hybrid_component_construct;

/*
* Static constructors are handled by the Linux startup code - so implement
Expand Down
2 changes: 1 addition & 1 deletion repos/base-linux/src/test/lx_hybrid_ctors/main.cc
Expand Up @@ -51,7 +51,7 @@ char const * Component::name() { return "lx_hybrid_ctors"; }
/*
* Component implements classical main function in construct.
*/
void Component::construct(Genode::Environment &env)
void Component::construct(Genode::Env &env)
{
printf("--- lx_hybrid global static constructor test ---\n");

Expand Down
2 changes: 1 addition & 1 deletion repos/base-linux/src/test/lx_hybrid_errno/main.cc
Expand Up @@ -55,7 +55,7 @@ struct Unexpected_errno_change { };
/*
* Component implements classical main function in construct.
*/
void Component::construct(Genode::Environment &env)
void Component::construct(Genode::Env &env)
{
Genode::printf("--- thread-local errno test ---\n");

Expand Down
2 changes: 1 addition & 1 deletion repos/base-linux/src/test/lx_hybrid_exception/main.cc
Expand Up @@ -34,7 +34,7 @@ char const * Component::name() { return "lx_hybrid_exception"; }
/*
* Component implements classical main function in construct.
*/
void Component::construct(Genode::Environment &env)
void Component::construct(Genode::Env &env)
{
printf("--- lx_hybrid exception test ---\n");

Expand Down
2 changes: 1 addition & 1 deletion repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc
Expand Up @@ -60,7 +60,7 @@ char const * Component::name() { return "lx_hybrid_pthread_ipc"; }
/*
* Component implements classical main function in construct.
*/
void Component::construct(Genode::Environment &env)
void Component::construct(Genode::Env &env)
{
Genode::printf("--- pthread IPC test ---\n");

Expand Down
54 changes: 11 additions & 43 deletions repos/base/include/base/component.h
Expand Up @@ -14,65 +14,33 @@
#ifndef _INCLUDE__BASE__COMPONENT_H_
#define _INCLUDE__BASE__COMPONENT_H_

#include <base/env.h>
#include <base/stdint.h>
#include <parent/parent.h>
#include <base/entrypoint.h>
#include <ram_session/capability.h>
#include <cpu_session/capability.h>
#include <rm_session/rm_session.h>
#include <pd_session/pd_session.h>


namespace Genode { struct Environment; }
namespace Genode { struct Env; }


/**
* Interface to be provided by the component implementation
*/
namespace Component
{
Genode::size_t stack_size();
char const *name();
void construct(Genode::Environment &);
}


struct Genode::Environment
{
virtual Parent &parent() = 0;

/**
* RAM session of the component
*
* The RAM Session represents a budget of memory (quota) that is available
* to the component. This budget can be used to allocate RAM dataspaces.
* Return stack size of the component's initial entrypoint
*/
virtual Ram_session &ram() = 0;

/**
* CPU session of the component
*
* This session is used to create the threads of the component.
*/
virtual Cpu_session &cpu() = 0;

/**
* Region map of the component's address space
*/
virtual Region_map &rm() = 0;
Genode::size_t stack_size();

/**
* PD session of the component as created by the parent
* Return component name
*/
virtual Pd_session &pd() = 0;
char const *name();

/**
* Entrypoint for handling RPC requests and signals
* Construct component
*
* \param env interface to the component's execution environment
*/
virtual Entrypoint &ep() = 0;

virtual Ram_session_capability ram_session_cap() = 0;
virtual Cpu_session_capability cpu_session_cap() = 0;
};
void construct(Genode::Env &env);
}

#endif /* _INCLUDE__BASE__COMPONENT_H_ */
8 changes: 4 additions & 4 deletions repos/base/include/base/entrypoint.h
Expand Up @@ -24,7 +24,7 @@
namespace Genode {
class Startup;
class Entrypoint;
class Environment;
class Env;
}


Expand Down Expand Up @@ -67,7 +67,7 @@ class Genode::Entrypoint : Genode::Noncopyable
void entry() override { ep._process_incoming_signals(); }
};

Environment &_env;
Env &_env;

Volatile_object<Rpc_entrypoint> _rpc_ep;

Expand Down Expand Up @@ -100,11 +100,11 @@ class Genode::Entrypoint : Genode::Noncopyable
/**
* Called by the startup code only
*/
Entrypoint(Environment &env);
Entrypoint(Env &env);

public:

Entrypoint(Environment &env, size_t stack_size, char const *name);
Entrypoint(Env &env, size_t stack_size, char const *name);

/**
* Associate RPC object with the entry point
Expand Down
99 changes: 22 additions & 77 deletions repos/base/include/base/env.h
@@ -1,11 +1,11 @@
/*
* \brief Environment of a component
* \brief Component environment
* \author Norman Feske
* \date 2006-07-01
* \date 2015-12-17
*/

/*
* Copyright (C) 2006-2013 Genode Labs GmbH
* Copyright (C) 2015 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
Expand All @@ -14,111 +14,56 @@
#ifndef _INCLUDE__BASE__ENV_H_
#define _INCLUDE__BASE__ENV_H_

#include <parent/capability.h>
#include <parent/parent.h>
#include <region_map/region_map.h>
#include <rm_session/rm_session.h> /* deprecated, kept for API compatibility only */
#include <ram_session/ram_session.h>
#include <cpu_session/cpu_session.h>
#include <base/entrypoint.h>
#include <ram_session/capability.h>
#include <cpu_session/capability.h>
#include <pd_session/capability.h>
#include <base/allocator.h>
#include <base/snprintf.h>
#include <base/lock.h>
#include <rm_session/rm_session.h>
#include <pd_session/pd_session.h>

namespace Genode {
/* maintain compatibility to deprecated API */
#include <deprecated/env.h>

struct Env;

/**
* Return the interface to the component's environment
*/
extern Env *env();
}
namespace Genode { struct Env; }


/**
* Component runtime environment
*
* The environment of a Genode component is defined by its parent. The 'Env'
* class allows the component to interact with its environment. It is
* initialized at the startup of the component.
*/
struct Genode::Env
{
virtual ~Env() { }

/**
* Communication channel to our parent
*/
virtual Parent *parent() = 0;
virtual Parent &parent() = 0;

/**
* RAM session of the component
*
* The RAM Session represents a budget of memory (quota) that is
* available to the component. This budget can be used to allocate
* RAM dataspaces.
* The RAM Session represents a budget of memory (quota) that is available
* to the component. This budget can be used to allocate RAM dataspaces.
*/
virtual Ram_session *ram_session() = 0;
virtual Ram_session_capability ram_session_cap() = 0;
virtual Ram_session &ram() = 0;

/**
* CPU session of the component
*
* This session is used to create the threads of the component.
*/
virtual Cpu_session *cpu_session() = 0;
virtual Cpu_session_capability cpu_session_cap() = 0;
virtual Cpu_session &cpu() = 0;

/**
* Region-manager session of the component as created by the parent
*
* \deprecated This function exists for API compatibility only.
* The functionality of the former RM service is now
* provided by the 'Region_map' interface.
* Region map of the component's address space
*/
virtual Region_map *rm_session() = 0;
virtual Region_map &rm() = 0;

/**
* PD session of the component as created by the parent
*/
virtual Pd_session *pd_session() = 0;
virtual Pd_session_capability pd_session_cap() = 0;
virtual Pd_session &pd() = 0;

/**
* Heap backed by the RAM session of the environment
* Entrypoint for handling RPC requests and signals
*/
virtual Allocator *heap() = 0;

/**
* Reload parent capability and reinitialize environment resources
*
* This function is solely used for implementing fork semantics.
* After forking a process, the new child process is executed
* within a copy of the address space of the forking process.
* Thereby, the new process inherits the original 'env' object of
* the forking process, which is meaningless in the context of the
* new process. By calling this function, the new process is able
* to reinitialize its 'env' with meaningful capabilities obtained
* via its updated parent capability.
*
* \noapi
*/
virtual void reinit(Native_capability::Dst, long) = 0;

/**
* Reinitialize main-thread object
*
* \param stack_area_rm new RM session of the stack area
*
* This function is solely used for implementing fork semantics
* as provided by the Noux environment.
*
* \noapi
*/
virtual void reinit_main_thread(Capability<Region_map> &stack_area_rm) = 0;
virtual Entrypoint &ep() = 0;

virtual Ram_session_capability ram_session_cap() = 0;
virtual Cpu_session_capability cpu_session_cap() = 0;
};

#endif /* _INCLUDE__BASE__ENV_H_ */

0 comments on commit 4f69772

Please sign in to comment.