Handing over alignment paramenter of morecore when spanning
authorReto Achermann <reto.achermann@inf.ethz.ch>
Thu, 19 Feb 2015 09:32:28 +0000 (10:32 +0100)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Mon, 4 May 2015 13:54:22 +0000 (15:54 +0200)
Spanning domains resulted in a NULL-pointer dereferencing
in when initializing libbarrelfish and parsing arguments
for the morecore alignment. Added new parameter to pass
the alignment of the spanning domain to the new dispatcher
on the remote core.

Signed-off-by: Reto Achermann <reto.achermann@inf.ethz.ch>

include/barrelfish_kpi/domain_params.h
lib/barrelfish/domain.c
lib/barrelfish/init.c

index 4e942d6..777cc3a 100644 (file)
@@ -24,6 +24,7 @@ struct spawn_domain_params {
     void *tls_init_base;        ///< Address of initialised TLS data block
     size_t tls_init_len;        ///< Length of initialised TLS data block
     size_t tls_total_len;       ///< Total (initialised + BSS) TLS data length
+    size_t pagesize;            ///< the page size to be used (domain spanning)
 };
 
 #endif // SPAWN_DOMAIN_PARAMS_H
index 7793195..befb510 100644 (file)
@@ -24,6 +24,7 @@
 #include <barrelfish/curdispatcher_arch.h>
 #include <barrelfish/dispatcher_arch.h>
 #include <barrelfish/waitset_chan.h>
+#include <barrelfish_kpi/domain_params.h>
 #include <arch/registers.h>
 #include <barrelfish/dispatch.h>
 #include <if/interdisp_defs.h>
@@ -51,6 +52,7 @@ struct remote_core_state {
     struct span_domain_state *span_domain_state; ///< Reference to the span_domain_state of the "server"
     bool initialized;             ///< true if remote core is fully initialized
     int cnt;                      ///< Used to count dispatcher connected
+    size_t pagesize;              ///< the pagesize to be used for the heap
 };
 
 ///< Struct for spanning domains state machine
@@ -461,8 +463,13 @@ static int remote_core_init_enabled(void *arg)
     struct remote_core_state *remote_core_state =
         (struct remote_core_state*)arg;
 
+    /* construct a temporary spawn param to supply the morecore alignment */
+    struct spawn_domain_params params;
+    memset(&params, 0, sizeof(params));
+    params.pagesize =  remote_core_state->pagesize;
+
     /* Initialize the barrelfish library */
-    err = barrelfish_init_onthread(NULL);
+    err = barrelfish_init_onthread(&params);
     if (err_is_fail(err)) {
         DEBUG_ERR(err, "barrelfish_init_onthread failed");
         abort();
@@ -649,6 +656,10 @@ static errval_t domain_new_dispatcher_varstack(coreid_t core_id,
     remote_core_state->core_id = disp_get_core_id();
     remote_core_state->iref    = domain_state->iref;
 
+    /* get the alignment of the morecore state */
+    struct morecore_state *state = get_morecore_state();
+    remote_core_state->pagesize = state->mmu_state.alignment;
+
     /* Create the thread for the new dispatcher to init on */
     struct thread *newthread =
         thread_create_unrunnable(remote_core_init_enabled,
index a3303c6..0072656 100644 (file)
@@ -151,6 +151,7 @@ static bool request_done = false;
 
 static bool parse_argv(struct spawn_domain_params *params, size_t *morecore_alignment)
 {
+    assert(params);
     // grab pagesize config from argv if available
     size_t morecore_pagesize = MORECORE_PAGESIZE;
     int i = 1;
@@ -243,11 +244,23 @@ errval_t barrelfish_init_onthread(struct spawn_domain_params *params)
         // in the base cn.
         err = morecore_init(BASE_PAGE_SIZE);
     } else {
+        /* if there is a pagesize supplied, use this one */
         size_t morecore_pagesize = 0;
-        parse_argv(params, &morecore_pagesize);
+        if (params != NULL && params->pagesize) {
+            morecore_pagesize =  params->pagesize;
+
+            assert(morecore_pagesize == BASE_PAGE_SIZE
+#ifdef __x86_64__
+                   || morecore_pagesize == HUGE_PAGE_SIZE
+#endif
+                   || morecore_pagesize == LARGE_PAGE_SIZE );
+
+        } else {
+            parse_argv(params, &morecore_pagesize);
 #if defined(__i386__) && !defined(CONFIG_PSE)
-        morecore_pagesize = BASE_PAGE_SIZE;
+            morecore_pagesize = BASE_PAGE_SIZE;
 #endif
+        }
         err = morecore_init(morecore_pagesize);
     }
     if (err_is_fail(err)) {