summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-02-16 12:41:30 -0600
committerDanny Holman <dholman@gymli.org>2024-02-16 12:41:30 -0600
commit5c8265d9634836217f1a814ee2b56942e06259a4 (patch)
tree5e11e99be4c04ab10b748479548501d7ffdb7857
parente8b9376573a1defbdc5ba496523c9e94031818a5 (diff)
include: kernel: add the container_of.h file
Add the container_of.h file that defines the container_of macro. This macro allows the kernel to get the parent struct of a pointer with an offset. Signed-off-by: Danny Holman <dholman@gymli.org>
-rw-r--r--include/kernel/container_of.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/kernel/container_of.h b/include/kernel/container_of.h
new file mode 100644
index 0000000..1b5b444
--- /dev/null
+++ b/include/kernel/container_of.h
@@ -0,0 +1,10 @@
+#ifndef KERNEL_CONTAINER_OF_H
+#define KERNEL_CONTAINER_OF_H
+
+#ifndef container_of
+#define container_of(ptr, type, member) ({ \
+ const typeof(((type*)0)->member)*__mptr = (ptr); \
+ (type*)((char*)__mptr - offsetof(type, member)); })
+#endif
+
+#endif