Index: kernel/generic/src/ddi/ddi.c
===================================================================
--- kernel/generic/src/ddi/ddi.c	(revision deaa22f01020fc8d432df92b990024d02d453083)
+++ kernel/generic/src/ddi/ddi.c	(revision 8b4be29e60da1d7e6355cb2b0bf8ae7e3c561965)
@@ -130,7 +130,9 @@
 	t = task_find_by_id(id);
 	
-	if (!t) {
+	if ((!t) || (!context_check(CONTEXT, t->context))) {
 		/*
-		 * There is no task with the specified ID.
+		 * There is no task with the specified ID
+		 * or the task belongs to a different security
+		 * context.
 		 */
 		spinlock_unlock(&tasks_lock);
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision deaa22f01020fc8d432df92b990024d02d453083)
+++ kernel/generic/src/proc/task.c	(revision 8b4be29e60da1d7e6355cb2b0bf8ae7e3c561965)
@@ -116,5 +116,5 @@
 	ta->main_thread = NULL;
 	ta->refcount = 0;
-	ta->context = THE->context;
+	ta->context = CONTEXT;
 
 	ta->capabilities = 0;
@@ -122,7 +122,7 @@
 	
 	ipc_answerbox_init(&ta->answerbox);
-	for (i=0; i < IPC_MAX_PHONES;i++)
+	for (i = 0; i < IPC_MAX_PHONES; i++)
 		ipc_phone_init(&ta->phones[i]);
-	if (ipc_phone_0)
+	if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context, ta->context)))
 		ipc_phone_connect(&ta->phones[0], ipc_phone_0);
 	atomic_set(&ta->active_calls, 0);
Index: kernel/generic/src/proc/the.c
===================================================================
--- kernel/generic/src/proc/the.c	(revision deaa22f01020fc8d432df92b990024d02d453083)
+++ kernel/generic/src/proc/the.c	(revision 8b4be29e60da1d7e6355cb2b0bf8ae7e3c561965)
@@ -59,5 +59,4 @@
 	the->task = NULL;
 	the->as = NULL;
-	the->context = 0;
 }
 
Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision deaa22f01020fc8d432df92b990024d02d453083)
+++ kernel/generic/src/proc/thread.c	(revision 8b4be29e60da1d7e6355cb2b0bf8ae7e3c561965)
@@ -319,5 +319,4 @@
 	memcpy(t->name, name, THREAD_NAME_BUFLEN);
 	
-	t->context = THE->context;
 	t->thread_code = func;
 	t->thread_arg = arg;
@@ -535,6 +534,6 @@
 		
 			t = (thread_t *) node->value[i];
-			printf("%s: address=%#zx, tid=%zd, context=%ld, state=%s, task=%#zx, code=%#zx, stack=%#zx, cpu=",
-				t->name, t, t->tid, t->context, thread_states[t->state], t->task, t->thread_code, t->kstack);
+			printf("%s: address=%#zx, tid=%zd, state=%s, task=%#zx, context=%ld, code=%#zx, stack=%#zx, cpu=",
+				t->name, t, t->tid, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack);
 			if (t->cpu)
 				printf("cpu%zd", t->cpu->id);
Index: kernel/generic/src/security/cap.c
===================================================================
--- kernel/generic/src/security/cap.c	(revision deaa22f01020fc8d432df92b990024d02d453083)
+++ kernel/generic/src/security/cap.c	(revision 8b4be29e60da1d7e6355cb2b0bf8ae7e3c561965)
@@ -112,5 +112,5 @@
 	spinlock_lock(&tasks_lock);
 	t = task_find_by_id((task_id_t) taskid_arg.value);
-	if (!t) {
+	if ((!t) || (!context_check(CONTEXT, t->context))) {
 		spinlock_unlock(&tasks_lock);
 		interrupts_restore(ipl);
@@ -123,7 +123,4 @@
 	
 	spinlock_unlock(&tasks_lock);
-	
-
-	
 	interrupts_restore(ipl);	
 	return 0;
@@ -154,5 +151,5 @@
 	spinlock_lock(&tasks_lock);	
 	t = task_find_by_id((task_id_t) taskid_arg.value);
-	if (!t) {
+	if ((!t) || (!context_check(CONTEXT, t->context))) {
 		spinlock_unlock(&tasks_lock);
 		interrupts_restore(ipl);
