From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 11 13:50:46 2011 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 91EA6106566C for ; Mon, 11 Jul 2011 13:50:46 +0000 (UTC) (envelope-from Petr.Salinger@seznam.cz) Received: from relay.felk.cvut.cz (relay.felk.cvut.cz [147.32.80.7]) by mx1.freebsd.org (Postfix) with ESMTP id E15D98FC15 for ; Mon, 11 Jul 2011 13:50:45 +0000 (UTC) Received: from sci.felk.cvut.cz (sci.felk.cvut.cz [147.32.83.100]) by relay.felk.cvut.cz (8.14.4/8.14.4) with ESMTP id p6BDIwwS069958; Mon, 11 Jul 2011 15:18:58 +0200 (CEST) (envelope-from Petr.Salinger@seznam.cz) Date: Mon, 11 Jul 2011 15:27:56 +0200 (CEST) From: Petr Salinger X-X-Sender: salinger@sci.felk.cvut.cz To: Kostik Belousov In-Reply-To: <20110711123332.GS43872@deviant.kiev.zoral.com.ua> Message-ID: References: <20110711123332.GS43872@deviant.kiev.zoral.com.ua> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-FELK-MailScanner-Information: X-MailScanner-ID: p6BDIwwS069958 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-1.119, required 6, AWL 0.00, BAYES_00 -1.90, FREEMAIL_FROM 0.00, SPF_NEUTRAL 0.78) X-FELK-MailScanner-From: petr.salinger@seznam.cz X-FELK-MailScanner-To: freebsd-hackers@freebsd.org, kostikbel@gmail.com, rmh@debian.org X-FELK-MailScanner-Watermark: 1310995139.16891@IcFE9t9GO2jAmOFT0yZaSg X-Spam-Status: No Cc: freebsd-hackers@freebsd.org, Robert Millan Subject: Re: [PATCH] Improve LinuxThreads compatibility in rfork() 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: Mon, 11 Jul 2011 13:50:46 -0000 >> This patch made by Petr Salinger improves compatibility with >> LinuxThreads in rfork() syscall. The Linux clone() implementation >> allows specifying the signal sent to parent when child terminates >> (instead of SIGCHLD). >> >> As the threading implementation in Debian GNU/kFreeBSD is >> LinuxThreads-based, we had to diverge from upstream kFreeBSD ABI and >> implement this extension. >> >> I hope it is acceptable for you to use the same encoding, this way we >> would archieve ABI compatibility to run Debian GNU/kFreeBSD inside a >> chroot/jail on top of a FreeBSD system. >> >> Thanks for considering >> >> -- >> Robert Millan > >> --- a/sys/kern/kern_fork.c >> +++ b/sys/kern/kern_fork.c >> @@ -477,7 +477,13 @@ >> p2->p_sigacts = newsigacts; >> } >> if (flags & RFLINUXTHPN) >> - p2->p_sigparent = SIGUSR1; >> + { >> + int sig; >> + sig = RFTHPNSIGNUM(flags); >> + if (sig == 0) sig = SIGUSR1; >> + if (sig == SIGCHLD) sig = 0; >> + p2->p_sigparent = sig; >> + } >> else >> p2->p_sigparent = SIGCHLD; >> >> --- a/sys/sys/unistd.h >> +++ b/sys/sys/unistd.h >> @@ -182,6 +182,10 @@ >> #define RFHIGHPID (1<<18) /* use a pid higher than 10 (idleproc) */ >> #define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ >> #define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPPWAIT) >> +#define RFTHPNSHIFT 24 /* reserve bits 24-30 */ >> +#define RFTHPNMASK 0x7F /* for compatibility with linuxthreads/clone() */ >> + /* allow to specify "clone exit parent notification" signal */ >> +#define RFTHPNSIGNUM(flags) (((flags) >> RFTHPNSHIFT) & RFTHPNMASK) >> >> #endif /* __BSD_VISIBLE */ >> > I looked at this patch some time ago already. > > Can you, please, describe the reasoning behind the >> + if (sig == SIGCHLD) sig = 0; > line ? The main reason is backward compatibility. The original FreeBSD code allows only to select between SIGUSR1 or SIGCHLD signals. The our extension changes meaning of RFLINUXTHPN to select signal based on bits 24-30 of passed flags instead of using SIGUSR1 every time. When the passed "signal" number is zero, it should behave identically on plain FreeBSD and in our environment, therefore SIGUSR1 is selected. The assumption is (have been) that (yet) undefined bits are zero. That way we are backward compatible with original FreeBSD. We still need an alternative way to select "none signal is sent" after child exit (under linux #0 is used). The SIGCHLD can be "selected" (also on original FreeBSD) by not specifying RFLINUXTHPN, therefore combination of RFLINUXTHPN and passed "signal" number SIGCHLD is (have been) used for "none signal". BTW, the opposite side is in http://anonscm.debian.org/viewvc/glibc-bsd/trunk/glibc-ports/kfreebsd/clone.c?view=markup Petr