fxlibc/src/time/clock.c
Lephenixnoir 8cedf411c4
gint: outline a Hardware Abstraction Layer (HAL) for use with gint
A standard libc would normally use the kernel's syscall interface to
connect with the lower level, and this interface would usually imitate
POSIX or a similar style. With the statically-linked unikernel design,
the syscalls would be functions, but the interface wouldn't change much.

However, there are some fundamental differences. For instance, in gint
there aren't separate kernel/userspace memory allocators, there's just a
unified allocator in the kernel. This makes malloc() conceptually a
direct syscall, which pushes the kernel/libc boundary at an unusual
location.

Having a clearly-marked HAL makes it easier to identify where the
boundary is. Code from <time.h> currently has an ad-hoc interface which
should be replaced with clock_gettime(2) in the future.

The HAL offers default implementations but these aren't used by gint
yet, because it's more practical to have undefined references than to
end up with the stubs in an executable. These are provided for future
completeness.

This change does not lift the requirement to recursively link gint with
the libc and the libc with gint.
2024-08-06 18:55:01 +02:00

15 lines
239 B
C

#include <time.h>
#include <fxlibc/hal.h>
static clock_t clock_init;
__attribute__((constructor))
static void clock_initialize(void)
{
clock_init = fxlibc_hal_clock();
}
clock_t clock(void)
{
return fxlibc_hal_clock() - clock_init;
}