From 2dc247fc34ed0fd256fd948c164aa2c3d2ba491f Mon Sep 17 00:00:00 2001 From: itojun Date: Thu, 2 Mar 2000 07:41:49 +0000 Subject: [PATCH] make CMSG_ALIGN always synchronize with kernel's idea of ALIGNBYTES. ancillary data alignment will be ALIGNBYTES, not sizeof(long) - 1, from now. CMSG_xx will NOT resolve into constant. if you use CMSG_xx to allocate arrays, you'll lose. bump shlib minor for libc. NOTE: if you are on top of arch with ALIGNBYTES != sizeof(long) - 1, you need to recompile IPv6-related binaries. there is no way to guarantee backward compat in this aspect. sorry for this. this should be the last backward compat breakage for IPv6-related ancillary data manipulation. (we still have PR 9516 for unix-domain sockets...) --- distrib/sets/lists/base/shl.mi | 4 +- lib/libc/net/Makefile.inc | 6 +-- lib/libc/net/__cmsg_alignbytes.c | 65 +++++++++++++++++++++++++++++ lib/libc/shlib_version | 4 +- sys/lib/libkern/Makefile | 4 +- sys/lib/libkern/__cmsg_alignbytes.c | 44 +++++++++++++++++++ sys/sys/socket.h | 14 +++++-- 7 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 lib/libc/net/__cmsg_alignbytes.c create mode 100644 sys/lib/libkern/__cmsg_alignbytes.c diff --git a/distrib/sets/lists/base/shl.mi b/distrib/sets/lists/base/shl.mi index 00f2a014f8d2..c5e78c97e25b 100644 --- a/distrib/sets/lists/base/shl.mi +++ b/distrib/sets/lists/base/shl.mi @@ -1,7 +1,7 @@ -# $NetBSD: shl.mi,v 1.55 2000/02/23 07:00:55 itojun Exp $ +# $NetBSD: shl.mi,v 1.56 2000/03/02 07:41:50 itojun Exp $ ./usr/lib/libamu.so.1.1 ./usr/lib/libbz2.so.0.0 -./usr/lib/libc.so.12.56 +./usr/lib/libc.so.12.57 ./usr/lib/libcrypt.so.0.0 ./usr/lib/libcurses.so.2.5 ./usr/lib/libedit.so.2.3 diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 23a00037b302..8a2e484a02f6 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -1,11 +1,11 @@ -# $NetBSD: Makefile.inc,v 1.51 2000/02/23 15:44:00 itojun Exp $ +# $NetBSD: Makefile.inc,v 1.52 2000/03/02 07:41:52 itojun Exp $ # @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 # net sources .PATH: ${ARCHDIR}/net ${.CURDIR}/net -SRCS+= base64.c ethers.c gethnamaddr.c getifaddrs.c getnetnamadr.c \ - getnetent.c getproto.c \ +SRCS+= __cmsg_alignbytes.c base64.c ethers.c gethnamaddr.c getifaddrs.c \ + getnetnamadr.c getnetent.c getproto.c \ getprotoent.c getprotoname.c getservbyname.c getservbyport.c \ getservent.c herror.c hesiod.c inet_lnaof.c inet_makeaddr.c \ inet_net_ntop.c inet_net_pton.c inet_neta.c inet_ntop.c inet_pton.c \ diff --git a/lib/libc/net/__cmsg_alignbytes.c b/lib/libc/net/__cmsg_alignbytes.c new file mode 100644 index 000000000000..594d34c8882d --- /dev/null +++ b/lib/libc/net/__cmsg_alignbytes.c @@ -0,0 +1,65 @@ +/* $NetBSD: __cmsg_alignbytes.c,v 1.1 2000/03/02 07:41:52 itojun Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jun-ichiro Hagino. + * + * 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 NetBSD Foundation 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 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. + */ + +#include +#include +#include +#include + +int +__cmsg_alignbytes() +{ + static int alignbytes = -1; +#ifdef HW_ALIGNBYTES + int mib[2]; + size_t len; + int ret; +#endif + + if (alignbytes > 0) + return alignbytes; + +#ifdef HW_ALIGNBYTES + mib[0] = CTL_HW; + mib[1] = HW_ALIGNBYTES; + len = sizeof(alignbytes); + ret = sysctl(mib, sizeof(mib)/sizeof(mib[0]), (void *)&alignbytes, + &len, NULL, 0); + if (ret >= 0 && alignbytes >= 0) + return alignbytes; +#endif + /* last resort */ + alignbytes = ALIGNBYTES; + return alignbytes; +} diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 14608be66b92..83ec76a120a7 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,5 +1,5 @@ -# $NetBSD: shlib_version,v 1.84 2000/02/23 07:00:54 itojun Exp $ +# $NetBSD: shlib_version,v 1.85 2000/03/02 07:41:49 itojun Exp $ # Remember to update distrib/sets/lists/base/shl.* when changing # major=12 -minor=56 +minor=57 diff --git a/sys/lib/libkern/Makefile b/sys/lib/libkern/Makefile index 0665d231bd8d..e6e962a1b582 100644 --- a/sys/lib/libkern/Makefile +++ b/sys/lib/libkern/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.53 1999/05/07 14:49:52 drochner Exp $ +# $NetBSD: Makefile,v 1.54 2000/03/02 07:41:51 itojun Exp $ LIB= kern MKPIC= no @@ -23,7 +23,7 @@ SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \ .endif # Other stuff -SRCS+= inet_addr.c intoa.c md5c.c sha1.c pmatch.c +SRCS+= __cmsg_alignbytes.c inet_addr.c intoa.c md5c.c sha1.c pmatch.c # Files to clean up CLEANFILES+= lib${LIB}.o lib${LIB}.po diff --git a/sys/lib/libkern/__cmsg_alignbytes.c b/sys/lib/libkern/__cmsg_alignbytes.c new file mode 100644 index 000000000000..0f3079a26a4a --- /dev/null +++ b/sys/lib/libkern/__cmsg_alignbytes.c @@ -0,0 +1,44 @@ +/* $NetBSD: __cmsg_alignbytes.c,v 1.1 2000/03/02 07:41:51 itojun Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jun-ichiro Hagino. + * + * 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 NetBSD Foundation 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 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. + */ + +#include +#include +#include + +int +__cmsg_alignbytes() +{ + + return ALIGNBYTES; +} diff --git a/sys/sys/socket.h b/sys/sys/socket.h index a8753e0f639b..66e2d94c6d40 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $NetBSD: socket.h,v 1.50 2000/02/18 05:19:25 itojun Exp $ */ +/* $NetBSD: socket.h,v 1.51 2000/03/02 07:41:50 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -401,10 +401,14 @@ struct cmsghdr { /* * Alignment requirement for CMSG struct manipulation. - * This is different from ALIGN() defined in ARCH/include/param.h. - * XXX think again carefully about architecture dependencies. + * This basically behaves the same as ALIGN() ARCH/include/param.h. + * We declare it separately for two reasons: + * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's + * idea of ALIGNBYTES at runtime. + * without (2), we can't guarantee binary compatibility in case of future + * changes in ALIGNBYTES. */ -#define CMSG_ALIGN(n) (((n) + (sizeof(long) - 1)) & ~(sizeof(long) - 1)) +#define CMSG_ALIGN(n) (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes()) /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ #define CMSG_NXTHDR(mhdr, cmsg) \ @@ -455,6 +459,8 @@ struct omsghdr { }; #endif +int __cmsg_alignbytes __P((void)); + #ifndef _KERNEL #include