Commit Graph

34 Commits

Author SHA1 Message Date
Christian Helmuth a54c04d247 libc: return EPIPE on send to shut down sockets
This intermediate fix still lacks the generation of SIGPIPE and return
of EINTR if the MSG_NOSIGNAL flag is not set in the call to send().
2019-11-19 14:54:14 +01:00
Norman Feske 648bcd1505 libc: unify use of namespaces
This patch unifies the patterns of using the 'Genode' and 'Libc'
namespaces.

Types defined in the 'internal/' headers reside in the 'Libc'
namespace. The code in the headers does not need to use the
'Libc::' prefix.

Compilation units import the 'Libc' namespace after the definition of
local types. Local types reside in the 'Libc' namespace (and should
eventually move to an 'internal/' header).

Since the 'Libc' namespace imports the 'Genode' namespace, there is
no need to use the 'Genode::' prefix. Consequently, code in the
compilation units rarely need to qualify the 'Genode' or 'Libc'
namespaces.

There are a few cases where the 'Libc', the 'Genode', and the global
(libc) namespaces are ambigious. In these cases, an explicit
clarification is needed:

- 'Genode::Allocator' differs from 'Libc::Allocator'.
- 'Genode::Env' differs from 'Libc::Env'.
- Genode's string functions (strcmp, memcpy, strcpy) conflict
  with the names of the (global) libc functions.
- There exist both 'Genode::uint64_t' and the libc'c 'uint64_t'.

Issue #3497
2019-11-19 14:10:55 +01:00
Norman Feske bf92232698 libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.

The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.

The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.

There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.

Issue #3497
2019-11-19 14:10:55 +01:00
Norman Feske 0aedabd245 libc: remove global constructors
- readv_writev: move 'rw_lock' instance into a function scope,
  constructing the instance on the first access.
- select: move 'select_cb_list' instance into function scope.
- thread: move 'key_list_lock' and 'keys' into function scope.
- rwlock, semaphore, socket_fs_plugin, thread, thread_create:
  instantiate 'Libc::Allocator' per use, alleviating the need for a
  global instance.

Issue #3496
2019-09-20 14:16:01 +02:00
Ehmry - 36111a2edf Libc: implement getifaddrs
Implement getifaddrs and freeifaddrs within the libc using socket
control files at the VFS. Add an "address" and "netmask" file to the
lwIP plugin.

Only a single IPv4 address is initially supported, and the broadcast
address returned will never be valid.

Fixes #3439
2019-09-02 16:36:07 +02:00
Norman Feske fd8a209da2 libc: fix warning in socket_fs_plugin.cc
By using Genode::strncpy instead of the libc's strncpy, we cannot end up
in the situation where the result lacks the zero termination (where the
number of charactors equals the destination buffer size).
2019-08-21 14:01:54 +02:00
Ehmry - 863654d188 Libc: update port to Freebsd 12
Fix #3289
2019-05-27 14:46:53 +02:00
Josef Söntgen b9e12d7c23 libc: always set O_RDWR in fcntl on a socket
For better or worse we have no proper way of handling this right now
but contrib libraries, e.g. glib, use it to determine if they can use
the underlying fd.

Fxies #3265.
2019-04-09 12:30:34 +02:00
Christian Prochaska db9ff821a2 libc: sync 'listen' socket fs control file
Fixes #3124
2019-02-12 10:33:14 +01:00
Christian Prochaska e8ea28d897 socket fs: support non-blocking 'connect()'
Fixes #3113
2019-01-30 13:35:28 +01:00
Sebastian Sumpf d3dbdae395 libc: add SO_LINGER and TCP_NODELY to socket fs plugin
issue #3060
2018-11-29 11:54:30 +01:00
Christian Prochaska 5adb6f0c5f socket_fs: show ioctl FIONREAD error message only once
Fixes #2969
2018-09-13 15:21:10 +02:00
Emery Hemingway d9a4773194 LwIP VFS plugin
This patch reintroduces the LwIP stack to libc as a VFS plugin
implementing the socket_fs interface. Rather than use LwIP's socket
emulation layer this plugin interfaces directly to LwIP raw API and is
single threaded.

The internal TCP parameters of the stack are untuned.

Fix #2050
Fix #2335
2018-08-02 14:36:48 +02:00
Ehmry - 1097a5c7c2 Libc: ignore address argument to TCP sendto
Generic code that operates over both UDP and TCP sockets might use
'sendto', but in the case of TCP the destination address ought to be
safely discarded. This seems to be the case for certain DNS software
that operates over both UDP and TCP.

