From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E3E5E3857736 for ; Mon, 15 May 2023 14:15:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3E5E3857736 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684160153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=99UmPbomHxPzrK+egadXez14p1vDJWlfDyTF9z+WIXI=; b=fnNeRzsdlqrIErrFQz3yUmD1W9yTBYTyK4fZWYy87iv3ArxsBt+HMVvXzVtcBqzUDWjbNd G/beJjJf+cqIEHZuvi6iU4/jsOAwnVWOLdV2dfJe7T2A5IGs/Bnv3sIF46hK1UrYn+WAbd fj5e6UBH3HQb/I2Hp4ahTkZDGZfK+ic= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-j1hbagKCOE69l5x3I53EEA-1; Mon, 15 May 2023 10:15:50 -0400 X-MC-Unique: j1hbagKCOE69l5x3I53EEA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4759381D1FD; Mon, 15 May 2023 14:15:49 +0000 (UTC) Received: from oak (unknown [10.22.32.82]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8804F40C206F; Mon, 15 May 2023 14:15:49 +0000 (UTC) Date: Mon, 15 May 2023 10:15:48 -0400 From: Joe Simmons-Talbott To: libc-alpha@sourceware.org, "H.J. Lu" Subject: Re: [PATCH v6 1/3] x86_64: Set the syscall register right before doing the syscall. Message-ID: <20230515141548.GA176347@oak> References: <20230424150353.1469397-1-josimmon@redhat.com> <20230424150353.1469397-2-josimmon@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230424150353.1469397-2-josimmon@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: Hi H.J., Is there anything else you are looking for on x86_64 WRT this patch? Thanks, Joe On Mon, Apr 24, 2023 at 11:03:51AM -0400, Joe Simmons-Talbott wrote: > To make identifying syscalls easier during call tree analysis load the > syscall number just before performing the syscall. > > Compiler optimizations can place quite a few instructions between the > setting of the syscall number and the syscall instruction. During call > tree analysis the number of instructions between the two can lead to > more difficulty for both tools and humans in properly identifying the > syscall number. Having the syscall number set in the prior instruction > to the syscall instruction makes this task easier and less error prone. > Being able to reliably identify syscalls made by a given API will make > it easier to understand and verify the safety and security of glibc. > --- > sysdeps/unix/sysv/linux/x86_64/sysdep.h | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h > index cfb51be8c5..0db8660531 100644 > --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h > +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h > @@ -257,9 +257,9 @@ > TYPEFY (arg1, __arg1) = ARGIFY (arg1); \ > register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ > asm volatile ( \ > - "syscall\n\t" \ > + "movl %1, %k0\n\tsyscall\n\t" \ > : "=a" (resultvar) \ > - : "0" (number), "r" (_a1) \ > + : "g" (number), "r" (_a1) \ > : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ > (long int) resultvar; \ > }) > @@ -273,9 +273,9 @@ > register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ > register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ > asm volatile ( \ > - "syscall\n\t" \ > + "movl %1, %k0\n\tsyscall\n\t" \ > : "=a" (resultvar) \ > - : "0" (number), "r" (_a1), "r" (_a2) \ > + : "g" (number), "r" (_a1), "r" (_a2) \ > : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ > (long int) resultvar; \ > }) > @@ -291,9 +291,9 @@ > register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ > register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ > asm volatile ( \ > - "syscall\n\t" \ > + "movl %1, %k0\n\tsyscall\n\t" \ > : "=a" (resultvar) \ > - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3) \ > + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3) \ > : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ > (long int) resultvar; \ > }) > @@ -311,9 +311,9 @@ > register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ > register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ > asm volatile ( \ > - "syscall\n\t" \ > + "movl %1, %k0\n\tsyscall\n\t" \ > : "=a" (resultvar) \ > - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \ > + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \ > : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ > (long int) resultvar; \ > }) > @@ -333,9 +333,9 @@ > register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ > register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ > asm volatile ( \ > - "syscall\n\t" \ > + "movl %1, %k0\n\tsyscall\n\t" \ > : "=a" (resultvar) \ > - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ > + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ > "r" (_a5) \ > : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ > (long int) resultvar; \ > @@ -358,9 +358,9 @@ > register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ > register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ > asm volatile ( \ > - "syscall\n\t" \ > + "movl %1, %k0\n\tsyscall\n\t" \ > : "=a" (resultvar) \ > - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ > + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ > "r" (_a5), "r" (_a6) \ > : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ > (long int) resultvar; \ > -- > 2.39.2 >