Cleanup of parent-cap handling

This patch alleviates the need for a Native_capability::Dst at the API
level. The former use case of this type as argument to
Deprecated_env::reinit uses the opaque Native_capability::Raw type
instead. The 'Raw' type contains the portion of the capability that is
transferred as-is when delegating the capability (i.e., when installing
the parent capability into a new component, or when installing a new
parent capability into a new forked Noux process). This information can
be retrieved via the new Native_capability::raw method.

Furthermore, this patch moves the functions for retriving the parent
capability to base/internal/parent_cap.h, which is meant to be
implemented in platform-specific ways. It replaces the former set of
startup/internal/_main_parent_cap.h headers.

Issue #1993
This commit is contained in:
Norman Feske 2016-06-13 15:14:32 +02:00
parent f7bdd383e2
commit d71f0a9606
29 changed files with 185 additions and 190 deletions

View File

@ -38,7 +38,6 @@ namespace Genode {
struct Raw struct Raw
{ {
Dst dst;
long local_name; long local_name;
}; };
@ -107,6 +106,8 @@ namespace Genode {
long local_name() const { return _idx ? _idx->id() : 0; } long local_name() const { return _idx ? _idx->id() : 0; }
Dst dst() const { return _idx ? Dst(_idx->kcap()) : Dst(); } Dst dst() const { return _idx ? Dst(_idx->kcap()) : Dst(); }
bool valid() const { return (_idx != 0) && _idx->valid(); } bool valid() const { return (_idx != 0) && _idx->valid(); }
Raw raw() const { return { local_name() }; }
}; };
} }

View File

@ -0,0 +1,50 @@
/*
* \brief Interface to obtain the parent capability for the component
* \author Norman Feske
* \date 2013-09-25
*
* On Fiasco.OC, we transfer merely the 'local_name' part of the capability
* via the '_parent_cap' field of the ELF binary.
*/
/*
* Copyright (C) 2006-2013 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.
*/
#ifndef _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
#define _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
/* Genode includes */
#include <parent/capability.h>
#include <util/string.h>
#include <foc/native_capability.h>
/* base-internal includes */
#include <base/internal/crt0.h>
namespace Genode {
static inline Parent_capability parent_cap()
{
unsigned long const local_name = _parent_cap;
static Cap_index *i = cap_map()->insert(local_name,
Fiasco::PARENT_CAP);
/*
* Update local name after a parent capability got reloaded via
* 'Platform_env::reload_parent_cap()'.
*/
if (i->id() != local_name) {
cap_map()->remove(i);
i = cap_map()->insert(local_name, Fiasco::PARENT_CAP);
}
return reinterpret_cap_cast<Parent>(Native_capability(i));
}
}
#endif /* _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ */

View File

@ -1,49 +0,0 @@
/*
* \brief Obtain parent capability
* \author Norman Feske
* \date 2010-01-26
*/
/*
* Copyright (C) 2010-2013 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.
*/
#ifndef _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_
#define _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_
/* Genode includes */
#include <base/native_capability.h>
#include <foc/native_capability.h>
/* base-internal includes */
#include <base/internal/crt0.h>
namespace Genode {
/**
* Return constructed parent capability
*/
Parent_capability parent_cap()
{
Native_capability::Raw *raw = (Native_capability::Raw *)&_parent_cap;
static Cap_index *i = cap_map()->insert(raw->local_name,
Fiasco::PARENT_CAP);
/*
* Update local name after a parent capability got reloaded via
* 'Platform_env::reload_parent_cap()'.
*/
if (i->id() != raw->local_name) {
cap_map()->remove(i);
i = cap_map()->insert(raw->local_name, Fiasco::PARENT_CAP);
}
return reinterpret_cap_cast<Parent>(Native_capability(i));
}
}
#endif /* _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ */

View File

