From patchwork Wed Apr 19 13:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 68007 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E297D3856972 for ; Wed, 19 Apr 2023 13:58:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E297D3856972 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681912737; bh=pqVlhb74m4PzlBkGvZvanDQH+Ljkh3bgwE2tW+vK+qk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kZQgOZQJfTUlrcNhXI+d5vq2YR/zkmzU2csjLapIQfsWUMTMvhxDNuwUfRUqMQk8P KR1h6ZiMUbvDg+AMJJBq7EP+uyTlBk49rB6AUG+Pooc7nsNY8vdZ8BUm3LTXK/LsRm bVOBpsytA1DgPmMo5tVu9oSy2zrBq4944DZ2Vzxc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 067963858D39 for ; Wed, 19 Apr 2023 13:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 067963858D39 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-UXU-lXtKPay0f9RZUETS0A-1; Wed, 19 Apr 2023 09:58:28 -0400 X-MC-Unique: UXU-lXtKPay0f9RZUETS0A-1 Received: by mail-qv1-f72.google.com with SMTP id j4-20020a0cc344000000b005e94fb0d2b0so14242085qvi.4 for ; Wed, 19 Apr 2023 06:58:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681912707; x=1684504707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pqVlhb74m4PzlBkGvZvanDQH+Ljkh3bgwE2tW+vK+qk=; b=GkGz6ctwNMY2xd2oUbFYMDUWcdPglf7r2/8myRTsRk8dssA64tx54z+6HHuGTv1lcP x3zqTD2e4ShjDu+8D3b5I9C8b1wcxgYfSRnaBMEu9dVDNybyd85fl2PQbCcVl4FZX2kH 1Lsc9wHhkEnCQBhKvwD2ah9qB7La0WhBApT++v+1XNc6vUNLG1XAS5p8zmSF9mQAgxzK Pw4BNCDSVK8YzT4sJ0SGeYbP/OHlc17Qcri1k3YpYIObn2NG+PRtbVOyvRVDojD5qAbk JJOTQJYrqm7sJrb/bv6/NTJ+kk7xLMh3MqUfrwgcMOCP5oNGpy8b0pF6syTrha7fVyG7 Ij1g== X-Gm-Message-State: AAQBX9dB7TciLvp76jHatajJ54pJQuOYMJ0cywtFa5WrERMoiuaVOr6n 9MM1S6F+KeoWal/8CQ4SArHTAdZv1Q9eadIsmyXz87dyYR9nIsniozhgJH+CLG4fZfio4v9X/mj pEu/B0kyN1+y5uS8DavacVbDXcIS2A7AB4Ll6NMOmMdlzC92gsG5xu9xzRLqLUidYRuQmX8Dz2r iK2m9T X-Received: by 2002:a05:6214:19cb:b0:5f1:89ba:c0b4 with SMTP id j11-20020a05621419cb00b005f189bac0b4mr4351483qvc.48.1681912707765; Wed, 19 Apr 2023 06:58:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Z6n5z4eXpMqGvEiK3BqP2tpaNgW/rSwXyRIgAzMCOHEfqP++ZJUquXrahX4IELu6pKuTLo7Q== X-Received: by 2002:a05:6214:19cb:b0:5f1:89ba:c0b4 with SMTP id j11-20020a05621419cb00b005f189bac0b4mr4351457qvc.48.1681912707510; Wed, 19 Apr 2023 06:58:27 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id ks7-20020a056214310700b005e8f61012e0sm4366953qvb.27.2023.04.19.06.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 06:58:26 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v5 2/3] aarch64: Set the syscall register right before doing the syscall. Date: Wed, 19 Apr 2023 09:58:20 -0400 Message-Id: <20230419135821.4113156-3-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419135821.4113156-1-josimmon@redhat.com> References: <20230411133004.2268170-1-josimmon@redhat.com> <20230419135821.4113156-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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 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: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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/aarch64/sysdep.h | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index e94d1703ad..6fe40aaf89 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -168,15 +168,26 @@ # define HAVE_CLONE3_WRAPPER 1 # undef INTERNAL_SYSCALL_RAW -# define INTERNAL_SYSCALL_RAW(name, nr, args...) \ - ({ long _sys_result; \ - { \ - LOAD_ARGS_##nr (args) \ - register long _x8 asm ("x8") = (name); \ - asm volatile ("svc 0 // syscall " # name \ - : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \ - _sys_result = _x0; \ - } \ +# define INTERNAL_SYSCALL_RAW(name, nr, args...) \ + ({ long _sys_result; \ + { \ + LOAD_ARGS_##nr (args) \ + if (__builtin_constant_p(name)) \ + asm volatile ("mov x8, %1 // syscall " # name "\n" \ + "svc 0" \ + : "=r" (_x0) \ + : "i" (name) ASM_ARGS_##nr \ + : "x8", "memory"); \ + else \ + { \ + register long _x8 asm ("x8") = (name); \ + asm volatile ("svc 0\n\t" \ + : "=r" (_x0) \ + : "r"(_x8) ASM_ARGS_##nr \ + : "memory"); \ + } \ + _sys_result = _x0; \ + } \ _sys_result; }) # undef INTERNAL_SYSCALL