From patchwork Mon Apr 24 15:03:52 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: 68214 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 9A6B8385701B for ; Mon, 24 Apr 2023 15:04:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A6B8385701B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682348667; bh=pntZ9B1F5kh3oAC+pQX9/hvpZsXg2NDeT4aoqcUxpVY=; 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=FzNtMF34rHP6hul4bRP2put96d6/DfGrqzMwBwnE/qcBRryEqfQQVHb1w3gNH2aHQ CihDj+1ntxASU7NqWnMyBupd6CQ79MeMELgw0Lg91uAeCeZslkQ+xDSSXXU/CC1NXr 8SPKEcBwjS4VYaehp+tanQTXJSTTuhZhMbuG8Khw= 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 E2B473858D1E for ; Mon, 24 Apr 2023 15:04:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2B473858D1E Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-QLhDCzrjMNWsOo0FbDS2tg-1; Mon, 24 Apr 2023 11:04:01 -0400 X-MC-Unique: QLhDCzrjMNWsOo0FbDS2tg-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3ef5c322d56so21063931cf.1 for ; Mon, 24 Apr 2023 08:04:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682348640; x=1684940640; 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=pntZ9B1F5kh3oAC+pQX9/hvpZsXg2NDeT4aoqcUxpVY=; b=k+iB8mDbKCqKtEdnMl0CFO7Ga77ajV39NP0pX9dkDlimJBhdQN8rwJH0A98Z0H/gyw gQCAOEw2qEF14Ta9gkm7pcqdJoPMv4ZgSejeuzx8ZbCXfAzQCmOHveiu749OldeBxuo7 5Nvc6cQKcD9JAw4Z6SdWHbL4wkA4MozQIXWG/jm5yAF6CXpUOln9qBTum5kKm2DbNGTg AVGMChS1acMonBN9jcdD9bM+Flsk4HXJxFt+f1w/EpE0oxfV94sFV0YQLX5yCY7TgcAn s9LAK3bdv8cYt8KioACuEF8Yw3NBs9MTteAgD5HLyGddKxnta6SRb1H6hozlfqA2ghcW Jrhg== X-Gm-Message-State: AAQBX9epctgOMp6OzNSiBnmzH469gqhgz35HRRsDEukE6AY3dq3Xfs/2 6kE7fwi++MrqHmGCt0l2tYz/Th1Y8eGBZFgAmxD2DTDAfdXUtTGSXGIc0C9q59r9FYVV/eR2rBB lIyDos+8fsT/Kauuz6dIOA1hTu7NruGwSQk1Z2HtwRi0oMuC9p6HLd6J5HyUNIIO5ZMRtfdhxE2 5jRtrJ X-Received: by 2002:ac8:7dd1:0:b0:3e6:93e4:1e46 with SMTP id c17-20020ac87dd1000000b003e693e41e46mr19665199qte.52.1682348640496; Mon, 24 Apr 2023 08:04:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Yxr/GdQ9nWTRZvwys12UM8PbxOo9FcYaFPyvojeezBlGuvu8aHyoobEUftMLbs12b348WWJg== X-Received: by 2002:ac8:7dd1:0:b0:3e6:93e4:1e46 with SMTP id c17-20020ac87dd1000000b003e693e41e46mr19665152qte.52.1682348640028; Mon, 24 Apr 2023 08:04:00 -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 t15-20020ac8530f000000b003e9c6a4a381sm3683807qtn.54.2023.04.24.08.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 08:03:59 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v6 2/3] aarch64: Set the syscall register right before doing the syscall. Date: Mon, 24 Apr 2023 11:03:52 -0400 Message-Id: <20230424150353.1469397-3-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424150353.1469397-1-josimmon@redhat.com> References: <20230424150353.1469397-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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. Reviewed-by: Szabolcs Nagy --- 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" \ + : "=r" (_x0) \ + : "r"(_x8) ASM_ARGS_##nr \ + : "memory"); \ + } \ + _sys_result = _x0; \ + } \ _sys_result; }) # undef INTERNAL_SYSCALL