From 17b60f8d412689b4a5d5e252f5313ca0f37488bd Mon Sep 17 00:00:00 2001
From: Norman Feske <norman.feske@genode-labs.com>
Date: Wed, 6 Jun 2012 17:30:06 +0200
Subject: [PATCH] Propagate loader-session errors as exceptions

---
 os/include/loader_session/loader_session.h | 14 +++++++++++---
 os/src/server/loader/child.h               | 11 ++++++++---
 os/src/server/loader/main.cc               | 12 ++++++++----
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/os/include/loader_session/loader_session.h b/os/include/loader_session/loader_session.h
index 418ea6f0d9..9d91352de5 100644
--- a/os/include/loader_session/loader_session.h
+++ b/os/include/loader_session/loader_session.h
@@ -108,6 +108,9 @@ namespace Loader {
 
 		/**
 		 * Start subsystem
+		 *
+		 * \throw Rom_module_does_not_exist  if the specified binary could
+		 *                                   not obtained as ROM module
 		 */
 		virtual void start(Name const &binary, Name const &label = "") = 0;
 
@@ -132,12 +135,17 @@ namespace Loader {
 
 		GENODE_RPC(Rpc_alloc_rom_module, Dataspace_capability, alloc_rom_module,
 		                                 Name const &, size_t);
-		GENODE_RPC(Rpc_commit_rom_module, void, commit_rom_module, Name const &);
+		GENODE_RPC_THROW(Rpc_commit_rom_module, void, commit_rom_module,
+		                 GENODE_TYPE_LIST(Rom_module_does_not_exist),
+		                 Name const &);
 		GENODE_RPC(Rpc_ram_quota, void, ram_quota, size_t);
 		GENODE_RPC(Rpc_constrain_geometry, void, constrain_geometry, int, int);
 		GENODE_RPC(Rpc_view_ready_sigh, void, view_ready_sigh, Signal_context_capability);
-		GENODE_RPC(Rpc_start, void, start, Name const &, Name const &);
-		GENODE_RPC(Rpc_view, Nitpicker::View_capability, view);
+		GENODE_RPC_THROW(Rpc_start, void, start,
+		                 GENODE_TYPE_LIST(Rom_module_does_not_exist),
+		                 Name const &, Name const &);
+		GENODE_RPC_THROW(Rpc_view, Nitpicker::View_capability, view,
+		                 GENODE_TYPE_LIST(View_does_not_exist));
 		GENODE_RPC(Rpc_view_geometry, View_geometry, view_geometry);
 
 		GENODE_RPC_INTERFACE(Rpc_alloc_rom_module, Rpc_commit_rom_module,
diff --git a/os/src/server/loader/child.h b/os/src/server/loader/child.h
index d1602add2f..a3c8db88ff 100644
--- a/os/src/server/loader/child.h
+++ b/os/src/server/loader/child.h
@@ -79,9 +79,14 @@ namespace Loader {
 
 			Rom_session_capability _rom_session(char const *name)
 			{
-				char args[Session::Name::MAX_SIZE];
-				snprintf(args, sizeof(args), "ram_quota=4K, filename=\"%s\"", name);
-				return static_cap_cast<Rom_session>(_local_rom_service.session(args));
+				try {
+					char args[Session::Name::MAX_SIZE];
+					snprintf(args, sizeof(args), "ram_quota=4K, filename=\"%s\"", name);
+					return static_cap_cast<Rom_session>(_local_rom_service.session(args));
+				} catch (Genode::Parent::Service_denied) {
+					PERR("Lookup for ROM module \"%s\" failed", name);
+					throw;
+				}
 			}
 
 		public:
diff --git a/os/src/server/loader/main.cc b/os/src/server/loader/main.cc
index 81e3945b8d..2533d5ca82 100644
--- a/os/src/server/loader/main.cc
+++ b/os/src/server/loader/main.cc
@@ -255,10 +255,14 @@ namespace Loader {
 				                         min(_subsystem_ram_quota_limit, _ram_session_client.avail()) :
 				                         _ram_session_client.avail();
 
-				_child = new (&_md_alloc)
-					Child(binary_name.string(), label.string(), _ep,
-					      _ram_session_client, ram_quota, _parent_services,
-					      _rom_service, _nitpicker_service, _width, _height);
+				try {
+					_child = new (&_md_alloc)
+						Child(binary_name.string(), label.string(), _ep,
+						      _ram_session_client, ram_quota, _parent_services,
+						      _rom_service, _nitpicker_service, _width, _height);
+				}
+				catch (Genode::Parent::Service_denied) {
+					throw Rom_module_does_not_exist(); }
 			}
 
 			Nitpicker::View_capability view()