Problem with setting up namespaces

Johannes Schlatow schlatow at ida.ing.tu-bs.de
Wed Jul 17 22:08:14 CEST 2013


Hi,

I was just trying to set up a simple application that uses L4Re namespaces.
I therefore took the clntsrv example and modified it as shown in the diff below with
the result that the server blocks on the bind_thread() call. Am I missing something?

Cheers
 Johannes

diff --git a/src/l4/pkg/examples/clntsrv/clntsrv.cfg b/src/l4/pkg/examples/clntsrv/clntsrv.cfg
index bb2ae50..dd7dfa5 100644
--- a/src/l4/pkg/examples/clntsrv/clntsrv.cfg
+++ b/src/l4/pkg/examples/clntsrv/clntsrv.cfg
@@ -9,13 +9,16 @@ local ld = L4.default_loader;
 -- Channel for the two programs to talk to each other.
 local calc_server = ld:new_channel();
 
+local server_ns   = ld:create_namespace({ calc_server = calc_server:svr()});
+local client_ns   = ld:create_namespace({ calc_server = calc_server});
+
 -- The server program, getting the channel in server mode.
-ld:start({ caps = { calc_server = calc_server:svr() },
+ld:start({ caps = { namespace = server_ns },
            log = { "server", "blue" } },
 	 "rom/ex_clntsrv-server");
 
 -- The client program, getting the 'calc_server' channel to be able to talk
 -- to the server. The client will be started with a green log output.
-ld:start({ caps = { calc_server = calc_server },
+ld:start({ caps = { namespace = client_ns },
            log = { "client", "green" } },
          "rom/ex_clntsrv-client");
diff --git a/src/l4/pkg/examples/clntsrv/server.cc b/src/l4/pkg/examples/clntsrv/server.cc
index 2f2e3fc..9c4c0b9 100644
--- a/src/l4/pkg/examples/clntsrv/server.cc
+++ b/src/l4/pkg/examples/clntsrv/server.cc
@@ -12,6 +12,7 @@
 #include <l4/re/util/cap_alloc>
 #include <l4/re/util/object_registry>
 #include <l4/cxx/ipc_server>
+#include <l4/re/namespace>
 
 #include "shared.h"
 
@@ -60,12 +61,34 @@ main()
 {
   static Calculation_server calc;
 
-  // Register calculation server
-  if (!server.registry()->register_obj(&calc, "calc_server").is_valid())
-    {
-      printf("Could not register my service, is there a 'calc_server' in the caps table?\n");
-      return 1;
-    }
+  L4::Cap<L4Re::Namespace> ns = L4Re::Env::env()->get_cap<L4Re::Namespace>("namespace");
+  if (!ns.is_valid()) {
+    printf("Could not get namespace cap from cap table.\n");
+    return 1;
+  }
+  L4::Cap<L4::Ipc_gate> calc_server = L4Re::Util::cap_alloc.alloc<L4::Ipc_gate>();
+
+  if (ns->query("calc_server", calc_server) != 0) {
+    printf("Could not get 'calc_server' cap from namespace\n");
+    return 1;
+  }
+
+  if (!calc_server.is_valid()) {
+    printf("calc_server cap is invalid\n");
+    return 1;
+  }
+
+  l4_umword_t id = l4_umword_t(0xcaffee);
+  L4::Cap<L4::Thread> tcap = L4Re::Env::env()->main_thread();
+
+  printf("bind_thread()...\n");
+  int err = l4_error(calc_server->bind_thread(tcap, id));
+  if (err < 0) {
+    printf("failed\n");
+    return 1;
+  }
+
+  printf("OK\n");
 
   printf("Welcome to the calculation server!\n"
          "I can do substractions and negations.\n");




More information about the l4-hackers mailing list