@ -36,13 +36,7 @@ class Genode::Native_capability
public: public:
struct Raw struct Raw { };
{
Dst dst;
/* obsolete in base-hw, but still used in generic code path */
addr_t local_name;
};
/** /**
* Create an invalid capability * Create an invalid capability
@ -90,6 +84,8 @@ class Genode::Native_capability
_inc(); _inc();
return *this; return *this;
} }
Raw raw() const { return Raw(); }
}; };
#endif /* _INCLUDE__BASE__NATIVE_CAPABILITY_H_ */ #endif /* _INCLUDE__BASE__NATIVE_CAPABILITY_H_ */

View File

@ -0,0 +1,30 @@
/*
* \brief Interface to obtain the parent capability for the component
* \author Stefan Kalkowski
* \date 2015-04-27
*/
/*
* Copyright (C) 2015-2016 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.
*/
#ifndef _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
#define _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
/* Genode includes */
#include <parent/capability.h>
namespace Hw { extern Genode::Untyped_capability _parent_cap; }
namespace Genode {
static inline Parent_capability parent_cap()
{
return reinterpret_cap_cast<Parent>(Hw::_parent_cap);
}
}
#endif /* _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ */

View File

@ -1,37 +0,0 @@
/*
* \brief Obtain parent capability
* \author Stefan Kalkowski
* \date 2015-04-27
*/
/*
* 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.
*/
#ifndef _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_
#define _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_
/* Genode includes */
#include <parent/capability.h>
/* base-internal includes */
#include <base/internal/crt0.h>
namespace Hw { extern Genode::Untyped_capability _parent_cap; }
namespace Genode {
/**
* Return constructed parent capability
*/
Parent_capability parent_cap()
{
/* assemble parent capability */
return reinterpret_cap_cast<Parent>(Hw::_parent_cap);
}
}
#endif /* _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ */

View File

@ -90,7 +90,7 @@ class Genode::Platform_env_base : public Env_deprecated
Pd_session *pd_session() override { return &_local_pd_session; } Pd_session *pd_session() override { return &_local_pd_session; }
Pd_session_capability pd_session_cap() override { return _pd_session_cap; } Pd_session_capability pd_session_cap() override { return _pd_session_cap; }
void reinit(Native_capability::Dst, long) override; void reinit(Native_capability::Raw) override;
void reinit_main_thread(Capability<Region_map> &) override; void reinit_main_thread(Capability<Region_map> &) override;
}; };

View File

@ -18,7 +18,7 @@
#include <base/internal/platform_env.h> #include <base/internal/platform_env.h>
void Genode::Platform_env_base::reinit(Native_capability::Dst, long) { } void Genode::Platform_env_base::reinit(Native_capability::Raw) { }
void Genode::Platform_env_base::reinit_main_thread(Capability<Region_map> &) { } void Genode::Platform_env_base::reinit_main_thread(Capability<Region_map> &) { }

View File

@ -30,16 +30,7 @@ namespace Genode {
typedef Nova::Obj_crd Dst; typedef Nova::Obj_crd Dst;
struct Raw struct Raw { };
{
Dst dst;
/*
* It is obsolete and unused in NOVA, however still used by
* generic base part
*/
addr_t local_name;
};
private: private:
@ -169,6 +160,8 @@ namespace Genode {
{ {
return Native_capability(); return Native_capability();
} }
Raw raw() const { return Raw(); }
}; };
} }

View File

@ -1,5 +1,5 @@
/* /*
* \brief Obtain parent capability * \brief Interface to obtain the parent capability for the component
* \author Norman Feske * \author Norman Feske
* \author Alexander Boettcher * \author Alexander Boettcher
* \date 2010-01-26 * \date 2010-01-26
@ -9,32 +9,29 @@
*/ */
/* /*
* Copyright (C) 2010-2013 Genode Labs GmbH * Copyright (C) 2010-2016 Genode Labs GmbH
* *
* This file is part of the Genode OS framework, which is distributed * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * under the terms of the GNU General Public License version 2.
*/ */
#ifndef _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ #ifndef _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
#define _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ #define _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
/* Genode includes */ /* Genode includes */
#include <util/string.h> #include <parent/capability.h>
/* NOVA includes */ /* NOVA includes */
#include <nova/syscalls.h> #include <nova/syscalls.h>
namespace Genode { namespace Genode {
/** static inline Parent_capability parent_cap()
* Return constructed parent capability
*/
Parent_capability parent_cap()
{ {
/* assemble parent capability */
return reinterpret_cap_cast<Parent>( return reinterpret_cap_cast<Parent>(
Native_capability(Nova::PT_SEL_PARENT)); Native_capability(Nova::PT_SEL_PARENT));
} }
} }
#endif /* _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ */ #endif /* _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ */

