From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,T_PDS_OTHER_BAD_TLD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DB4971F4C1 for ; Tue, 29 Nov 2022 09:13:21 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="IMAmmZHj"; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B232E385222E for ; Tue, 29 Nov 2022 09:13:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B232E385222E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669713197; bh=5peGNaYUAH3ezqV6A8mwU/LSUYoAu0LHu0B7l3WAkmk=; h=Subject:To:Cc:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IMAmmZHjprE9R4FynYLPTYxqaDe+grCfwNyK9aedkAshOSBsv2Bgbb71eIfH4cxvS gGIeS1uTfks7zJm33LNDsZz8BlI2q+wva6W2L/8Sm3zYdFNFSrUAJx0TvTGXZZ5GoH cvvFt1LLGFrCebcLCQyfvcFzO8tWAKyLKe73sULc= Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 4DC1E3852233 for ; Tue, 29 Nov 2022 09:12:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4DC1E3852233 Received: from [IPv6:240e:358:112c:8300:dc73:854d:832e:3] (unknown [IPv6:240e:358:112c:8300:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 2BA3465DB5; Tue, 29 Nov 2022 04:12:51 -0500 (EST) Message-ID: Subject: Re: [PATCH] linux: Change syscall return value to long int To: Szabolcs Nagy , XingLi , Wang Xuerui Cc: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, caiyinyu@loongson.cn, wanghongliang@loongson.cn, hejinyang@loongson.cn Date: Tue, 29 Nov 2022 17:12:44 +0800 In-Reply-To: References: <20221129031659.2263453-1-lixing@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Xi Ruoyao via Libc-alpha Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Xuerui: can you help to rewrite the commit message? The code change seems obvious but I'm not sure how to describe the rationale precisely either. On Tue, 2022-11-29 at 08:55 +0000, Szabolcs Nagy wrote: > The 11/29/2022 11:16, XingLi wrote: > > From: Xing Li > >=20 > > The kernel syscall return is long value. > > The generic syscall interface return value > > is int, which may lead to incorrect return value. >=20 > it's not clear what you mean here, the generic syscall > function returns long (according to unistd.h). >=20 > >=20 > > The following test is syscall with mmap executed on LoongArch, > > only 32bits and sign extension value returned leading to mmap > > failure, > > which should be with 47bits address returned. > >=20 > > Testcase: > >=20 > > =C2=A0#include > > =C2=A0#include > > =C2=A0#include > >=20 > > void main() > > { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 long int ret; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D syscall(SYS_mmap, NU= LL, 0x801000, PROT_READ | > > PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); >=20 > Note: there are many reasons why direct calls to syscall > may not work. >=20 > syscall is a variadic argument function that takes long > arguments, but you pass ints that may *not* be sign/zero > extended on the caller site so e.g. the top 32bits of > size and offset can be arbitrary on a 64bit system. > (you have to cast args to long to make the example valid). >=20 > and some systems use SYS_mmap2. >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 printf("map address is %lx\n= ",ret); > > } > >=20 > > Result: > > [lixing@Sunhaiyong test]$ ./mmap > > map address is fffffffff008c000 > > --- > > =C2=A0sysdeps/unix/sysv/linux/syscall.c | 2 +- > > =C2=A01 file changed, 1 insertion(+), 1 deletion(-) > >=20 > > diff --git a/sysdeps/unix/sysv/linux/syscall.c > > b/sysdeps/unix/sysv/linux/syscall.c > > index 7303ba7188..8cb0b66b1c 100644 > > --- a/sysdeps/unix/sysv/linux/syscall.c > > +++ b/sysdeps/unix/sysv/linux/syscall.c > > @@ -33,7 +33,7 @@ syscall (long int number, ...) > > =C2=A0=C2=A0 long int a5 =3D va_arg (args, long int); > > =C2=A0=C2=A0 va_end (args); > > =C2=A0 > > -=C2=A0 int r =3D INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4= , > > a5); > > +=C2=A0 long int r =3D INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a= 3, > > a4, a5); > > =C2=A0=C2=A0 if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r))) >=20 > this change looks reasonable to me. >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __set_errno (-r); > > --=20 > > 2.31.1 > >=20 --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University