mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
libc: use File_descriptor::lock in pread/pwrite
Replace the static lock with the file descriptor lock because recursive calls of p{read,write} would result in a deadlock when using multiple libc-plugins at the same time. Fixes #948.
This commit is contained in:
parent
36f91c2007
commit
d0ddc11c09
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
#include <base/lock.h>
|
#include <base/lock.h>
|
||||||
|
#include <libc-plugin/fd_alloc.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -20,31 +21,32 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
static Genode::Lock rw_lock;
|
|
||||||
|
|
||||||
|
|
||||||
struct Read
|
struct Read
|
||||||
{
|
{
|
||||||
ssize_t operator()(int fd, void *buf, size_t count)
|
ssize_t operator()(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
return read(fd, buf, count);
|
return read(fd, buf, count);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Write
|
struct Write
|
||||||
{
|
{
|
||||||
ssize_t operator()(int fd, const void *buf, size_t count)
|
ssize_t operator()(int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
return write(fd, buf, count);
|
return write(fd, buf, count);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename Rw_func, typename Buf_type>
|
template <typename Rw_func, typename Buf_type>
|
||||||
static ssize_t pread_pwrite_impl(Rw_func rw_func, int fd, Buf_type buf, ::size_t count, ::off_t offset)
|
static ssize_t pread_pwrite_impl(Rw_func rw_func, int fd, Buf_type buf, ::size_t count, ::off_t offset)
|
||||||
{
|
{
|
||||||
Genode::Lock_guard<Genode::Lock> rw_lock_guard(rw_lock);
|
Libc::File_descriptor *fdesc = Libc::file_descriptor_allocator()->find_by_libc_fd(fd);
|
||||||
|
if (fdesc == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
Genode::Lock_guard<Genode::Lock> rw_lock_guard(fdesc->lock);
|
||||||
|
|
||||||
off_t old_offset = lseek(fd, 0, SEEK_CUR);
|
off_t old_offset = lseek(fd, 0, SEEK_CUR);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user