Module Name:    src
Committed By:   joerg
Date:           Fri Jan 20 14:08:07 UTC 2012

Modified Files:
        src/external/bsd/tmux/dist/compat: imsg-buffer.c imsg.c
        src/external/ibm-public/postfix/dist/src/util: unix_recv_fd.c
            unix_send_fd.c
        src/lib/libc/compat/net: Makefile.inc
        src/lib/libc/net: Makefile.inc
        src/sys/arch/alpha/include: cdefs.h param.h
        src/sys/arch/amd64/include: cdefs.h param.h
        src/sys/arch/arm/include: cdefs.h param.h
        src/sys/arch/hppa/include: cdefs.h param.h
        src/sys/arch/i386/include: cdefs.h param.h
        src/sys/arch/ia64/include: cdefs.h param.h
        src/sys/arch/m68k/include: cdefs.h param.h
        src/sys/arch/mips/include: cdefs.h mips_param.h
        src/sys/arch/powerpc/include: cdefs.h param.h
        src/sys/arch/sh3/include: cdefs.h param.h
        src/sys/arch/sparc/include: cdefs.h param.h
        src/sys/arch/sparc64/include: param.h
        src/sys/arch/vax/include: cdefs.h param.h
        src/sys/compat/linux/common: linux_socket.c
        src/sys/compat/netbsd32: netbsd32_socket.c netbsd32_sysctl.c
        src/sys/sys: socket.h
Added Files:
        src/lib/libc/compat/net: __cmsg_alignbytes.c
Removed Files:
        src/common/lib/libc/net: __cmsg_alignbytes.c

Log Message:
Change CMSG_SPACE and CMSG_LEN to provide Integer Constant Expressions
again. This was changed in sys/socket.h r1.51 to work around fallout
from the IPv6 aux data migration. It broke the historic ABI on some
platforms. This commit restores compatibility for netbsd32 code on such
platforms and provides a template for future changes to the CMSG_*
alignment. Revert PCC/Clang workarounds in postfix and tmux.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r0 src/common/lib/libc/net/__cmsg_alignbytes.c
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/tmux/dist/compat/imsg-buffer.c \
    src/external/bsd/tmux/dist/compat/imsg.c
cvs rdiff -u -r1.6 -r1.7 \
    src/external/ibm-public/postfix/dist/src/util/unix_recv_fd.c
cvs rdiff -u -r1.5 -r1.6 \
    src/external/ibm-public/postfix/dist/src/util/unix_send_fd.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/compat/net/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/compat/net/__cmsg_alignbytes.c
