From owner-freebsd-emulation@FreeBSD.ORG Thu May 1 10:03:01 2008 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 329B41065673 for ; Thu, 1 May 2008 10:03:01 +0000 (UTC) (envelope-from rdivacky@vlk.vlakno.cz) Received: from vlakno.cz (vlk.vlakno.cz [62.168.28.247]) by mx1.freebsd.org (Postfix) with ESMTP id DD4D08FC21 for ; Thu, 1 May 2008 10:03:00 +0000 (UTC) (envelope-from rdivacky@vlk.vlakno.cz) Received: from localhost (localhost [127.0.0.1]) by vlakno.cz (Postfix) with ESMTP id 4C9B567D5E6; Thu, 1 May 2008 12:02:31 +0200 (CEST) X-Virus-Scanned: amavisd-new at vlakno.cz Received: from vlakno.cz ([127.0.0.1]) by localhost (vlk.vlakno.cz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RWQ0drjl827t; Thu, 1 May 2008 12:02:30 +0200 (CEST) Received: from vlk.vlakno.cz (localhost [127.0.0.1]) by vlakno.cz (Postfix) with ESMTP id E7D4667D5A8; Thu, 1 May 2008 12:02:29 +0200 (CEST) Received: (from rdivacky@localhost) by vlk.vlakno.cz (8.14.2/8.14.2/Submit) id m41A2Tii060497; Thu, 1 May 2008 12:02:29 +0200 (CEST) (envelope-from rdivacky) Date: Thu, 1 May 2008 12:02:29 +0200 From: Roman Divacky To: Pieter de Boer Message-ID: <20080501100229.GA60391@freebsd.org> References: <481897AB.7070003@thedarkside.nl> <20080501081811.GB54624@freebsd.org> <48199416.5000407@thedarkside.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48199416.5000407@thedarkside.nl> User-Agent: Mutt/1.4.2.3i Cc: freebsd-emulation@freebsd.org Subject: Re: Linux compat ioctl return values X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 May 2008 10:03:01 -0000 On Thu, May 01, 2008 at 11:57:42AM +0200, Pieter de Boer wrote: > Roman Divacky wrote: > > >>I've been working on a kernel driver that creates a device. This device > >>in turn is opened and ioctl'd from a Linux executable. I've registered a > >>handler for these ioctl's and my ioctl handler is succesfully executed. > >> > >>My ioctl-handler returns a large positive value, but the userland > >>application retrieves the value 1, EPERM. If I return 42, the userland > >>application retrieves 42, but 260 is retrieved as 1. It appears there's a > >>threshold somewhere above which the return value is set to 1, but I > >>haven't been able to find out where in the code this is done. The Linux > >>executable actually expects the value I return, and doesn't work when > >>EPERM is found instead. > >> > >>So, the question is: does anyone know where such a threshold may > >>reside and how to work around it? > > > >this is done in (for i386) sys/i386/i386/trap.c around line 1050. > > > >in short, we define in the sysvec structure sv_errtbl and if returned > >error > the size of the table we just return -1. error table for > >linux is roughly to 70. thats why you are getting -1 (1 after translation) > > > >you might extend the errno table (i386/linux/linux_sysvec.c for i386, line > >126) > > The issue appears to be a bit more involved. It seems that in Linux, > when the ioctl() syscall returns a negative value 'error', 'errno' is > set to '-error' and the return value of the ioctl() library call is -1. > All positive values are simply passed through: when the ioctl() syscall > returns 35235, the ioctl() library call also returns 35235. > > This seems to be a difference in semantics between FreeBSD and Linux; > FreeBSD is a bit more conservative. As the trap code in > sys/i386/i386/trap.c is used for both FreeBSD and Linux executables, I > wonder how to differentiate between both in trap.c. > > To see if I can at least make my Linux executable work for now, I'm > going to test the following patch (to trap.c): > - error = -1; /* XXX */ > + /* Do nothing */ > > I suppose a patch that differentiates between Linux and FreeBSD syscalls > is needed here, but how this could be done, dunno. I dont think so.... native freebsd does NOT have errno translation table. you patch makes sense I'd say