libc: add Genode::Lock to File_descriptor class

This lock is needed to prevent multiple threads and/or multiple
libc-plugins from using the same file descriptor in p{read,write}.

Fixes #948.
This commit is contained in:
Josef Söntgen 2013-11-13 13:36:18 +01:00 committed by Norman Feske
parent 607036718c
commit 36f91c2007
2 changed files with 4 additions and 1 deletions

View File

@ -16,6 +16,7 @@
#define _LIBC_PLUGIN__FD_ALLOC_H_
#include <base/allocator_avl.h>
#include <base/lock.h>
#include <base/printf.h>
#include <os/path.h>
@ -42,6 +43,7 @@ namespace Libc {
char *fd_path; /* for 'fchdir()' */
Plugin *plugin;
Plugin_context *context;
Genode::Lock lock;
void path(char const *newpath)
{

View File

@ -49,7 +49,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
/* allocate fresh fd if the default value for 'libc_fd' was specified */
bool alloc_ok = false;
if (addr == ANY_FD)
if (addr == ANY_FD)
alloc_ok = Allocator_avl_base::alloc(1, reinterpret_cast<void**>(&addr));
else
alloc_ok = (Allocator_avl_base::alloc_addr(1, addr).is_ok());
@ -65,6 +65,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
fdo->fd_path = 0;
fdo->plugin = plugin;
fdo->context = context;
fdo->lock = Lock(Lock::UNLOCKED);
return fdo;
}