From owner-freebsd-bugs@FreeBSD.ORG Sat Jan 31 00:12:25 2015 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B1F086EA for ; Sat, 31 Jan 2015 00:12:25 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 92BC1CBE for ; Sat, 31 Jan 2015 00:12:25 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.9/8.14.9) with ESMTP id t0V0CPgV093438 for ; Sat, 31 Jan 2015 00:12:25 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 197216] incorrect signal delivery for linux apps Date: Sat, 31 Jan 2015 00:12:25 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: henry.hu.sh@gmail.com X-Bugzilla-Status: New X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Jan 2015 00:12:25 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197216 Bug ID: 197216 Summary: incorrect signal delivery for linux apps Product: Base System Version: 11.0-CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: freebsd-bugs@FreeBSD.org Reporter: henry.hu.sh@gmail.com FreeBSD's Linux emulation tries to translate between Linux signals and FreeBSD signals. However, this is not a one-to-one mapping, which results in some incorrect behavior. For example, if an application sets a signal handler for SIGPWR(30), and sends SIGPWR to itself, then the signal handler would be called, but the signal number passed in is not 30, but 23(SIGURG). The reason is that FreeBSD translates Linux's SIGPWR(30) to FreeBSD's SIGURG(16), but FreeBSD's SIGURG(16) is translated back to Linux's SIGURG(23). A simple test program: #include #include #include #include #include const int SIGNAL_TO_TEST = SIGPWR; void handler(int signum) { if (signum != SIGNAL_TO_TEST) { printf("Error! got signal %d expected %d\n", signum, SIGNAL_TO_TEST); } else { printf("Got signal %d as expected\n", signum); } } int main() { struct sigaction sigact; sigact.sa_handler = handler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; if (sigaction(SIGNAL_TO_TEST, &sigact, NULL) == -1) { perror("fail to call sigaction"); } kill(getpid(), SIGNAL_TO_TEST); sleep(1); } It should output Got signal 30 as expected but on FreeBSD it says Error! got signal 23 expected 30 instead. A real example can be found at https://github.com/mono/mono/blob/master/libgc/pthread_stop_world.c where it uses SIG_SUSPEND to pause threads. SIG_SUSPEND is defined to be SIGPWR. The signal handler checks the value of signal passed in: if (sig != SIG_SUSPEND) ABORT("Bad signal in suspend_handler"); A reasonable fix would be mapping SIGPWR to some currently unmapped FreeBSD signal, like SIGEMT. Although it's not completely correct in semantics, at least it works for signal delivery between Linux applications. For the uncommon signals like SIGURG and SIGPWR, usually they are not sent between FreeBSD and Linux applications. I think that we'd better keep them working as expected when being sent between Linux applications. -- You are receiving this mail because: You are the assignee for the bug.