From patchwork Sun Aug 25 01:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1976426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WrxLP37VTz1yNm for ; Sun, 25 Aug 2024 11:39:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BFB4384DEE3 for ; Sun, 25 Aug 2024 01:39:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 87E9E384F00E for ; Sun, 25 Aug 2024 01:38:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87E9E384F00E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 87E9E384F00E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.77.166.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724549909; cv=none; b=EJOfJ35CjTtXS/t0jbmxCvyCUri034nuXUk6THpDVvu8VtPUHvOXBmcsEBFayDjTs8hkEluJmfx/P+YCmdQ9jRav0htOMYNwIY+uZuTWikPkVZuX3aZMkvK+vWa34MC9w73I1Lqf9lrdpDD8Am7RvSpWa/E7x3deRaAlxef7cuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724549909; c=relaxed/simple; bh=yRzZ3EmkwGwYZEVx9ck3S0uTHJkY8AAFIvNEMtiurMI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fQBKWSZ52c3siDw9t7vx9/ywEyqTtB1jRHY7tIJQ7BlmZt6dq/DKht3WlgvXsLFNJiZ3JsvqlG5Ebwwc/V9MGVpg3FaCnIMDNyscCMav9TP2uRhVIh336+CT9ovKbST8lK/BlOjoSh/3K98l2y0+N30oglMXLUqv2igd7Yr9KRk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 57845A0358; Sun, 25 Aug 2024 03:38:20 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KGItedIl-Nta; Sun, 25 Aug 2024 03:38:20 +0200 (CEST) Received: from begin (aamiens-653-1-40-48.w83-192.abo.wanadoo.fr [83.192.199.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 3ADF2A0316; Sun, 25 Aug 2024 03:38:20 +0200 (CEST) Received: from samy by begin with local (Exim 4.98) (envelope-from ) id 1si2Cx-00000001jrT-3BL7; Sun, 25 Aug 2024 03:38:19 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] mach: Fix bogus negative return Date: Sun, 25 Aug 2024 03:38:16 +0200 Message-ID: <20240825013816.414609-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org One can be very unlucky to call time_now first just before a second switch, and mach_msg sleep just a bit more enough for the second time_now call to count one second too many (or even more if scheduling is really unlucky). So we have to protect against returning a bogus negative value in such case. --- sysdeps/mach/sleep.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c index 572be150bc..aa750c13c5 100644 --- a/sysdeps/mach/sleep.c +++ b/sysdeps/mach/sleep.c @@ -43,6 +43,9 @@ __sleep (unsigned int seconds) after = time_now (); __mach_port_destroy (__mach_task_self (), recv); + if (after - before > seconds) + return 0; + return seconds - (after - before); } weak_alias (__sleep, sleep)