mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-20 08:03:56 +00:00
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references wherever feasible. This has the following benefits: * The contract between caller and callee becomes more obvious. When passing a reference, the contract says that the argument cannot be a null pointer. The caller is responsible to ensure that. Therefore, the use of reference eliminates the need to add defensive null-pointer checks at the callee site, which sometimes merely exist to be on the safe side. The bottom line is that the code becomes easier to follow. * Reference members must be initialized via an object initializer, which promotes a programming style that avoids intermediate object- construction states. Within core, there are still a few pointers as member variables left though. E.g., caused by the late association of 'Platform_thread' objects with their 'Platform_pd' objects. * If no pointers are present as member variables, we don't need to manually provide declarations of a private copy constructor and an assignment operator to avoid -Weffc++ errors "class ... has pointer data members [-Werror=effc++]". This patch also changes a few system bindings on NOVA and Fiasco.OC, e.g., the return value of the global 'cap_map' accessor has become a reference. Hence, the patch touches a few places outside of core. Fixes #3135
This commit is contained in:
@ -21,10 +21,10 @@
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
Capability_map *Genode::cap_map()
|
||||
Capability_map &Genode::cap_map()
|
||||
{
|
||||
static Genode::Capability_map map;
|
||||
return ↦
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,14 +29,14 @@ Native_capability::Native_capability()
|
||||
|
||||
void Native_capability::_inc()
|
||||
{
|
||||
Cap_index idx(cap_map()->find(local_name()));
|
||||
Cap_index idx(cap_map().find(local_name()));
|
||||
idx.inc();
|
||||
}
|
||||
|
||||
|
||||
void Native_capability::_dec()
|
||||
{
|
||||
Cap_index idx(cap_map()->find(local_name()));
|
||||
Cap_index idx(cap_map().find(local_name()));
|
||||
idx.dec();
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ bool Receive_window::rcv_cleanup(bool keep, unsigned short const new_max)
|
||||
|
||||
/* free rest of indexes if new_max is smaller then last window */
|
||||
if (i >= new_max && _rcv_pt_cap_free[i] == FREE_SEL)
|
||||
cap_map()->remove(_rcv_pt_base + i, 0, false);
|
||||
cap_map().remove(_rcv_pt_base + i, 0, false);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -164,7 +164,7 @@ bool Receive_window::rcv_cleanup(bool keep, unsigned short const new_max)
|
||||
for (unsigned i = 0; i < MAX_CAP_ARGS; i++) {
|
||||
if (_rcv_pt_cap_free[i] == FREE_INVALID)
|
||||
continue;
|
||||
cap_map()->remove(_rcv_pt_base + i, 0, _rcv_pt_cap_free[i] != FREE_SEL);
|
||||
cap_map().remove(_rcv_pt_base + i, 0, _rcv_pt_cap_free[i] != FREE_SEL);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -191,7 +191,7 @@ bool Receive_window::prepare_rcv_window(Nova::Utcb &utcb, addr_t rcv_window)
|
||||
/* allocate receive window if necessary, otherwise use old one */
|
||||
if (rcv_invalid() || rcv_cleanup(true, 1U << _rcv_wnd_log2))
|
||||
{
|
||||
_rcv_pt_base = cap_map()->insert(_rcv_wnd_log2);
|
||||
_rcv_pt_base = cap_map().insert(_rcv_wnd_log2);
|
||||
|
||||
if (_rcv_pt_base == INVALID_INDEX) {
|
||||
/* no mappings can be received */
|
||||
|
@ -61,10 +61,10 @@ class Initial_cap_range : public Cap_range
|
||||
};
|
||||
|
||||
|
||||
Initial_cap_range * initial_cap_range()
|
||||
Initial_cap_range &initial_cap_range()
|
||||
{
|
||||
static Initial_cap_range s;
|
||||
return &s;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -76,26 +76,26 @@ void prepare_init_main_thread()
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
cap_map()->insert(initial_cap_range());
|
||||
cap_map().insert(initial_cap_range());
|
||||
|
||||
/* for Core we can't perform the following code so early */
|
||||
if (!__initial_sp) {
|
||||
|
||||
enum { CAP_RANGES = 32 };
|
||||
|
||||
unsigned index = initial_cap_range()->base() +
|
||||
initial_cap_range()->elements();
|
||||
unsigned index = initial_cap_range().base() +
|
||||
initial_cap_range().elements();
|
||||
|
||||
static char local[CAP_RANGES][sizeof(Cap_range)];
|
||||
|
||||
for (unsigned i = 0; i < CAP_RANGES; i++) {
|
||||
|
||||
Cap_range * range = reinterpret_cast<Cap_range *>(local[i]);
|
||||
construct_at<Cap_range>(range, index);
|
||||
Cap_range &range = *reinterpret_cast<Cap_range *>(local[i]);
|
||||
construct_at<Cap_range>(&range, index);
|
||||
|
||||
cap_map()->insert(range);
|
||||
cap_map().insert(range);
|
||||
|
||||
index = range->base() + range->elements();
|
||||
index = range.base() + range.elements();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,8 +103,8 @@ void prepare_init_main_thread()
|
||||
void prepare_reinit_main_thread()
|
||||
{
|
||||
using namespace Genode;
|
||||
construct_at<Capability_map>(cap_map());
|
||||
construct_at<Initial_cap_range>(initial_cap_range());
|
||||
construct_at<Capability_map>(&cap_map());
|
||||
construct_at<Initial_cap_range>(&initial_cap_range());
|
||||
prepare_init_main_thread();
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ void Thread::_init_platform_thread(size_t weight, Type type)
|
||||
addr_t utcb = reinterpret_cast<addr_t>(&_stack->utcb());
|
||||
revoke(Mem_crd(utcb >> 12, 0, rwx));
|
||||
|
||||
native_thread().exc_pt_sel = cap_map()->insert(NUM_INITIAL_PT_LOG2);
|
||||
native_thread().exc_pt_sel = cap_map().insert(NUM_INITIAL_PT_LOG2);
|
||||
if (native_thread().exc_pt_sel == Native_thread::INVALID_INDEX)
|
||||
throw Cpu_session::Thread_creation_failed();
|
||||
|
||||
@ -124,14 +124,14 @@ void Thread::_deinit_platform_thread()
|
||||
|
||||
if (native_thread().ec_sel != Native_thread::INVALID_INDEX) {
|
||||
revoke(Obj_crd(native_thread().ec_sel, 0));
|
||||
cap_map()->remove(native_thread().ec_sel, 0, false);
|
||||
cap_map().remove(native_thread().ec_sel, 0, false);
|
||||
}
|
||||
|
||||
/* de-announce thread */
|
||||
if (_thread_cap.valid())
|
||||
_cpu_session->kill_thread(_thread_cap);
|
||||
|
||||
cap_map()->remove(native_thread().exc_pt_sel, NUM_INITIAL_PT_LOG2);
|
||||
cap_map().remove(native_thread().exc_pt_sel, NUM_INITIAL_PT_LOG2);
|
||||
}
|
||||
|
||||
|
||||
@ -173,7 +173,7 @@ void Thread::start()
|
||||
cpu_thread.start(thread_ip, _stack->top());
|
||||
|
||||
/* request native EC thread cap */
|
||||
native_thread().ec_sel = cap_map()->insert();
|
||||
native_thread().ec_sel = cap_map().insert();
|
||||
if (native_thread().ec_sel == Native_thread::INVALID_INDEX)
|
||||
throw Cpu_session::Thread_creation_failed();
|
||||
|
||||
|
Reference in New Issue
Block a user