From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 30 21:42:54 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 0A869106566C for ; Wed, 30 Jun 2010 21:42:54 +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 B03718FC36 for ; Wed, 30 Jun 2010 21:42:53 +0000 (UTC) Received: by vws6 with SMTP id 6so467599vws.13 for ; Wed, 30 Jun 2010 14:42:47 -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=o6EZVDBdfJNqSKhJW6HYbHhAcH06iE1Qu3Ia++N7pTg=; b=ho9rCqWV//t6AYcbmR0jQF6WFEx7ObfFkxx+mKlBBSXyExi4DdGIyENn6e79w0Eiac /T0+f/vJLKtyo6I6uugB3B0NTW7af9Ds854ERIVnzYU7oZ3wRFzFogHvby7CgkOTfLZB TInNJF0mkhM2BcjGng0nF0tEKzGS8iHn+X7Rc= 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=abLsY1D7GfPjbz0eXOS5ZmtErRZNdbs7xx3gv+Lwm/tmpoVC3+BsMppRdSjKNI0jhX oYhf3VqugqqV86rDPztjOvw+5dIyIDuw8M4kczTnOjhAi2Ja7Z8BcaG77lnRnRTu8zoL PX1rEWPLxu0VAIkWwk0RkYMgCUsRHejvQLqN8= MIME-Version: 1.0 Received: by 10.229.96.209 with SMTP id i17mr5492676qcn.293.1277934167236; Wed, 30 Jun 2010 14:42:47 -0700 (PDT) Received: by 10.229.221.83 with HTTP; Wed, 30 Jun 2010 14:42:47 -0700 (PDT) In-Reply-To: References: <20100630105027.GJ13238@deviant.kiev.zoral.com.ua> Date: Wed, 30 Jun 2010 14:42:47 -0700 Message-ID: From: Garrett Cooper To: "Sam Fourman Jr." Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: 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 21:42:54 -0000 On Wed, Jun 30, 2010 at 2:22 PM, Sam Fourman Jr. wrote= : > On Wed, Jun 30, 2010 at 11:26 AM, Garrett Cooper wro= te: >> On Wed, Jun 30, 2010 at 8:43 AM, Sam Fourman Jr. wr= ote: >>>> 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) { trapped =3D 1; } /* * icebp * ret */ char icebp_func[] =3D "\xf1\xc3"; typedef void (*icebp_call)(void); int main(int argc, char **argv) { icebp_call func =3D (icebp_call)icebp_func; if (signal(SIGTRAP, trap_handler) =3D=3D SIG_ERR) err(1, "signal"); func(); if (trapped) printf("Admiral Ackbar: it's a trap!\n"); return 0; } Ran it and it segfaulted on CURRENT: $ sudo truss ./test_sigtrap __sysctl(0x7fffffffe590,0x2,0x7fffffffe5ac,0x7fffffffe5a0,0x0,0x0) =3D 0 (0= x0) mmap(0x0,672,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) =3D 34365169664 (0x80052= e000) munmap(0x80052e000,672) =3D 0 (0x0) __sysctl(0x7fffffffe600,0x2,0x800638848,0x7fffffffe5f8,0x0,0x0) =3D 0 (0x0) mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) =3D 34365169664 (0x80052e000) issetugid(0x80052f015,0x8005294e4,0x800644f50,0x800644f20,0x5b31,0x0) =3D 0= (0x0) open("/etc/libmap.conf",O_RDONLY,0666) ERR#2 'No such file or directory' open("/var/run/ld-elf.so.hints",O_RDONLY,057) =3D 2 (0x2) read(2,"Ehnt\^A\0\0\0\M^@\0\0\0}\0\0\0\0"...,128) =3D 128 (0x80) lseek(2,0x80,SEEK_SET) =3D 128 (0x80) read(2,"/lib:/usr/lib:/usr/lib/compat:/u"...,125) =3D 125 (0x7d) close(2) =3D 0 (0x0) access("/lib/libc.so.7",0) =3D 0 (0x0) open("/lib/libc.so.7",O_RDONLY,030703440) =3D 2 (0x2) fstat(2,{ mode=3D-r--r--r-- ,inode=3D353312,size=3D1192760,blksize=3D16384 = }) =3D 0 (0x0) pread(0x2,0x800637700,0x1000,0x0,0x101010101010101,0x8080808080808080) =3D 4096 (0x1000) mmap(0x0,2318336,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) =3D 34366312448 (0x800645000) mmap(0x800645000,1028096,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCO= RE,2,0x0) =3D 34366312448 (0x800645000) mmap(0x80083f000,135168,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,2,0xfa00= 0) =3D 34368385024 (0x80083f000) mprotect(0x800860000,110592,PROT_READ|PROT_WRITE) =3D 0 (0x0) close(2) =3D 0 (0x0) sysarch(0x81,0x7fffffffe680,0x800533088,0x0,0xffffffffffcea590,0x8080808080= 808080) =3D 0 (0x0) mmap(0x0,176,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) =3D 34365202432 (0x80053= 6000) munmap(0x800536000,176) =3D 0 (0x0) mmap(0x0,44064,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) =3D 34365202432 (0x800= 536000) munmap(0x800536000,44064) =3D 0 (0x0) sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM= |SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXF= SZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) =3D 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0) =3D 0 (0x0) __sysctl(0x7fffffffe620,0x2,0x800866d20,0x7fffffffe618,0x0,0x0) =3D 0 (0x0) sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM= |SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXF= SZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) =3D 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0) =3D 0 (0x0) sigaction(SIGTRAP,{ 0x4005f0 SA_RESTART ss_t },{ SIG_DFL 0x0 ss_t }) =3D 0 = (0x0) SIGNAL 11 (SIGSEGV) process exit, rval =3D 0 Also, is there perhaps a sideeffect dealing with the size of a char on FreeBSD vs Linux? That's a pretty badass way to load assembler instructions on the stack :). Thanks! -Garrett