cvs rdiff -u -r1.80 -r1.81 src/lib/libc/net/Makefile.inc
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/include/cdefs.h
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/alpha/include/param.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/amd64/include/cdefs.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/amd64/include/param.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/include/cdefs.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/include/param.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/hppa/include/cdefs.h
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/hppa/include/param.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/i386/include/cdefs.h
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/i386/include/param.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/ia64/include/cdefs.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/ia64/include/param.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/m68k/include/cdefs.h
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/m68k/include/param.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/mips/include/cdefs.h
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/mips/include/mips_param.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/powerpc/include/cdefs.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/powerpc/include/param.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/sh3/include/cdefs.h
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/sh3/include/param.h
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/sparc/include/cdefs.h
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/sparc/include/param.h
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/sparc64/include/param.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/vax/include/cdefs.h
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/vax/include/param.h
cvs rdiff -u -r1.111 -r1.112 src/sys/compat/linux/common/linux_socket.c
cvs rdiff -u -r1.38 -r1.39 src/sys/compat/netbsd32/netbsd32_socket.c
cvs rdiff -u -r1.32 -r1.33 src/sys/compat/netbsd32/netbsd32_sysctl.c
cvs rdiff -u -r1.103 -r1.104 src/sys/sys/socket.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/tmux/dist/compat/imsg-buffer.c
diff -u src/external/bsd/tmux/dist/compat/imsg-buffer.c:1.4 src/external/bsd/tmux/dist/compat/imsg-buffer.c:1.5
--- src/external/bsd/tmux/dist/compat/imsg-buffer.c:1.4	Wed Aug 31 20:13:31 2011
+++ src/external/bsd/tmux/dist/compat/imsg-buffer.c	Fri Jan 20 14:08:04 2012
@@ -1,4 +1,4 @@
-/* $Id: imsg-buffer.c,v 1.4 2011/08/31 20:13:31 plunky Exp $ */
+/* $Id: imsg-buffer.c,v 1.5 2012/01/20 14:08:04 joerg Exp $ */
 /*	$OpenBSD: imsg-buffer.c,v 1.3 2010/05/26 13:56:07 nicm Exp $	*/
 
 /*
@@ -228,11 +228,7 @@ msgbuf_write(struct msgbuf *msgbuf)
 	struct cmsghdr	*cmsg;
 	union {
 		struct cmsghdr	hdr;
-#if defined(__clang__) || defined(__PCC__)
-		char		buf[128];
-#else
 		char		buf[CMSG_SPACE(sizeof(int))];
-#endif
 	} cmsgbuf;
 
 	bzero(&iov, sizeof(iov));
Index: src/external/bsd/tmux/dist/compat/imsg.c
diff -u src/external/bsd/tmux/dist/compat/imsg.c:1.4 src/external/bsd/tmux/dist/compat/imsg.c:1.5
--- src/external/bsd/tmux/dist/compat/imsg.c:1.4	Wed Aug 31 20:13:31 2011
+++ src/external/bsd/tmux/dist/compat/imsg.c	Fri Jan 20 14:08:04 2012
@@ -1,4 +1,4 @@
-/* $Id: imsg.c,v 1.4 2011/08/31 20:13:31 plunky Exp $ */
+/* $Id: imsg.c,v 1.5 2012/01/20 14:08:04 joerg Exp $ */
 /*	$OpenBSD: imsg.c,v 1.3 2010/05/26 13:56:07 nicm Exp $	*/
 
 /*
@@ -48,11 +48,7 @@ imsg_read(struct imsgbuf *ibuf)
 	struct cmsghdr		*cmsg;
 	union {
 		struct cmsghdr hdr;
-#if defined(__clang__) || defined(__PCC__)
-		char	buf[128];
-#else
 		char	buf[CMSG_SPACE(sizeof(int) * 16)];
-#endif
 	} cmsgbuf;
 	struct iovec		 iov;
 	ssize_t			 n;

Index: src/external/ibm-public/postfix/dist/src/util/unix_recv_fd.c
diff -u src/external/ibm-public/postfix/dist/src/util/unix_recv_fd.c:1.6 src/external/ibm-public/postfix/dist/src/util/unix_recv_fd.c:1.7
--- src/external/ibm-public/postfix/dist/src/util/unix_recv_fd.c:1.6	Mon May 30 18:47:27 2011
+++ src/external/ibm-public/postfix/dist/src/util/unix_recv_fd.c	Fri Jan 20 14:08:04 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix_recv_fd.c,v 1.6 2011/05/30 18:47:27 pgoyette Exp $	*/
+/*	$NetBSD: unix_recv_fd.c,v 1.7 2012/01/20 14:08:04 joerg Exp $	*/
 
 /*++
 /* NAME
@@ -70,11 +70,7 @@ int     unix_recv_fd(int fd)
 #if defined(CMSG_SPACE) && !defined(NO_MSGHDR_MSG_CONTROL)
     union {
 	struct cmsghdr just_for_alignment;
-#  ifdef __clang__
-	char    control[128];
-#  else
 	char    control[CMSG_SPACE(sizeof(newfd))];
-#  endif
     }       control_un;
     struct cmsghdr *cmptr;
 

Index: src/external/ibm-public/postfix/dist/src/util/unix_send_fd.c
diff -u src/external/ibm-public/postfix/dist/src/util/unix_send_fd.c:1.5 src/external/ibm-public/postfix/dist/src/util/unix_send_fd.c:1.6
--- src/external/ibm-public/postfix/dist/src/util/unix_send_fd.c:1.5	Mon May 30 16:24:13 2011
+++ src/external/ibm-public/postfix/dist/src/util/unix_send_fd.c	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix_send_fd.c,v 1.5 2011/05/30 16:24:13 joerg Exp $	*/
+/*	$NetBSD: unix_send_fd.c,v 1.6 2012/01/20 14:08:05 joerg Exp $	*/
 
 /*++
 /* NAME
@@ -72,11 +72,7 @@ int     unix_send_fd(int fd, int sendfd)
 #if defined(CMSG_SPACE) && !defined(NO_MSGHDR_MSG_CONTROL)
     union {
 	struct cmsghdr just_for_alignment;
-#  ifdef __clang__
-	char    control[128];
-#  else
 	char    control[CMSG_SPACE(sizeof(sendfd))];
-#  endif
     }       control_un;
     struct cmsghdr *cmptr;
 

Index: src/lib/libc/compat/net/Makefile.inc
diff -u src/lib/libc/compat/net/Makefile.inc:1.1 src/lib/libc/compat/net/Makefile.inc:1.2
--- src/lib/libc/compat/net/Makefile.inc:1.1	Sat Aug 26 16:07:01 2006
+++ src/lib/libc/compat/net/Makefile.inc	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.1 2006/08/26 16:07:01 matt Exp $
+#	$NetBSD: Makefile.inc,v 1.2 2012/01/20 14:08:05 joerg Exp $
 
 .PATH: ${COMPATDIR}/net
-SRCS+=compat_ns_addr.c compat_ns_ntoa.c
+SRCS+=	__cmsg_alignbytes.c compat_ns_addr.c compat_ns_ntoa.c

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.80 src/lib/libc/net/Makefile.inc:1.81
--- src/lib/libc/net/Makefile.inc:1.80	Sun Dec 25 12:32:36 2011
+++ src/lib/libc/net/Makefile.inc	Fri Jan 20 14:08:05 2012
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile.inc,v 1.80 2011/12/25 12:32:36 tsutsui Exp $
+#	$NetBSD: Makefile.inc,v 1.81 2012/01/20 14:08:05 joerg Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
 .PATH: ${ARCHDIR}/net ${.CURDIR}/net
 
-SRCS+=	__cmsg_alignbytes.c base64.c ethers.c gethnamaddr.c getifaddrs.c \
+SRCS+=	base64.c ethers.c gethnamaddr.c getifaddrs.c \
 	getnetnamadr.c getnetent.c getpeereid.c \
 	getprotobyname.c getprotobynumber.c getprotoent.c \
 	getprotobyname_r.c getprotobynumber_r.c getprotoent_r.c \

Index: src/sys/arch/alpha/include/cdefs.h
diff -u src/sys/arch/alpha/include/cdefs.h:1.11 src/sys/arch/alpha/include/cdefs.h:1.12
--- src/sys/arch/alpha/include/cdefs.h:1.11	Sat Mar 20 01:40:25 1999
+++ src/sys/arch/alpha/include/cdefs.h	Fri Jan 20 14:08:05 2012
@@ -1,8 +1,8 @@
-/* $NetBSD: cdefs.h,v 1.11 1999/03/20 01:40:25 thorpej Exp $ */
+/* $NetBSD: cdefs.h,v 1.12 2012/01/20 14:08:05 joerg Exp $ */
 
 #ifndef _MACHINE_CDEFS_H_
 #define	_MACHINE_CDEFS_H_
 
-/* No arch-specific cdefs. */
+#define	__ALIGNBYTES		7
 
 #endif /* !_MACHINE_CDEFS_H_ */

