From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by sourceware.org (Postfix) with ESMTPS id 8184A38977BD for ; Wed, 13 Jul 2022 22:25:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8184A38977BD 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-f42.google.com with SMTP id v16so17405008wrd.13 for ; Wed, 13 Jul 2022 15:25:30 -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=hVPy7U1E4SOikSg0zhO5k3NLh4YSiCYApfoi5/s1dm1UskZyiVH1okq0HgE3/DUuiO XsI10iBTwhiXA7fRe9gcadX8+77aGD6Q1/MOrLtgzd2S21YOXGc3D76tfFZXsUkq/6wn XH6GxF4s8MJ4k1O8J4rp7O5dhrZ7p4V4teajBhr2v88eU5GfvbL87CFhQvpFXZ512ZaJ mvXHLdyRwcDevW52M1YvTP5CMc0Ir2Im+si7g1VLFf3wmV2b/lL3Fr5wCgRC3y2i53VW IJinXWi3olbtzQGjTFDgYPHu4xWFFfv2lgIjgUNzgd1kWcImwZYozNYy2sSdcq6cQyAQ 383A== X-Gm-Message-State: AJIora8GVoV5PCMMfHpxwlo2CYh3Ue1qERREcZWaEJHoPsJy4M1nPooW baJ2tlF23vNKSL7TZrsZLAx/6Rj2Hh4= X-Google-Smtp-Source: AGRyM1sHEgYj3urMbe+ZMWX7eUY9n01L07+RZdeL92gnttkQ6pvBfua8tJuEMYvqBQSGIUlcL83GvA== X-Received: by 2002:adf:e30b:0:b0:21d:8f3e:a370 with SMTP id b11-20020adfe30b000000b0021d8f3ea370mr5149277wrj.124.1657751128646; Wed, 13 Jul 2022 15:25:28 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id e5-20020a05600c4e4500b003a2e42ae9a4sm3878250wmq.14.2022.07.13.15.25.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Jul 2022 15:25:27 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 24/29] gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro Date: Wed, 13 Jul 2022 23:24:28 +0100 Message-Id: <20220713222433.374898-25-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220713222433.374898-1-pedro@palves.net> References: <20220713222433.374898-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 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: Wed, 13 Jul 2022 22:25:31 -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