From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1669713176; bh=xCnL1mBBKNe7iQZUF4lrKAitoQA3U3xTUFKJe/FQVfs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ZlBbUpRSKpt4lq9IZMf0BpCQ4RfnFaaKL1jjRgeYlbpGCElWiJ/4JxdcFb6erO/Xv pIm8v6O+RbIhM7cJ2QVrYrkf67WcsF8O3WhkIoosXrzwNPDE2t4BQuHG5hRCAvo12F yJ5NtE5waCViDRyW75I/dJzkI8yrRZ1mcSzPqqLU= 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 From: Xi Ruoyao 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-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,GIT_PATCH_0,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_PDS_OTHER_BAD_TLD autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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