From unknown Sun Aug 17 01:01:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#21694: 'clone' syscall binding unreliable Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 16 Oct 2015 20:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21694 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: David Thompson Cc: 21694@debbugs.gnu.org X-Debbugs-Original-Cc: bug-guix@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.144502801332151 (code B ref -1); Fri, 16 Oct 2015 20:41:02 +0000 Received: (at submit) by debbugs.gnu.org; 16 Oct 2015 20:40:13 +0000 Received: from localhost ([127.0.0.1]:53643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnBnQ-0008MU-J1 for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33664) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnBnN-0008MM-VI for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnBnM-0005zW-GN for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:09 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:53828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnBnM-0005zS-EY for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnBnL-00030I-6j for bug-guix@gnu.org; Fri, 16 Oct 2015 16:40:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnBnH-0005tN-3G for bug-guix@gnu.org; Fri, 16 Oct 2015 16:40:07 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnBnH-0005tH-0A for bug-guix@gnu.org; Fri, 16 Oct 2015 16:40:03 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:37224 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZnBnG-00025i-DN; Fri, 16 Oct 2015 16:40:02 -0400 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 25 =?UTF-8?Q?Vend=C3=A9miaire?= an 224 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x3D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Date: Fri, 16 Oct 2015 22:39:59 +0200 Message-ID: <87zizio8dc.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I=E2=80=99m reporting the problem and (hopefully) the solution, but I think= we=E2=80=99d better double-check this. The problem: Running the test below in a loop sometimes gets a SIGSEGV in the child process (on x86_64, libc 2.22.) --8<---------------cut here---------------start------------->8--- (use-modules (guix build syscalls) (ice-9 match)) (match (clone (logior CLONE_NEWUSER CLONE_CHILD_SETTID CLONE_CHILD_CLEARTID SIGCHLD)) (0 (throw 'x)) ;XXX: sometimes segfaults (pid (match (waitpid pid) ((_ . status) (pk 'status status) (exit (not (status:term-sig status))))))) --8<---------------cut here---------------end--------------->8--- Looking at (guix build syscalls) though, I see an ABI mismatch between our definition and the actual =E2=80=98syscall=E2=80=99 C function, and bet= ween our =E2=80=98clone=E2=80=99 definition and the actual C function. This leads to the attached patch, which also fixes the above problem for me. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 80b9d00..f931f8d 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -322,10 +322,16 @@ string TMPL and return its file name. TMPL must end with 'XXXXXX'." (define CLONE_NEWNET #x40000000) ;; The libc interface to sys_clone is not useful for Scheme programs, so the -;; low-level system call is wrapped instead. +;; low-level system call is wrapped instead. The 'syscall' function is +;; declared in as a variadic function; in practice, it expects 6 +;; pointer-sized arguments, as shown in, e.g., x86_64/syscall.S. (define clone (let* ((ptr (dynamic-func "syscall" (dynamic-link))) - (proc (pointer->procedure int ptr (list int int '*))) + (proc (pointer->procedure long ptr + (list long ;sysno + unsigned-long ;flags + '* '* '* + '*))) ;; TODO: Don't do this. (syscall-id (match (utsname:machine (uname)) ("i686" 120) @@ -336,7 +342,10 @@ string TMPL and return its file name. TMPL must end with 'XXXXXX'." "Create a new child process by duplicating the current parent process. Unlike the fork system call, clone accepts FLAGS that specify which resources are shared between the parent and child processes." - (let ((ret (proc syscall-id flags %null-pointer)) + (let ((ret (proc syscall-id flags + %null-pointer ;child stack + %null-pointer %null-pointer ;ptid & ctid + %null-pointer)) ;unused (err (errno))) (if (= ret -1) (throw 'system-error "clone" "~d: ~A" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Could you test this patch? Now, there remains the question of CLONE_CHILD_SETTID and CLONE_CHILD_CLEARTID. Since we=E2=80=99re passing NULL for =E2=80=98ctid= =E2=80=99, I expect that these flags have no effect at all. Conversely, libc uses these flags to update the thread ID in the child process (x86_64/arch-fork.h): --8<---------------cut here---------------start------------->8--- #define ARCH_FORK() \ INLINE_SYSCALL (clone, 4, = \ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, = \ NULL, &THREAD_SELF->tid) --8<---------------cut here---------------end--------------->8--- This is certainly useful, but we=E2=80=99d have troubles doing it from the = FFI=E2=80=A6 It may that this is fine if the process doesn=E2=80=99t use threads. Ludo=E2=80=99. --=-=-=-- From unknown Sun Aug 17 01:01:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#21694: 'clone' syscall binding unreliable Resent-From: "Thompson, David" Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 16 Oct 2015 23:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21694 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 21694@debbugs.gnu.org, David Thompson Received: via spool by 21694-submit@debbugs.gnu.org id=B21694.144503717712979 (code B ref 21694); Fri, 16 Oct 2015 23:13:02 +0000 Received: (at 21694) by debbugs.gnu.org; 16 Oct 2015 23:12:57 +0000 Received: from localhost ([127.0.0.1]:53709 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnEBE-0003NG-PW for submit@debbugs.gnu.org; Fri, 16 Oct 2015 19:12:57 -0400 Received: from mail-yk0-f182.google.com ([209.85.160.182]:34084) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnEBC-0003N8-Hn for 21694@debbugs.gnu.org; Fri, 16 Oct 2015 19:12:55 -0400 Received: by ykfy204 with SMTP id y204so98924067ykf.1 for <21694@debbugs.gnu.org>; Fri, 16 Oct 2015 16:12:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=nTOmWiZtFeaXhn/AyCVHN++iQsnWC4QbhA7T41WfQ74=; b=Y+c05HJ+qK+Fc0vAyzyiFFBdNNfeQgcXjP1dWBZpqmenNxwOLn2jLFHahW+TdchlY+ qHBvwgdlD1SvvLui4NAcJJ6CXGX45ARHv3skH+Q/w++2ZLdqHjWhzG2rVoYyawp++bMw 0JuNunafBmEV9lJMlvp9HNUmMoRHgdT7pxsW5+7ZZ9mXxCBzXCwhFPWggByqzlhwaLVt vYLOgAnOKxdZp1nLbXVk5cq+szHML11B7s6l0Sp5kbJQeAZZGgi8Jh7fNfNVViXZaI/C ewlZjmbWo808YY0fvIx3cDo4yf8YY3lHLqQksCg3m5asiMn1ji7LhvPrkhhxKOmGafAC OwKA== X-Gm-Message-State: ALoCoQlwcnh/Ixb0qvemvuH76PBeAl7NIpvJ9PhzFgS1YGPn7RjcVmFXjAkwQ13MD/mt9Oqv296D MIME-Version: 1.0 X-Received: by 10.129.53.12 with SMTP id c12mr1487812ywa.150.1445037173979; Fri, 16 Oct 2015 16:12:53 -0700 (PDT) Received: by 10.37.39.11 with HTTP; Fri, 16 Oct 2015 16:12:53 -0700 (PDT) In-Reply-To: <87zizio8dc.fsf@gnu.org> References: <87zizio8dc.fsf@gnu.org> Date: Fri, 16 Oct 2015 19:12:53 -0400 Message-ID: From: "Thompson, David" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On Fri, Oct 16, 2015 at 4:39 PM, Ludovic Court=C3=A8s wrote: > I=E2=80=99m reporting the problem and (hopefully) the solution, but I thi= nk we=E2=80=99d > better double-check this. > > The problem: Running the test below in a loop sometimes gets a SIGSEGV > in the child process (on x86_64, libc 2.22.) > > --8<---------------cut here---------------start------------->8--- > (use-modules (guix build syscalls) (ice-9 match)) > > (match (clone (logior CLONE_NEWUSER > CLONE_CHILD_SETTID > CLONE_CHILD_CLEARTID > SIGCHLD)) > (0 > (throw 'x)) ;XXX: sometimes segfaul= ts > (pid > (match (waitpid pid) > ((_ . status) > (pk 'status status) > (exit (not (status:term-sig status))))))) > --8<---------------cut here---------------end--------------->8--- > > Looking at (guix build syscalls) though, I see an ABI mismatch between > our definition and the actual =E2=80=98syscall=E2=80=99 C function, and b= etween our > =E2=80=98clone=E2=80=99 definition and the actual C function. > > This leads to the attached patch, which also fixes the above problem for = me. > > Could you test this patch? The patch looks good. Thanks for catching this! > Now, there remains the question of CLONE_CHILD_SETTID and > CLONE_CHILD_CLEARTID. Since we=E2=80=99re passing NULL for =E2=80=98ctid= =E2=80=99, I expect > that these flags have no effect at all. I added those flags in commit ee78d02 because they solved a real issue I ran into. Adding those flags made 'clone' look like a 'primitive-fork' call when examined with strace. > Conversely, libc uses these flags to update the thread ID in the child > process (x86_64/arch-fork.h): > > --8<---------------cut here---------------start------------->8--- > #define ARCH_FORK() \ > INLINE_SYSCALL (clone, 4, = \ > CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0,= \ > NULL, &THREAD_SELF->tid) > --8<---------------cut here---------------end--------------->8--- > > This is certainly useful, but we=E2=80=99d have troubles doing it from th= e FFI=E2=80=A6 > It may that this is fine if the process doesn=E2=80=99t use threads. Right, so here's what 'primitive-fork' does: clone(child_stack=3D0, flags=3DCLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=3D0x7fc5398cea10) =3D 13247 Here's what 'clone' does: clone(child_stack=3D0, flags=3DCLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=3D0) =3D 14038 In practice it may not be a problem since most of the time you'd 'exec' after cloning. Is there any reliable way to get a hold of whatever THREAD_SELF is? I wish the libc 'clone' function didn't have that silly callback and behaved like 'fork', then we could have avoided these issues altogether. - Dave From unknown Sun Aug 17 01:01:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#21694: 'clone' syscall binding unreliable Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 17 Oct 2015 10:15:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21694 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: "Thompson\, David" Cc: 21694@debbugs.gnu.org, David Thompson Received: via spool by 21694-submit@debbugs.gnu.org id=B21694.14450768846102 (code B ref 21694); Sat, 17 Oct 2015 10:15:03 +0000 Received: (at 21694) by debbugs.gnu.org; 17 Oct 2015 10:14:44 +0000 Received: from localhost ([127.0.0.1]:53840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnOVf-0001aM-E4 for submit@debbugs.gnu.org; Sat, 17 Oct 2015 06:14:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58241) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnOVd-0001aE-8u for 21694@debbugs.gnu.org; Sat, 17 Oct 2015 06:14:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnOVZ-0003zI-S9 for 21694@debbugs.gnu.org; Sat, 17 Oct 2015 06:14:41 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnOVZ-0003zE-Op; Sat, 17 Oct 2015 06:14:37 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:42136 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZnOVY-0007Io-Pj; Sat, 17 Oct 2015 06:14:37 -0400 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <87zizio8dc.fsf@gnu.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 26 =?UTF-8?Q?Vend=C3=A9miaire?= an 224 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x3D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Date: Sat, 17 Oct 2015 12:14:34 +0200 In-Reply-To: (David Thompson's message of "Fri, 16 Oct 2015 19:12:53 -0400") Message-ID: <87k2qlls39.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) "Thompson, David" skribis: > On Fri, Oct 16, 2015 at 4:39 PM, Ludovic Court=C3=A8s wrot= e: >> I=E2=80=99m reporting the problem and (hopefully) the solution, but I th= ink we=E2=80=99d >> better double-check this. >> >> The problem: Running the test below in a loop sometimes gets a SIGSEGV >> in the child process (on x86_64, libc 2.22.) >> >> --8<---------------cut here---------------start------------->8--- >> (use-modules (guix build syscalls) (ice-9 match)) >> >> (match (clone (logior CLONE_NEWUSER >> CLONE_CHILD_SETTID >> CLONE_CHILD_CLEARTID >> SIGCHLD)) >> (0 >> (throw 'x)) ;XXX: sometimes segfau= lts >> (pid >> (match (waitpid pid) >> ((_ . status) >> (pk 'status status) >> (exit (not (status:term-sig status))))))) >> --8<---------------cut here---------------end--------------->8--- >> >> Looking at (guix build syscalls) though, I see an ABI mismatch between >> our definition and the actual =E2=80=98syscall=E2=80=99 C function, and = between our >> =E2=80=98clone=E2=80=99 definition and the actual C function. >> >> This leads to the attached patch, which also fixes the above problem for= me. >> >> Could you test this patch? > > The patch looks good. Thanks for catching this! Great, pushed as 0e3cc31. >> Now, there remains the question of CLONE_CHILD_SETTID and >> CLONE_CHILD_CLEARTID. Since we=E2=80=99re passing NULL for =E2=80=98cti= d=E2=80=99, I expect >> that these flags have no effect at all. > > I added those flags in commit ee78d02 because they solved a real issue > I ran into. Adding those flags made 'clone' look like a > 'primitive-fork' call when examined with strace. Could you check whether removing these flags makes a difference now? How can we test? (Preferably not at the REPL.) >> Conversely, libc uses these flags to update the thread ID in the child >> process (x86_64/arch-fork.h): >> >> --8<---------------cut here---------------start------------->8--- >> #define ARCH_FORK() \ >> INLINE_SYSCALL (clone, 4, = \ >> CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0= , \ >> NULL, &THREAD_SELF->tid) >> --8<---------------cut here---------------end--------------->8--- >> >> This is certainly useful, but we=E2=80=99d have troubles doing it from t= he FFI=E2=80=A6 >> It may that this is fine if the process doesn=E2=80=99t use threads. > > Right, so here's what 'primitive-fork' does: > > clone(child_stack=3D0, > flags=3DCLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, > child_tidptr=3D0x7fc5398cea10) =3D 13247 > > Here's what 'clone' does: > > clone(child_stack=3D0, > flags=3DCLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=3D0) > =3D 14038 You mean =E2=80=98clone=E2=80=99 from libc? I guess CLONE_CHILD_{CLEARTID,SETTID} don=E2=80=99t hurt here, but they hav= e no effect either. That=E2=80=99s what the clone(2) page suggests: CLONE_CHILD_CLEARTID (since Linux 2.5.49) Erase child thread ID at location ctid in child memory when the child exits, and do a wakeup on the futex at that address. The address involved may be changed by the set_tid_address(2) system call. This is used by threading libraries. CLONE_CHILD_SETTID (since Linux 2.5.49) Store child thread ID at location ctid in child memory. And here ctid =3D=3D NULL. And indeed, kernel/fork.c in Linux does: p->set_child_tid =3D (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr = : NULL; /* * Clear TID on mm_release()? */ p->clear_child_tid =3D (clone_flags & CLONE_CHILD_CLEARTID) ? child_tid= ptr : NULL; So in effect, using NULL for ctid equates to not passing the CLEARTID/SETTID flags. QED. :-) > In practice it may not be a problem since most of the time you'd > 'exec' after cloning. Is there any reliable way to get a hold of > whatever THREAD_SELF is?=20 THREAD_SELF is really not something we want to poke at; quoth x86_64/tls.h: --8<---------------cut here---------------start------------->8--- # define THREAD_SELF \ ({ struct pthread *__self; \ asm ("mov %%fs:%c1,%0" : "=3Dr" (__self) \ : "i" (offsetof (struct pthread, header.self))); \ __self;}) --8<---------------cut here---------------end--------------->8--- > I wish the libc 'clone' function didn't have that silly callback and > behaved like 'fork', then we could have avoided these issues > altogether. Is the callback really an issue? We have =E2=80=98procedure->pointer=E2=80= =99 after all. Thanks, Ludo=E2=80=99. From unknown Sun Aug 17 01:01:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#21694: 'clone' syscall binding unreliable Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Thu, 22 Oct 2015 14:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21694 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 21694@debbugs.gnu.org, David Thompson Received: via spool by 21694-submit@debbugs.gnu.org id=B21694.144552473126609 (code B ref 21694); Thu, 22 Oct 2015 14:39:02 +0000 Received: (at 21694) by debbugs.gnu.org; 22 Oct 2015 14:38:51 +0000 Received: from localhost ([127.0.0.1]:32980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZpH11-0006v6-2i for submit@debbugs.gnu.org; Thu, 22 Oct 2015 10:38:51 -0400 Received: from world.peace.net ([50.252.239.5]:53720) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZpH0g-0006uc-V1 for 21694@debbugs.gnu.org; Thu, 22 Oct 2015 10:38:49 -0400 Received: from [10.1.10.104] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1ZpH0Y-0008Nf-J6; Thu, 22 Oct 2015 10:38:22 -0400 From: Mark H Weaver References: <87zizio8dc.fsf@gnu.org> Date: Thu, 22 Oct 2015 10:38:21 -0400 In-Reply-To: <87zizio8dc.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Fri, 16 Oct 2015 22:39:59 +0200") Message-ID: <87fv13j7du.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Looking at (guix build syscalls) though, I see an ABI mismatch between > our definition and the actual =E2=80=98syscall=E2=80=99 C function, and b= etween our > =E2=80=98clone=E2=80=99 definition and the actual C function. Good catch! However, please see below. > This leads to the attached patch, which also fixes the above problem for = me. > > diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm > index 80b9d00..f931f8d 100644 > --- a/guix/build/syscalls.scm > +++ b/guix/build/syscalls.scm > @@ -322,10 +322,16 @@ string TMPL and return its file name. TMPL must en= d with 'XXXXXX'." > (define CLONE_NEWNET #x40000000) >=20=20 > ;; The libc interface to sys_clone is not useful for Scheme programs, so= the > -;; low-level system call is wrapped instead. > +;; low-level system call is wrapped instead. The 'syscall' function is > +;; declared in as a variadic function; in practice, it expect= s 6 > +;; pointer-sized arguments, as shown in, e.g., x86_64/syscall.S. > (define clone > (let* ((ptr (dynamic-func "syscall" (dynamic-link))) > - (proc (pointer->procedure int ptr (list int int '*))) > + (proc (pointer->procedure long ptr > + (list long ;s= ysno > + unsigned-long ;f= lags 'long' and 'unsigned long' might not be the same size as a pointer. Better to use 'size_t' for both of these. While not strictly guaranteed to be the same size as a pointer, in practice they should be the same except on architectures with segmented memory models. What do you think? Mark PS: 'intptr_t' and 'uintptr_t' would be best, but they are optional in C99 and not in (system foreign). 'ptrdiff_t' would be better, but was not available in (system foreign) before guile-2.0.9. From unknown Sun Aug 17 01:01:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#21694: 'clone' syscall binding unreliable Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sun, 25 Oct 2015 21:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21694 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Mark H Weaver Cc: 21694@debbugs.gnu.org, David Thompson Received: via spool by 21694-submit@debbugs.gnu.org id=B21694.144580681818414 (code B ref 21694); Sun, 25 Oct 2015 21:01:01 +0000 Received: (at 21694) by debbugs.gnu.org; 25 Oct 2015 21:00:18 +0000 Received: from localhost ([127.0.0.1]:38239 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZqSOn-0004mw-IY for submit@debbugs.gnu.org; Sun, 25 Oct 2015 17:00:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60110) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZqSOR-0004ky-Q5 for 21694@debbugs.gnu.org; Sun, 25 Oct 2015 17:00:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqSOQ-0003G4-CA for 21694@debbugs.gnu.org; Sun, 25 Oct 2015 16:59:55 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:53866) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqSOL-0003ES-2j; Sun, 25 Oct 2015 16:59:49 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:52368 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZqSOK-0003Xm-2D; Sun, 25 Oct 2015 16:59:48 -0400 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <87zizio8dc.fsf@gnu.org> <87fv13j7du.fsf@netris.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 4 Brumaire an 224 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x3D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Date: Sun, 25 Oct 2015 21:59:45 +0100 In-Reply-To: <87fv13j7du.fsf@netris.org> (Mark H. Weaver's message of "Thu, 22 Oct 2015 10:38:21 -0400") Message-ID: <87y4eqmzpa.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: [...] >> ;; The libc interface to sys_clone is not useful for Scheme programs, s= o the >> -;; low-level system call is wrapped instead. >> +;; low-level system call is wrapped instead. The 'syscall' function is >> +;; declared in as a variadic function; in practice, it expec= ts 6 >> +;; pointer-sized arguments, as shown in, e.g., x86_64/syscall.S. >> (define clone >> (let* ((ptr (dynamic-func "syscall" (dynamic-link))) >> - (proc (pointer->procedure int ptr (list int int '*))) >> + (proc (pointer->procedure long ptr >> + (list long ;= sysno >> + unsigned-long ;= flags > > 'long' and 'unsigned long' might not be the same size as a pointer. > Better to use 'size_t' for both of these. While not strictly guaranteed > to be the same size as a pointer, in practice they should be the same > except on architectures with segmented memory models. > > What do you think? I had the same reaction, but posix/unistd.h in libc really uses these types for =E2=80=98syscall=E2=80=99 so I thought it=E2=80=99d be best to st= ick to them. WDYT? Ludo=E2=80=99. From unknown Sun Aug 17 01:01:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#21694: 'clone' syscall binding unreliable Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Wed, 28 Oct 2015 04:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21694 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 21694@debbugs.gnu.org, David Thompson Received: via spool by 21694-submit@debbugs.gnu.org id=B21694.144600801923523 (code B ref 21694); Wed, 28 Oct 2015 04:54:02 +0000 Received: (at 21694) by debbugs.gnu.org; 28 Oct 2015 04:53:39 +0000 Received: from localhost ([127.0.0.1]:41068 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrIjy-00067L-Mt for submit@debbugs.gnu.org; Wed, 28 Oct 2015 00:53:39 -0400 Received: from world.peace.net ([50.252.239.5]:42332) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrIjw-00067D-Jq for 21694@debbugs.gnu.org; Wed, 28 Oct 2015 00:53:37 -0400 Received: from ip70-188-130-17.ri.ri.cox.net ([70.188.130.17] helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1ZrIjp-0001DL-Tm; Wed, 28 Oct 2015 00:53:30 -0400 From: Mark H Weaver References: <87zizio8dc.fsf@gnu.org> <87fv13j7du.fsf@netris.org> <87y4eqmzpa.fsf@gnu.org> Date: Wed, 28 Oct 2015 00:53:28 -0400 In-Reply-To: <87y4eqmzpa.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sun, 25 Oct 2015 21:59:45 +0100") Message-ID: <87si4v1tmf.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Mark H Weaver skribis: > >> ludo@gnu.org (Ludovic Court=C3=A8s) writes: > > [...] > >>> ;; The libc interface to sys_clone is not useful for Scheme programs, = so the >>> -;; low-level system call is wrapped instead. >>> +;; low-level system call is wrapped instead. The 'syscall' function is >>> +;; declared in as a variadic function; in practice, it expe= cts 6 >>> +;; pointer-sized arguments, as shown in, e.g., x86_64/syscall.S. >>> (define clone >>> (let* ((ptr (dynamic-func "syscall" (dynamic-link))) >>> - (proc (pointer->procedure int ptr (list int int '*))) >>> + (proc (pointer->procedure long ptr >>> + (list long = ;sysno >>> + unsigned-long = ;flags >> >> 'long' and 'unsigned long' might not be the same size as a pointer. >> Better to use 'size_t' for both of these. While not strictly guaranteed >> to be the same size as a pointer, in practice they should be the same >> except on architectures with segmented memory models. >> >> What do you think? > > I had the same reaction, but posix/unistd.h in libc really uses these > types for =E2=80=98syscall=E2=80=99 so I thought it=E2=80=99d be best to = stick to them. Okay, makes sense. Thanks, Mark From unknown Sun Aug 17 01:01:30 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Subject: bug#21694: closed (Re: bug#21694: 'clone' syscall binding unreliable) Message-ID: References: <87vb9r83be.fsf@gnu.org> <87zizio8dc.fsf@gnu.org> X-Gnu-PR-Message: they-closed 21694 X-Gnu-PR-Package: guix Reply-To: 21694@debbugs.gnu.org Date: Wed, 28 Oct 2015 14:40:05 +0000 Content-Type: multipart/mixed; boundary="----------=_1446043205-13824-1" This is a multi-part message in MIME format... ------------=_1446043205-13824-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #21694: 'clone' syscall binding unreliable which was filed against the guix package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 21694@debbugs.gnu.org. --=20 21694: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D21694 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1446043205-13824-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 21694-done) by debbugs.gnu.org; 28 Oct 2015 14:40:01 +0000 Received: from localhost ([127.0.0.1]:42619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrRtR-0003ah-4y for submit@debbugs.gnu.org; Wed, 28 Oct 2015 10:40:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46989) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrRtP-0003aY-7g for 21694-done@debbugs.gnu.org; Wed, 28 Oct 2015 10:39:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrRtL-0004ZS-Do for 21694-done@debbugs.gnu.org; Wed, 28 Oct 2015 10:39:59 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:50151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrRtI-0004Xs-3c; Wed, 28 Oct 2015 10:39:52 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:59920 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZrRtH-0004oe-GJ; Wed, 28 Oct 2015 10:39:51 -0400 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: "Thompson\, David" Subject: Re: bug#21694: 'clone' syscall binding unreliable References: <87zizio8dc.fsf@gnu.org> <87k2qlls39.fsf@gnu.org> Date: Wed, 28 Oct 2015 15:39:49 +0100 In-Reply-To: <87k2qlls39.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sat, 17 Oct 2015 12:14:34 +0200") Message-ID: <87vb9r83be.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 21694-done Cc: 21694-done@debbugs.gnu.org, David Thompson X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) ludo@gnu.org (Ludovic Court=C3=A8s) skribis: > "Thompson, David" skribis: > >> On Fri, Oct 16, 2015 at 4:39 PM, Ludovic Court=C3=A8s wro= te: [...] >>> Now, there remains the question of CLONE_CHILD_SETTID and >>> CLONE_CHILD_CLEARTID. Since we=E2=80=99re passing NULL for =E2=80=98ct= id=E2=80=99, I expect >>> that these flags have no effect at all. >> >> I added those flags in commit ee78d02 because they solved a real issue >> I ran into. Adding those flags made 'clone' look like a >> 'primitive-fork' call when examined with strace. > > Could you check whether removing these flags makes a difference now? I removed them in commit after confirming that it affects neither the test suite nor =E2=80=98guix system environment=E2=80=99 (on x86_64, with L= inux-libre 4.2.3-gnu.) Thanks, Ludo=E2=80=99. ------------=_1446043205-13824-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 16 Oct 2015 20:40:13 +0000 Received: from localhost ([127.0.0.1]:53643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnBnQ-0008MU-J1 for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33664) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnBnN-0008MM-VI for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnBnM-0005zW-GN for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:09 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:53828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnBnM-0005zS-EY for submit@debbugs.gnu.org; Fri, 16 Oct 2015 16:40:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnBnL-00030I-6j for bug-guix@gnu.org; Fri, 16 Oct 2015 16:40:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnBnH-0005tN-3G for bug-guix@gnu.org; Fri, 16 Oct 2015 16:40:07 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnBnH-0005tH-0A for bug-guix@gnu.org; Fri, 16 Oct 2015 16:40:03 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:37224 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZnBnG-00025i-DN; Fri, 16 Oct 2015 16:40:02 -0400 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: David Thompson Subject: 'clone' syscall binding unreliable X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 25 =?utf-8?Q?Vend=C3=A9miaire?= an 224 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x3D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Date: Fri, 16 Oct 2015 22:39:59 +0200 Message-ID: <87zizio8dc.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit Cc: bug-guix@gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I=E2=80=99m reporting the problem and (hopefully) the solution, but I think= we=E2=80=99d better double-check this. The problem: Running the test below in a loop sometimes gets a SIGSEGV in the child process (on x86_64, libc 2.22.) --8<---------------cut here---------------start------------->8--- (use-modules (guix build syscalls) (ice-9 match)) (match (clone (logior CLONE_NEWUSER CLONE_CHILD_SETTID CLONE_CHILD_CLEARTID SIGCHLD)) (0 (throw 'x)) ;XXX: sometimes segfaults (pid (match (waitpid pid) ((_ . status) (pk 'status status) (exit (not (status:term-sig status))))))) --8<---------------cut here---------------end--------------->8--- Looking at (guix build syscalls) though, I see an ABI mismatch between our definition and the actual =E2=80=98syscall=E2=80=99 C function, and bet= ween our =E2=80=98clone=E2=80=99 definition and the actual C function. This leads to the attached patch, which also fixes the above problem for me. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 80b9d00..f931f8d 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -322,10 +322,16 @@ string TMPL and return its file name. TMPL must end with 'XXXXXX'." (define CLONE_NEWNET #x40000000) ;; The libc interface to sys_clone is not useful for Scheme programs, so the -;; low-level system call is wrapped instead. +;; low-level system call is wrapped instead. The 'syscall' function is +;; declared in as a variadic function; in practice, it expects 6 +;; pointer-sized arguments, as shown in, e.g., x86_64/syscall.S. (define clone (let* ((ptr (dynamic-func "syscall" (dynamic-link))) - (proc (pointer->procedure int ptr (list int int '*))) + (proc (pointer->procedure long ptr + (list long ;sysno + unsigned-long ;flags + '* '* '* + '*))) ;; TODO: Don't do this. (syscall-id (match (utsname:machine (uname)) ("i686" 120) @@ -336,7 +342,10 @@ string TMPL and return its file name. TMPL must end with 'XXXXXX'." "Create a new child process by duplicating the current parent process. Unlike the fork system call, clone accepts FLAGS that specify which resources are shared between the parent and child processes." - (let ((ret (proc syscall-id flags %null-pointer)) + (let ((ret (proc syscall-id flags + %null-pointer ;child stack + %null-pointer %null-pointer ;ptid & ctid + %null-pointer)) ;unused (err (errno))) (if (= ret -1) (throw 'system-error "clone" "~d: ~A" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Could you test this patch? Now, there remains the question of CLONE_CHILD_SETTID and CLONE_CHILD_CLEARTID. Since we=E2=80=99re passing NULL for =E2=80=98ctid= =E2=80=99, I expect that these flags have no effect at all. Conversely, libc uses these flags to update the thread ID in the child process (x86_64/arch-fork.h): --8<---------------cut here---------------start------------->8--- #define ARCH_FORK() \ INLINE_SYSCALL (clone, 4, = \ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, = \ NULL, &THREAD_SELF->tid) --8<---------------cut here---------------end--------------->8--- This is certainly useful, but we=E2=80=99d have troubles doing it from the = FFI=E2=80=A6 It may that this is fine if the process doesn=E2=80=99t use threads. Ludo=E2=80=99. --=-=-=-- ------------=_1446043205-13824-1--