From nobody Sat Nov 15 14:09:42 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1595362740; cv=none; d=zohomail.com; s=zohoarc; b=IQX0eY1wqbx5+ld7t7NVDUHoO9vpiFdXggG10uZ5gF/Xbo+iwFr6JF7N41rSJjstRjlRooDb++VyN5Pfw6WDerPPx3RqINpLfUA9sgznxIw6jn1ws2q0MN5fx9e5DksUn/gaDugHDhzdkD8v1ABHlAq55+s5beuMLcgB9dnBIFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595362740; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=jRSgnu8DQ8yAN3WvCBE4WZQfXxQJXQ/iZfG9MEnCETs=; b=apXlM33cUKjcnACYEdm9h0ye3RQ2UR4E8LVaQbULoEn1eh8Rfx3Hm7iJAXTcr4nC+V+aK7LBUUpLXdARZvzARbJm3kg8vGFlwA/JMQcK80x67sOjHHVnc8Cdo8B8dKwbbBdvo40KmzUmpYJhoX8ubU4qlVX1KXwbQsL2CYiTaO4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595362740668758.441387987546; Tue, 21 Jul 2020 13:19:00 -0700 (PDT) Received: from localhost ([::1]:44852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxyj4-0001MW-PS for importer@patchew.org; Tue, 21 Jul 2020 16:18:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxyiE-0000wE-01 for qemu-devel@nongnu.org; Tue, 21 Jul 2020 16:18:06 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:54603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxyiC-0005fS-7d for qemu-devel@nongnu.org; Tue, 21 Jul 2020 16:18:05 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N336J-1kyULg49G9-013NuK; Tue, 21 Jul 2020 22:17:58 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH] linux-user: fix clock_nanosleep() Date: Tue, 21 Jul 2020 22:17:54 +0200 Message-Id: <20200721201754.2731479-1-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ii3jxqkRO/HPYb/ekUYcNb86TzNNz6BaN1vtFbCu8KR9SJ3f4L2 0dgJR0epBgxJZlATTDscaC3JGLRwKpo2hdFgNvzZOsmhwfaeImSKO3so0tsppvW8vlFIUKE fNjKY2GqkUzeTIjAXwlZTiukryMtNhxL2qQzZ+NaF/o1J+DAerJOPaxVu4Eboc0mUDyF8+x KzmT7qkADp0XgOw+GvIoA== X-UI-Out-Filterresults: notjunk:1;V03:K0:PyymBnG4ZO4=:8bPi+EPlssMIjdf/04Rarx smk5msY3Th2EcvJ7CycybHkJWR1vPkO5wo6VHs4uHiLNT1UpbyNUrWGdjHk4EGb5MbLJ0mKkj RnZNGax66pbcME6z0zaC6sY+XcRO2mXcgTe17wSbQO1ObcZB68CjPI61D3cOheekIYogxGIWP 6rPYlxqBOOFMCYhy7ihvHZRc/IWNv3n+b318erJKfWA1OKkzjHbfQnyse9Vf2tBPOQLMmwU4x FEcBal++KTk6VvCuaC4AC74UeZ8bGW8v41SHZqMmPp8ymRzyBu15fTSP6o91a1nS25HoiQogL Co0c78IX3p4R29MCbJI0bSmfgscpQRaRsAYcQ6lDAuK3HUxx/aAY8W7ddcF/c6R8+iNSf/hQN wiwThDz6K8GxVnr/S9nhXGBbB0iaI74Rf5yqVf35+7QTfYZ6zjhN0PmvKex/DEtHUoAmORD3o cD3kohDZ+G4cZyN4gEf/wEVNvUDFxR2KNSCh2wBEsD8SZZSXHWqU1NRI3wKiu88uk3crWZTZj BTlxt1PRhhpML8LlKUUpUHo7MyDks9ph3HQBJFS30GEt+fAlGbSZ3oYcctJIzv+an+5h9LgWc 9k5gCKDsv8jQgoY5JCdIcISG3WzIUwn6v7es3A7llApa3YFefy8rhY4Io742YS2pM7NpxKtoC zjSpz+b/X5ybY6Oml3Cf7FoEwTMIFZORla0pzIXIRXrfnMMpDwnYi/EydfrW2eMzBSzbnDXUJ OMK7HwKyHagWXhgJyN1yDCI5X0Pk9tNPBqXP10kBIV7+whadQYwg915j35OGKtt2yd+SfSCaZ qMOWT3z6ybXL9tLnpp8pqwcMehnWqZYX5AZC2Fz6U+2gWa/8iwCIlYheCdXP5oYOQ05Qi4v Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/21 16:18:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" If clock_nanosleep() encounters an error, it returns one of the positive error number. If the call is interrupted by a signal handler, it fails with error EINTR and if "remain" is not NULL and "flags" is not TIMER_ABSTIME, it returns the remaining unslept time in "remain". Update linux-user to not overwrite the "remain" structure if there is no error. Found with "make check-tcg", linux-test fails on nanosleep test: TEST linux-test on x86_64 .../tests/tcg/multiarch/linux-test.c:242: nanosleep make[2]: *** [../Makefile.target:153: run-linux-test] Error 1 make[1]: *** [.../tests/tcg/Makefile.qemu:76: run-guest-tests] Error 2 make: *** [.../tests/Makefile.include:857: run-tcg-tests-x86_64-linux-user]= Error 2 Reported-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1211e759c26c..caa7cd3cab94 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11829,10 +11829,19 @@ static abi_long do_syscall1(void *cpu_env, int nu= m, abi_long arg1, { struct timespec ts; target_to_host_timespec(&ts, arg3); - ret =3D get_errno(safe_clock_nanosleep(arg1, arg2, - &ts, arg4 ? &ts : NULL)); - if (arg4) + /* + * clock_nanosleep() returns 0 or one of the *positive* error numb= er. + */ + ret =3D host_to_target_errno(safe_clock_nanosleep(arg1, arg2, &ts, + arg4 ? &ts : NULL)= ); + /* + * if the call is interrupted by a signal handler, it fails + * with error TARGET_EINTR and if arg4 is not NULL and arg2 is not + * TIMER_ABSTIME, it returns the remaining unslept time in arg4. + */ + if (ret =3D=3D TARGET_EINTR && arg4 && arg2 !=3D TIMER_ABSTIME) { host_to_target_timespec(arg4, &ts); + } =20 #if defined(TARGET_PPC) /* clock_nanosleep is odd in that it returns positive errno values. --=20 2.26.2