From 5c8265d9634836217f1a814ee2b56942e06259a4 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Fri, 16 Feb 2024 12:41:30 -0600 Subject: 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 --- include/kernel/container_of.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 include/kernel/container_of.h (limited to 'include/kernel') 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 -- cgit v1.2.3