From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 10 18:20:07 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8690B16A41F for ; Wed, 10 Aug 2005 18:20:07 +0000 (GMT) (envelope-from Danovitsch@Vitsch.net) Received: from amsfep15-int.chello.nl (amsfep15-int.chello.nl [213.46.243.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9FE8A43D58 for ; Wed, 10 Aug 2005 18:20:06 +0000 (GMT) (envelope-from Danovitsch@Vitsch.net) Received: from Vitsch.net ([62.195.249.78]) by amsfep15-int.chello.nl (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP id <20050810182004.NJPM10024.amsfep15-int.chello.nl@Vitsch.net>; Wed, 10 Aug 2005 20:20:04 +0200 Received: from [192.168.45.9] (i248222.upc-i.chello.nl [62.195.248.222]) by Vitsch.net (8.12.3p2/8.11.3) with ESMTP id j7AIIewU074801; Wed, 10 Aug 2005 20:18:45 +0200 (CEST) (envelope-from Danovitsch@Vitsch.net) From: "Daan Vreeken [PA4DAN]" Organization: Vitsch Electronics To: Alexander , freebsd-hackers@freebsd.org Date: Wed, 10 Aug 2005 20:19:14 +0200 User-Agent: KMail/1.8 References: <20050809133109.GA15300@skatecity> <20050809192530.GA19230@skatecity> <20050810130928.GA2027@skatecity> In-Reply-To: <20050810130928.GA2027@skatecity> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200508102019.15147.Danovitsch@Vitsch.net> Cc: Subject: Re: Using sysarch specific syscalls in assembly? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2005 18:20:07 -0000 On Wednesday 10 August 2005 15:09, alexander wrote: > I tried to write a little C app that uses sysarch and i386_set_ioperm to > gain access to certain ports and after a bit of testing I'm pretty sure > that there is a bug or better a timing issue with the sysarch syscall or > the > i386_set_ioperm procedure. Please have a look at the following code: > > //CODE START > > #include > > int main (void) { > > unsigned int port = 0x378; > unsigned char val = 'A'; > int number = 4; > > static inline void outb (unsigned short int port, unsigned char val) { > __asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port) ); > } > > struct i386_ioperm_args { > unsigned int start; > unsigned int length; > int enable; > }; > > struct i386_ioperm_args *args; > struct i386_ioperm_args arg; > args = &arg; > > args->start = 0x378; > args->length = 1; > args->enable = 1; > > if(sysarch(number,args) == 0) { > /* int i; > for(i=0; i < 100; i++) { > printf("DELAY\n"); > } > */ > outb(0x378,0xF); > exit(0); > } > > else { > printf("Error during syscall"); > exit(1); > } > } > > //eof > > //CODE END > > On my PC this code will cause a core dump (Bus error: 10). If I however add > a delay (the code that's commented out) the app will end without any > errors. > > It seems FBSD needs some time to set the I/O permissions for an app. Can > somebody test this code on his computer? Maybe this is a bug in RELENG_6. > I'm running: > > FreeBSD 6.0-BETA1 #0: Mon Jul 18 03:00:45 CEST 2005 I can confirm that. I have tested the program on 5.4-RELEASE here. Testing your program (I called it "p") 10 times gives the following output : root@Racebeest# for a in 0 1 2 3 4 5 6 7 8 9;do echo "starting p"; ./p ;done starting p starting p starting p Bus error (core dumped) starting p Bus error (core dumped) starting p starting p starting p Bus error (core dumped) starting p Bus error (core dumped) starting p starting p root@Racebeest# However, opening /dev/io to gain IO privileges instead of using sysarch always works. I tested that with the following program : #include static inline void outb (unsigned short int port, unsigned char val) { __asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port) ); } int main (void) { if (open("/dev/io", O_RDONLY) == -1) { printf("EEK!\n"); exit(1); } outb(0x378, 0xff); } --- EOF --- grtz, Daan