Browse Source

base: hide internals of the Thread API

This patch moves details about the stack allocation and organization
the base-internal headers. Thereby, I replaced the notion of "thread
contexts" by "stacks" as this term is much more intuitive. The fact that
we place thread-specific information at the bottom of the stack is not
worth introducing new terminology.

Issue #1832
devel
Norman Feske 7 years ago committed by Christian Helmuth
parent
commit
7f73e5e879
  1. 12
      repos/base-fiasco/include/base/native_types.h
  2. 2
      repos/base-fiasco/lib/mk/base-common.mk
  3. 2
      repos/base-fiasco/lib/mk/base.mk
  4. 10
      repos/base-fiasco/src/core/platform.cc
  5. 4
      repos/base-fiasco/src/core/target.inc
  6. 5
      repos/base-fiasco/src/core/thread_start.cc
  7. 24
      repos/base-foc/include/base/native_types.h
  8. 4
      repos/base-foc/include/base/thread_state.h
  9. 2
      repos/base-foc/include/signal_source/client.h
  10. 12
      repos/base-foc/include/spec/arm/base/native_config.h
  11. 12
      repos/base-foc/include/spec/x86/base/native_config.h
  12. 3
      repos/base-foc/lib/mk/base-common.mk
  13. 2
      repos/base-foc/lib/mk/base.mk
  14. 23
      repos/base-foc/src/base/thread/thread_start.cc
  15. 4
      repos/base-foc/src/core/cpu_session_extension.cc
  16. 2
      repos/base-foc/src/core/include/irq_object.h
  17. 4
      repos/base-foc/src/core/include/platform_pd.h
  18. 4
      repos/base-foc/src/core/include/platform_thread.h
  19. 6
      repos/base-foc/src/core/ipc_pager.cc
  20. 2
      repos/base-foc/src/core/irq_session_component.cc
  21. 6
      repos/base-foc/src/core/pager.cc
  22. 10
      repos/base-foc/src/core/platform.cc
  23. 17
      repos/base-foc/src/core/platform_pd.cc
  24. 2
      repos/base-foc/src/core/platform_thread.cc
  25. 4
      repos/base-foc/src/core/target.inc
  26. 18
      repos/base-foc/src/core/thread_start.cc
  27. 6
      repos/base-foc/src/include/base/internal/lock_helper.h
  28. 17
      repos/base-hw/include/base/native_types.h
  29. 2
      repos/base-hw/lib/mk/base-common.inc
  30. 2
      repos/base-hw/lib/mk/base.mk
  31. 2
      repos/base-hw/lib/mk/core.inc
  32. 7
      repos/base-hw/src/base/thread/bootstrap.cc
  33. 46
      repos/base-hw/src/base/thread/start.cc
  34. 2
      repos/base-hw/src/core/include/platform_thread.h
  35. 4
      repos/base-hw/src/core/platform.cc
  36. 16
      repos/base-hw/src/core/thread_start.cc
  37. 16
      repos/base-linux/include/base/native_types.h
  38. 2
      repos/base-linux/lib/mk/base-common.mk
  39. 2
      repos/base-linux/lib/mk/base.inc
  40. 4
      repos/base-linux/mk/spec/linux.mk
  41. 2
      repos/base-linux/mk/spec/linux_arm.mk
  42. 2
      repos/base-linux/mk/spec/linux_x86_32.mk
  43. 2
      repos/base-linux/mk/spec/linux_x86_64.mk
  44. 20
      repos/base-linux/src/base/env/rm_session_mmap.cc
  45. 5
      repos/base-linux/src/base/thread/thread_linux.cc
  46. 1
      repos/base-linux/src/core/include/core_env.h
  47. 40
      repos/base-linux/src/core/stack_area.cc
  48. 2
      repos/base-linux/src/core/target.mk
  49. 2
      repos/base-linux/src/include/base/internal/platform_env.h
  50. 20
      repos/base-linux/src/include/base/internal/stack_area.h
  51. 8
      repos/base-linux/src/ld/stack_area.nostdlib.ld
  52. 4
      repos/base-linux/src/ld/stack_area.stdlib.ld
  53. 8
      repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc
  54. 10
      repos/base-nova/include/base/native_types.h
  55. 4
      repos/base-nova/lib/mk/base-common.mk
  56. 2
      repos/base-nova/lib/mk/base.mk
  57. 5
      repos/base-nova/src/base/server/server.cc
  58. 11
      repos/base-nova/src/base/thread/stack.cc
  59. 8
      repos/base-nova/src/base/thread/thread_nova.cc
  60. 9
      repos/base-nova/src/core/include/platform_thread.h
  61. 30
      repos/base-nova/src/core/platform.cc
  62. 15
      repos/base-nova/src/core/platform_thread.cc
  63. 4
      repos/base-nova/src/core/target.inc
  64. 11
      repos/base-nova/src/core/thread_start.cc
  65. 12
      repos/base-okl4/include/base/native_types.h
  66. 2
      repos/base-okl4/lib/mk/base-common.mk
  67. 2
      repos/base-okl4/lib/mk/base.mk
  68. 6
      repos/base-okl4/src/core/platform.cc
  69. 4
      repos/base-okl4/src/core/target.inc
  70. 5
      repos/base-okl4/src/core/thread_start.cc
  71. 14
      repos/base-pistachio/include/base/native_types.h
  72. 2
      repos/base-pistachio/lib/mk/base-common.mk
  73. 2
      repos/base-pistachio/lib/mk/base.mk
  74. 10
      repos/base-pistachio/src/core/platform.cc
  75. 4
      repos/base-pistachio/src/core/target.inc
  76. 5
      repos/base-pistachio/src/core/thread_start.cc
  77. 10
      repos/base-sel4/include/base/native_types.h
  78. 2
      repos/base-sel4/lib/mk/base-common.inc
  79. 2
      repos/base-sel4/lib/mk/base.mk
  80. 2
      repos/base-sel4/lib/mk/core.mk
  81. 5
      repos/base-sel4/src/base/thread/thread_bootstrap.cc
  82. 2
      repos/base-sel4/src/core/include/platform_thread.h
  83. 6
      repos/base-sel4/src/core/platform.cc
  84. 2
      repos/base-sel4/src/core/platform_pd.cc
  85. 35
      repos/base-sel4/src/core/stack_area.cc
  86. 5
      repos/base-sel4/src/core/thread_start.cc
  87. 4
      repos/base/include/base/env.h
  88. 246
      repos/base/include/base/thread.h
  89. 2
      repos/base/include/spec/arm/cpu/consts.h
  90. 2
      repos/base/include/spec/x86/cpu/consts.h
  91. 2
      repos/base/lib/mk/ldso.inc
  92. 10
      repos/base/src/base/env/reinitialize.cc
  93. 18
      repos/base/src/base/env/stack_area.cc
  94. 78
      repos/base/src/base/thread/context_allocator.cc
  95. 16
      repos/base/src/base/thread/myself.cc
  96. 78
      repos/base/src/base/thread/stack_allocator.cc
  97. 140
      repos/base/src/base/thread/thread.cc
  98. 7
      repos/base/src/base/thread/thread_start.cc
  99. 26
      repos/base/src/base/thread/thread_utcb.cc
  100. 37
      repos/base/src/core/stack_area.cc
  101. Some files were not shown because too many files have changed in this diff Show More

