Index: libcfa/src/concurrency/kernel/startup.cfa
===================================================================
--- libcfa/src/concurrency/kernel/startup.cfa	(revision fe9468e277ef63e8b357a912be5295032d77be2c)
+++ libcfa/src/concurrency/kernel/startup.cfa	(revision bfcf6b93d595af7bc5fcb05405720c63f503db8f)
@@ -29,4 +29,5 @@
 #include "kernel_private.hfa"
 #include "startup.hfa"          // STARTUP_PRIORITY_XXX
+#include "math.hfa"
 
 //-----------------------------------------------------------------------------
@@ -539,4 +540,5 @@
 }
 
+extern size_t __page_size;
 void ^?{}(processor & this) with( this ){
 	if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
@@ -550,8 +552,5 @@
 	}
 
-	int err = pthread_join( kernel_thread, 0p );
-	if( err != 0 ) abort("KERNEL ERROR: joining processor %p caused error %s\n", &this, strerror(err));
-
-	free( this.stack );
+	__destroy_pthread( kernel_thread, this.stack, 0p );
 
 	disable_interrupts();
@@ -678,14 +677,23 @@
 
 	void * stack;
-	__cfaabi_dbg_debug_do(
-		stack = memalign( __page_size, stacksize + __page_size );
-		// pthread has no mechanism to create the guard page in user supplied stack.
-		if ( mprotect( stack, __page_size, PROT_NONE ) == -1 ) {
-			abort( "mprotect : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) );
-		} // if
-	);
-	__cfaabi_dbg_no_debug_do(
-		stack = malloc( stacksize );
-	);
+	#warning due to the thunk problem, stack creation uses mmap, revert to malloc once this goes away
+	// __cfaabi_dbg_debug_do(
+	// 	stack = memalign( __page_size, stacksize + __page_size );
+	// 	// pthread has no mechanism to create the guard page in user supplied stack.
+	// 	if ( mprotect( stack, __page_size, PROT_NONE ) == -1 ) {
+	// 		abort( "mprotect : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) );
+	// 	} // if
+	// );
+	// __cfaabi_dbg_no_debug_do(
+	// 	stack = malloc( stacksize );
+	// );
+	stacksize = ceiling( stacksize, __page_size ) + __page_size;
+	stack = mmap(0p, stacksize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if(stack == ((void*)-1)) {
+		abort( "pthread stack creation : internal error, mmap failure, error(%d) %s.", errno, strerror( errno ) );
+	}
+	if ( mprotect( stack, __page_size, PROT_NONE ) == -1 ) {
+		abort( "pthread stack creation : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) );
+	} // if
 
 	check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
@@ -694,4 +702,24 @@
 	return stack;
 }
+
+void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) {
+	int err = pthread_join( pthread, retval );
+	if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err));
+
+	pthread_attr_t attr;
+
+	check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
+
+	size_t stacksize;
+	// default stack size, normally defined by shell limit
+	check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
+	assert( stacksize >= PTHREAD_STACK_MIN );
+	stacksize += __page_size;
+
+	if(munmap(stack, stacksize) == -1) {
+		abort( "pthread stack destruction : internal error, munmap failure, error(%d) %s.", errno, strerror( errno ) );
+	}
+}
+
 
 #if defined(__CFA_WITH_VERIFY__)