View File

@ -23,12 +23,10 @@ namespace Genode {
public: public:
/* /*
* XXX remove dependency in 'process.cc' and 'core_env.h' from * Platform-specific raw information of the capability that is
* 'Raw', 'Dst', and the 'dst' member. * transferred as-is when the capability is delegated.
*/ */
typedef int Dst; struct Raw { long v[4]; };
struct Raw { Dst dst = 0; long local_name = 0; };
Dst dst() const { return 0; }
/** /**
* Forward declaration of the platform-specific internal capability * Forward declaration of the platform-specific internal capability
@ -96,6 +94,8 @@ namespace Genode {
long local_name() const; long local_name() const;
bool valid() const; bool valid() const;
Raw raw() const { return { { 0, 0, 0, 0 } }; }
}; };
} }

View File

@ -1,31 +1,32 @@
/* /*
* \brief Obtain parent capability * \brief Interface to obtain the parent capability for the component
* \author Norman Feske * \author Norman Feske
* \date 2015-05-12 * \date 2015-05-12
*
* On seL4, no information is propagated via the '_parent_cap' field of the
* ELF image.
*/ */
/* /*
* Copyright (C) 2015 Genode Labs GmbH * Copyright (C) 2015-2016 Genode Labs GmbH
* *
* This file is part of the Genode OS framework, which is distributed * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * under the terms of the GNU General Public License version 2.
*/ */
#ifndef _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ #ifndef _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
#define _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ #define _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
/* Genode includes */ /* Genode includes */
#include <util/string.h> #include <parent/capability.h>
/* base-internal includes */ /* base-internal includes */
#include <base/internal/capability_space_sel4.h> #include <base/internal/capability_space_sel4.h>
namespace Genode { namespace Genode {
/** static inline Parent_capability parent_cap()
* Return constructed parent capability
*/
Parent_capability parent_cap()
{ {
Capability_space::Ipc_cap_data const Capability_space::Ipc_cap_data const
ipc_cap_data(Rpc_obj_key(), INITIAL_SEL_PARENT); ipc_cap_data(Rpc_obj_key(), INITIAL_SEL_PARENT);
@ -36,4 +37,4 @@ namespace Genode {
} }
} }
#endif /* _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ */ #endif /* _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ */

View File

@ -113,6 +113,11 @@ class Genode::Native_capability_tpl
* Return capability destination * Return capability destination
*/ */
Dst dst() const { return _dst; } Dst dst() const { return _dst; }
/**
* Return raw data representation of the capability
*/
Raw raw() const { return { _dst, _local_name }; }
}; };
#endif /* _INCLUDE__BASE__NATIVE_CAPABILITY_TPL_H_ */ #endif /* _INCLUDE__BASE__NATIVE_CAPABILITY_TPL_H_ */

View File

@ -106,7 +106,7 @@ struct Genode::Env_deprecated
* *
* \noapi * \noapi
*/ */
virtual void reinit(Native_capability::Dst, long) = 0; virtual void reinit(Native_capability::Raw) = 0;
/** /**
* Reinitialize main-thread object * Reinitialize main-thread object

View File

@ -199,7 +199,7 @@ namespace Genode {
return Pd_session_capability(); return Pd_session_capability();
} }
void reinit(Capability<Parent>::Dst, long) override { } void reinit(Capability<Parent>::Raw) override { }
void reinit_main_thread(Capability<Region_map> &) override { } void reinit_main_thread(Capability<Region_map> &) override { }
}; };

View File

@ -37,8 +37,9 @@ extern unsigned _stack_high; /* upper bound of intial stack */
***************************************************/ ***************************************************/
/* /*
* The protection domain creator initializes the information about * The protection domain creator initializes the information about the parent
* the parent capability prior the execution of the main thread. * capability prior the execution of the main thread. It corresponds to the
* '_parent_cap' symbol defined in 'src/ld/genode.ld'.
*/ */
extern unsigned long _parent_cap; extern unsigned long _parent_cap;