12
repos/base-fiasco/include/base/native_types.h

@ -65,7 +65,7 @@ namespace Genode {
/**
* Empty UTCB type expected by the thread library
*
* On this kernel, UTCBs are not placed within the the context area. Each
* On this kernel, UTCBs are not placed within the the stack area. Each
* thread can request its own UTCB pointer using the kernel interface.
*/
typedef struct { } Native_utcb;
@ -76,17 +76,17 @@ namespace Genode {
struct Native_config
{
/**
* Thread-context area configuration.
* Stack area configuration
*/
static constexpr addr_t context_area_virtual_base() {
static constexpr addr_t stack_area_virtual_base() {
return 0x40000000UL; }
static constexpr addr_t context_area_virtual_size() {
static constexpr addr_t stack_area_virtual_size() {
return 0x10000000UL; }
/**
* Size of virtual address region holding the context of one thread
* Size of virtual address region holding the stack of one thread
*/
static constexpr addr_t context_virtual_size() { return 0x00100000UL; }
static constexpr addr_t stack_virtual_size() { return 0x00100000UL; }
};
struct Native_pd_args { };

2
repos/base-fiasco/lib/mk/base-common.mk

@ -21,7 +21,7 @@ SRC_CC += signal/signal.cc signal/common.cc signal/platform.cc
SRC_CC += server/server.cc server/common.cc
SRC_CC += thread/thread.cc thread/thread_bootstrap.cc thread/trace.cc
SRC_CC += thread/myself.cc
SRC_CC += thread/context_allocator.cc
SRC_CC += thread/stack_allocator.cc
SRC_CC += sleep.cc
SRC_CC += rm_session_client.cc

2
repos/base-fiasco/lib/mk/base.mk

@ -8,7 +8,7 @@ LIBS += base-common
SRC_CC += console/log_console.cc
SRC_CC += cpu/cache.cc
SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc
SRC_CC += env/env.cc env/stack_area.cc env/reinitialize.cc
SRC_CC += thread/thread_start.cc
SRC_CC += irq/platform.cc
SRC_CC += server/rpc_cap_alloc.cc

10
repos/base-fiasco/src/core/platform.cc

@ -306,8 +306,8 @@ void Platform::_setup_mem_alloc()
}
region.start = addr; region.end = addr + size;
if (!region.intersects(Native_config::context_area_virtual_base(),
Native_config::context_area_virtual_size())) {
if (!region.intersects(Native_config::stack_area_virtual_base(),
Native_config::stack_area_virtual_size())) {
add_region(region, _ram_alloc);
add_region(region, _core_address_ranges());
}
@ -411,9 +411,9 @@ void Platform::_setup_basics()
_vm_start = _vm_start == 0 ? L4_PAGESIZE : _vm_start;
_region_alloc.add_range(_vm_start, _vm_size);
/* preserve context area in core's virtual address space */
_region_alloc.remove_range(Native_config::context_area_virtual_base(),
Native_config::context_area_virtual_size());
/* preserve stack area in core's virtual address space */
_region_alloc.remove_range(Native_config::stack_area_virtual_base(),
Native_config::stack_area_virtual_size());
/* I/O memory could be the whole user address space */
/* FIXME if the kernel helps to find out max address - use info here */

4
repos/base-fiasco/src/core/target.inc

@ -2,7 +2,7 @@ TARGET = core
GEN_CORE_DIR = $(BASE_DIR)/src/core
SRC_CC += context_area.cc \
SRC_CC += stack_area.cc \
core_printf.cc \
core_rpc_cap_alloc.cc \
cpu_session_component.cc \
@ -62,7 +62,7 @@ vpath signal_source_component.cc $(GEN_CORE_DIR)
vpath trace_session_component.cc $(GEN_CORE_DIR)
vpath dataspace_component.cc $(GEN_CORE_DIR)
vpath dump_alloc.cc $(GEN_CORE_DIR)
vpath context_area.cc $(GEN_CORE_DIR)
vpath stack_area.cc $(GEN_CORE_DIR)
vpath pager_object.cc $(GEN_CORE_DIR)
vpath pager_ep.cc $(GEN_CORE_DIR)
vpath core_printf.cc $(BASE_DIR)/src/base/console

5
repos/base-fiasco/src/core/thread_start.cc

@ -15,6 +15,9 @@
#include <base/thread.h>
#include <base/sleep.h>
/* base-internal includes */
#include <base/internal/stack.h>
/* core includes */
#include <platform.h>
#include <core_env.h>
@ -35,7 +38,7 @@ void Thread_base::start()
{
/* create and start platform thread */
_tid.pt = new(platform()->core_mem_alloc())
Platform_thread(0, _context->name);
Platform_thread(0, _stack->name().string());
platform_specific()->core_pd()->bind_thread(_tid.pt);

24
repos/base-foc/include/base/native_types.h

@ -82,9 +82,29 @@ namespace Fiasco {
namespace Genode {
typedef Fiasco::l4_cap_idx_t Native_thread_id;
typedef Fiasco::l4_cap_idx_t Native_thread;
struct Native_thread
{
Fiasco::l4_cap_idx_t kcap = 0;
Native_thread() { }
explicit Native_thread(Fiasco::l4_cap_idx_t kcap) : kcap(kcap) { }
};
typedef Fiasco::l4_cap_idx_t Native_task;
typedef Fiasco::l4_utcb_t* Native_utcb;
struct Native_utcb
{
/*
* The 'Native_utcb' is located within the stack slot of the thread.
* We merely use it for remembering a pointer to the real UTCB, which
* resides somewhere in the kernel's address space.
*/
Fiasco::l4_utcb_t *foc_utcb = nullptr;
};
/**

4
repos/base-foc/include/base/thread_state.h

@ -24,9 +24,9 @@ namespace Genode {
struct Thread_state : Thread_state_base
{
Native_thread kcap; /* thread's gate cap in its pd */
Fiasco::l4_cap_idx_t kcap; /* thread's gate cap in its pd */
int id; /* id of gate capability */
Native_utcb utcb; /* thread's utcb in its pd */
addr_t utcb; /* thread's utcb in its pd */
unsigned exceptions; /* counts exceptions raised by the thread */
bool paused; /* indicates whether thread is stopped */
bool in_exception; /* true if thread is in exception */

2
repos/base-foc/include/signal_source/client.h

@ -53,7 +53,7 @@ namespace Genode {
_sem = call<Rpc_request_semaphore>();
l4_msgtag_t tag = l4_irq_attach(_sem.dst(), 0,
Thread_base::myself()->tid());
Thread_base::myself()->tid().kcap);
if (l4_error(tag))
PERR("l4_irq_attach failed with %ld!", l4_error(tag));
}

12
repos/base-foc/include/spec/arm/base/native_config.h

@ -1,5 +1,5 @@
/*
* \brief Platform-specific context area definitions
* \brief Platform-specific stack area definitions
* \author Stefan Kalkowski
* \date 2014-01-24
*/
@ -21,17 +21,17 @@ namespace Genode {
struct Native_config
{
/**
* Thread-context area configuration
* Stack area configuration
*/
static constexpr addr_t context_area_virtual_base() {
static constexpr addr_t stack_area_virtual_base() {
return 0x20000000UL; }
static constexpr addr_t context_area_virtual_size() {
static constexpr addr_t stack_area_virtual_size() {
return 0x10000000UL; }
/**
* Size of virtual address region holding the context of one thread
* Size of virtual address region holding the stack of one thread
*/
static constexpr addr_t context_virtual_size() { return 0x00100000UL; }
static constexpr addr_t stack_virtual_size() { return 0x00100000UL; }
};
}

12
repos/base-foc/include/spec/x86/base/native_config.h

@ -1,5 +1,5 @@
/*
* \brief Platform-specific context area definitions
* \brief Platform-specific stack area definitions
* \author Stefan Kalkowski
* \date 2014-01-24
*/
@ -21,17 +21,17 @@ namespace Genode {
struct Native_config
{
/**
* Thread-context area configuration
* Stack area configuration
*/
static constexpr addr_t context_area_virtual_base() {
static constexpr addr_t stack_area_virtual_base() {
return 0x40000000UL; }
static constexpr addr_t context_area_virtual_size() {
static constexpr addr_t stack_area_virtual_size() {
return 0x10000000UL; }
/**
* Size of virtual address region holding the context of one thread
* Size of virtual address region holding the stack of one thread
*/
static constexpr addr_t context_virtual_size() { return 0x00100000UL; }
static constexpr addr_t stack_virtual_size() { return 0x00100000UL; }
};
}

3
repos/base-foc/lib/mk/base-common.mk

@ -21,7 +21,8 @@ SRC_CC += signal/signal.cc signal/common.cc signal/platform.cc
SRC_CC += server/server.cc server/common.cc
SRC_CC += thread/thread.cc thread/thread_bootstrap.cc thread/trace.cc
SRC_CC += thread/myself.cc
SRC_CC += thread/context_allocator.cc
SRC_CC += thread/stack_allocator.cc
SRC_CC += thread/thread_utcb.cc
SRC_CC += sleep.cc
SRC_CC += rm_session_client.cc

2
repos/base-foc/lib/mk/base.mk

@ -8,7 +8,7 @@ LIBS += base-common
SRC_CC += console/log_console.cc
SRC_CC += cpu/cache.cc
SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc \
SRC_CC += env/env.cc env/stack_area.cc env/reinitialize.cc \
env/cap_map_remove.cc env/cap_alloc.cc
SRC_CC += thread/thread_start.cc
SRC_CC += irq/platform.cc

23
repos/base-foc/src/base/thread/thread_start.cc

@ -19,6 +19,9 @@
#include <base/sleep.h>
#include <base/env.h>
/* base-internal includes */
#include <base/internal/stack.h>
namespace Fiasco {
#include <l4/sys/utcb.h>
}
@ -30,8 +33,8 @@ void Thread_base::_deinit_platform_thread()
{
using namespace Fiasco;
if (_context->utcb && _thread_cap.valid()) {
Cap_index *i = (Cap_index*)l4_utcb_tcr_u(_context->utcb)->user[UTCB_TCR_BADGE];
if (_tid.kcap && _thread_cap.valid()) {
Cap_index *i = (Cap_index*)l4_utcb_tcr_u(utcb()->foc_utcb)->user[UTCB_TCR_BADGE];
cap_map()->remove(i);
_cpu_session->kill_thread(_thread_cap);
env()->rm_session()->remove_client(_pager_cap);
@ -59,7 +62,7 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
return;
}
/* adjust values whose computation differs for a main thread */
_tid = Fiasco::MAIN_THREAD_CAP;
_tid.kcap = Fiasco::MAIN_THREAD_CAP;
_thread_cap = env()->parent()->main_thread_cap();
if (!_thread_cap.valid())
@ -83,15 +86,19 @@ void Thread_base::start()
Thread_state state;
try { state = _cpu_session->state(_thread_cap); }
catch (...) { throw Cpu_session::Thread_creation_failed(); }
_tid = state.kcap;
_context->utcb = state.utcb;
/* remember UTCB of the new thread */
Fiasco::l4_utcb_t * const foc_utcb = (Fiasco::l4_utcb_t *)state.utcb;
utcb()->foc_utcb = foc_utcb;
_tid = Native_thread(state.kcap);
Cap_index *i = cap_map()->insert(state.id, state.kcap);
l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_BADGE] = (unsigned long) i;
l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this;
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_BADGE] = (unsigned long) i;
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this;
/* register initial IP and SP at core */
_cpu_session->start(_thread_cap, (addr_t)_thread_start, _context->stack_top());
_cpu_session->start(_thread_cap, (addr_t)_thread_start, _stack->top());
}

4
repos/base-foc/src/core/cpu_session_extension.cc

@ -43,7 +43,7 @@ void Genode::Cpu_session_component::enable_vcpu(Genode::Thread_capability thread
auto lambda = [&] (Cpu_thread_component *thread) {
if (!thread) return;
Native_thread tid = thread->platform_thread()->thread().local.dst();
l4_cap_idx_t tid = thread->platform_thread()->thread().local.dst();
l4_msgtag_t tag = l4_thread_vcpu_control(tid, vcpu_state);
if (l4_msgtag_has_error(tag))
@ -103,7 +103,7 @@ void Genode::Cpu_session_component::single_step(Genode::Thread_capability thread
auto lambda = [&] (Cpu_thread_component *thread) {
if (!thread) return;
Native_thread tid = thread->platform_thread()->thread().local.dst();
Fiasco::l4_cap_idx_t tid = thread->platform_thread()->thread().local.dst();
enum { THREAD_SINGLE_STEP = 0x40000 };
int flags = enable ? THREAD_SINGLE_STEP : 0;

2
repos/base-foc/src/core/include/irq_object.h

@ -38,7 +38,7 @@ class Genode::Irq_object
Signal_context_capability _sig_cap;
Native_thread _capability() const { return _cap->kcap(); }
Fiasco::l4_cap_idx_t _capability() const { return _cap->kcap(); }
public:

4
repos/base-foc/src/core/include/platform_pd.h

@ -48,8 +48,8 @@ namespace Genode {
addr_t utcb_area_start()
{
return (Native_config::context_area_virtual_base() +
THREAD_MAX * Native_config::context_virtual_size());
return (Native_config::stack_area_virtual_base() +
THREAD_MAX * Native_config::stack_virtual_size());
}
Cap_mapping _task;

4
repos/base-foc/src/core/include/platform_thread.h

@ -42,7 +42,7 @@ namespace Genode {
Cap_mapping _gate;
Cap_mapping _pager;
Cap_mapping _irq;
Native_utcb _utcb;
addr_t _utcb;
char _name[32]; /* thread name that will be
registered at the kernel
debugger */
@ -185,7 +185,7 @@ namespace Genode {
Cap_mapping& gate() { return _gate; }
const char *name() const { return _name; }
bool core_thread() const { return _core_thread; }
Native_utcb utcb() const { return _utcb; }
addr_t utcb() const { return _utcb; }
};
}

6
repos/base-foc/src/core/ipc_pager.cc

@ -106,7 +106,7 @@ void Ipc_pager::reply_and_wait_for_fault()
}
l4_utcb_mr()->mr[1] = _reply_mapping.fpage().raw;
_tag = l4_ipc_send_and_wait(_last, l4_utcb(), snd_tag,
_tag = l4_ipc_send_and_wait(_last.kcap, l4_utcb(), snd_tag,
&label, L4_IPC_SEND_TIMEOUT_0);
int err = l4_ipc_error(_tag, l4_utcb());
if (err) {
@ -119,7 +119,7 @@ void Ipc_pager::reply_and_wait_for_fault()
void Ipc_pager::acknowledge_wakeup()
{
l4_cap_idx_t dst = Fiasco::Capability::valid(_last) ? _last : L4_SYSF_REPLY;
l4_cap_idx_t dst = Fiasco::Capability::valid(_last.kcap) ? _last.kcap : 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);
@ -129,7 +129,7 @@ void Ipc_pager::acknowledge_wakeup()
void Ipc_pager::acknowledge_exception()
{
memcpy(l4_utcb_exc(), &_regs, sizeof(l4_exc_regs_t));
l4_cap_idx_t dst = Fiasco::Capability::valid(_last) ? _last : L4_SYSF_REPLY;
l4_cap_idx_t dst = Fiasco::Capability::valid(_last.kcap) ? _last.kcap : L4_SYSF_REPLY;
l4_ipc_send(dst, l4_utcb(), l4_msgtag(0, L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0), L4_IPC_SEND_TIMEOUT_0);
}

2
repos/base-foc/src/core/irq_session_component.cc

@ -53,7 +53,7 @@ class Genode::Interrupt_handler : public Thread<2048*sizeof(long)>
void entry();
static Native_thread handler_cap()
static Fiasco::l4_cap_idx_t handler_cap()
{
static Interrupt_handler handler;
return handler._thread_cap.dst();

6
repos/base-foc/src/core/pager.cc

@ -69,7 +69,7 @@ void Pager_entrypoint::entry()
PDBG("Could not resolve pf=%p ip=%p",
(void*)_pager.fault_addr(), (void*)_pager.fault_ip());
} else {
_pager.set_reply_dst(obj->badge());
_pager.set_reply_dst(Native_thread(obj->badge()));
reply_pending = true;
return;
}
@ -99,7 +99,7 @@ void Pager_entrypoint::entry()
}
/* send wake up message to requested thread */
_pager.set_reply_dst(obj->badge());
_pager.set_reply_dst(Native_thread(obj->badge()));
_pager.acknowledge_exception();
break;
}
@ -121,7 +121,7 @@ void Pager_entrypoint::entry()
* that case we unblock it immediately.
*/
if (!obj->state.paused) {
_pager.set_reply_dst(obj->badge());
_pager.set_reply_dst(Native_thread(obj->badge()));
reply_pending = true;
}
break;

10
repos/base-foc/src/core/platform.cc

@ -327,8 +327,8 @@ void Platform::_setup_mem_alloc()
}
region.start = addr; region.end = addr + size;
if (!region.intersects(Native_config::context_area_virtual_base(),
Native_config::context_area_virtual_size())) {
if (!region.intersects(Native_config::stack_area_virtual_base(),
Native_config::stack_area_virtual_size())) {
add_region(region, _ram_alloc);
add_region(region, _core_address_ranges());
}
@ -402,9 +402,9 @@ void Platform::_setup_basics()
_vm_start = _vm_start == 0 ? L4_PAGESIZE : _vm_start;
_region_alloc.add_range(_vm_start, _vm_size);
/* preserve context area in core's virtual address space */
_region_alloc.remove_range(Native_config::context_area_virtual_base(),
Native_config::context_area_virtual_size());
/* preserve stack area in core's virtual address space */
_region_alloc.remove_range(Native_config::stack_area_virtual_base(),
Native_config::stack_area_virtual_size());
/* preserve utcb- area in core's virtual address space */
_region_alloc.remove_range((addr_t)l4_utcb(), L4_PAGESIZE * 16);

17
repos/base-foc/src/core/platform_pd.cc

@ -54,16 +54,19 @@ int Platform_pd::bind_thread(Platform_thread *thread)
if (_threads[i])
continue;
_threads[i] = thread;
_threads[i] = thread;
if (thread->core_thread())
thread->_utcb = (l4_utcb_t*) (core_utcb_base() + i * L4_UTCB_OFFSET);
thread->_utcb = (addr_t) (core_utcb_base() + i * L4_UTCB_OFFSET);
else
thread->_utcb =
reinterpret_cast<l4_utcb_t*>(utcb_area_start() + i * L4_UTCB_OFFSET);
Native_thread cap_offset = THREAD_AREA_BASE + i * THREAD_AREA_SLOT;
thread->_gate.remote = cap_offset + THREAD_GATE_CAP;
thread->_pager.remote = cap_offset + THREAD_PAGER_CAP;
thread->_irq.remote = cap_offset + THREAD_IRQ_CAP;
reinterpret_cast<addr_t>(utcb_area_start() + i * L4_UTCB_OFFSET);
Fiasco::l4_cap_idx_t cap_offset = THREAD_AREA_BASE + i * THREAD_AREA_SLOT;
thread->_gate.remote = cap_offset + THREAD_GATE_CAP;
thread->_pager.remote = cap_offset + THREAD_PAGER_CAP;
thread->_irq.remote = cap_offset + THREAD_IRQ_CAP;
/* if it's no core-thread we have to map parent and pager gate cap */
if (!thread->core_thread()) {

2
repos/base-foc/src/core/platform_thread.cc

@ -45,7 +45,7 @@ int Platform_thread::start(void *ip, void *sp)
l4_thread_control_start();
l4_thread_control_pager(_pager.remote);
l4_thread_control_exc_handler(_pager.remote);
l4_thread_control_bind(_utcb, _platform_pd->native_task().dst());
l4_thread_control_bind((l4_utcb_t *)_utcb, _platform_pd->native_task().dst());
l4_msgtag_t tag = l4_thread_control_commit(_thread.local.dst());
if (l4_msgtag_has_error(tag)) {
PWRN("l4_thread_control_commit for %lx failed!",

4
repos/base-foc/src/core/target.inc

@ -5,7 +5,7 @@ GEN_CORE_DIR = $(BASE_DIR)/src/core
LIBS += base-common
SRC_CC += context_area.cc \
SRC_CC += stack_area.cc \
core_printf.cc \
core_rpc_cap_alloc.cc \
cpu_session_component.cc \
@ -45,7 +45,7 @@ INC_DIR += $(REP_DIR)/src/core/include \
include $(GEN_CORE_DIR)/version.inc
vpath context_area.cc $(GEN_CORE_DIR)
vpath stack_area.cc $(GEN_CORE_DIR)
vpath cpu_session_component.cc $(GEN_CORE_DIR)
vpath dataspace_component.cc $(GEN_CORE_DIR)
vpath dump_alloc.cc $(GEN_CORE_DIR)

18
repos/base-foc/src/core/thread_start.cc

@ -16,6 +16,9 @@
#include <base/thread.h>
#include <base/sleep.h>
/* base-internal includes */
#include <base/internal/stack.h>
/* core includes */
#include <platform.h>
#include <core_env.h>
@ -43,19 +46,24 @@ void Thread_base::start()
/* create and start platform thread */
Platform_thread *pt =
new(platform()->core_mem_alloc()) Platform_thread(_context->name);
new(platform()->core_mem_alloc()) Platform_thread(_stack->name().string());
if (platform_specific()->core_pd()->bind_thread(pt))
throw Cpu_session::Thread_creation_failed();
_tid = pt->gate().remote;
l4_utcb_t *foc_utcb = (l4_utcb_t *)(pt->utcb());
_tid = Native_thread(pt->gate().remote);
utcb()->foc_utcb = foc_utcb;
_thread_cap =
reinterpret_cap_cast<Cpu_thread>(Native_capability(pt->thread().local));
pt->pager(platform_specific()->core_pager());
_context->utcb = pt->utcb();
l4_utcb_tcr_u(pt->utcb())->user[UTCB_TCR_BADGE] = (unsigned long) pt->gate().local.idx();
l4_utcb_tcr_u(pt->utcb())->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this;
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_BADGE] = (unsigned long) pt->gate().local.idx();
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this;
pt->start((void *)_thread_start, stack_top());
}

6
repos/base-foc/src/include/base/internal/lock_helper.h

@ -48,7 +48,7 @@ static inline void thread_yield() { Fiasco::l4_thread_yield(); }
static inline bool thread_check_stopped_and_restart(Genode::Thread_base *thread_base)
{
Genode::Native_thread_id tid = thread_base ?
thread_base->tid() :
thread_base->tid().kcap :
Fiasco::MAIN_THREAD_CAP;
Genode::Native_thread_id irq = tid + Fiasco::THREAD_IRQ_CAP;
Fiasco::l4_irq_trigger(irq);
@ -62,7 +62,7 @@ static inline bool thread_check_stopped_and_restart(Genode::Thread_base *thread_
static inline void thread_switch_to(Genode::Thread_base *thread_base)
{
Genode::Native_thread_id tid = thread_base ?
thread_base->tid() :
thread_base->tid().kcap :
Fiasco::MAIN_THREAD_CAP;
Fiasco::l4_thread_switch(tid);
}
@ -82,7 +82,7 @@ static void thread_stop_myself()
Genode::Thread_base *myself = Genode::Thread_base::myself();
Genode::Native_thread_id tid = myself ?
myself->tid() :
myself->tid().kcap :
Fiasco::MAIN_THREAD_CAP;
Genode::Native_thread_id irq = tid + THREAD_IRQ_CAP;
l4_irq_receive(irq, L4_IPC_NEVER);

17
repos/base-hw/include/base/native_types.h

@ -19,6 +19,7 @@
#include <kernel/log.h>
#include <base/native_capability.h>
#include <base/ipc_msgbuf.h>
#include <base/printf.h>
namespace Genode
{
@ -80,17 +81,17 @@ struct Genode::Native_region
struct Genode::Native_config
{
/**
* Thread-context area configuration.
* Stack area configuration
*/
static constexpr addr_t context_area_virtual_base() {
static constexpr addr_t stack_area_virtual_base() {
return 0xe0000000UL; }
static constexpr addr_t context_area_virtual_size() {
static constexpr addr_t stack_area_virtual_size() {
return 0x10000000UL; }
/**
* Size of virtual address region holding the context of one thread
* Size of virtual address region holding the stack of one thread
*/
static constexpr addr_t context_virtual_size() { return 0x00100000UL; }
static constexpr addr_t stack_virtual_size() { return 0x00100000UL; }
};
@ -105,8 +106,8 @@ class Genode::Native_utcb
private:
Kernel::capid_t _caps[MAX_CAP_ARGS]; /* capability buffer */
size_t _cap_cnt = 0; /* capability counter */
size_t _size = 0; /* bytes to transfer */
size_t _cap_cnt; /* capability counter */
size_t _size; /* bytes to transfer */
uint8_t _buf[get_page_size() - sizeof(_caps) -
sizeof(_cap_cnt) - sizeof(_size)];
@ -190,7 +191,7 @@ namespace Genode
/**
* The main thread's UTCB, used during bootstrap of the main thread before it
* allocates its context area, needs to be outside the virtual memory area
* allocates its stack area, needs to be outside the virtual memory area
* controlled by the RM session, because it is needed before the main
* thread can access its RM session.
*/

2
repos/base-hw/lib/mk/base-common.inc

@ -25,7 +25,7 @@ SRC_CC += thread/thread.cc
SRC_CC += thread/myself.cc
SRC_CC += thread/bootstrap.cc
SRC_CC += thread/trace.cc
SRC_CC += thread/context_allocator.cc
SRC_CC += thread/stack_allocator.cc
SRC_CC += kernel/interface.cc
SRC_CC += sleep.cc
SRC_CC += rm_session_client.cc

2
repos/base-hw/lib/mk/base.mk

@ -9,7 +9,7 @@ LIBS += base-common startup
SRC_CC += console/log_console.cc
SRC_CC += cpu/cache.cc
SRC_CC += env/env.cc
SRC_CC += env/context_area.cc
SRC_CC += env/stack_area.cc
SRC_CC += env/reinitialize.cc
SRC_CC += thread/start.cc
SRC_CC += irq/platform.cc

2
repos/base-hw/lib/mk/core.inc

@ -33,7 +33,7 @@ SRC_CC += pd_assign_pci.cc
SRC_CC += platform.cc
SRC_CC += platform_pd.cc
SRC_CC += platform_thread.cc
SRC_CC += context_area.cc
SRC_CC += stack_area.cc
SRC_CC += ram_session_component.cc
SRC_CC += ram_session_support.cc
SRC_CC += rm_session_component.cc

7
repos/base-hw/src/base/thread/bootstrap.cc

@ -17,6 +17,9 @@
#include <base/env.h>
#include <base/sleep.h>
/* base-internal includes */
#include <base/internal/stack.h>
/* base-hw includes */
#include <kernel/interface.h>
@ -57,9 +60,9 @@ void prepare_reinit_main_thread() { prepare_init_main_thread(); }
** Thread_base **
*****************/
Native_utcb * Thread_base::utcb()
Native_utcb *Thread_base::utcb()
{
if (this) { return &_context->utcb; }
if (this) { return &_stack->utcb(); }
return utcb_main_thread();
}

46
repos/base-hw/src/base/thread/start.cc

@ -18,9 +18,12 @@
#include <base/sleep.h>
#include <base/env.h>
/* base-internal includes */
#include <base/internal/stack_allocator.h>
using namespace Genode;
namespace Genode { Rm_session * env_context_area_rm_session(); }
namespace Genode { Rm_session * env_stack_area_rm_session(); }
namespace Hw {
extern Ram_dataspace_capability _main_thread_utcb_ds;
@ -39,18 +42,19 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
/* create server object */
char buf[48];
name(buf, sizeof(buf));
addr_t const utcb = (addr_t)&_context->utcb;
addr_t const utcb = (addr_t)&_stack->utcb();
_thread_cap = _cpu_session->create_thread(weight, buf, utcb);
return;
}
/* if we got reinitialized we have to get rid of the old UTCB */
size_t const utcb_size = sizeof(Native_utcb);
addr_t const context_area = Native_config::context_area_virtual_base();
addr_t const utcb_new = (addr_t)&_context->utcb - context_area;
Rm_session * const rm = env_context_area_rm_session();
size_t const utcb_size = sizeof(Native_utcb);
addr_t const stack_area = Native_config::stack_area_virtual_base();
addr_t const utcb_new = (addr_t)&_stack->utcb() - stack_area;
Rm_session * const rm = env_stack_area_rm_session();
if (type == REINITIALIZED_MAIN) { rm->detach(utcb_new); }
/* remap initial main-thread UTCB according to context-area spec */
/* remap initial main-thread UTCB according to stack-area spec */
try { rm->attach_at(Hw::_main_thread_utcb_ds, utcb_new, utcb_size); }
catch(...) {
PERR("failed to re-map UTCB");
@ -69,12 +73,12 @@ void Thread_base::_deinit_platform_thread()
_cpu_session->kill_thread(_thread_cap);
/* detach userland thread-context */
size_t const size = sizeof(_context->utcb);
addr_t utcb = Context_allocator::addr_to_base(_context) +
Native_config::context_virtual_size() - size -
Native_config::context_area_virtual_base();
env_context_area_rm_session()->detach(utcb);
/* detach userland stack */
size_t const size = sizeof(_stack->utcb());
addr_t utcb = Stack_allocator::addr_to_base(_stack) +
Native_config::stack_virtual_size() - size -
Native_config::stack_area_virtual_base();
env_stack_area_rm_session()->detach(utcb);
if (_pager_cap.valid()) {
env()->rm_session()->remove_client(_pager_cap);
@ -91,20 +95,20 @@ void Thread_base::start()
_pager_cap = env()->rm_session()->add_client(_thread_cap);
_cpu_session->set_pager(_thread_cap, _pager_cap);
/* attach userland thread-context */
/* attach userland stack */
try {
Ram_dataspace_capability ds = _cpu_session->utcb(_thread_cap);
size_t const size = sizeof(_context->utcb);
addr_t dst = Context_allocator::addr_to_base(_context) +
Native_config::context_virtual_size() - size -
Native_config::context_area_virtual_base();
env_context_area_rm_session()->attach_at(ds, dst, size);
size_t const size = sizeof(_stack->utcb());
addr_t dst = Stack_allocator::addr_to_base(_stack) +
Native_config::stack_virtual_size() - size -
Native_config::stack_area_virtual_base();
env_stack_area_rm_session()->attach_at(ds, dst, size);
} catch (...) {
PERR("failed to attach userland thread-context");
PERR("failed to attach userland stack");
sleep_forever();
}
/* start thread with its initial IP and aligned SP */
_cpu_session->start(_thread_cap, (addr_t)_thread_start, _context->stack_top());
_cpu_session->start(_thread_cap, (addr_t)_thread_start, _stack->top());
}

2
repos/base-hw/src/core/include/platform_thread.h

@ -95,7 +95,7 @@ namespace Genode {
* \param quota CPU quota that shall be granted to the thread
* \param label debugging label
* \param virt_prio unscaled processor-scheduling priority
* \param utcb core local pointer to userland thread-context
* \param utcb core local pointer to userland stack
*/
Platform_thread(size_t const quota, const char * const label,
unsigned const virt_prio, addr_t const utcb);

4
repos/base-hw/src/core/platform.cc

@ -138,8 +138,8 @@ Platform::Platform()
/* preserve stack area in core's virtual address space */
_core_mem_alloc.virt_alloc()->remove_range(
Native_config::context_area_virtual_base(),
Native_config::context_area_virtual_size());
Native_config::stack_area_virtual_base(),
Native_config::stack_area_virtual_size());
_init_io_port_alloc();

16
repos/base-hw/src/core/thread_start.cc

@ -17,6 +17,9 @@
#include <base/sleep.h>
#include <base/env.h>
/* base-internal stack */
#include <base/internal/stack.h>
/* core includes */
#include <map_local.h>
#include <kernel/kernel.h>
@ -25,11 +28,10 @@
using namespace Genode;
namespace Genode { Rm_session * env_context_area_rm_session(); }
namespace Genode { Rm_session *env_stack_area_rm_session(); }
namespace Hw { extern Untyped_capability _main_thread_cap; }
namespace Hw {
extern Untyped_capability _main_thread_cap;
}
void Thread_base::start()
{
@ -56,13 +58,13 @@ void Thread_base::_init_platform_thread(size_t, Type type)
{
if (type == NORMAL) {
_tid.platform_thread = new (platform()->core_mem_alloc())
Platform_thread(_context->name, &_context->utcb);
Platform_thread(_stack->name().string(), &_stack->utcb());
return;
}
/* remap initial main-thread UTCB according to context-area spec */
/* remap initial main-thread UTCB according to stack-area spec */
Genode::map_local((addr_t)Kernel::Core_thread::singleton().utcb(),
(addr_t)&_context->utcb,
(addr_t)&_stack->utcb(),
max(sizeof(Native_utcb) / get_page_size(), (size_t)1));
/* adjust initial object state in case of a main thread */

16
repos/base-linux/include/base/native_types.h

@ -26,7 +26,7 @@
* Genode from POSIX.
*/
extern Genode::addr_t _context_area_start;
extern Genode::addr_t _stack_area_start;
namespace Genode {
@ -128,21 +128,21 @@ namespace Genode {
struct Native_config
{
/**
* Thread-context area configuration.
* Stack area configuration
*
* Please update platform-specific files after changing these
* functions, e.g., 'base-linux/src/ld/context_area.*.ld'.
* functions, e.g., 'base-linux/src/ld/stack_area.*.ld'.
*/
static addr_t context_area_virtual_base() {
return align_addr((addr_t)&_context_area_start, 20); }
static addr_t stack_area_virtual_base() {
return align_addr((addr_t)&_stack_area_start, 20); }
static constexpr addr_t context_area_virtual_size() {
static constexpr addr_t stack_area_virtual_size() {
return 0x10000000UL; }
/**
* Size of virtual address region holding the context of one thread
* Size of virtual address region holding the stack of one thread
*/
static constexpr addr_t context_virtual_size() { return 0x00100000UL; }
static constexpr addr_t stack_virtual_size() { return 0x00100000UL; }
};
class Native_pd_args

2
repos/base-linux/lib/mk/base-common.mk

@ -19,7 +19,7 @@ SRC_CC += lock/lock.cc
SRC_CC += env/rm_session_mmap.cc env/debug.cc
SRC_CC += signal/signal.cc signal/common.cc signal/platform.cc
SRC_CC += server/server.cc server/common.cc
SRC_CC += thread/trace.cc thread/thread_env.cc thread/context_allocator.cc
SRC_CC += thread/trace.cc thread/thread_env.cc thread/stack_allocator.cc
SRC_CC += irq/platform.cc
SRC_CC += sleep.cc
SRC_CC += rm_session_client.cc

2
repos/base-linux/lib/mk/base.inc

@ -10,7 +10,7 @@
LIBS += base-common syscall cxx
SRC_CC += console/log_console.cc
SRC_CC += env/env.cc env/platform_env.cc env/context_area.cc
SRC_CC += env/env.cc env/platform_env.cc env/stack_area.cc
SRC_CC += server/rpc_cap_alloc.cc
INC_DIR += $(REP_DIR)/src/include $(BASE_DIR)/src/include

4
repos/base-linux/mk/spec/linux.mk

@ -4,13 +4,13 @@
#
# Startup code to be used when building a program and linker script that is
# specific for Linux. We also reserve the thread-context area via a segment in
# specific for Linux. We also reserve the stack area via a segment in
# the program under Linux to prevent clashes with vdso.
#
ifneq ($(USE_HOST_LD_SCRIPT),yes)
LD_TEXT_ADDR ?= 0x01000000
LD_SCRIPT_STATIC = $(call select_from_repositories,src/ld/genode.ld) \
$(call select_from_repositories,src/ld/context_area.nostdlib.ld)
$(call select_from_repositories,src/ld/stack_area.nostdlib.ld)
else
LD_SCRIPT_STATIC ?=
endif

2
repos/base-linux/mk/spec/linux_arm.mk

@ -10,7 +10,7 @@ endif
#
# We need to manually add the default linker script on the command line in case
# of standard library use. Otherwise, we were not able to extend it by the
# context area section.
# stack area section.
#
ifeq ($(USE_HOST_LD_SCRIPT),yes)
LD_SCRIPT_STATIC = ldscripts/armelf_linux_eabi.xc

2
repos/base-linux/mk/spec/linux_x86_32.mk

@ -6,7 +6,7 @@ SPECS += linux x86_32
#
# We need to manually add the default linker script on the command line in case
# of standard library use. Otherwise, we were not able to extend it by the
# context area section.
# stack area section.
#
ifeq ($(USE_HOST_LD_SCRIPT),yes)
LD_SCRIPT_DEFAULT = ldscripts/elf_i386.xc

2
repos/base-linux/mk/spec/linux_x86_64.mk

@ -6,7 +6,7 @@ SPECS += linux x86_64
#
# We need to manually add the default linker script on the command line in case
# of standard library use. Otherwise, we were not able to extend it by the
# context area section.
# stack area section.
#
ifeq ($(USE_HOST_LD_SCRIPT),yes)
LD_SCRIPT_DEFAULT = ldscripts/elf_x86_64.xc

20
repos/base-linux/src/base/env/rm_session_mmap.cc vendored

@ -8,7 +8,7 @@
* dataspaces and 2) get the kernel to manage VM regions as we intent.
*
* The kernel sets up mappings for the binary on execve(), which are text and
* data segments, the context area and special regions (stack, vdso, vsyscall).
* data segments, the stack area and special regions (stack, vdso, vsyscall).
* Later mappings are done by the Genode program itself, which knows nothing
* about these initial mappings. Therefore, most mmap() operations are _soft_
* to detect region conflicts with existing mappings or let the kernel find
@ -17,10 +17,10 @@
* but not populated dataspaces are "holes" in the Linux VM space represented
* by PROT_NONE mappings (see _reserve_local()).
*
* The context area is a managed dataspace as on other platforms, which is
* The stack area is a managed dataspace as on other platforms, which is
* created and attached during program launch. The managed dataspace replaces
* the inital reserved area, which is therefore flushed beforehand. Hybrid
* programs have no context area.
* programs have no stack area.
*
* Note, we do not support nesting of managed dataspaces.
*/
@ -40,7 +40,7 @@
/* base-internal includes */
#include <base/internal/local_capability.h>
#include <base/internal/platform_env.h>
#include <base/internal/context_area.h>
#include <base/internal/stack_area.h>
using namespace Genode;
@ -58,13 +58,13 @@ addr_t Platform_env_base::Rm_session_mmap::_reserve_local(bool use_loc
addr_t local_addr,
Genode::size_t size)
{
/* special handling for context area */
/* special handling for stack area */
if (use_local_addr
&& local_addr == Native_config::context_area_virtual_base()
&& size == Native_config::context_area_virtual_size()) {
&& local_addr == Native_config::stack_area_virtual_base()
&& size == Native_config::stack_area_virtual_size()) {
/*
* On the first request to reserve the context area, we flush the
* On the first request to reserve the stack area, we flush the
* initial mapping preserved in linker script and apply the actual
* reservation. Subsequent requests are just ignored.
*/
@ -73,8 +73,8 @@ addr_t Platform_env_base::Rm_session_mmap::_reserve_local(bool use_loc
{
Context()
{
flush_context_area();
reserve_context_area();
flush_stack_area();
reserve_stack_area();
}
} inst;

5
repos/base-linux/src/base/thread/thread_linux.cc

@ -19,6 +19,9 @@
#include <base/sleep.h>
#include <linux_cpu_session/linux_cpu_session.h>
/* base-internal includes */
#include <base/internal/stack.h>
/* Linux syscall bindings */
#include <linux_syscalls.h>
@ -77,7 +80,7 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
/* for normal threads create an object at the CPU session */
if (type == NORMAL) {
_thread_cap = _cpu_session->create_thread(weight, _context->name);
_thread_cap = _cpu_session->create_thread(weight, _stack->name().string());
return;
}
/* adjust initial object state for main threads */

1
repos/base-linux/src/core/include/core_env.h

@ -28,7 +28,6 @@
/* base-internal includes */
#include <base/internal/platform_env.h>
namespace Genode {
/**