Index: src/sys/arch/alpha/include/param.h
diff -u src/sys/arch/alpha/include/param.h:1.38 src/sys/arch/alpha/include/param.h:1.39
--- src/sys/arch/alpha/include/param.h:1.38	Tue Feb  8 20:20:07 2011
+++ src/sys/arch/alpha/include/param.h	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.38 2011/02/08 20:20:07 rmind Exp $ */
+/* $NetBSD: param.h,v 1.39 2012/01/20 14:08:05 joerg Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -60,7 +60,7 @@
  * (within reasonable limits). 
  *
  */
-#define	ALIGNBYTES		7
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)		(((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 

Index: src/sys/arch/amd64/include/cdefs.h
diff -u src/sys/arch/amd64/include/cdefs.h:1.2 src/sys/arch/amd64/include/cdefs.h:1.3
--- src/sys/arch/amd64/include/cdefs.h:1.2	Sun Oct 26 00:08:15 2008
+++ src/sys/arch/amd64/include/cdefs.h	Fri Jan 20 14:08:05 2012
@@ -1,8 +1,8 @@
-/*	$NetBSD: cdefs.h,v 1.2 2008/10/26 00:08:15 mrg Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.3 2012/01/20 14:08:05 joerg Exp $	*/
 
 #ifndef	_X86_64_CDEFS_H_
 #define	_X86_64_CDEFS_H_
 
-/* No arch-specific cdefs. */
+#define __ALIGNBYTES		(sizeof(long) - 1)
 
 #endif /* !_X86_64_CDEFS_H_ */

Index: src/sys/arch/amd64/include/param.h
diff -u src/sys/arch/amd64/include/param.h:1.14 src/sys/arch/amd64/include/param.h:1.15
--- src/sys/arch/amd64/include/param.h:1.14	Tue Jul 26 12:55:35 2011
+++ src/sys/arch/amd64/include/param.h	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.14 2011/07/26 12:55:35 yamt Exp $	*/
+/*	$NetBSD: param.h,v 1.15 2012/01/20 14:08:05 joerg Exp $	*/
 
 #ifdef __x86_64__
 
@@ -23,7 +23,7 @@
  * (within reasonable limits). 
  *
  */
-#define ALIGNBYTES		(sizeof(long) - 1)
+#define ALIGNBYTES		__ALIGNBYTES
 #define ALIGN(p)		(((u_long)(p) + ALIGNBYTES) &~ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	1
 

Index: src/sys/arch/arm/include/cdefs.h
diff -u src/sys/arch/arm/include/cdefs.h:1.3 src/sys/arch/arm/include/cdefs.h:1.4
--- src/sys/arch/arm/include/cdefs.h:1.3	Wed Oct 17 19:53:41 2007
+++ src/sys/arch/arm/include/cdefs.h	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.3 2007/10/17 19:53:41 garbled Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.4 2012/01/20 14:08:05 joerg Exp $	*/
 
 #ifndef	_MACHINE_CDEFS_H_
 #define	_MACHINE_CDEFS_H_
@@ -17,4 +17,6 @@
 #define _ARM_ARCH_4T
 #endif
 
+#define __ALIGNBYTES		(sizeof(int) - 1)
+
 #endif /* !_MACHINE_CDEFS_H_ */

Index: src/sys/arch/arm/include/param.h
diff -u src/sys/arch/arm/include/param.h:1.13 src/sys/arch/arm/include/param.h:1.14
--- src/sys/arch/arm/include/param.h:1.13	Thu May  6 19:10:26 2010
+++ src/sys/arch/arm/include/param.h	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.13 2010/05/06 19:10:26 joerg Exp $	*/
+/*	$NetBSD: param.h,v 1.14 2012/01/20 14:08:05 joerg Exp $	*/
 
 /*
  * Copyright (c) 1994,1995 Mark Brinicombe.
@@ -90,7 +90,7 @@
  * (within reasonable limits). 
  *
  */
-#define ALIGNBYTES		(sizeof(int) - 1)
+#define	ALIGNBYTES	__ALIGNBYTES
 #define ALIGN(p)		(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 /* ARM-specific macro to align a stack pointer (downwards). */

Index: src/sys/arch/hppa/include/cdefs.h
diff -u src/sys/arch/hppa/include/cdefs.h:1.1 src/sys/arch/hppa/include/cdefs.h:1.2
--- src/sys/arch/hppa/include/cdefs.h:1.1	Wed Jun  5 01:04:21 2002
+++ src/sys/arch/hppa/include/cdefs.h	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.1 2002/06/05 01:04:21 fredette Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.2 2012/01/20 14:08:05 joerg Exp $	*/
 
 #ifndef	_HPPA_CDEFS_H_
 #define	_HPPA_CDEFS_H_
@@ -10,4 +10,6 @@
  */
 #define __ASM_DELIMITER "\n\t"
 
+#define	__ALIGNBYTES	7
+
 #endif /* !_HPPA_CDEFS_H_ */

Index: src/sys/arch/hppa/include/param.h
diff -u src/sys/arch/hppa/include/param.h:1.15 src/sys/arch/hppa/include/param.h:1.16
--- src/sys/arch/hppa/include/param.h:1.15	Mon Feb  8 19:02:29 2010
+++ src/sys/arch/hppa/include/param.h	Fri Jan 20 14:08:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.15 2010/02/08 19:02:29 joerg Exp $	*/
+/*	$NetBSD: param.h,v 1.16 2012/01/20 14:08:05 joerg Exp $	*/
 
 /*	$OpenBSD: param.h,v 1.12 2001/07/06 02:07:41 provos Exp $	*/
 
@@ -42,7 +42,7 @@
  * data types (int, long, ...).   The result is u_int and must be cast to
  * any desired pointer type.
  */
-#define	ALIGNBYTES	7
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)	(((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 #define	ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t) - 1)) == 0)
 

Index: src/sys/arch/i386/include/cdefs.h
diff -u src/sys/arch/i386/include/cdefs.h:1.8 src/sys/arch/i386/include/cdefs.h:1.9
--- src/sys/arch/i386/include/cdefs.h:1.8	Thu Jun 16 13:27:59 2011
+++ src/sys/arch/i386/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.8 2011/06/16 13:27:59 joerg Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.9 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifndef	_I386_CDEFS_H_
 #define	_I386_CDEFS_H_
@@ -7,4 +7,6 @@
 #define	__compactcall	__attribute__((__regparm__(3)))
 #endif
 
+#define __ALIGNBYTES	(sizeof(int) - 1)
+
 #endif /* !_I386_CDEFS_H_ */

Index: src/sys/arch/i386/include/param.h
diff -u src/sys/arch/i386/include/param.h:1.72 src/sys/arch/i386/include/param.h:1.73
--- src/sys/arch/i386/include/param.h:1.72	Mon Feb  8 19:02:29 2010
+++ src/sys/arch/i386/include/param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.72 2010/02/08 19:02:29 joerg Exp $	*/
+/*	$NetBSD: param.h,v 1.73 2012/01/20 14:08:06 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -62,7 +62,7 @@
  * (within reasonable limits). 
  *
  */
-#define ALIGNBYTES		(sizeof(int) - 1)
+#define ALIGNBYTES		__ALIGNBYTES
 #define ALIGN(p)		(((u_int)(u_long)(p) + ALIGNBYTES) &~ \
     ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	1

Index: src/sys/arch/ia64/include/cdefs.h
diff -u src/sys/arch/ia64/include/cdefs.h:1.1 src/sys/arch/ia64/include/cdefs.h:1.2
--- src/sys/arch/ia64/include/cdefs.h:1.1	Fri Apr  7 14:21:18 2006
+++ src/sys/arch/ia64/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.1 2006/04/07 14:21:18 cherry Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.2 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifndef	_MACHINE_CDEFS_H_
 #define	_MACHINE_CDEFS_H_
@@ -8,4 +8,6 @@
 #define __ELF__
 #endif
 
+#define	__ALIGNBYTES		15
+
 #endif /* !_MACHINE_CDEFS_H_ */

Index: src/sys/arch/ia64/include/param.h
diff -u src/sys/arch/ia64/include/param.h:1.5 src/sys/arch/ia64/include/param.h:1.6
--- src/sys/arch/ia64/include/param.h:1.5	Sat Oct  1 15:59:28 2011
+++ src/sys/arch/ia64/include/param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.5 2011/10/01 15:59:28 chs Exp $	*/
+/*	$NetBSD: param.h,v 1.6 2012/01/20 14:08:06 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -89,7 +89,7 @@
  *
  */
 
-#define	ALIGNBYTES		15
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)		(((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 

Index: src/sys/arch/m68k/include/cdefs.h
diff -u src/sys/arch/m68k/include/cdefs.h:1.6 src/sys/arch/m68k/include/cdefs.h:1.7
--- src/sys/arch/m68k/include/cdefs.h:1.6	Sat Mar 20 01:40:26 1999
+++ src/sys/arch/m68k/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,8 +1,8 @@
-/*	$NetBSD: cdefs.h,v 1.6 1999/03/20 01:40:26 thorpej Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.7 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifndef	_M68K_CDEFS_H_
 #define	_M68K_CDEFS_H_
 
-/* No arch-specific cdefs. */
+#define __ALIGNBYTES		(sizeof(int) - 1)
 
 #endif /* !_M68K_CDEFS_H_ */

Index: src/sys/arch/m68k/include/param.h
diff -u src/sys/arch/m68k/include/param.h:1.19 src/sys/arch/m68k/include/param.h:1.20
--- src/sys/arch/m68k/include/param.h:1.19	Sat Mar  5 14:32:32 2011
+++ src/sys/arch/m68k/include/param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.19 2011/03/05 14:32:32 matt Exp $	*/
+/*	$NetBSD: param.h,v 1.20 2012/01/20 14:08:06 joerg Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -67,7 +67,7 @@
  * (within reasonable limits). 
  *
  */
-#define ALIGNBYTES		(sizeof(int) - 1)
+#define	ALIGNBYTES		__ALIGNBYTES
 #define	ALIGN(p)		(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 

Index: src/sys/arch/mips/include/cdefs.h
diff -u src/sys/arch/mips/include/cdefs.h:1.13 src/sys/arch/mips/include/cdefs.h:1.14
--- src/sys/arch/mips/include/cdefs.h:1.13	Mon Dec 14 00:46:04 2009
+++ src/sys/arch/mips/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.13 2009/12/14 00:46:04 matt Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.14 2012/01/20 14:08:06 joerg Exp $	*/
 
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
@@ -71,4 +71,6 @@
 #define	_MIPS_ISA_MIPS32	5
 #define	_MIPS_ISA_MIPS64	6
 
+#define	__ALIGNBYTES	7
+
 #endif /* !_MIPS_CDEFS_H_ */

Index: src/sys/arch/mips/include/mips_param.h
diff -u src/sys/arch/mips/include/mips_param.h:1.30 src/sys/arch/mips/include/mips_param.h:1.31
--- src/sys/arch/mips/include/mips_param.h:1.30	Thu Jan 19 20:55:38 2012
+++ src/sys/arch/mips/include/mips_param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_param.h,v 1.30 2012/01/19 20:55:38 matt Exp $	*/
+/*	$NetBSD: mips_param.h,v 1.31 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifdef _KERNEL
 #include <machine/cpu.h>
@@ -78,7 +78,7 @@
  * (within reasonable limits).
  *
  */
-#define	ALIGNBYTES	7
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGNBYTES32	ALIGNBYTES
 #define	ALIGN(p)	(((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 #define	ALIGN32(p)	(((uintptr_t)(p) + ALIGNBYTES32) & ~ALIGNBYTES32)

Index: src/sys/arch/powerpc/include/cdefs.h
diff -u src/sys/arch/powerpc/include/cdefs.h:1.6 src/sys/arch/powerpc/include/cdefs.h:1.7
--- src/sys/arch/powerpc/include/cdefs.h:1.6	Sun Nov  3 22:36:22 2002
+++ src/sys/arch/powerpc/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,8 +1,8 @@
-/*	$NetBSD: cdefs.h,v 1.6 2002/11/03 22:36:22 matt Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.7 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifndef	_POWERPC_CDEFS_H_
 #define	_POWERPC_CDEFS_H_
 
-/* No arch-specific cdefs. */
+#define	__ALIGNBYTES	(sizeof(double) - 1)
 
 #endif /* !_POWERPC_CDEFS_H_ */

Index: src/sys/arch/powerpc/include/param.h
diff -u src/sys/arch/powerpc/include/param.h:1.24 src/sys/arch/powerpc/include/param.h:1.25
--- src/sys/arch/powerpc/include/param.h:1.24	Mon Jun 20 06:29:54 2011
+++ src/sys/arch/powerpc/include/param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.24 2011/06/20 06:29:54 matt Exp $	*/
+/*	$NetBSD: param.h,v 1.25 2012/01/20 14:08:06 joerg Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -53,7 +53,7 @@
 #define	MACHINE_ARCH	"powerpc"
 #define	MID_MACHINE	MID_POWERPC
 
-#define	ALIGNBYTES		(sizeof(double) - 1)
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)		(((u_long)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 #define	ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 

Index: src/sys/arch/sh3/include/cdefs.h
diff -u src/sys/arch/sh3/include/cdefs.h:1.5 src/sys/arch/sh3/include/cdefs.h:1.6
--- src/sys/arch/sh3/include/cdefs.h:1.5	Sun Apr 28 17:10:33 2002
+++ src/sys/arch/sh3/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,8 +1,10 @@
-/*	$NetBSD: cdefs.h,v 1.5 2002/04/28 17:10:33 uch Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.6 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifndef _SH3_CDEFS_H_
 #define	_SH3_CDEFS_H_
 
+#define	__ALIGNBYTES		(sizeof(int) - 1)
+
 /*
  * The old NetBSD/sh3 ELF toolchain used underscores.  The new
  * NetBSD/sh3 ELF toolchain does not.  The C pre-processor

Index: src/sys/arch/sh3/include/param.h
diff -u src/sys/arch/sh3/include/param.h:1.20 src/sys/arch/sh3/include/param.h:1.21
--- src/sys/arch/sh3/include/param.h:1.20	Mon Feb  8 19:02:31 2010
+++ src/sys/arch/sh3/include/param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.20 2010/02/08 19:02:31 joerg Exp $	*/
+/*	$NetBSD: param.h,v 1.21 2012/01/20 14:08:06 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
@@ -62,7 +62,7 @@
  * (within reasonable limits).
  *
  */
-#define	ALIGNBYTES		(sizeof(int) - 1)
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)		(((u_int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 #define	ALIGNED_POINTER(p, t)	((((u_long)(p)) & (sizeof(t) - 1)) == 0)
 

Index: src/sys/arch/sparc/include/cdefs.h
diff -u src/sys/arch/sparc/include/cdefs.h:1.11 src/sys/arch/sparc/include/cdefs.h:1.12
--- src/sys/arch/sparc/include/cdefs.h:1.11	Sun Dec 11 12:19:05 2005
+++ src/sys/arch/sparc/include/cdefs.h	Fri Jan 20 14:08:06 2012
@@ -1,8 +1,13 @@
-/*	$NetBSD: cdefs.h,v 1.11 2005/12/11 12:19:05 christos Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.12 2012/01/20 14:08:06 joerg Exp $	*/
 
 #ifndef	_MACHINE_CDEFS_H_
 #define	_MACHINE_CDEFS_H_
 
 /* No arch-specific cdefs. */
+#ifdef __arch64__
+#define	__ALIGNBYTES		0xf
+#else
+#define	__ALIGNBYTES		0x7
+#endif
 
 #endif /* !_MACHINE_CDEFS_H_ */

Index: src/sys/arch/sparc/include/param.h
diff -u src/sys/arch/sparc/include/param.h:1.67 src/sys/arch/sparc/include/param.h:1.68
--- src/sys/arch/sparc/include/param.h:1.67	Mon Feb  8 19:02:31 2010
+++ src/sys/arch/sparc/include/param.h	Fri Jan 20 14:08:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.67 2010/02/08 19:02:31 joerg Exp $ */
+/*	$NetBSD: param.h,v 1.68 2012/01/20 14:08:06 joerg Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -68,7 +68,7 @@
  * (within reasonable limits). 
  *
  */
-#define	ALIGNBYTES		7
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)		(((u_int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 

Index: src/sys/arch/sparc64/include/param.h
diff -u src/sys/arch/sparc64/include/param.h:1.45 src/sys/arch/sparc64/include/param.h:1.46
--- src/sys/arch/sparc64/include/param.h:1.45	Thu May 12 05:41:50 2011
+++ src/sys/arch/sparc64/include/param.h	Fri Jan 20 14:08:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.45 2011/05/12 05:41:50 mrg Exp $ */
+/*	$NetBSD: param.h,v 1.46 2012/01/20 14:08:07 joerg Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -100,11 +100,7 @@
  */
 #define ALIGNBYTES32		0x7
 #define ALIGNBYTES64		0xf
-#ifdef __arch64__
-#define	ALIGNBYTES		ALIGNBYTES64
-#else
-#define	ALIGNBYTES		ALIGNBYTES32
-#endif
+#define	ALIGNBYTES	__ALIGNBYTES
 #define	ALIGN(p)		(((u_long)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 #define ALIGN32(p)		(((u_long)(p) + ALIGNBYTES32) & ~ALIGNBYTES32)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)

Index: src/sys/arch/vax/include/cdefs.h
diff -u src/sys/arch/vax/include/cdefs.h:1.6 src/sys/arch/vax/include/cdefs.h:1.7
--- src/sys/arch/vax/include/cdefs.h:1.6	Sat Mar 20 01:40:27 1999
+++ src/sys/arch/vax/include/cdefs.h	Fri Jan 20 14:08:07 2012
@@ -1,8 +1,8 @@
-/*	$NetBSD: cdefs.h,v 1.6 1999/03/20 01:40:27 thorpej Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.7 2012/01/20 14:08:07 joerg Exp $	*/
 
 #ifndef	_MACHINE_CDEFS_H_
 #define	_MACHINE_CDEFS_H_
 
-/* No arch-specific cdefs. */
+#define	__ALIGNBYTES		(sizeof(int) - 1)
 
 #endif /* !_MACHINE_CDEFS_H_ */

Index: src/sys/arch/vax/include/param.h
diff -u src/sys/arch/vax/include/param.h:1.58 src/sys/arch/vax/include/param.h:1.59
--- src/sys/arch/vax/include/param.h:1.58	Mon Feb  8 19:02:32 2010
+++ src/sys/arch/vax/include/param.h	Fri Jan 20 14:08:07 2012
@@ -1,4 +1,4 @@
-/*      $NetBSD: param.h,v 1.58 2010/02/08 19:02:32 joerg Exp $    */
+/*      $NetBSD: param.h,v 1.59 2012/01/20 14:08:07 joerg Exp $    */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -58,7 +58,7 @@
  *
  */
 
-#define ALIGNBYTES		(sizeof(int) - 1)
+#define ALIGNBYTES		__ALIGNBYTES
 #define ALIGN(p)		(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
 

Index: src/sys/compat/linux/common/linux_socket.c
diff -u src/sys/compat/linux/common/linux_socket.c:1.111 src/sys/compat/linux/common/linux_socket.c:1.112
--- src/sys/compat/linux/common/linux_socket.c:1.111	Tue Dec 20 23:56:28 2011
+++ src/sys/compat/linux/common/linux_socket.c	Fri Jan 20 14:08:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_socket.c,v 1.111 2011/12/20 23:56:28 christos Exp $	*/
+/*	$NetBSD: linux_socket.c,v 1.112 2012/01/20 14:08:07 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.111 2011/12/20 23:56:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.112 2012/01/20 14:08:07 joerg Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -595,11 +595,11 @@ linux_sys_sendmsg(struct lwp *l, const s
 
 			/* Zero area between header and data */
 			memset(cmsg + 1, 0, 
-				CMSG_ALIGN(sizeof(cmsg)) - sizeof(cmsg));
+				CMSG_ALIGN(sizeof(*cmsg)) - sizeof(*cmsg));
 
 			/* Copyin the data */
 			error = copyin(LINUX_CMSG_DATA(l_cc),
-				CMSG_DATA(control),
+				CMSG_DATA(cmsg),
 				l_cmsg.cmsg_len - sizeof(l_cmsg));
 			if (error)
 				goto done;

Index: src/sys/compat/netbsd32/netbsd32_socket.c
diff -u src/sys/compat/netbsd32/netbsd32_socket.c:1.38 src/sys/compat/netbsd32/netbsd32_socket.c:1.39
--- src/sys/compat/netbsd32/netbsd32_socket.c:1.38	Fri Jan 13 21:02:03 2012
+++ src/sys/compat/netbsd32/netbsd32_socket.c	Fri Jan 20 14:08:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_socket.c,v 1.38 2012/01/13 21:02:03 joerg Exp $	*/
+/*	$NetBSD: netbsd32_socket.c,v 1.39 2012/01/20 14:08:07 joerg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.38 2012/01/13 21:02:03 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.39 2012/01/20 14:08:07 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -49,9 +49,113 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_soc
 #include <compat/netbsd32/netbsd32_conv.h>
 
 /*
- * XXX Assumes that sockaddr is compatible.
- * XXX Assumes that copyout_msg_control uses identical alignment.
+ * XXX Assumes that struct sockaddr is compatible.
  */
+
+#define	CMSG32_ALIGN(n)	(((n) + ALIGNBYTES32) & ~ALIGNBYTES32)
+#define	CMSG32_DATA(cmsg) \
+	((u_char *)(void *)(cmsg) + CMSG32_ALIGN(sizeof(struct cmsghdr)))
+
+#define	CMSG32_NXTHDR(mhdr, cmsg)	\
+	(((char *)(cmsg) + CMSG32_ALIGN((cmsg)->cmsg_len) + \
+			    CMSG32_ALIGN(sizeof(struct cmsghdr)) > \
+	    (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
+	    (struct cmsghdr *)0 : \
+	    (struct cmsghdr *)((char *)(cmsg) + \
+	        CMSG32_ALIGN((cmsg)->cmsg_len)))
+#define	CMSG32_FIRSTHDR(mhdr) \
+	((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
+	 (struct cmsghdr *)(mhdr)->msg_control : \
+	 (struct cmsghdr *)0)
+
+#define CMSG32_SPACE(l)	(CMSG32_ALIGN(sizeof(struct cmsghdr)) + CMSG32_ALIGN(l))
+#define CMSG32_LEN(l)	(CMSG32_ALIGN(sizeof(struct cmsghdr)) + (l))
+
+static int
+copyout32_msg_control_mbuf(struct lwp *l, struct msghdr *mp, int *len, struct mbuf *m, char **q, bool *truncated)
+{
+	struct cmsghdr *cmsg, cmsg32;
+	int i, j, error;
+
+	*truncated = false;
+	cmsg = mtod(m, struct cmsghdr *);
+	do {
+		if ((char *)cmsg == mtod(m, char *) + m->m_len)
+			break;
+		if ((char *)cmsg > mtod(m, char *) + m->m_len - sizeof(*cmsg))
+			return EINVAL;
+		cmsg32 = *cmsg;
+		j = cmsg->cmsg_len - CMSG_LEN(0);
+		i = cmsg32.cmsg_len = CMSG32_LEN(j);
+		if (i > *len) {
+			mp->msg_flags |= MSG_CTRUNC;
+			if (cmsg->cmsg_level == SOL_SOCKET
+			    && cmsg->cmsg_type == SCM_RIGHTS) {
+				*truncated = true;
+				return 0;
+			}
+			j -= i - *len;
+			i = *len;
+		}
+
+		ktrkuser("msgcontrol", cmsg, cmsg->cmsg_len);
+		error = copyout(&cmsg32, *q, MAX(i, sizeof(cmsg32)));
+		if (error)
+			return (error);
+		if (i > CMSG32_LEN(0)) {
+			error = copyout(CMSG_DATA(cmsg), *q + CMSG32_LEN(0), i - CMSG32_LEN(0));
+			if (error)
+				return (error);
+		}
+		j = CMSG32_SPACE(cmsg->cmsg_len - CMSG_LEN(0));
+		if (*len >= j) {
+			*len -= j;
+			*q += j;
+		} else {
+			*q += i;
+			*len = 0;
+		}
+		cmsg = (void *)((char *)cmsg + CMSG_ALIGN(cmsg->cmsg_len));
+	} while (*len > 0);
+
+	return 0;
+}
+
+static int
+copyout32_msg_control(struct lwp *l, struct msghdr *mp, struct mbuf *control)
+{
+	int len, error = 0;
+	struct mbuf *m;
+	char *q;
+	bool truncated;
+
+	len = mp->msg_controllen;
+	if (len <= 0 || control == 0) {
+		mp->msg_controllen = 0;
+		free_control_mbuf(l, control, control);
+		return 0;
+	}
+
+	q = (char *)mp->msg_control;
+
+	for (m = control; m != NULL; m = m->m_next) {
+		error = copyout32_msg_control_mbuf(l, mp, &len, m, &q, &truncated);
+		if (truncated) {
+			m = control;
+			break;
+		}
+		if (error)
+			break;
+		if (len <= 0)
+			break;
+	}
+
+	free_control_mbuf(l, control, m);
+
+	mp->msg_controllen = q - (char *)mp->msg_control;
+	return error;
+}
+
 int
 netbsd32_recvmsg(struct lwp *l, const struct netbsd32_recvmsg_args *uap, register_t *retval)
 {
@@ -97,7 +201,7 @@ netbsd32_recvmsg(struct lwp *l, const st
 		goto done;
 
 	if (msg.msg_control != NULL)
-		error = copyout_msg_control(l, &msg, control);
+		error = copyout32_msg_control(l, &msg, control);
 
 	if (error == 0)
 		error = copyout_sockname(msg.msg_name, &msg.msg_namelen, 0,
@@ -118,6 +222,107 @@ netbsd32_recvmsg(struct lwp *l, const st
 	return (error);
 }
 
+static int
+copyin32_msg_control(struct lwp *l, struct msghdr *mp)
+{
+	/*
+	 * Handle cmsg if there is any.
+	 */
+	struct cmsghdr *cmsg, cmsg32, *cc;
+	struct mbuf *ctl_mbuf;
+	ssize_t resid = mp->msg_controllen;
+	size_t clen, cidx = 0, cspace;
+	u_int8_t *control;
+	int error;
+
+	ctl_mbuf = m_get(M_WAIT, MT_CONTROL);
+	clen = MLEN;
+	control = mtod(ctl_mbuf, void *);
+	memset(control, 0, clen);
+
+	cc = CMSG32_FIRSTHDR(mp);
+	do {
+		error = copyin(cc, &cmsg32, sizeof(cmsg32));
+		if (error)
+			goto failure;
+
+		/*
+		 * Sanity check the control message length.
+		 */
+		if (cmsg32.cmsg_len > resid ||
+		    cmsg32.cmsg_len < sizeof(cmsg32)) {
+			error = EINVAL;
+			goto failure;
+		}
+
+		cspace = CMSG_SPACE(cmsg32.cmsg_len - CMSG32_LEN(0));
+
+		/* Check the buffer is big enough */
+		if (__predict_false(cidx + cspace > clen)) {
+			u_int8_t *nc;
+			size_t nclen;
+
+			nclen = cidx + cspace;
+			if (nclen >= PAGE_SIZE) {
+				error = EINVAL;
+				goto failure;
+			}
+			nc = realloc(clen <= MLEN ? NULL : control,
+				     nclen, M_TEMP, M_WAITOK);
+			if (!nc) {
+				error = ENOMEM;
+				goto failure;
+			}
+			if (cidx <= MLEN) {
+				/* Old buffer was in mbuf... */
+				memcpy(nc, control, cidx);
+				memset(nc + cidx, 0, nclen - cidx);
+			} else {
+				memset(nc + nclen, 0, nclen - clen);
+			}
+			control = nc;
+			clen = nclen;
+		}
+
+		/* Copy header */
+		cmsg = (void *)&control[cidx];
+		cmsg->cmsg_len = CMSG_LEN(cmsg32.cmsg_len - CMSG32_LEN(0));
+		cmsg->cmsg_level = cmsg32.cmsg_level;
+		cmsg->cmsg_type = cmsg32.cmsg_type;
+
+		/* Copyin the data */
+		error = copyin(CMSG32_DATA(cc), CMSG_DATA(cmsg),
+		    cmsg32.cmsg_len - CMSG32_LEN(0));
+		if (error)
+			goto failure;
+
+		resid -= CMSG32_ALIGN(cmsg32.cmsg_len);
+		cidx += cmsg->cmsg_len;
+	} while ((cc = CMSG32_NXTHDR(mp, cc)) && resid > 0);
+
+	/* If we allocated a buffer, attach to mbuf */
+	if (cidx > MLEN) {
+		MEXTADD(ctl_mbuf, control, clen, M_MBUF, NULL, NULL);
+		ctl_mbuf->m_flags |= M_EXT_RW;
+	}
+	control = NULL;
+	mp->msg_controllen = ctl_mbuf->m_len = CMSG_ALIGN(cidx);
+
+	mp->msg_control = ctl_mbuf;
+	mp->msg_flags |= MSG_CONTROLMBUF;
+
+	ktrkuser("msgcontrol", mtod(ctl_mbuf, void *),
+	    mp->msg_controllen);
+
+	return 0;
+
+failure:
+	if (control != mtod(ctl_mbuf, void *))
+		free(control, M_MBUF);
+	m_free(ctl_mbuf);
+	return error;
+}
+
 int
 netbsd32_sendmsg(struct lwp *l, const struct netbsd32_sendmsg_args *uap, register_t *retval)
 {
@@ -137,6 +342,16 @@ netbsd32_sendmsg(struct lwp *l, const st
 	if (error)
 		return (error);
 	netbsd32_to_msghdr(&msg32, &msg);
+	msg.msg_flags = 0;
+
+	if (CMSG32_FIRSTHDR(&msg)) {
+		error = copyin32_msg_control(l, &msg);
+		if (error)
+			return (error);
+	} else {
+		msg.msg_control = NULL;
+		msg.msg_controllen = 0;
+	}
 
 	iovsz = msg.msg_iovlen * sizeof(struct iovec);
 	if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
@@ -151,10 +366,7 @@ netbsd32_sendmsg(struct lwp *l, const st
 	if (error)
 		goto done;
 	msg.msg_iov = iov;
-	msg.msg_flags = 0;
 
-	/* Luckily we can use this directly */
-	/* XXX: dsl (June'07) The cmsg alignment rules differ ! */
 	error = do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
 done:
 	if (iov != aiov)

Index: src/sys/compat/netbsd32/netbsd32_sysctl.c
diff -u src/sys/compat/netbsd32/netbsd32_sysctl.c:1.32 src/sys/compat/netbsd32/netbsd32_sysctl.c:1.33
--- src/sys/compat/netbsd32/netbsd32_sysctl.c:1.32	Mon May 23 21:34:01 2011
+++ src/sys/compat/netbsd32/netbsd32_sysctl.c	Fri Jan 20 14:08:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_sysctl.c,v 1.32 2011/05/23 21:34:01 joerg Exp $	*/
+/*	$NetBSD: netbsd32_sysctl.c,v 1.33 2012/01/20 14:08:07 joerg Exp $	*/
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.32 2011/05/23 21:34:01 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.33 2012/01/20 14:08:07 joerg Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -141,6 +141,11 @@ netbsd32_sysctl_init(void)
 		       NULL, 0, NULL, 0,
 		       CTL_HW, CTL_EOL);
 	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
+		       CTLTYPE_INT, "alignbytes", NULL,
+		       NULL, ALIGNBYTES32, NULL, 0,
+		       CTL_HW, HW_ALIGNBYTES, CTL_EOL);
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "machine", NULL,
 		       NULL, 0, __UNCONST(&machine32), 0,

Index: src/sys/sys/socket.h
diff -u src/sys/sys/socket.h:1.103 src/sys/sys/socket.h:1.104
--- src/sys/sys/socket.h:1.103	Fri Jan 20 01:17:01 2012
+++ src/sys/sys/socket.h	Fri Jan 20 14:08:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: socket.h,v 1.103 2012/01/20 01:17:01 joerg Exp $	*/
+/*	$NetBSD: socket.h,v 1.104 2012/01/20 14:08:07 joerg Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -531,11 +531,9 @@ struct cmsghdr {
  * without (2), we can't guarantee binary compatibility in case of future
  * changes in ALIGNBYTES.
  */
+#define __CMSG_ALIGN(n)	(((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
 #ifdef _KERNEL
-#define __CMSG_ALIGN(n)	(((n) + ALIGNBYTES) & ~ALIGNBYTES)
 #define CMSG_ALIGN(n)	__CMSG_ALIGN(n)
-#else
-#define __CMSG_ALIGN(n)	(((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes())
 #endif
 
 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
@@ -576,12 +574,6 @@ struct cmsghdr {
 
 #include <sys/cdefs.h>
 
-#ifndef	_KERNEL
-__BEGIN_DECLS
-int	__cmsg_alignbytes(void) __constfunc;
-__END_DECLS
-#endif
-
 #ifdef	_KERNEL
 static inline socklen_t
 sockaddr_getlen(const struct sockaddr *sa)

Added files:

Index: src/lib/libc/compat/net/__cmsg_alignbytes.c
diff -u /dev/null src/lib/libc/compat/net/__cmsg_alignbytes.c:1.1
--- /dev/null	Fri Jan 20 14:08:08 2012
+++ src/lib/libc/compat/net/__cmsg_alignbytes.c	Fri Jan 20 14:08:05 2012
@@ -0,0 +1,68 @@
+/*	$NetBSD: __cmsg_alignbytes.c,v 1.1 2012/01/20 14:08:05 joerg 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.
+ *
+ * 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 <sys/cdefs.h>
+__RCSID("$NetBSD: __cmsg_alignbytes.c,v 1.1 2012/01/20 14:08:05 joerg Exp $");
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+
+int __cmsg_alignbytes(void);
+
+int
+__cmsg_alignbytes(void)
+{
+	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, (u_int) (sizeof(mib) / sizeof(mib[0])),
+	    (void *)&alignbytes, &len, NULL, (size_t)0);
+	if (ret >= 0 && alignbytes >= 0)
+		return alignbytes;
+#endif
+	/* last resort */
+	alignbytes = ALIGNBYTES;
+	return alignbytes;
+}

Reply via email to