From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by sourceware.org (Postfix) with ESMTPS id 9A55A3841893 for ; Mon, 20 Jun 2022 22:55:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9A55A3841893 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f54.google.com with SMTP id e25so12634492wrc.13 for ; Mon, 20 Jun 2022 15:55:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qoNR/MW2uyuit5PHujuHYm2iAJi1soSeUkvx5+9nztY=; b=Cd8f7zJ3LfII6p99TA0+uMlET6Mt7iXObjJ0SxV8a23ONu8Wq5NwmnpO+M9Ey0Epq6 +q4XmPTeI36IJdjDYvWzk+HFeJEdgXVLiHngKtX8XAisJ/PRp0S3zc7SebZtQz6Me2KI VIggeY+uitfu7iH4tCXXl5PcuD8f91C5eO1AzNSo+JEuThDTm2fTwAsY6GoLBGZogj0d IkUP4U/Bw3LFfIxy3fcRn9o2jwXj0M80crqyiZiHZIF+v/2qzVH1VtKUUTqgA5AIWBp5 svR9aJb90/hmrIUy1FtHhO+bMCctsXEXSHiRM4IRwgaTvODxJvj/rD7n/l7s+9CzymjC KdEA== X-Gm-Message-State: AJIora9iwguMuV246U1RUe98zbLqSQ4f4vZKBefWmUXEpSa/NpHGqUPy Zx+e+lUc72/dcCHJvS/l+3prxM3oIRk= X-Google-Smtp-Source: AGRyM1uNoCLjYe4J1+xz3oPPZ8lIQjyl8AHReyHAfbRLRK/9yzhDjHXIPyJkf7h0ZXosape0UiSZOA== X-Received: by 2002:a05:6000:1446:b0:218:5a5d:6cb5 with SMTP id v6-20020a056000144600b002185a5d6cb5mr24771833wrx.629.1655765711638; Mon, 20 Jun 2022 15:55:11 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id h18-20020a5d4312000000b002167efdd549sm14460072wrq.38.2022.06.20.15.55.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jun 2022 15:55:10 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 23/25] gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro Date: Mon, 20 Jun 2022 23:54:17 +0100 Message-Id: <20220620225419.382221-24-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220620225419.382221-1-pedro@palves.net> References: <20220620225419.382221-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2022 22:55:14 -0000 Refactor the syscall assembly code in gdb/testsuite/lib/my-syscalls.S behind a SYSCALL macro so that it's easy to add new syscalls without duplicating code. Note that the way the macro is implemented, it only works correctly for syscalls with up to 3 arguments, and, if the syscall doesn't return (the macro doesn't bother to save/restore callee-saved registers). The following patch will want to use the macro to define a wrapper for the "exit" syscall, so the limitations continue to be sufficient. Change-Id: I8acf1463b11a084d6b4579aaffb49b5d0dea3bba --- gdb/testsuite/lib/my-syscalls.S | 50 +++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/gdb/testsuite/lib/my-syscalls.S b/gdb/testsuite/lib/my-syscalls.S index 5fc38948217..50544d101e0 100644 --- a/gdb/testsuite/lib/my-syscalls.S +++ b/gdb/testsuite/lib/my-syscalls.S @@ -21,36 +21,50 @@ #include -/* int my_execve (const char *file, char *argv[], char *envp[]); */ - -.global my_execve -my_execve: +/* The SYSCALL macro below current supports calling syscalls with up + to 3 arguments, and, assumes the syscall never returns, like exec + and exit. If you need to call syscalls with more arguments or you + need to call syscalls that actually return, you'll need to update + the macros. We don't bother with optimizing setting up fewer + arguments for syscalls that take fewer arguments, as we're not + optimizating for speed or space, but for maintainability. */ #if defined(__x86_64__) - mov $__NR_execve, %rax - /* rdi, rsi and rdx already contain the right arguments. */ -my_execve_syscall: - syscall - ret +#define SYSCALL(NAME, NR) \ +.global NAME ;\ +NAME: ;\ + mov $NR, %rax ;\ + /* rdi, rsi and rdx already contain the right arguments. */ \ +NAME ## _syscall: ;\ + syscall ;\ + ret ; #elif defined(__i386__) - mov $__NR_execve, %eax - mov 4(%esp), %ebx - mov 8(%esp), %ecx - mov 12(%esp), %edx -my_execve_syscall: - int $0x80 +#define SYSCALL(NAME, NR) \ +.global NAME ;\ +NAME: ;\ + mov $NR, %eax ;\ + mov 4(%esp), %ebx ;\ + mov 8(%esp), %ecx ;\ + mov 12(%esp), %edx ;\ +NAME ## _syscall: ;\ + int $0x80 ;\ ret #elif defined(__aarch64__) - mov x8, #__NR_execve - /* x0, x1 and x2 already contain the right arguments. */ -my_execve_syscall: +#define SYSCALL(NAME, NR) \ +.global NAME ;\ +NAME: ;\ + mov x8, NR ;\ + /* x0, x1 and x2 already contain the right arguments. */ \ +NAME ## _syscall: ;\ svc #0 #else # error "Unsupported architecture" #endif + +SYSCALL (my_execve, __NR_execve) -- 2.36.0