2017-12-20 12:11:11 +01:00
|
|
|
/*
|
|
|
|
* \brief C-library back end
|
|
|
|
* \author Christian Prochaska
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2010-05-19
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-11-24 14:53:52 +01:00
|
|
|
* Copyright (C) 2010-2018 Genode Labs GmbH
|
2017-12-20 12:11:11 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
/* Genode includes */
|
|
|
|
#include <base/log.h>
|
|
|
|
#include <vfs/vfs_handle.h>
|
|
|
|
|
|
|
|
/* libc includes */
|
2017-12-20 12:11:11 +01:00
|
|
|
#include <sys/time.h>
|
2019-08-12 16:28:29 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
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
|
|
|
/* libc-internal includes */
|
|
|
|
#include <internal/legacy.h>
|
|
|
|
#include <internal/errno.h>
|
|
|
|
#include <internal/init.h>
|
|
|
|
#include <internal/current_time.h>
|
2019-08-12 16:28:29 +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
|
|
|
static Libc::Current_time *_current_time_ptr;
|
|
|
|
static char const *_rtc_path;
|
2017-12-20 12:11:11 +01:00
|
|
|
|
2018-11-24 14:53:52 +01: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
|
|
|
void Libc::init_time(Current_time ¤t_time, Rtc_path const &rtc_path)
|
|
|
|
{
|
|
|
|
static Rtc_path rtc_path_inst = rtc_path;
|
2019-08-12 16:28:29 +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
|
|
|
_current_time_ptr = ¤t_time;
|
|
|
|
_rtc_path = rtc_path_inst.string();
|
2019-08-12 16:28:29 +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
|
|
|
namespace Libc { struct Rtc; }
|
|
|
|
|
|
|
|
|
|
|
|
struct Libc::Rtc : Vfs::Watch_response_handler
|
2019-08-12 16:28:29 +02:00
|
|
|
{
|
2019-08-12 18:10:38 +02:00
|
|
|
Vfs::Vfs_watch_handle *_watch_handle { nullptr };
|
2019-08-12 16:28:29 +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
|
|
|
Rtc_path const _rtc_path;
|
|
|
|
|
|
|
|
bool _read_file { true };
|
|
|
|
time_t _rtc_value { 0 };
|
|
|
|
|
|
|
|
bool const _rtc_path_valid = (_rtc_path != "");
|
|
|
|
|
|
|
|
Rtc(Rtc_path const &rtc_path)
|
|
|
|
:
|
|
|
|
_rtc_path(rtc_path)
|
2019-08-12 18:10:38 +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
|
|
|
if (!_rtc_path_valid) {
|
2019-08-12 18:10:38 +02:00
|
|
|
Genode::warning("rtc not configured, returning ", _rtc_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
_watch_handle = Libc::watch(_rtc_path.string());
|
2019-08-12 18:10:38 +02:00
|
|
|
if (_watch_handle) {
|
|
|
|
_watch_handle->handler(this);
|
|
|
|
}
|
2019-08-12 16:28:29 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 18:10:38 +02:00
|
|
|
/******************************************
|
|
|
|
** Vfs::Watch_reponse_handler interface **
|
|
|
|
******************************************/
|
|
|
|
|
|
|
|
void watch_response() override
|
|
|
|
{
|
|
|
|
_read_file = true;
|
2019-08-12 16:28:29 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 18:10:38 +02:00
|
|
|
time_t read()
|
|
|
|
{
|
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
|
|
|
if (!_rtc_path_valid) { return 0; }
|
2019-08-12 18:10:38 +02:00
|
|
|
|
|
|
|
/* return old value */
|
|
|
|
if (!_read_file) { return _rtc_value; }
|
|
|
|
|
|
|
|
_read_file = false;
|
|
|
|
|
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
|
|
|
int fd = open(_rtc_path.string(), O_RDONLY);
|
2019-08-12 18:10:38 +02:00
|
|
|
if (fd == -1) {
|
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
|
|
|
Genode::warning(_rtc_path, " not readable, returning ", _rtc_value);
|
2019-08-12 18:10:38 +02:00
|
|
|
return _rtc_value;
|
2019-08-12 16:28:29 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 18:10:38 +02:00
|
|
|
char buf[32];
|
|
|
|
ssize_t n = ::read(fd, buf, sizeof(buf));
|
|
|
|
if (n > 0) {
|
|
|
|
buf[n - 1] = '\0';
|
|
|
|
struct tm tm;
|
|
|
|
Genode::memset(&tm, 0, sizeof(tm));
|
|
|
|
|
|
|
|
if (strptime(buf, "%Y-%m-%d %R", &tm)) {
|
|
|
|
_rtc_value = mktime(&tm);
|
|
|
|
if (_rtc_value == (time_t)-1)
|
|
|
|
_rtc_value = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-08-12 16:28:29 +02:00
|
|
|
|
2019-08-12 18:10:38 +02:00
|
|
|
close(fd);
|
|
|
|
|
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
|
|
|
struct Missing_call_of_init_time : Exception { };
|
|
|
|
if (!_current_time_ptr)
|
|
|
|
throw Missing_call_of_init_time();
|
|
|
|
|
|
|
|
Genode::uint64_t const ts_value =
|
|
|
|
_current_time_ptr->current_time().trunc_to_plain_ms().value;
|
2019-08-12 18:10:38 +02:00
|
|
|
_rtc_value += (time_t)ts_value / 1000;
|
|
|
|
|
|
|
|
return _rtc_value;
|
|
|
|
}
|
|
|
|
};
|
2017-12-20 12:11:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
extern "C" __attribute__((weak))
|
|
|
|
int clock_gettime(clockid_t clk_id, struct timespec *ts)
|
|
|
|
{
|
2018-10-19 15:38:46 +02:00
|
|
|
if (!ts) return Libc::Errno(EFAULT);
|
2017-12-20 12:11:11 +01: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
|
|
|
auto current_time = [&] ()
|
|
|
|
{
|
|
|
|
struct Missing_call_of_init_time : Genode::Exception { };
|
|
|
|
if (!_current_time_ptr)
|
|
|
|
throw Missing_call_of_init_time();
|
|
|
|
|
|
|
|
return _current_time_ptr->current_time();
|
|
|
|
};
|
|
|
|
|
2018-10-19 15:38:46 +02:00
|
|
|
/* initialize timespec just in case users do not check for errors */
|
2017-12-20 12:11:11 +01:00
|
|
|
ts->tv_sec = 0;
|
|
|
|
ts->tv_nsec = 0;
|
|
|
|
|
2018-10-19 15:38:46 +02:00
|
|
|
switch (clk_id) {
|
|
|
|
|
|
|
|
/* IRL wall-time */
|
|
|
|
case CLOCK_REALTIME:
|
|
|
|
case CLOCK_SECOND: /* FreeBSD specific */
|
|
|
|
{
|
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
|
|
|
/*
|
|
|
|
* XXX move instance to Libc::Kernel
|
|
|
|
*/
|
|
|
|
static Libc::Rtc rtc(_rtc_path);
|
2018-10-19 15:38:46 +02:00
|
|
|
|
2019-08-12 18:10:38 +02:00
|
|
|
time_t const rtc_value = rtc.read();
|
|
|
|
if (!rtc_value) return Libc::Errno(EINVAL);
|
2017-12-20 12:11:11 +01: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
|
|
|
Genode::uint64_t const time = current_time().trunc_to_plain_ms().value;
|
2017-12-20 12:11:11 +01:00
|
|
|
|
2019-08-12 18:10:38 +02:00
|
|
|
ts->tv_sec = rtc_value + time/1000;
|
2018-10-19 15:38:46 +02:00
|
|
|
ts->tv_nsec = (time % 1000) * (1000*1000);
|
|
|
|
break;
|
2017-12-20 12:11:11 +01:00
|
|
|
}
|
|
|
|
|
2018-10-19 15:38:46 +02:00
|
|
|
/* component uptime */
|
|
|
|
case CLOCK_MONOTONIC:
|
|
|
|
case CLOCK_UPTIME:
|
|
|
|
{
|
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
|
|
|
Genode::uint64_t us = current_time().trunc_to_plain_us().value;
|
2017-12-20 12:11:11 +01:00
|
|
|
|
2018-10-19 15:38:46 +02:00
|
|
|
ts->tv_sec = us / (1000*1000);
|
|
|
|
ts->tv_nsec = (us % (1000*1000)) * 1000;
|
|
|
|
break;
|
|
|
|
}
|
2017-12-20 12:11:11 +01:00
|
|
|
|
2018-10-19 15:38:46 +02:00
|
|
|
default:
|
|
|
|
return Libc::Errno(EINVAL);
|
|
|
|
}
|
2017-12-20 12:11:11 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-26 12:47:33 +02:00
|
|
|
extern "C" __attribute__((weak, alias("clock_gettime")))
|
|
|
|
int __sys_clock_gettime(clockid_t clk_id, struct timespec *ts);
|
|
|
|
|
|
|
|
|
2017-12-20 12:11:11 +01:00
|
|
|
extern "C" __attribute__((weak))
|
|
|
|
int gettimeofday(struct timeval *tv, struct timezone *)
|
|
|
|
{
|
|
|
|
if (!tv) return 0;
|
|
|
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
2018-10-19 15:38:46 +02:00
|
|
|
if (int ret = clock_gettime(CLOCK_REALTIME, &ts))
|
2017-12-20 12:11:11 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
tv->tv_sec = ts.tv_sec;
|
|
|
|
tv->tv_usec = ts.tv_nsec / 1000;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-11-24 14:53:52 +01:00
|
|
|
|
|
|
|
|
2019-04-26 12:47:33 +02:00
|
|
|
extern "C" __attribute__((weak, alias("gettimeofday")))
|
|
|
|
int __sys_gettimeofday(struct timeval *tv, struct timezone *);
|
|
|
|
|
|
|
|
|
2018-11-24 14:53:52 +01:00
|
|
|
extern "C"
|
|
|
|
clock_t clock()
|
|
|
|
{
|
|
|
|
Genode::error(__func__, " not implemented, use 'clock_gettime' instead");
|
|
|
|
return -1;
|
|
|
|
}
|