View File

@ -2,6 +2,9 @@
* \brief Interface to obtain the parent capability for the component * \brief Interface to obtain the parent capability for the component
* \author Norman Feske * \author Norman Feske
* \date 2013-09-25 * \date 2013-09-25
*
* This implementation is used on platforms that rely on global IDs (thread
* IDs, global unique object IDs) as capability representation.
*/ */
/* /*
@ -14,8 +17,22 @@
#ifndef _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ #ifndef _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
#define _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ #define _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_
/* Genode includes */
#include <parent/capability.h> #include <parent/capability.h>
#include <util/string.h>
namespace Genode { Parent_capability parent_cap(); } /* base-internal includes */
#include <base/internal/crt0.h>
namespace Genode {
static inline Parent_capability parent_cap()
{
Parent_capability cap;
memcpy(&cap, (void *)&_parent_cap, sizeof(cap));
return Parent_capability(cap);
}
}
#endif /* _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ */ #endif /* _INCLUDE__BASE__INTERNAL__PARENT_CAP_H_ */

View File

@ -108,7 +108,7 @@ class Genode::Platform_env : public Env_deprecated,
/* /*
* Support functions for implementing fork on Noux. * Support functions for implementing fork on Noux.
*/ */
void reinit(Native_capability::Dst, long) override; void reinit(Native_capability::Raw) override;
void reinit_main_thread(Capability<Region_map> &) override; void reinit_main_thread(Capability<Region_map> &) override;

View File

@ -1,36 +0,0 @@
/*
* \brief Obtain parent capability
* \author Norman Feske
* \date 2010-01-26
*
* This implementation is used on platforms that rely on global IDs (thread
* IDs, global unique object IDs) as capability representation.
*/
/*
* Copyright (C) 2010-2013 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.
*/
#ifndef _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_
#define _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_
/* base-internal includes */
#include <base/internal/crt0.h>
namespace Genode {
/**
* Return constructed parent capability
*/
Parent_capability parent_cap()
{
Parent_capability cap;
memcpy(&cap, (void *)&_parent_cap, sizeof(cap));
return Parent_capability(cap);
}
}
#endif /* _INCLUDE__STARTUP__INTERNAL___MAIN_PARENT_CAP_H_ */

View File

