From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 3C0223858C53 for ; Mon, 17 Apr 2023 22:36:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C0223858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62b.google.com with SMTP id ud9so68082918ejc.7 for ; Mon, 17 Apr 2023 15:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681771006; x=1684363006; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BFatz38KTQz38DWtz6kEGLN6OcbgNibFILR5PqLgzZs=; b=bxiR1m7TQobII5POeheISkSo2mKkXzDxZzfhZpSOzHMt5D8l3pcqd7prRtsb6Exr5j gjKnBdHPtZbqR3FAn8FD01j9a3+8PumUTddg0RoWLyC0RJkbQ84D9iU47txz31axcNsy K4zYqEctAbUS2/rCONhkwJevK3lKZqpfNDUYYrO6BnyNcZjxoAUkWWMRRkiL8FZTIRFF 1KKZZGaWOBR4qnD29gBYQAaOWRFvBwlQvGVybESVBcJvpHHkvYpfkCSOKQJduJIJ42i/ rSXaRcsue7Gf8Tl82oNpa1qbEnJ5esnSPyvslbR2ewRI9CssyuVeeNUw8NKsXrBjjk7i E4KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681771006; x=1684363006; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BFatz38KTQz38DWtz6kEGLN6OcbgNibFILR5PqLgzZs=; b=SJTybjOjC17dzoHBC+GxXV9pvHd7SDo0De9L/cvgJVOnm1ailavcIojzGW46rXE65h XVuCN4tGD2a7Tdz8nEQ/qIfEDfqZlis3RwR20Vesyd07AAClblr9Rja7WqAzC7KOTBEE dSgaFWdDbhOO1Ccc1ncZgxWC6CWEANfmLL+aK4Hw7S3U6Y/+MHL+eXoA0vNcjzqJYeML nN9z+pLuAd2p9ZIUsBF6JdqJNn8inhbCUHWxOaIDFUyFnYTEzn1XfGIjPR8HVX198bh4 RS3b8Skl0r3gJuxzU1CGMm7GshU8SzJhPB9XpLSX37pj0nmJMI4yskjh/p/gcl/gXXOF jC4g== X-Gm-Message-State: AAQBX9crDr+V8luoLBNe7nTF4DU4k8k5bZG66kadkagLbfM0z86XMNdC 5CQWXvGzwsBd+9tjKHC9ptvWlSV1fYf7hIp2ZJ8wvZ8O X-Google-Smtp-Source: AKy350bkP8lMgWiSfPXwTu4P29dfl9UfWUDffVbZn5zDXMFEQD5OHhxR7W7hQNAGE1DVbTiX8eHpVKWcgwFLPyUYLLk= X-Received: by 2002:a17:906:ae09:b0:94f:12bf:c819 with SMTP id le9-20020a170906ae0900b0094f12bfc819mr9114399ejb.64.1681771005745; Mon, 17 Apr 2023 15:36:45 -0700 (PDT) MIME-Version: 1.0 References: <20230411133004.2268170-1-josimmon@redhat.com> <20230411133004.2268170-2-josimmon@redhat.com> In-Reply-To: From: Noah Goldstein Date: Mon, 17 Apr 2023 17:36:34 -0500 Message-ID: Subject: Re: [PATCH 1/2] x86_64: Set the syscall register right before doing the syscall. To: Joe Simmons-Talbott Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On Mon, Apr 17, 2023 at 5:35=E2=80=AFPM Noah Goldstein wrote: > > > > On Tue, Apr 11, 2023 at 8:32=E2=80=AFAM Joe Simmons-Talbott via Libc-alph= a wrote: > > > > To make identifying syscalls easier during call tree analysis load the > > syscall number just before performing the syscall. > > --- > > sysdeps/unix/sysv/linux/x86_64/sysdep.h | 33 +++++++++++++++++++++++++ > > 1 file changed, 33 insertions(+) > > > > diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sys= v/linux/x86_64/sysdep.h > > index cfb51be8c5..800a56723f 100644 > > --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h > > +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h > > @@ -250,12 +250,20 @@ > > (long int) resultvar; = \ > > }) > > > > +#define MSTR_HELPER(x) #x > > +#define MSTR(x) MSTR_HELPER(x) > > + > > #undef internal_syscall1 > > #define internal_syscall1(number, arg1) = \ > > ({ = \ > > unsigned long int resultvar; = \ > > TYPEFY (arg1, __arg1) =3D ARGIFY (arg1); = \ > > register TYPEFY (arg1, _a1) asm ("rdi") =3D __arg1; = \ > > + if (__builtin_constant_p(number)) \ > > + asm volatile ("movl $" MSTR(number) ", %%eax\n\t" \ > > + : /* no outputs */ \ > > + : "i" (number) \ > > + : "eax"); \ > > asm volatile ( = \ > > "syscall\n\t" = \ > > : "=3Da" (resultvar) = \ > > @@ -272,6 +280,11 @@ > > TYPEFY (arg1, __arg1) =3D ARGIFY (arg1); = \ > > register TYPEFY (arg2, _a2) asm ("rsi") =3D __arg2; = \ > > register TYPEFY (arg1, _a1) asm ("rdi") =3D __arg1; = \ > > + if (__builtin_constant_p(number)) \ > > + asm volatile ("movl $" MSTR(number) ", %%eax\n\t" \ > > + : /* no outputs */ \ > > + : "i" (number) \ > > + : "eax"); \ > Is it ever possible for another instruction to be re-ordered between sett= ing > `eax` and the `syscall`? nevermind, you addressed in V2. > > asm volatile ( = \ > > "syscall\n\t" = \ > > : "=3Da" (resultvar) = \ > > @@ -290,6 +303,11 @@ > > register TYPEFY (arg3, _a3) asm ("rdx") =3D __arg3; = \ > > register TYPEFY (arg2, _a2) asm ("rsi") =3D __arg2; = \ > > register TYPEFY (arg1, _a1) asm ("rdi") =3D __arg1; = \ > > + if (__builtin_constant_p(number)) \ > > + asm volatile ("movl $" MSTR(number) ", %%eax\n\t" \ > > + : /* no outputs */ \ > > + : "i" (number) \ > > + : "eax"); \ > > asm volatile ( = \ > > "syscall\n\t" = \ > > : "=3Da" (resultvar) = \ > > @@ -310,6 +328,11 @@ > > register TYPEFY (arg3, _a3) asm ("rdx") =3D __arg3; = \ > > register TYPEFY (arg2, _a2) asm ("rsi") =3D __arg2; = \ > > register TYPEFY (arg1, _a1) asm ("rdi") =3D __arg1; = \ > > + if (__builtin_constant_p(number)) \ > > + asm volatile ("movl $" MSTR(number) ", %%eax\n\t" \ > > + : /* no outputs */ \ > > + : "i" (number) \ > > + : "eax"); \ > > asm volatile ( = \ > > "syscall\n\t" = \ > > : "=3Da" (resultvar) = \ > > @@ -332,6 +355,11 @@ > > register TYPEFY (arg3, _a3) asm ("rdx") =3D __arg3; = \ > > register TYPEFY (arg2, _a2) asm ("rsi") =3D __arg2; = \ > > register TYPEFY (arg1, _a1) asm ("rdi") =3D __arg1; = \ > > + if (__builtin_constant_p(number)) \ > > + asm volatile ("movl $" MSTR(number) ", %%eax\n\t" \ > > + : /* no outputs */ \ > > + : "i" (number) \ > > + : "eax"); \ > > asm volatile ( = \ > > "syscall\n\t" = \ > > : "=3Da" (resultvar) = \ > > @@ -357,6 +385,11 @@ > > register TYPEFY (arg3, _a3) asm ("rdx") =3D __arg3; = \ > > register TYPEFY (arg2, _a2) asm ("rsi") =3D __arg2; = \ > > register TYPEFY (arg1, _a1) asm ("rdi") =3D __arg1; = \ > > + if (__builtin_constant_p(number)) \ > > + asm volatile ("movl $" MSTR(number) ", %%eax\n\t" \ > > + : /* no outputs */ \ > > + : "i" (number) \ > > + : "eax"); \ > > asm volatile ( = \ > > "syscall\n\t" = \ > > : "=3Da" (resultvar) = \ > > -- > > 2.39.2 > >