base-linux: implement IPC server destruction

When an IPC server is finalized two important things should happen:
First, the association of the server socket with a capability must be
invalidated. And finally, the server socket pair (server side and client
side) must be closed.

Related to #38.
This commit is contained in:
Christian Helmuth 2012-11-15 12:53:32 +01:00
parent d23ee02e9a
commit 2995011b34
3 changed files with 56 additions and 15 deletions

View File

@ -14,9 +14,11 @@
#include <util/arg_string.h>
#include <base/platform_env.h>
#include <base/thread.h>
#include <linux_syscalls.h>
using namespace Genode;
/********************************
** Platform_env::Local_parent **
********************************/
@ -124,4 +126,11 @@ namespace Genode {
}
return ncs;
}
void destroy_server_socket_pair(Native_connection_state const &ncs)
{
/* close local file descriptor if it is valid */
if (ncs.server_sd != -1) lx_close(ncs.server_sd);
if (ncs.client_sd != -1) lx_close(ncs.client_sd);
}
}

View File

@ -46,6 +46,28 @@
using namespace Genode;
namespace Genode {
/*
* Helper for obtaining a bound and connected socket pair
*
* For core, the implementation is just a wrapper around
* 'lx_server_socket_pair()'. For all other processes, the implementation
* requests the socket pair from the Env::CPU session interface using a
* Linux-specific interface extension.
*/
Native_connection_state server_socket_pair();
/*
* Helper to destroy the server socket pair
*
* For core, this is a no-op. For all other processes, the server and client
* sockets are closed.
*/
void destroy_server_socket_pair(Native_connection_state const &ncs);
}
/******************************
** File-descriptor registry **
******************************/
@ -390,7 +412,20 @@ Ipc_istream::Ipc_istream(Msgbuf_base *rcv_msg)
{ }
Ipc_istream::~Ipc_istream() { }
Ipc_istream::~Ipc_istream()
{
/*
* The association of the capability (client) socket must be invalidated on
* server destruction. We implement it here as the IPC server currently has
* no destructor. We have the plan to remove Ipc_istream and Ipc_ostream
* in the future and, then, move this into the server destructor.
*
* IPC clients have -1 as client_sd and need no disassociation.
*/
if (_rcv_cs.client_sd != -1)
Genode::ep_sd_registry()->disassociate(_rcv_cs.client_sd);
destroy_server_socket_pair(_rcv_cs);
}
/****************
@ -503,20 +538,6 @@ void Ipc_server::_reply_wait()
}
namespace Genode {
/*
* Helper for obtaining a bound and connected socket pair
*
* For core, the implementation is just a wrapper around
* 'lx_server_socket_pair()'. For all other processes, the implementation
* requests the socket pair from the Env::CPU session interface using a
* Linux-specific interface extension.
*/
Native_connection_state server_socket_pair();
}
Ipc_server::Ipc_server(Msgbuf_base *snd_msg, Msgbuf_base *rcv_msg)
:
Ipc_istream(rcv_msg),

View File

@ -73,5 +73,16 @@ namespace Genode {
{
return create_server_socket_pair(Thread_base::myself()->tid().tid);
}
void destroy_server_socket_pair(Native_connection_state const &ncs)
{
/*
* As entrypoints in core are never destructed, this function is only
* called on IPC-client destruction. In this case, it's a no-op in core
* as well as in Genode processes.
*/
if (ncs.server_sd != -1 || ncs.client_sd != -1)
PERR("%s called for IPC server which should never happen", __func__);
}
}