2015-06-29 17:02:08 +02:00
|
|
|
/*
|
|
|
|
* \brief File-operation utilities
|
|
|
|
* \author Christian Helmuth
|
2017-02-01 11:28:15 +01:00
|
|
|
* \author Emery Hemingway
|
2015-06-29 17:02:08 +02:00
|
|
|
* \date 2015-06-30
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-01 11:28:15 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-06-29 17:02:08 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-06-29 17:02:08 +02:00
|
|
|
*/
|
|
|
|
|
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-09-18 20:19:10 +02:00
|
|
|
#ifndef _LIBC__INTERNAL__FILE_H_
|
|
|
|
#define _LIBC__INTERNAL__FILE_H_
|
2015-06-29 17:02:08 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2015-06-29 17:02:08 +02:00
|
|
|
|
|
|
|
/* Genode-specific libc interfaces */
|
|
|
|
#include <libc-plugin/fd_alloc.h>
|
|
|
|
#include <libc-plugin/plugin_registry.h>
|
|
|
|
|
|
|
|
|
|
|
|
enum { INVALID_FD = -1 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find plugin responsible for the specified libc file descriptor
|
|
|
|
*
|
|
|
|
* \param func_name function name of the caller for printing an error message
|
|
|
|
*/
|
|
|
|
static inline Libc::File_descriptor *libc_fd_to_fd(int libc_fd, const char *func_name)
|
|
|
|
{
|
|
|
|
Libc::File_descriptor *fd =
|
|
|
|
Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd);
|
|
|
|
if (!fd)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("no plugin found for ", func_name, "(", libc_fd, ")");
|
2015-06-29 17:02:08 +02:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate body of wrapper function taking a file descriptor as first argument
|
|
|
|
*/
|
|
|
|
#define FD_FUNC_WRAPPER_GENERIC(result_stm, result_err_val, func_name, libc_fd, ...) \
|
|
|
|
{ \
|
|
|
|
File_descriptor *fd = libc_fd_to_fd(libc_fd, #func_name); \
|
|
|
|
if (!fd || !fd->plugin) { \
|
|
|
|
errno = EBADF; \
|
|
|
|
result_stm result_err_val; \
|
|
|
|
} else \
|
|
|
|
result_stm fd->plugin->func_name(fd, ##__VA_ARGS__ ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FD_FUNC_WRAPPER(func_name, libc_fd, ...) \
|
|
|
|
FD_FUNC_WRAPPER_GENERIC(return, INVALID_FD, func_name, libc_fd, ##__VA_ARGS__ )
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate body of wrapper function taking a path name as first argument
|
|
|
|
*/
|
|
|
|
#define FNAME_FUNC_WRAPPER_GENERIC(result_stm, func_name, path, ...) \
|
|
|
|
{ \
|
|
|
|
Plugin *plugin = plugin_registry()->get_plugin_for_##func_name(path, ##__VA_ARGS__); \
|
|
|
|
if (!plugin) { \
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("no plugin found for ", #func_name, "(\"", Genode::Cstring(path), "\")");\
|
2015-06-29 17:02:08 +02:00
|
|
|
errno = ENOSYS; \
|
|
|
|
result_stm -1; \
|
|
|
|
} else \
|
|
|
|
result_stm plugin->func_name(path, ##__VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FNAME_FUNC_WRAPPER(func_name, path, ...) \
|
|
|
|
FNAME_FUNC_WRAPPER_GENERIC(return, func_name, path, ##__VA_ARGS__ )
|
|
|
|
|
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-09-18 20:19:10 +02:00
|
|
|
#endif /* _LIBC__INTERNAL__FILE_H_ */
|