@ -19,6 +19,7 @@
/* base-internal includes */ /* base-internal includes */
#include <base/internal/elf.h> #include <base/internal/elf.h>
#include <base/internal/parent_cap.h>
using namespace Genode; using namespace Genode;
@ -123,11 +124,7 @@ Child::Process::Loaded_executable::Loaded_executable(Dataspace_capability elf_ds
* data segment * data segment
*/ */
if (!parent_info) { if (!parent_info) {
Native_capability::Raw *raw = (Native_capability::Raw *)ptr; *(Untyped_capability::Raw *)ptr = parent_cap.raw();
raw->dst = parent_cap.dst();
raw->local_name = parent_cap.local_name();
parent_info = true; parent_info = true;
} }

View File

@ -27,8 +27,7 @@ void reinit_main_thread();
namespace Genode { extern bool inhibit_tracing; } namespace Genode { extern bool inhibit_tracing; }
void Genode::Platform_env::reinit(Native_capability::Dst dst, void Genode::Platform_env::reinit(Native_capability::Raw raw)
long local_name)
{ {
/* /*
* This function is unused during the normal operation of Genode. It is * This function is unused during the normal operation of Genode. It is
@ -54,9 +53,7 @@ void Genode::Platform_env::reinit(Native_capability::Dst dst,
* Patch new parent capability into the original location as specified by * Patch new parent capability into the original location as specified by
* the linker script. * the linker script.
*/ */
Native_capability::Raw *raw = (Native_capability::Raw *)(&_parent_cap); *(Native_capability::Raw *)(&_parent_cap) = raw;
raw->dst = dst;
raw->local_name = local_name;
/* /*
* Re-initialize 'Platform_env' members * Re-initialize 'Platform_env' members

View File

@ -26,7 +26,7 @@
#include <base/component.h> #include <base/component.h>
/* platform-specific local helper functions */ /* platform-specific local helper functions */
#include <startup/internal/_main_parent_cap.h> #include <base/internal/parent_cap.h>
#include <base/internal/crt0.h> #include <base/internal/crt0.h>

View File

@ -0,0 +1,29 @@
+++ arch/l4/kernel/arch-arm/vmlinux.lds.S
@@ -108,6 +108,12 @@ SECTIONS
LONG(0xffffffff);
_parent_cap_local_name = .;
LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
} : rw
. = ALIGN(4096);
+++ arch/l4/kernel/arch-x86/vmlinux.lds.S
@@ -101,6 +101,13 @@ SECTIONS
LONG(0xffffffff);
_parent_cap_local_name = .;
LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
+ LONG(0xffffffff);
/*
* Platform-specific entry for Fiasco.OC.

View File

@ -1 +1 @@
07d72c264878024efa078d14241f1648172a39de 1e6243ccb8f368ed15b7f42c339434e46d0062a9

View File

@ -4,6 +4,8 @@ DOWNLOADS := l4android.git
URL(l4android) := https://github.com/skalk/l4linux.git URL(l4android) := https://github.com/skalk/l4linux.git
REV(l4android) := cea6e7ab97a5ad421e53d456dd940893d5a14866 REV(l4android) := cea6e7ab97a5ad421e53d456dd940893d5a14866
DIR(l4android) := src/l4android DIR(l4android) := src/l4android
PATCHES := patches/parent_cap_ld_script.patch
PATCH_OPT := -p0 -d src/l4android
sym_link := src/l4android/arch/l4/drivers sym_link := src/l4android/arch/l4/drivers
default: $(sym_link) default: $(sym_link)

View File

@ -1 +1 @@
64de371ac6ca2e4c117e0d3eb827aa97216d30e7 153fac6366d79b8380ccc97a3a7ed099cedb51b2

View File

@ -4,6 +4,8 @@ DOWNLOADS := l4linux.git
URL(l4linux) := https://github.com/skalk/l4linux.git URL(l4linux) := https://github.com/skalk/l4linux.git
REV(l4linux) := 25aa4a5f25c920e18aa18899e45c71974058d813 REV(l4linux) := 25aa4a5f25c920e18aa18899e45c71974058d813
DIR(l4linux) := src/l4linux DIR(l4linux) := src/l4linux
PATCHES := patches/parent_cap_ld_script.patch
PATCH_OPT := -p0 -d src/l4linux
sym_link := src/l4linux/arch/l4/drivers sym_link := src/l4linux/arch/l4/drivers
default: $(sym_link) default: $(sym_link)

View File

@ -523,7 +523,7 @@ extern "C" void fork_trampoline()
{ {
/* reinitialize environment */ /* reinitialize environment */
using namespace Genode; using namespace Genode;
env()->reinit(new_parent.dst, new_parent.local_name); env()->reinit(new_parent);
/* reinitialize standard-output connection */ /* reinitialize standard-output connection */
stdout_reconnect(); stdout_reconnect();

View File

@ -453,8 +453,7 @@ namespace Noux {
void start_forked_main_thread(addr_t ip, addr_t sp, addr_t parent_cap_addr) void start_forked_main_thread(addr_t ip, addr_t sp, addr_t parent_cap_addr)
{ {
/* poke parent_cap_addr into child's address space */ /* poke parent_cap_addr into child's address space */
Capability<Parent> const &cap = _child.parent_cap(); Capability<Parent>::Raw const raw = _child.parent_cap().raw();
Capability<Parent>::Raw raw = { cap.dst(), cap.local_name() };
_pd.poke(parent_cap_addr, &raw, sizeof(raw)); _pd.poke(parent_cap_addr, &raw, sizeof(raw));