mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 14:37:50 +00:00
Unify policy name for Native_capability_tpl.
This commit unifies the policy name for the template argument for Native_capability_tpl to Cap_dst_policy, like suggested by Norman in the discussion resulting from issue #145. Moreover, it takes the memcpy operation for copying a Native_capability out of the template, which is included by a significant bunch of files, and separates it in a library, analog to the suggestion in issue #145.
This commit is contained in:
parent
35384faa7a
commit
42b7c01685
@ -27,10 +27,19 @@ namespace Genode {
|
||||
|
||||
class Platform_thread;
|
||||
|
||||
struct Native_thread_id
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef int Dst;
|
||||
|
||||
static bool valid(Dst tid) { return tid != Codezero::NILTHREAD; }
|
||||
static Dst invalid() { return Codezero::NILTHREAD; }
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
struct Native_thread_id
|
||||
{
|
||||
typedef Cap_dst_policy::Dst Dst;
|
||||
|
||||
Dst tid;
|
||||
|
||||
/**
|
||||
@ -51,9 +60,6 @@ namespace Genode {
|
||||
Native_thread_id(Dst l4id) : tid(l4id), running_lock(0) { }
|
||||
|
||||
Native_thread_id(Dst l4id, Codezero::l4_mutex *rl) : tid(l4id), running_lock(rl) { }
|
||||
|
||||
static bool valid(Dst tid) { return tid != Codezero::NILTHREAD; }
|
||||
static Dst invalid() { return Codezero::NILTHREAD; }
|
||||
};
|
||||
|
||||
struct Native_thread
|
||||
@ -107,7 +113,7 @@ namespace Genode {
|
||||
inline bool operator == (Native_thread_id t1, Native_thread_id t2) { return t1.tid == t2.tid; }
|
||||
inline bool operator != (Native_thread_id t1, Native_thread_id t2) { return t1.tid != t2.tid; }
|
||||
|
||||
typedef Native_capability_tpl<Native_thread_id> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
SRC_CC = ipc.cc pager.cc
|
||||
INC_DIR += $(REP_DIR)/include/codezero/dummies
|
||||
LIBS = cap_copy
|
||||
|
||||
vpath %.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -18,13 +18,6 @@
|
||||
|
||||
namespace Fiasco {
|
||||
#include <l4/sys/types.h>
|
||||
|
||||
struct Thread_id_check
|
||||
{
|
||||
typedef l4_threadid_t Dst;
|
||||
static bool valid(Dst id) { return !l4_is_invalid_id(id); }
|
||||
static Dst invalid() { return L4_INVALID_ID;}
|
||||
};
|
||||
}
|
||||
|
||||
namespace Genode {
|
||||
@ -35,6 +28,18 @@ namespace Genode {
|
||||
|
||||
typedef Fiasco::l4_threadid_t Native_thread_id;
|
||||
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef Fiasco::l4_threadid_t Dst;
|
||||
static bool valid(Dst id) { return !Fiasco::l4_is_invalid_id(id); }
|
||||
static Dst invalid()
|
||||
{
|
||||
using namespace Fiasco;
|
||||
return L4_INVALID_ID;
|
||||
}
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
struct Native_thread
|
||||
{
|
||||
Native_thread_id l4id;
|
||||
@ -66,7 +71,7 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
typedef Native_capability_tpl<Fiasco::Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef Fiasco::l4_threadid_t Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
SRC_CC = ipc.cc pager.cc
|
||||
LIBS = cap_copy
|
||||
|
||||
vpath %.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -8,16 +8,6 @@ namespace Fiasco {
|
||||
#include <l4/sys/types.h>
|
||||
#include <l4/sys/utcb.h>
|
||||
|
||||
struct Thread_id_check
|
||||
{
|
||||
typedef l4_cap_idx_t Dst;
|
||||
|
||||
static bool valid(Dst idx) {
|
||||
return !(idx & Fiasco::L4_INVALID_CAP_BIT) && idx != 0; }
|
||||
|
||||
static Dst invalid() { return L4_INVALID_CAP;}
|
||||
};
|
||||
|
||||
enum Cap_selectors {
|
||||
TASK_CAP = L4_BASE_TASK_CAP,
|
||||
PARENT_CAP = 0x8UL << L4_CAP_SHIFT,
|
||||
@ -38,6 +28,17 @@ namespace Fiasco {
|
||||
|
||||
namespace Genode {
|
||||
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef Fiasco::l4_cap_idx_t Dst;
|
||||
|
||||
static bool valid(Dst idx) {
|
||||
return !(idx & Fiasco::L4_INVALID_CAP_BIT) && idx != 0; }
|
||||
|
||||
static Dst invalid() { return Fiasco::L4_INVALID_CAP;}
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
typedef volatile int Native_lock;
|
||||
typedef Fiasco::l4_cap_idx_t Native_thread_id;
|
||||
typedef Fiasco::l4_cap_idx_t Native_thread;
|
||||
@ -45,7 +46,7 @@ namespace Genode {
|
||||
typedef Fiasco::l4_utcb_t* Native_utcb;
|
||||
typedef int Native_connection_state;
|
||||
|
||||
typedef Native_capability_tpl<Fiasco::Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
LIBS = syscalls
|
||||
LIBS = syscalls cap_copy
|
||||
SRC_CC += ipc.cc pager.cc
|
||||
INC_DIR += $(REP_DIR)/src/base/lock
|
||||
|
||||
|
@ -98,7 +98,7 @@ void Ipc_pager::reply_and_wait_for_fault()
|
||||
|
||||
void Ipc_pager::acknowledge_wakeup()
|
||||
{
|
||||
l4_cap_idx_t dst = Thread_id_check::valid(_last) ? _last : L4_SYSF_REPLY;
|
||||
l4_cap_idx_t dst = Cap_dst_policy::valid(_last) ? _last : L4_SYSF_REPLY;
|
||||
|
||||
/* answer wakeup call from one of core's region-manager sessions */
|
||||
l4_ipc_send(dst, l4_utcb(), l4_msgtag(0, 0, 0, 0), L4_IPC_SEND_TIMEOUT_0);
|
||||
|
@ -81,7 +81,7 @@ static inline Genode::Native_thread_id thread_invalid_id()
|
||||
*/
|
||||
static inline bool thread_id_valid(Genode::Native_thread_id tid)
|
||||
{
|
||||
return Fiasco::Thread_id_check::valid(tid);
|
||||
return Genode::Cap_dst_policy::valid(tid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ static addr_t core_utcb_base() {
|
||||
|
||||
void Platform_pd::_create_pd(bool syscall)
|
||||
{
|
||||
if (!Thread_id_check::valid(_l4_task_cap))
|
||||
if (!Cap_dst_policy::valid(_l4_task_cap))
|
||||
_l4_task_cap = cap_alloc()->alloc();
|
||||
|
||||
if (syscall) {
|
||||
|
@ -18,10 +18,11 @@
|
||||
|
||||
namespace Genode {
|
||||
|
||||
struct Empty_thread_id {
|
||||
struct Cap_dst_policy {
|
||||
typedef int Dst;
|
||||
static bool valid(Dst) { return false; }
|
||||
static Dst invalid() { return false; }
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
typedef volatile int Native_lock;
|
||||
@ -29,7 +30,7 @@ namespace Genode {
|
||||
typedef Native_thread Native_thread_id;
|
||||
typedef struct { } Native_utcb;
|
||||
typedef int Native_connection_state;
|
||||
typedef Native_capability_tpl<Empty_thread_id,Empty_thread_id> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -1,3 +1,4 @@
|
||||
SRC_CC = ipc.cc
|
||||
LIBS = cap_copy
|
||||
|
||||
vpath ipc.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -93,10 +93,11 @@ namespace Genode {
|
||||
inline bool operator != (Native_thread_id t1, Native_thread_id t2) {
|
||||
return (t1.tid != t2.tid) || (t1.pid != t2.pid); }
|
||||
|
||||
struct Thread_id_check {
|
||||
struct Cap_dst_policy {
|
||||
typedef long Dst;
|
||||
static bool valid(Dst id) { return id != 0; }
|
||||
static Dst invalid() { return 0; }
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -104,7 +105,7 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
typedef Native_capability_tpl<Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state; /* socket descriptor */
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
REQUIRES = linux
|
||||
SRC_CC = ipc.cc
|
||||
LIBS = syscall rpath
|
||||
LIBS = syscall rpath cap_copy
|
||||
|
||||
vpath ipc.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -30,16 +30,17 @@ namespace Genode {
|
||||
|
||||
Native_thread_id my_thread_id();
|
||||
|
||||
struct Thread_id_check
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef Kernel::Thread_id Dst;
|
||||
static bool valid(Dst tid) {
|
||||
return tid != Kernel::INVALID_THREAD_ID; }
|
||||
static Dst invalid()
|
||||
{ return Kernel::INVALID_THREAD_ID; }
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
typedef Native_capability_tpl<Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
SRC_CC = ipc.cc
|
||||
SRC_CC += pager.cc
|
||||
LIBS += thread_context
|
||||
LIBS += thread_context cap_copy
|
||||
|
||||
vpath ipc.cc $(REP_DIR)/src/base/ipc
|
||||
vpath pager.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -53,14 +53,15 @@ namespace Genode {
|
||||
long _utcb[UTCB_SIZE/sizeof(long)];
|
||||
};
|
||||
|
||||
struct Portal_checker
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef int Dst;
|
||||
static bool valid(Dst pt) { return pt != 0; }
|
||||
static Dst invalid() { return 0; }
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
typedef Native_capability_tpl<Portal_checker> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
SRC_CC = ipc.cc pager.cc
|
||||
LIBS = thread_context
|
||||
LIBS = thread_context cap_copy
|
||||
INC_DIR += $(REP_DIR)/src/platform
|
||||
|
||||
vpath ipc.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -78,14 +78,15 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
struct Thread_id_checker
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef Okl4::L4_ThreadId_t Dst;
|
||||
static bool valid(Dst tid) { return !Okl4::L4_IsNilThread(tid); }
|
||||
static Dst invalid() { return Okl4::L4_nilthread; }
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
typedef Native_capability_tpl<Thread_id_checker> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef Okl4::L4_ThreadId_t Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
SRC_CC = ipc.cc pager.cc
|
||||
LIBS = cap_copy
|
||||
|
||||
vpath %.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -18,13 +18,6 @@
|
||||
|
||||
namespace Pistachio {
|
||||
#include <l4/types.h>
|
||||
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef L4_ThreadId_t Dst;
|
||||
static bool valid(Dst tid) { return !L4_IsNilThread(tid); }
|
||||
static Dst invalid() { return L4_nilthread; }
|
||||
};
|
||||
}
|
||||
|
||||
namespace Genode {
|
||||
@ -35,6 +28,18 @@ namespace Genode {
|
||||
|
||||
typedef Pistachio::L4_ThreadId_t Native_thread_id;
|
||||
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
typedef Pistachio::L4_ThreadId_t Dst;
|
||||
static bool valid(Dst tid) { return !Pistachio::L4_IsNilThread(tid); }
|
||||
static Dst invalid()
|
||||
{
|
||||
using namespace Pistachio;
|
||||
return L4_nilthread;
|
||||
}
|
||||
static void copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src);
|
||||
};
|
||||
|
||||
struct Native_thread
|
||||
{
|
||||
Native_thread_id l4id;
|
||||
@ -66,7 +71,7 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
typedef Native_capability_tpl<Pistachio::Cap_dst_policy> Native_capability;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
|
||||
typedef Pistachio::L4_ThreadId_t Native_connection_state;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
SRC_CC = ipc.cc pager.cc
|
||||
LIBS = cap_copy
|
||||
|
||||
vpath %.cc $(REP_DIR)/src/base/ipc
|
||||
|
@ -18,8 +18,6 @@
|
||||
#ifndef _INCLUDE__BASE__NATIVE_CAPABILITY_H_
|
||||
#define _INCLUDE__BASE__NATIVE_CAPABILITY_H_
|
||||
|
||||
#include <util/string.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/**
|
||||
@ -102,8 +100,7 @@ namespace Genode {
|
||||
/**
|
||||
* Copy this capability to another PD
|
||||
*/
|
||||
void copy_to(void* dst) {
|
||||
memcpy(dst, this, sizeof(Native_capability_tpl)); }
|
||||
void copy_to(void* dst) { POLICY::copy(dst, this); }
|
||||
|
||||
|
||||
/*****************************************
|
||||
|
3
base/lib/mk/cap_copy.mk
Normal file
3
base/lib/mk/cap_copy.mk
Normal file
@ -0,0 +1,3 @@
|
||||
SRC_CC = cap_copy.cc
|
||||
|
||||
vpath cap_copy.cc $(BASE_DIR)/src/platform
|
@ -6,7 +6,7 @@
|
||||
#
|
||||
BASE_LIBS = alarm allocator_avl avl_tree cxx env heap \
|
||||
ipc lock slab timed_semaphore thread signal \
|
||||
log_console slab
|
||||
log_console slab cap_copy
|
||||
|
||||
#
|
||||
# Name of Genode's dynamic linker
|
||||
|
20
base/src/platform/cap_copy.cc
Normal file
20
base/src/platform/cap_copy.cc
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* \brief Copy a platform-capability to another protection domain.
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2012-03-09
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 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.
|
||||
*/
|
||||
|
||||
#include <util/string.h>
|
||||
#include <base/native_types.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
void Cap_dst_policy::copy(void* dst, Native_capability_tpl<Cap_dst_policy>* src) {
|
||||
memcpy(dst, src, sizeof(Native_capability_tpl<Cap_dst_policy>)); }
|
Loading…
Reference in New Issue
Block a user