From 90395e9428cab065cb6e167d2f39ee9c2a7aa2d8 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 5 Nov 2012 17:23:50 +0100 Subject: [PATCH] Linux: Add 'Platform_thread' destructor --- base-linux/src/base/ipc/ipc.cc | 9 ++++++++- .../src/base/ipc/socket_descriptor_registry.h | 18 ++++++++++++++++++ base-linux/src/core/include/platform_thread.h | 2 ++ base-linux/src/core/platform_thread.cc | 12 ++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/base-linux/src/base/ipc/ipc.cc b/base-linux/src/base/ipc/ipc.cc index 8017e788b..6b7b06d04 100644 --- a/base-linux/src/base/ipc/ipc.cc +++ b/base-linux/src/base/ipc/ipc.cc @@ -68,7 +68,14 @@ Genode::Ep_socket_descriptor_registry *Genode::ep_sd_registry() */ static int lookup_tid_by_client_socket(int sd) { - sockaddr_un name; + /* + * Synchronize calls so that the large 'sockaddr_un' can be allocated + * in the BSS rather than the stack. + */ + Lock lock; + Lock::Guard guard(lock); + + static sockaddr_un name; socklen_t name_len = sizeof(name); int ret = lx_getpeername(sd, (sockaddr *)&name, &name_len); if (ret < 0) diff --git a/base-linux/src/base/ipc/socket_descriptor_registry.h b/base-linux/src/base/ipc/socket_descriptor_registry.h index 29e24a510..6044b1242 100644 --- a/base-linux/src/base/ipc/socket_descriptor_registry.h +++ b/base-linux/src/base/ipc/socket_descriptor_registry.h @@ -60,6 +60,8 @@ class Genode::Socket_descriptor_registry Entry(int fd, int global_id) : fd(fd), global_id(global_id) { } bool is_free() const { return fd == -1; } + + void mark_as_free() { fd = -1; } }; Entry _entries[MAX_FDS]; @@ -75,6 +77,15 @@ class Genode::Socket_descriptor_registry throw Limit_reached(); } + Entry &_find_entry_by_fd(int fd) + { + for (unsigned i = 0; i < MAX_FDS; i++) + if (_entries[i].fd == fd) + return _entries[i]; + + throw Limit_reached(); + } + bool _is_registered(int global_id) const { for (unsigned i = 0; i < MAX_FDS; i++) @@ -112,6 +123,13 @@ class Genode::Socket_descriptor_registry entry = Entry(sd, global_id); } + void disassociate(int sd) + { + Genode::Lock::Guard guard(_lock); + + _find_entry_by_fd(sd).mark_as_free(); + } + /** * Lookup file descriptor that belongs to specified global ID * diff --git a/base-linux/src/core/include/platform_thread.h b/base-linux/src/core/include/platform_thread.h index f729934ce..66743ccda 100644 --- a/base-linux/src/core/include/platform_thread.h +++ b/base-linux/src/core/include/platform_thread.h @@ -41,6 +41,8 @@ namespace Genode { */ Platform_thread(const char *name, unsigned priority, addr_t); + ~Platform_thread(); + /** * Cancel currently blocking operation */ diff --git a/base-linux/src/core/platform_thread.cc b/base-linux/src/core/platform_thread.cc index 8f595318a..fd47787f7 100644 --- a/base-linux/src/core/platform_thread.cc +++ b/base-linux/src/core/platform_thread.cc @@ -33,6 +33,18 @@ Platform_thread::Platform_thread(const char *name, unsigned, addr_t) } +Platform_thread::~Platform_thread() +{ + ep_sd_registry()->disassociate(_ncs.client_sd); + + if (_ncs.client_sd) + lx_close(_ncs.client_sd); + + if (_ncs.server_sd) + lx_close(_ncs.server_sd); +} + + void Platform_thread::cancel_blocking() { PDBG("send cancel-blocking signal to %ld\n", _tid);