xref: /aosp_15_r20/external/llvm-libc/src/__support/OSUtil/linux/vdso_sym.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===------------- Linux VDSO Symbols ---------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #include "hdr/types/clock_t.h"
9 #include "hdr/types/clockid_t.h"
10 #include "hdr/types/struct_timespec.h"
11 #include "hdr/types/struct_timeval.h"
12 #include "hdr/types/time_t.h"
13 #include "src/__support/common.h"
14 #include <stddef.h> // For size_t.
15 
16 // NOLINTBEGIN(llvmlibc-implementation-in-namespace)
17 // TODO: some of the following can be defined via proxy headers.
18 struct __kernel_timespec;
19 struct timezone;
20 struct riscv_hwprobe;
21 struct getcpu_cache;
22 struct cpu_set_t;
23 // NOLINTEND(llvmlibc-implementation-in-namespace)
24 
25 namespace LIBC_NAMESPACE_DECL {
26 namespace vdso {
27 
28 enum class VDSOSym {
29   ClockGetTime,
30   ClockGetTime64,
31   GetTimeOfDay,
32   GetCpu,
33   Time,
34   ClockGetRes,
35   RTSigReturn,
36   FlushICache,
37   RiscvHwProbe,
38   VDSOSymCount
39 };
40 
dispatcher()41 template <VDSOSym sym> LIBC_INLINE constexpr auto dispatcher() {
42   if constexpr (sym == VDSOSym::ClockGetTime)
43     return static_cast<int (*)(clockid_t, timespec *)>(nullptr);
44   else if constexpr (sym == VDSOSym::ClockGetTime64)
45     return static_cast<int (*)(clockid_t, __kernel_timespec *)>(nullptr);
46   else if constexpr (sym == VDSOSym::GetTimeOfDay)
47     return static_cast<int (*)(timeval *__restrict,
48                                struct timezone *__restrict)>(nullptr);
49   else if constexpr (sym == VDSOSym::GetCpu)
50     return static_cast<int (*)(unsigned *, unsigned *, getcpu_cache *)>(
51         nullptr);
52   else if constexpr (sym == VDSOSym::Time)
53     return static_cast<time_t (*)(time_t *)>(nullptr);
54   else if constexpr (sym == VDSOSym::ClockGetRes)
55     return static_cast<int (*)(clockid_t, timespec *)>(nullptr);
56   else if constexpr (sym == VDSOSym::RTSigReturn)
57     return static_cast<void (*)(void)>(nullptr);
58   else if constexpr (sym == VDSOSym::FlushICache)
59     return static_cast<void (*)(void *, void *, unsigned int)>(nullptr);
60   else if constexpr (sym == VDSOSym::RiscvHwProbe)
61     return static_cast<int (*)(riscv_hwprobe *, size_t, size_t, cpu_set_t *,
62                                unsigned)>(nullptr);
63   else
64     return static_cast<void *>(nullptr);
65 }
66 
67 template <VDSOSym sym> using VDSOSymType = decltype(dispatcher<sym>());
68 
69 } // namespace vdso
70 } // namespace LIBC_NAMESPACE_DECL
71