From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10931 invoked from network); 19 Jan 2021 20:35:51 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 19 Jan 2021 20:35:51 -0000 Received: (qmail 23838 invoked by uid 550); 19 Jan 2021 20:35:49 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 23817 invoked from network); 19 Jan 2021 20:35:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=notion-se.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=GVTcpw3bHgeMhKFlGfMtu/ftVdY1Nm1uj7fO9aA1dQ4=; b=tqd03mA4w0W2svkIkbEb9pHwfw0ccWo2SZoLp2rXu5zwOn6b+j6I9b5n3B3Bxfeg8K nP1Og59+KjmDEA1OSo/M0/yDYA5A+XzXwtMNkkYUJvmGC+BvRGZNE0V4oAaLEbw7ii/d J8eXllaJq1PP8E3uKlTPUtv96KlW9kypNcvjm59iCxYDqilU3iPbmPSkLCPdpQOoenbu sxO2hLuAW8gMPIBw4vrijxnUu/3oi5pipkGiJWOwBzCCiAJn0Ltw02CdvAvjdKLns4sX 68AJJjl8izb1qCrwaDEssFLOiU4WMWk6Qsi3p9irDKjxJbSATW4jbk5J3rUJQau6JT6q zqLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=GVTcpw3bHgeMhKFlGfMtu/ftVdY1Nm1uj7fO9aA1dQ4=; b=IvKqEmEurpunODHsPVFPsB7OaBcS0DgnyFQ8YbD+WTZ6DVuDs3XN0/Zxj2sWDmCX3e HBAhAuq5bcC1/BVZcd85PKQnHVA4YNhRk5SNxJOarFt5xt3aqTjQqst+gs1Cokgqk/wI 4iS8KUkDodllRQFm5+dcUKevIQi/GrbtNAV9Y07asHfMtNdi9yuPpkYFrRX/+kC6GgYl rPr+qJPQoD8leP2GeVCHJ7u283iDe3Xh10g045TITk649MvG1R6Vnm/SqcDgg8y6/mwZ vdO8kUIUTZ/PY8BijXki6FP9hL01473LjPiMXIvoiG07oQdcpMOUOUJcueCzooNHg/EH aLew== X-Gm-Message-State: AOAM532I1MjEbn1Ye4CXJDBz/WqqqYD2c9rQmWvKqdr6kxiMb31gUGpa kL9eAfvIHdqgWYcgO9lSnqGQGFr/79/V9aWgyNZd1fbmdITZ9w== X-Google-Smtp-Source: ABdhPJy+Sb5j5xJ7odvqm8GfeDl3VmFgLhF2Gw4RnNwYBOlyeR9HFukXMPBxYj3m3/x2funb27VmsK/2/0RJlGIcJtI= X-Received: by 2002:a63:2352:: with SMTP id u18mr6039313pgm.385.1611088536976; Tue, 19 Jan 2021 12:35:36 -0800 (PST) MIME-Version: 1.0 References: <20210119193337.GB2006@voyager> In-Reply-To: From: Rasmus Andersson Date: Tue, 19 Jan 2021 12:35:26 -0800 Message-ID: To: musl@lists.openwall.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [musl] waitpid (wait4) on Linux 5 returns invalid values Relevant parts from disassembly: (objdump --disassemble --source --line-numbers a.out) 0000000000401f61 <__syscall_cp_c>: sccp(): 401f61: 48 89 f8 mov %rdi,%rax 401f64: 4d 89 c2 mov %r8,%r10 401f67: 48 89 f7 mov %rsi,%rdi 401f6a: 4d 89 c8 mov %r9,%r8 401f6d: 48 89 d6 mov %rdx,%rsi 401f70: 4c 8b 4c 24 08 mov 0x8(%rsp),%r9 401f75: 48 89 ca mov %rcx,%rdx 401f78: 0f 05 syscall 401f7a: c3 retq 0000000000401f7b <__syscall_cp>: __syscall_cp(): 401f7b: e9 e1 ff ff ff jmpq 401f61 <__syscall_cp_c> 00000000004004fd : waitpid(): ... 40051a: e8 5c 1a 00 00 callq 401f7b <__syscall_cp> 40051f: 48 83 c4 18 add $0x18,%rsp 400523: c3 retq main(): ... 4002a2: e8 56 02 00 00 callq 4004fd On Tue, Jan 19, 2021 at 12:28 PM Rasmus Andersson wrote: > > In the meantime, in case you're curious, here's a program that > reproduces the issue. I've attached a statically-compiled version too > that can be disassembled. Running it: > $ gcc -static a.c && ./a.out > waitpid returned -10, wstat=0 > > #include > #include > int main(int argc, char **argv) { > int wstat = 0; > pid_t child = waitpid(-1, &wstat, WNOHANG); > printf("waitpid returned %d, wstat=%d\n", child, wstat); > return 0; > } > > On Tue, Jan 19, 2021 at 12:17 PM Rasmus Andersson wrote: > > > > On Tue, Jan 19, 2021 at 11:33 AM Markus Wichmann wrote: > > > > > > On Tue, Jan 19, 2021 at 10:18:04AM -0800, Rasmus Andersson wrote: > > > > However the wait4 syscall[3] in Linux 5 returns other values, > > > > specifically it returns errors as negative values. The error that > > > > trips up programs like runit's runsv is ECHILD (-10) which wait4 > > > > returns when there are no children (i.e. they have exited.) > > > > > > > > > > Hmm... that is very weird. That should not happen. Because the > > > syscall_cp macro already contains a call to __syscall_ret(), which does > > > exactly what you propose. So that means, there is something else going > > > on in your copy of the code. Did you change anything about the source > > > code? Or can you disassemble the function to see what it does? > > > > > Strange! You are right of course; looking at src/internal/syscall.h I > > indeed see that syscall_cp calls __syscall_ret(__syscall_cp(args)) > > The musl I'm building with comes from https://musl.cc/#binaries which > > is created from these scripts according to the author: > > https://git.zv.io/xstatic/mcm It doesn't seem to apply any patches. > > Anyhow, I'm currently building musl & gcc myself using > > musl-cross-make. I will see how that pans out and report back. > > Thank you for your quick response Markus!