Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jul 2013 21:01:13 +0200
From:      =?utf-8?Q?Hans_Petter_Selasky?= <hans.petter.selasky@bitfrost.no>
To:        =?utf-8?Q?Damjan_Jovanovic?= <damjan.jov@gmail.com>
Cc:        =?utf-8?Q?freebsd-usb=40freebsd=2Eorg?= <freebsd-usb@freebsd.org>
Subject:   RE: COMPAT_32BIT libusb ABI problem
Message-ID:  <zarafa.51f175f9.25d7.1ecfc86c5d6b39b6@mail.lockless.no>
In-Reply-To: <CAJm2B-nBTKUw42U_6OkLoYEZg8Fwd9J1zeVwZvgEj5Z_gLscrg@mail.gmail.com>
References:  <CAJm2B-mfidBre0tCwJg=6OirBtdgvxCTrGGVX-3kqQ8vYf1kFw@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

Hi,



LibUSB 32-bit is compiled using -m32 in a 64-bit environment. What happens when you pass -m32 to the compiler?



Thank you for your report.



Another alternative is to use __packed attribute, but that has some implications too.



--HPS

 

-----Original message-----

> From:Damjan Jovanovic <damjan.jov@gmail.com <mailto:damjan.jov@gmail.com> >

> Sent: Thursday 25th July 2013 20:55

> To: Hans Petter Selasky <hans.petter.selasky@bitfrost.no <mailto:hans.petter.selasky@bitfrost.no> >

> Cc: freebsd-usb@freebsd.org <mailto:freebsd-usb@freebsd.org> 

> Subject: Re: COMPAT_32BIT libusb ABI problem

> 

> On Thu, Jul 25, 2013 at 6:11 AM, Hans Petter Selasky <hps@bitfrost.no <mailto:hps@bitfrost.no> > wrote:

> > On 07/24/13 22:09, Damjan Jovanovic wrote:

> >>

> >> Hi

> >>

> >> The ioctl:

> >> #define USB_FS_INIT             _IOW ('U', 195, struct usb_fs_init)

> >> when used by a COMPAT_32BIT libusb on amd64, fails (causing

> >> libusb_open() to fail) due to:

> >>

> >> freebsd32_ioctl(0x6,0x800c55c3,0xffffc710,0x0,0x0,0x0) ERR#25

> >> 'Inappropriate ioctl for device'

> >> but when hacked a bit:

> >> freebsd32_ioctl(0x6,0x801055c3,0xffffc710,0x0,0x0,0x0) = 0 (0x0)

> >>

> >> because sizeof(struct usb_fs_init) is 12 bytes on i386, and 16 bytes on

> >> amd64.

> >>

> >> But the failure of even libusb_open() - a fundamental libusb function

> >> - must mean that the COMPAT_32BIT libusb never worked. Can we please

> >> take this opportunity to kill it and do a real 32 bit compatibility

> >> layer in the kernel that will work from 32 bit chroots and statically

> >> linked 32 bit binaries? I'll help.

> >

> >

> > Hi,

> >

> > How did you compile it? Is the structure the same size, compiled with GCC

> > and LLVM?

> 

> GCC 4.2.1

> "gcc file.c -o file -lusb" in a 32 bit chroot = 12 bytes

> "gcc file.c -o file -lusb" 64 bit = 16 bytes

> 

> Clang 3.1

> "clang file.c -o file -lusb" in a 32 bit chroot = 12 bytes

> "clang file.c -o file -lusb" 64 bit = 16 bytes

> 

> The "uint8_t ep_index_max" field at the end of struct usb_fs_init must

> be getting padded to a 4 byte boundary on 32 bit, and 8 byte boundary

> on 64 bit.

> 

> > The LIB32 for USB has been tested. I did a quick test and found on 9-stable:

> >

> > cc -m32 -I . -L /usr/lib32 -lusb usbconfig.c dump.c

> > env LD_PRELOAD=/usr/lib32/libusb.so ./a.out

> > ugen0.1: <UHCI root HUB Intel> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps)

> > pwr=SAVE (0mA)

> > ugen1.1: <UHCI root HUB Intel> at usbus1, cfg=0 md=HOST spd=FULL (12Mbps)

> > pwr=SAVE (0mA)

> >

> > ...

> 

> But usbconfig uses the libusb20 API and never seems to get to that broken ioctl.

> 

> > Your approach requires much more code. It is not just about some structures,

> > but also about code accessing those structures. Feel free to submit a patch

> > however.

> 

> I'll see what I can do.

> 

> > I would rather fix this by adding the proper __aligned() to the structures

> > in question.

> 

> Do that in the meanwhile?

> 

> > --HPS

> >

> 

> Damjan

> 




From owner-freebsd-usb@FreeBSD.ORG  Fri Jul 26 02:03:11 2013
Return-Path: <owner-freebsd-usb@FreeBSD.ORG>
Delivered-To: freebsd-usb@smarthost.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTP id 14292360;
 Fri, 26 Jul 2013 02:03:11 +0000 (UTC)
 (envelope-from linimon@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org
 [IPv6:2001:1900:2254:206c::16:87])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id DAEDE2BDF;
 Fri, 26 Jul 2013 02:03:10 +0000 (UTC)
Received: from freefall.freebsd.org (localhost [127.0.0.1])
 by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6Q23AU3089500;
 Fri, 26 Jul 2013 02:03:10 GMT
 (envelope-from linimon@freefall.freebsd.org)
Received: (from linimon@localhost)
 by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6Q23Axa089499;
 Fri, 26 Jul 2013 02:03:10 GMT (envelope-from linimon)
Date: Fri, 26 Jul 2013 02:03:10 GMT
Message-Id: <201307260203.r6Q23Axa089499@freefall.freebsd.org>
To: linimon@FreeBSD.org, freebsd-bugs@FreeBSD.org, freebsd-usb@FreeBSD.org
From: linimon@FreeBSD.org
Subject: Re: usb/180837: [scsi_da] [patch] Kingston DT 101 G2 usb stick quirk
 (scsi_da quirk)
X-BeenThere: freebsd-usb@freebsd.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: FreeBSD support for USB <freebsd-usb.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/freebsd-usb>,
 <mailto:freebsd-usb-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-usb>;
List-Post: <mailto:freebsd-usb@freebsd.org>
List-Help: <mailto:freebsd-usb-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-usb>,
 <mailto:freebsd-usb-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Jul 2013 02:03:11 -0000

Old Synopsis: QUIRK: Kingston DT 101 G2 usb stick (scsi_da quirk)
New Synopsis: [scsi_da] [patch] Kingston DT 101 G2 usb stick quirk (scsi_da quirk)

Responsible-Changed-From-To: freebsd-bugs->freebsd-usb
Responsible-Changed-By: linimon
Responsible-Changed-When: Fri Jul 26 02:02:33 UTC 2013
Responsible-Changed-Why:
Over to maintainer(s).

http://www.freebsd.org/cgi/query-pr.cgi?pr0837


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?zarafa.51f175f9.25d7.1ecfc86c5d6b39b6>