Module Name: src
Committed By: christos
Date: Tue Oct 8 22:53:21 UTC 2024
Modified Files:
src/distrib/sets/lists/comp: mi
src/include: Makefile
src/sys/sys: Makefile
Added Files:
src/sys/sys: container_of.h stddef.h
Removed Files:
src/include: stddef.h
Log Message:
PR/58729: Taylor R Campbell: container_of is not documented or available
in userland
To generate a diff of this commit:
cvs rdiff -u -r1.2474 -r1.2475 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.148 -r1.149 src/include/Makefile
cvs rdiff -u -r1.24 -r0 src/include/stddef.h
cvs rdiff -u -r1.184 -r1.185 src/sys/sys/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/sys/container_of.h src/sys/sys/stddef.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2474 src/distrib/sets/lists/comp/mi:1.2475
--- src/distrib/sets/lists/comp/mi:1.2474 Thu Oct 3 13:14:12 2024
+++ src/distrib/sets/lists/comp/mi Tue Oct 8 18:53:21 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.2474 2024/10/03 17:14:12 christos Exp $
+# $NetBSD: mi,v 1.2475 2024/10/08 22:53:21 christos Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@@ -3419,6 +3419,7 @@
./usr/include/sys/common_wchar_limits.h comp-c-include
./usr/include/sys/condvar.h comp-c-include
./usr/include/sys/conf.h comp-c-include
+./usr/include/sys/container_of.h comp-c-include
./usr/include/sys/core.h comp-c-include
./usr/include/sys/cpu_data.h comp-obsolete obsolete
./usr/include/sys/cpufreq.h comp-c-include
@@ -3588,6 +3589,7 @@
./usr/include/sys/stdalign.h comp-c-include
./usr/include/sys/stdarg.h comp-c-include
./usr/include/sys/stdbool.h comp-c-include
+./usr/include/sys/stddef.h comp-c-include
./usr/include/sys/stdint.h comp-c-include
./usr/include/sys/swap.h comp-c-include
./usr/include/sys/syncobj.h comp-c-include
Index: src/include/Makefile
diff -u src/include/Makefile:1.148 src/include/Makefile:1.149
--- src/include/Makefile:1.148 Sun Aug 25 18:10:40 2024
+++ src/include/Makefile Tue Oct 8 18:53:20 2024
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.148 2024/08/25 22:10:40 christos Exp $
+# $NetBSD: Makefile,v 1.149 2024/10/08 22:53:20 christos Exp $
# @(#)Makefile 8.2 (Berkeley) 1/4/94
# Doing a make includes builds /usr/include
@@ -18,7 +18,7 @@ INCS= a.out.h aio.h ar.h assert.h atomic
ndbm.h netconfig.h netdb.h netgroup.h nlist.h nl_types.h nsswitch.h \
paths.h pwd.h quota.h randomid.h ranlib.h re_comp.h regex.h regexp.h \
resolv.h res_update.h rmt.h sched.h search.h semaphore.h setjmp.h \
- string.h sgtty.h signal.h spawn.h stab.h stddef.h stdio.h \
+ string.h sgtty.h signal.h spawn.h stab.h stdio.h \
stdlib.h stdnoreturn.h strings.h stringlist.h struct.h sysexits.h \
tar.h time.h ttyent.h tzfile.h \
uchar.h \
Index: src/sys/sys/Makefile
diff -u src/sys/sys/Makefile:1.184 src/sys/sys/Makefile:1.185
--- src/sys/sys/Makefile:1.184 Sun Aug 25 18:10:40 2024
+++ src/sys/sys/Makefile Tue Oct 8 18:53:20 2024
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.184 2024/08/25 22:10:40 christos Exp $
+# $NetBSD: Makefile,v 1.185 2024/10/08 22:53:20 christos Exp $
.include <bsd.own.mk>
@@ -12,7 +12,7 @@ INCS= acct.h acl.h agpio.h aio.h ansi.h
common_ansi.h common_int_const.h common_int_fmtio.h \
common_int_limits.h common_int_mwgwtypes.h common_int_types.h \
common_limits.h common_lock.h common_wchar_limits.h \
- condvar.h conf.h core.h \
+ condvar.h conf.h container_of.h core.h \
cpufreq.h cpuio.h ctype_bits.h ctype_inline.h \
device.h device_if.h \
dir.h dirent.h \
@@ -42,7 +42,7 @@ INCS= acct.h acl.h agpio.h aio.h ansi.h
sleepq.h socket.h \
socketvar.h sockio.h spawn.h specificdata.h stat.h \
statvfs.h syscall.h syscallargs.h sysctl.h stdalign.h stdarg.h \
- stdbool.h stdint.h swap.h syncobj.h syslimits.h syslog.h \
+ stdbool.h stddef.h stdint.h swap.h syncobj.h syslimits.h syslog.h \
tape.h termios.h time.h timeb.h timepps.h timerfd.h times.h timespec.h \
timex.h tls.h trace.h tree.h tty.h ttychars.h ttycom.h \
ttydefaults.h ttydev.h types.h \
@@ -54,18 +54,19 @@ INCSYMLINKS=\
sys/cdbr.h /usr/include/cdbr.h \
sys/exec_elf.h /usr/include/elf.h \
sys/fcntl.h /usr/include/fcntl.h \
+ sys/md4.h /usr/include/md4.h \
+ sys/md5.h /usr/include/md5.h \
sys/poll.h /usr/include/poll.h \
+ sys/rmd160.h /usr/include/rmd160.h \
+ sys/sha1.h /usr/include/sha1.h \
+ sys/sha2.h /usr/include/sha2.h \
sys/stdalign.h /usr/include/stdalign.h \
sys/stdarg.h /usr/include/stdarg.h \
sys/stdbool.h /usr/include/stdbool.h \
+ sys/stddef.h /usr/include/stddef.h \
sys/stdint.h /usr/include/stdint.h \
sys/syslog.h /usr/include/syslog.h \
- sys/termios.h /usr/include/termios.h \
- sys/rmd160.h /usr/include/rmd160.h \
- sys/sha1.h /usr/include/sha1.h \
- sys/sha2.h /usr/include/sha2.h \
- sys/md4.h /usr/include/md4.h \
- sys/md5.h /usr/include/md5.h
+ sys/termios.h /usr/include/termios.h
INCSYMLINKS+= ../soundcard.h ${INCSDIR}/soundcard.h
Added files:
Index: src/sys/sys/container_of.h
diff -u /dev/null src/sys/sys/container_of.h:1.1
--- /dev/null Tue Oct 8 18:53:21 2024
+++ src/sys/sys/container_of.h Tue Oct 8 18:53:20 2024
@@ -0,0 +1,75 @@
+/* $NetBSD: container_of.h,v 1.1 2024/10/08 22:53:20 christos Exp $ */
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_CONTAINER_OF_H_
+#define _SYS_CONTAINER_OF_H_
+
+#include <sys/stddef.h>
+
+/*
+ * Return the container of an embedded struct. Given x = &c->f,
+ * container_of(x, T, f) yields c, where T is the type of c. Example:
+ *
+ * struct foo { ... };
+ * struct bar {
+ * int b_x;
+ * struct foo b_foo;
+ * ...
+ * };
+ *
+ * struct bar b;
+ * struct foo *fp = &b.b_foo;
+ *
+ * Now we can get at b from fp by:
+ *
+ * struct bar *bp = container_of(fp, struct bar, b_foo);
+ *
+ * The 0*sizeof((PTR) - ...) causes the compiler to warn if the type of
+ * *fp does not match the type of struct bar::b_foo.
+ * We skip the validation for coverity runs to avoid warnings.
+ */
+#if defined(__COVERITY__) || defined(__LGTM_BOT__)
+#define __validate_container_of(PTR, TYPE, FIELD) 0
+#define __validate_const_container_of(PTR, TYPE, FIELD) 0
+#else
+#define __validate_container_of(PTR, TYPE, FIELD) \
+ (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) - \
+ offsetof(TYPE, FIELD)))->FIELD))
+#define __validate_const_container_of(PTR, TYPE, FIELD) \
+ (0 * sizeof((PTR) - &((const TYPE *)(((const char *)(PTR)) - \
+ offsetof(TYPE, FIELD)))->FIELD))
+#endif
+
+#define container_of(PTR, TYPE, FIELD) \
+ ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \
+ + __validate_container_of(PTR, TYPE, FIELD))
+#define const_container_of(PTR, TYPE, FIELD) \
+ ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD)) \
+ + __validate_const_container_of(PTR, TYPE, FIELD))
+
+#endif /* !_SYS_CONTAINER_OF_H_ */
Index: src/sys/sys/stddef.h
diff -u /dev/null src/sys/sys/stddef.h:1.1
--- /dev/null Tue Oct 8 18:53:21 2024
+++ src/sys/sys/stddef.h Tue Oct 8 18:53:20 2024
@@ -0,0 +1,78 @@
+/* $NetBSD: stddef.h,v 1.1 2024/10/08 22:53:20 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)stddef.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_STDDEF_H_
+#define _SYS_STDDEF_H_
+
+#include <sys/cdefs.h>
+#include <sys/featuretest.h>
+#include <machine/ansi.h>
+
+#ifdef _BSD_PTRDIFF_T_
+typedef _BSD_PTRDIFF_T_ ptrdiff_t;
+#undef _BSD_PTRDIFF_T_
+#endif
+
+#ifdef _BSD_SIZE_T_
+typedef _BSD_SIZE_T_ size_t;
+#undef _BSD_SIZE_T_
+#endif
+
+#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
+typedef _BSD_WCHAR_T_ wchar_t;
+#undef _BSD_WCHAR_T_
+#endif
+
+#include <sys/null.h>
+
+#if __GNUC_PREREQ__(4, 0)
+#define offsetof(type, member) __builtin_offsetof(type, member)
+#elif !defined(__cplusplus)
+#define offsetof(type, member) ((size_t)(unsigned long)(&((type *)0)->member))
+#else
+#if !__GNUC_PREREQ__(3, 4)
+#define __offsetof__(a) a
+#endif
+#define offsetof(type, member) __offsetof__((reinterpret_cast<size_t> \
+ (&reinterpret_cast<const volatile char &>(static_cast<type *>(0)->member))))
+#endif
+
+#if (__STDC_VERSION__ - 0) >= 201112L || (__cplusplus - 0) >= 201103L
+typedef union {
+ void *_v;
+ long double _ld;
+ long long int _ll;
+} max_align_t;
+#endif
+
+#endif /* _SYS_STDDEF_H_ */