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 E2B473858D1E for ; Mon, 24 Apr 2023 15:04:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2B473858D1E 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=1682348642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pntZ9B1F5kh3oAC+pQX9/hvpZsXg2NDeT4aoqcUxpVY=; b=iwlzpfPvMizk0JX7fuupGZgWtX+9UIf3w80Ti4Vxx0HUyCurd8zdIaIA1LUOU4lxJmmRsM suyaUJqDFy9SeR2fHXcVKpc80lSHpKJspugTqYDor5mTg4fXwJ2cwVQQULqDmBB3J4OVfW 6/QIGa7CUtYf9sgFERXSeJWQSnhZ1hk= 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) From: Joe Simmons-Talbott 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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" \ + : "=r" (_x0) \ + : "r"(_x8) ASM_ARGS_##nr \ + : "memory"); \ + } \ + _sys_result = _x0; \ + } \ _sys_result; }) # undef INTERNAL_SYSCALL -- 2.39.2