From owner-freebsd-questions@FreeBSD.ORG Sun Jan 28 18:37:37 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E30D816A401 for ; Sun, 28 Jan 2007 18:37:37 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 5D03313C4B4 for ; Sun, 28 Jan 2007 18:37:37 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (dsl-88-218-3-137.customers.vivodi.gr [88.218.3.137]) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-3) with ESMTP id l0SIb8I6027809 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 28 Jan 2007 20:37:15 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.13.8/8.13.8) with ESMTP id l0SIb2DO088524; Sun, 28 Jan 2007 20:37:02 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.13.8/8.13.8/Submit) id l0SIawiV088523; Sun, 28 Jan 2007 20:36:58 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Sun, 28 Jan 2007 20:36:58 +0200 From: Giorgos Keramidas To: usleepless@gmail.com Message-ID: <20070128183657.GA88428@kobe.laptop> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.606, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.59, BAYES_00 -2.60, DNS_FROM_RFC_ABUSE 0.20) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-questions@freebsd.org Subject: Re: structure alignment problems X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Jan 2007 18:37:38 -0000 On 2007-01-28 12:24, usleepless@gmail.com wrote: > Hi, > i am working on getting mythtv-0.20 talking to the pvrxxx driver. > > the problem appears when i want to do: > v4l2_capabilities vcap; > ioctl(videofd, VIDIOC_QUERYCAP, &vcap); > > the driver and mythtv have the struct differently aligned, and i get > an "inappropiate ioctl for device". this is what the struct + IOR look > like: Welcome to the world of structure alignment issues :) > struct v4l2_capability > { > __u8 driver[16]; /* i.e. "bttv" */ > __u8 card[32]; /* i.e. "Hauppauge WinTV" */ > __u8 bus_info[32]; /* "PCI:" + pci_name(pci_dev) */ > __u32 version; /* should use KERNEL_VERSION() */ > __u32 capabilities; /* Device capabilities */ > __u32 reserved[4]; > }; > #define VIDIOC_QUERYCAP _IOR ('V', 0, struct v4l2_capability) > > the driver is compiled like this: > > cc -O -pipe -Werror -D_KERNEL -DKLD_MODULE -nostdinc -I- -I../../.. > -I. -I@ -I@/contrib/altq -I@/../include -finline-limit=8000 > -fno-common -fno-omit-frame-pointer -mcmodel=kernel -mno-red-zone > -mfpmath=387 -mno-sse -mno-sse2 -mno-mmx -mno-3dnow -msoft-float > -fno-asynchronous-unwind-tables -ffreestanding -Wall -Wredundant-decls > -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes > -Wpointer-arith -Winline -Wcast-qual -fformat-extensions -std=c99 -c > /usr/ports/multimedia/pvrxxx/work/modules/cxm/cxm/../../../dev/cxm/cxm.c > > it yields a struct-size of 104 bytes. > > mythtv is compiled like this: > > g++ -c -pipe -I/usr/local/include/artsc -D_REENTRANT > -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -g > -Wall -W -O2 -pthread -Wall -Wno-switch -fomit-frame-pointer > -I/usr/local/include/freetype2 -I/usr/local/include -DPIC -fPIC > -DUSING_FREEBOX -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 > -DPREFIX=\"/usr/local\" -DLIBDIR=\"/usr/local/lib\" > -D_LARGEFILE_SOURCE -DUSING_OSS -DUSING_H264TOOLS -DUSING_XV > -DUSING_FRONTEND -DUSING_CRC_IP_NETWORK_REC -DUSING_V4L -DUSING_DBOX2 > -DUSING_FREEBOX -DUSING_HDHOMERUN -DUSING_IVTV -DUSING_BACKEND > -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT > -I/usr/local/share/qt/mkspecs/freebsd-g++ -I. > -I../../../../../../../local/include > -I../../../../../../../X11R6/include -I../.. -I.. -I../libmyth > -I../libavcodec -I../libavutil -I../libmythmpeg2 -Idvbdev -Impeg > -I../libmythlivemedia/BasicUsageEnvironment/include > -I../libmythlivemedia/groupsock/include > -I../libmythlivemedia/liveMedia/include > -I../libmythlivemedia/UsageEnvironment/include > -I../../../../../../../local/include -I/usr/X11R6/include -o > cardutil.o cardutil.cpp > > and it yields a struct-size of 128. > > is it the -std=c99? is it because this is on amd64? Most probably it's the -O2 flag, because -O2 enables -fstrict-aliasing on top of the usual -O optimizations. You can probably disable this per-structure, by using the special __packed macro for this structure when building both the kernel *and* userland structures.