From df3c0d47861adc9b0afb49c174cb9f5ceed312bf Mon Sep 17 00:00:00 2001
From: Alexander Boettcher <alexander.boettcher@genode-labs.com>
Date: Mon, 3 Dec 2012 13:02:34 +0100
Subject: [PATCH] base: throw exception if thread creation failed

Sanity check that the context area has been attached. Otherwise the code
later tries to access the context area and core dies with a unhandled page
fault.
---
 base/src/base/thread/thread.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/base/src/base/thread/thread.cc b/base/src/base/thread/thread.cc
index 89b77cfff3..5449f599f3 100644
--- a/base/src/base/thread/thread.cc
+++ b/base/src/base/thread/thread.cc
@@ -142,7 +142,8 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
 	try {
 		ds_cap = env_context_area_ram_session()->alloc(ds_size);
 		addr_t attach_addr = ds_addr - Native_config::context_area_virtual_base();
-		env_context_area_rm_session()->attach_at(ds_cap, attach_addr, ds_size);
+		if (attach_addr != (addr_t)env_context_area_rm_session()->attach_at(ds_cap, attach_addr, ds_size))
+			throw Stack_alloc_failed(); 
 	}
 	catch (Ram_session::Alloc_failed) { throw Stack_alloc_failed(); }