From owner-freebsd-usb@FreeBSD.ORG Thu Jul 25 18:55:03 2013 Return-Path: Delivered-To: freebsd-usb@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 29738C33 for ; Thu, 25 Jul 2013 18:55:03 +0000 (UTC) (envelope-from damjan.jov@gmail.com) Received: from mail-wi0-x22a.google.com (mail-wi0-x22a.google.com [IPv6:2a00:1450:400c:c05::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AB18929CA for ; Thu, 25 Jul 2013 18:55:02 +0000 (UTC) Received: by mail-wi0-f170.google.com with SMTP id ey16so11335wid.5 for ; Thu, 25 Jul 2013 11:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=5L9jsCfSd8pHu0/fDWTdlHDjzCUtMoVeNVGohBTuEJg=; b=emo24NJI8IiWu3ENCjPHutoaAJwGvKqtY46xOZl6ORKuH5Il/GVmZ/3rRvztoBZrVo /C6Hp8rEa5FgydhSZF1fpHOx48zvYyG80tVnfkdzQmeK4Khf2ZbmD3nQmoy7yCl2JjMA qQQU1ylvCUjsC0joTw/OtIh1Fn3soyhIg8ylLJZbohLPAPActD+4PBFxaURxDeXkYWum yey57Ro/37N/PW75++g9YL2phkJWcGLcBRFsI4b98RXWV/Ptu4uUjXiaE1uIZNF5Abgu 0WaTjx6/K9A34W/hsQj+eq6sepGUc4oDBpbBw65FvA+MrG2zVMmPb0A1BCu2pBf7LWTE Vkhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=5L9jsCfSd8pHu0/fDWTdlHDjzCUtMoVeNVGohBTuEJg=; b=c/TzDLfg65XktGuzD3+vXKCrcCk+hhAgo0VBSYqWLKgGPy6a7NG0RjPUMAwIZEHJPm oFX4JQtO26C3IbqdqRyJbU3JJi3r+7uatEYnPKvfN/+SoChVAAeifnGuXoDzpBZQ3U5f i6A0YtbM1vBSOOdzvQ04qlskiU6UWTphLs2wogyte7gsML+F/lZZcVb32FzYsdfYHWcI cvaoCeI9Tq9phal8waCr3/YOoASpaGUpO/sPnjbtnce+6V4h1ogM3k+ULk2dmxZ85y6V 4flexGsCzKE4ZQQWZg5j0YobZqui2SLmOFhhXz2fyUHe1zEXFxfJngUuVFoBCAlrcaTC PzxA== X-Received: by 10.180.160.240 with SMTP id xn16mr3065225wib.62.1374778501013; Thu, 25 Jul 2013 11:55:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.181.10 with HTTP; Thu, 25 Jul 2013 11:54:40 -0700 (PDT) In-Reply-To: <51F0C193.4000104@bitfrost.no> References: <51F0C193.4000104@bitfrost.no> From: Damjan Jovanovic Date: Thu, 25 Jul 2013 18:54:40 +0000 Message-ID: Subject: Re: COMPAT_32BIT libusb ABI problem To: Hans Petter Selasky Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-usb@freebsd.org X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jul 2013 18:55:03 -0000 On Thu, Jul 25, 2013 at 6:11 AM, Hans Petter Selasky 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: at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) > pwr=SAVE (0mA) > ugen1.1: 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