From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 30 23:45:24 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B0785106566C for ; Wed, 30 Jun 2010 23:45:24 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id 603698FC24 for ; Wed, 30 Jun 2010 23:45:24 +0000 (UTC) Received: by vws6 with SMTP id 6so615910vws.13 for ; Wed, 30 Jun 2010 16:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9CvyZrWGM9oHoCXsk5CFxEW35St/SKkMu2rJOJjPwwQ=; b=HfgGNa5RLbfSszcnDBHPflNVShtpDxG+DqcmTv6OyBvPozUU0hC33f24qDtzec4e8z hKGXnXknuWqYa3aFCU2e1YfKpsmkDNGE5bUVDD+rMaEgzYxNDmmpmwHnzzFfoHJ47xp8 bENo6suCezULHpoT/A+PsSs2bvOX072VVocAU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=wFvKYCi1y5LDDzcdx/aTvl2crTMBvZPLmU6F92ODcRJpH/tPsrYnow6ZXOtOghWoFY WsGjK88r9BC+xKfF4GsFj6Ir//8HroGYh46Yn5KfOuOEredqgfQcoEJKPrzjVeVhalnM 4gNRWOl51lKBVy3gX8dgHFFIo0G3LGsI47mjE= MIME-Version: 1.0 Received: by 10.229.215.145 with SMTP id he17mr5557656qcb.95.1277941519039; Wed, 30 Jun 2010 16:45:19 -0700 (PDT) Received: by 10.229.221.83 with HTTP; Wed, 30 Jun 2010 16:45:18 -0700 (PDT) In-Reply-To: <20100630192350.105e8303@kan.dnsalias.net> References: <20100630105027.GJ13238@deviant.kiev.zoral.com.ua> <20100630192350.105e8303@kan.dnsalias.net> Date: Wed, 30 Jun 2010 16:45:18 -0700 Message-ID: From: Garrett Cooper To: Alexander Kabaev Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "Sam Fourman Jr." , Kostik Belousov , freebsd-hackers@freebsd.org Subject: Re: kernel patch needed for wine? 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, 30 Jun 2010 23:45:24 -0000 2010/6/30 Alexander Kabaev : > On Wed, 30 Jun 2010 14:42:47 -0700 > Garrett Cooper wrote: > >> On Wed, Jun 30, 2010 at 2:22 PM, Sam Fourman Jr. >> wrote: >> > On Wed, Jun 30, 2010 at 11:26 AM, Garrett Cooper >> > wrote: >> >> On Wed, Jun 30, 2010 at 8:43 AM, Sam Fourman Jr. >> >> wrote: >> >>>> Which patch ? icebp generates the SIGTRAP on latest 8-stable, >> >>>> verified by the following trivival assembler program: >> >>>> =A0 =A0 =A0 =A0.text >> >>>> =A0 =A0 =A0 =A0.globl =A0main >> >>>> main: >> >>>> =A0 =A0 =A0 =A0.byte =A0 0xf1 >> >>>> =A0 =A0 =A0 =A0xorl =A0 =A0%edi,%edi >> >>>> =A0 =A0 =A0 =A0call =A0 =A0exit >> >>>> >> >>> >> > >> > Here is the C program that the linux people used as a test case. >> > >> > *************************************************************** >> > #include >> > #include >> > >> > >> > >> > void trap_handler(int sig) >> > { >> > =A0 =A0 =A0 =A0printf("trapped\n"); >> > } >> > >> > >> > /* >> > =A0* icebp >> > =A0* ret >> > =A0*/ >> > char icebp_func[] =3D "\xf1\xc3"; >> > typedef void (*icebp_call)(void); >> > >> > int main(int argc, char **argv) >> > { >> > =A0 =A0 =A0 =A0icebp_call func =3D (icebp_call)icebp_func; >> > >> > =A0 =A0 =A0 =A0signal(SIGTRAP, trap_handler); >> > >> > =A0 =A0 =A0 =A0func(); >> > >> > =A0 =A0 =A0 =A0return 0; >> > } >> > >> > *************************************************************** >> > >> > My question is why doe the above code not print trapped on amd64? >> > >> > FreeBSD 8.1 i386 this code prints "Trapped" as intended >> > FreeBSD 8.1 amd64 this code prints "Segmentation fault: 11" >> > FreeBSD 8.1 amd64 chrooted to 32bit prints "Segmentation fault" >> > >> > I did verify that from Linux amd64 this works and prints "Trapped" >> > uname -a >> > Linux workstation 2.6.32-23-generic #37-Ubuntu SMP Fri Jun 11 >> > 08:03:28 UTC 2010 x86_64 GNU/Linux >> >> Hmmm... I've seen similar whackiness with Linux and signals, but >> that's a different thing entirely (it was rt signals vs non-rt >> signals). >> >> Here's a modified version of the testcase (wanted to make sure that >> things were sane): >> >> $ cat test_sigtrap.c >> #include >> #include >> #include >> >> int trapped =3D 0; >> >> void trap_handler(int sig) >> { >> =A0 =A0 =A0 trapped =3D 1; >> } >> >> >> /* >> =A0* icebp >> =A0* ret >> =A0*/ >> char icebp_func[] =3D "\xf1\xc3"; >> typedef void (*icebp_call)(void); >> >> int main(int argc, char **argv) >> { >> =A0 =A0 =A0 icebp_call func =3D (icebp_call)icebp_func; >> >> =A0 =A0 =A0 if (signal(SIGTRAP, trap_handler) =3D=3D SIG_ERR) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 err(1, "signal"); >> >> =A0 =A0 =A0 func(); >> >> =A0 =A0 =A0 if (trapped) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("Admiral Ackbar: it's a trap!\n"); >> >> =A0 =A0 =A0 return 0; >> } >> >> Ran it and it segfaulted on CURRENT: >> > > Now make icebp_func const and observe the program start working. The > test case is broken as written, because icebp_func array is writable, > so in ends up in a non-const part of .bss, which is not marked as > executable and rightfully causes SIGSEGV when jumped to. Which means that Linux is broken in this regard because it's loading data as text, not data as data and text as text? Thanks, -Garrett