From 04106920c30937f389ac47a48fe93f883ec7cc7a Mon Sep 17 00:00:00 2001
From: Adrian Danis <Adrian.Danis@nicta.com.au>
Date: Fri, 17 Oct 2014 15:51:52 +1100
Subject: [PATCH] Derive a new IPC buffer cap when inserting into the initial
 threads TCB to remove mapping information

For any other thread setting the IPC buffer via TCB_Configure will result
in a derived capability being installed that does not have mapping information.
This leads to a expected behaviour that setting a new IPC buffer (even if it is
the same as the current one), will not perform an unmapping.
---
 src/kernel/boot.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/kernel/boot.c b/src/kernel/boot.c
index 549e8a22a..a7700c8f5 100644
--- a/src/kernel/boot.c
+++ b/src/kernel/boot.c
@@ -370,6 +370,7 @@ create_initial_thread(
     pptr_t pptr;
     cap_t  cap;
     tcb_t* tcb;
+    deriveCap_ret_t dc_ret;
 
     /* allocate TCB */
     pptr = alloc_region(TCB_BLOCK_SIZE_BITS);
@@ -382,6 +383,13 @@ create_initial_thread(
     tcb->tcbTimeSlice = CONFIG_TIME_SLICE;
     Arch_initContext(&tcb->tcbContext);
 
+    /* derive a copy of the IPC buffer cap for inserting */
+    dc_ret = deriveCap(SLOT_PTR(pptr_of_cap(root_cnode_cap), BI_CAP_IT_IPCBUF), ipcbuf_cap);
+    if (dc_ret.status != EXCEPTION_NONE) {
+        printf("Failed to derive copy of IPC Buffer\n");
+        return false;
+    }
+
     /* initialise TCB (corresponds directly to abstract specification) */
     cteInsert(
         root_cnode_cap,
@@ -394,7 +402,7 @@ create_initial_thread(
         SLOT_PTR(pptr, tcbVTable)
     );
     cteInsert(
-        ipcbuf_cap,
+        dc_ret.cap,
         SLOT_PTR(pptr_of_cap(root_cnode_cap), BI_CAP_IT_IPCBUF),
         SLOT_PTR(pptr, tcbBuffer)
     );
-- 
GitLab