Fix #2807
2018-05-30 13:36:13 +02:00
Ehmry - 96579a72e0 Libc: gracefully handle invalid socketaddr arguments
Ref #2682
2018-05-03 15:31:58 +02:00
Ehmry - 401ba6e7fd Manage socket_fs socket lifetime via handles
Socket_fs sockets are now created each time a 'new_socket' control file
is opened, not each time a 'new_socket' file is read. When a handle on a
'new_socket' file is closed the socket and its socket files are
destroyed. The accept control file on a listening socket reads "1" or
reads nothing to indicate a client connection is queued. Client sockets
are accepted by opening an 'accept_socket' file in the listen socket
directory. This file behaves like the aforementioned 'new_socket' file.

Ref #2707
2018-05-03 15:31:57 +02:00
Christian Helmuth adc3aa452a libc: close all handles of a socket before release
This prevents diagnostic messages like

  Error: partial write detected 0 vs 31

for writes into already released socket directories due to a still-open
handle to the socket data file.
2018-02-28 11:05:05 +01:00
Christian Helmuth 064e738d53 libc: reduce noise on setsockopt/getsockopt 2018-02-28 11:05:04 +01:00
Emery Hemingway 88757a674a libc: sync socket control files to check for write errors
Ref #2335
2018-02-28 11:04:58 +01:00
Christian Helmuth 2b649cb633 libc: handle socket_fs special cases
- catch inaccessible file on bind()
- support UDP ENETDOWN and TCP EAGAIN on sendto()
2017-11-30 11:23:17 +01:00
Emery Hemingway 8207fb8d98 libc: sync bind sock control file before continuing with listen
Fix #2512
2017-10-05 17:39:54 +02:00
Christian Helmuth c223f74ce5 libc: support getsockopt(SO_TYPE) 2017-06-19 12:35:57 +02:00
Josef Söntgen b361de8379 libc: return true on writefd checks in select on sockets
Instead of files we have to check this condition on sockets but
technically our sockets are regular files as well...
2017-05-31 13:16:15 +02:00
Josef Söntgen dbec8d7710 libc: pretend to support SO_ERROR
There are programs, e.g. curl, that check if a connection was
established successfully by looking at SO_ERROR. Pretend that
the getsockopt() call was executed to keep them happy. If they
try to use a broken connection, the other socket functions will
bail.
2017-05-31 13:16:15 +02:00
Christian Helmuth 9802ae83e0 libc: rework socket fs for O_NONBLOCK 2017-05-31 13:15:58 +02:00
Emery Hemingway 50ee91e738 libc: poll listening sockets during select
Open the accept file at the listen call and poll for read henceforce.

Fix #2319
2017-03-24 16:19:55 +01:00
Emery Hemingway 7ef8c81607 libc: socket fcntl flags inheritence
Set O_NONBLOCK on sockets from the fcntl syscall and propagate this flag
to socket_fs control files and sockets returned from accept.

Fix #2318
2017-03-24 16:19:55 +01:00
Norman Feske 29b8d609c9 Adjust file headers to refer to the AGPLv3 2017-02-28 12:59:29 +01:00
Josef Söntgen b2dd0ab436 libc: remove global env from socket_fs_plugin
Issue #2280.
2017-02-28 12:59:27 +01:00
Martin Stein d61cb2714c libc/socket_fs: unlink during close
If 'close' does not call 'unlink' like 'shutdown', the Lxip_socket_dir
never gets destroyed and thus the socket server leaks resources like
RAM and ports.

Ref #2285
2017-02-28 12:59:25 +01:00
Martin Stein 43fcdc43e6 libc/socket_fs: warn on unexpected arg in shutdown
Our 'shutdown' implementation handles only the case that 'how' is 'RDWR'.
Thus, print an error and continue if a user calls it with another value.

Fixes #2285
2017-02-28 12:59:24 +01:00
Alexander Boettcher 1a6963813c libc: avoid race using Libc::suspend with pthreads
TOCTTOU bug, in our case time of check to time of sleep bug
2017-02-28 12:59:24 +01:00
Martin Stein 222a789fef LibC socket FS: Fix leak of remote and local files 2017-02-28 12:59:19 +01:00
Christian Helmuth fdad5116dd libc: support for socket file system
The socket file system can be configured in the "socket" attribute of
the libc config node like follows.

  <vfs> <dir name="socket"> <fs/> </dir> </vfs>
  <libc ... socket="/socket"/>

This configures the socket file system libc backend to access files in
"/socket" for socket operations.
2017-02-28 12:59:16 +01:00