[libc-commits] [libc] [libc][time] Implement timer_create. (PR #217920)

via libc-commits libc-commits at lists.llvm.org
Fri Aug 21 10:47:37 PDT 2026


================
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for timer_create syscall wrapper.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_CREATE_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_CREATE_H
+
+#include "hdr/types/clockid_t.h"
+#include "hdr/types/pid_t.h"
+#include "hdr/types/struct_sigevent.h"
+#include "hdr/types/timer_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+#define __SIGEV_MAX_SIZE 64
+#define __SIGEV_PAD_SIZE                                                       \
+  ((__SIGEV_MAX_SIZE - sizeof(int) * 2 - sizeof(sigval)) / sizeof(int))
+
+// Linux kernel ABI layout for struct sigevent (64 bytes total):
+// https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h
+// https://man7.org/linux/man-pages/man2/timer_create.2.html
+struct KernelSigevent {
+  sigval sigev_value;
+  int sigev_signo;
+  int sigev_notify;
+  union {
+    int _pad[__SIGEV_PAD_SIZE];
+    pid_t _tid;
+    struct {
+      void (*_function)(sigval);
+      void *_attribute;
+    } _sigev_thread;
+  } _sigev_un;
+
+  LIBC_INLINE KernelSigevent() = default;
+
+  LIBC_INLINE KernelSigevent(const sigevent &sev) {
+    sigev_value = sev.sigev_value;
+    sigev_signo = sev.sigev_signo;
+    sigev_notify = sev.sigev_notify;
+    _sigev_un._tid = sev.sigev_notify_thread_id;
+    _sigev_un._sigev_thread._function = sev.sigev_notify_function;
+    _sigev_un._sigev_thread._attribute = sev.sigev_notify_attributes;
----------------
lntue wrote:

Fixed.

https://github.com/llvm/llvm-project/pull/217920


More information about the libc-commits mailing list