[libc-commits] [libc] [libc] Provide sys/queue.h (PR #78081)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Jan 18 14:59:43 PST 2024
================
@@ -0,0 +1,20 @@
+//===-- Definition of the containerof macro -------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H
+#define __LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H
+
+#include <llvm-libc-macros/offsetof-macro.h>
+
+#define __containerof(ptr, type, member) \
+ ({ \
+ const __typeof(((type *)0)->member) *__ptr = ptr; \
+ (type *)(void *)((const char *)__ptr - offsetof(type, member)); \
----------------
nickdesaulniers wrote:
Note: the Linux kernel has some updates to this macro, such as:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/kernel.h?id=c7acec713d14c6ce8a20154f9dfda258d6bcad3b
I don't think we need those per-se at the moment, but I do wonder when we will.
https://github.com/llvm/llvm-project/pull/78081
More information about the libc-commits
mailing list