From nobody Fri Dec 19 20:12:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 155415688277435.9707076615216; Mon, 1 Apr 2019 15:14:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:57196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB5CO-0002gF-JG for importer@patchew.org; Mon, 01 Apr 2019 18:14:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB475-0003co-Jw for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:05:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hB474-0004xU-6C for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:05:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41894 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hB474-0004mU-0j for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:05:02 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x31L4bSf053573 for ; Mon, 1 Apr 2019 17:04:46 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 2rkrjx58sw-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 01 Apr 2019 17:04:41 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 1 Apr 2019 22:03:00 +0100 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 1 Apr 2019 22:02:57 +0100 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x31L2uYc21692482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Apr 2019 21:02:56 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 588E57806D; Mon, 1 Apr 2019 21:02:56 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 216E778070; Mon, 1 Apr 2019 21:02:56 +0000 (GMT) Received: from localhost (unknown [9.80.94.43]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 1 Apr 2019 21:02:56 +0000 (GMT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 1 Apr 2019 15:59:53 -0500 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190401210011.16009-1-mdroth@linux.vnet.ibm.com> References: <20190401210011.16009-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19040121-8235-0000-0000-00000E781EF7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010857; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000283; SDB=6.01182941; UDB=6.00619269; IPR=6.00963684; MB=3.00026249; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-01 21:02:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19040121-8236-0000-0000-000044FDC11F Message-Id: <20190401210011.16009-80-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-01_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904010136 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id x31L4bSf053573 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 79/97] linux-user: write(fd, NULL, 0) parity with linux's treatment of same X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Tony Garnock-Jones , qemu-stable@nongnu.org, Tony Garnock-Jones Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Tony Garnock-Jones Bring linux-user write(2) handling into line with linux for the case of a 0-byte write with a NULL buffer. Based on a patch originally written by Zhuowei Zhang. Addresses https://bugs.launchpad.net/qemu/+bug/1716292. >From Zhuowei Zhang's patch (https://lists.gnu.org/archive/html/qemu-devel/= 2017-09/msg08073.html): Linux returns success for the special case of calling write with a zero-length NULL buffer: compiling and running int main() { ssize_t ret =3D write(STDOUT_FILENO, NULL, 0); fprintf(stderr, "write returned %ld\n", ret); return 0; } gives "write returned 0" when run directly, but "write returned -1" in QEMU. This commit checks for this situation and returns success if found. Subsequent discussion raised the following questions (and my answers): - Q. Should TARGET_NR_read pass through to safe_read in this situation too? A. I'm wary of changing unrelated code to the specific problem I'm addressing. TARGET_NR_read is already consistent with Linux for this case. - Q. Do pread64/pwrite64 need to be changed similarly? A. Experiment suggests not: both linux and linux-user yield -1 for NULL 0-length reads/writes. Signed-off-by: Tony Garnock-Jones Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Laurent Vivier Message-Id: <20180908182205.GB409@mornington.dcs.gla.ac.uk> Signed-off-by: Laurent Vivier (cherry picked from commit 58cfa6c2e6eb51b23cc98f81d16136b3ca929b31) Signed-off-by: Michael Roth --- linux-user/syscall.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5a4af76c03..1477509cf2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8077,6 +8077,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, } break; case TARGET_NR_write: + if (arg2 =3D=3D 0 && arg3 =3D=3D 0) { + return get_errno(safe_write(arg1, 0, 0)); + } if (!(p =3D lock_user(VERIFY_READ, arg2, arg3, 1))) goto efault; if (fd_trans_target_to_host_data(arg1)) { --=20 2.17.1