Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Feb 2011 12:28:15 +0200
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Marcel Moolenaar <xcllnt@mac.com>
Cc:        current@freebsd.org, marcel@FreeBSD.org, Pawel Jakub Dawidek <pjd@FreeBSD.org>, ia64@freebsd.org, FreeBSD Tinderbox <tinderbox@freebsd.org>
Subject:   Re: [head tinderbox] failure on ia64/ia64
Message-ID:  <20110201102815.GA1953@pm513-1.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <F3F2991E-A783-451C-95B5-3E5BC2E5772B@mac.com>
References:  <201101312256.p0VMuI6F075840@freebsd-current.sentex.ca> <20110131235153.GC1746@garage.freebsd.pl> <F3F2991E-A783-451C-95B5-3E5BC2E5772B@mac.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 31, 2011 at 04:56:06PM -0800, Marcel Moolenaar wrote:
> 
> Take the statement at line 116 for example:
> 	*((int *)CMSG_DATA(cmsg)) = fd;
> 
> We're effectively casting from a (char *) to a (int *) and then doing
> a 32-bit access (write). The easy fix (casting through (void *) is not
> possible, because you cannot guarantee that the address is properly
> aligned. cmsg points to memory set aside by the following local
> variable:
> 	unsigned char ctrl[CMSG_SPACE(sizeof(fd))];
> 
> There's no guarantee that the compiler will align the character array
> at a 32-bit boundary (though in practice it seems to be). I have seen
> this kind of construct fail on ARM and PowerPC for example.
> 

Why not to use such declaration:

	union {
		struct cmsghdr cm;
		char ctrl[CMSG_SPACE(sizeof(fd))];
	} control_un;

At least this is necessary to satisfy that CMSG_FIRSTHDR() will give
address of correctly aligned struct cmsghdr{}.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110201102815.GA1953>