From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by sourceware.org (Postfix) with ESMTPS id D6104385B528 for ; Mon, 13 Nov 2023 15:06:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6104385B528 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D6104385B528 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887964; cv=none; b=gUKfTHahLxPMNzIdCa3+4d6d1cvN8XqNH0p+Rpo7rq2MCp8Zx6iEKLtheJWuS5LS6IAP6wmyQupLW7gEBwAKjLg9CzNFh9KWGacas3m0LL99Bvd3P35LBW73Q5/Gwx6OTBKoQD9jz2U9ej0v6Vh0h8esQtu/QnF3hQHzf7hhZ7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887964; c=relaxed/simple; bh=3FAFcNB6orBj8ADs7nDkc4VeI5KMlxomNt0Oy0SiHqQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=OYUhKILvsaI683+AG6hRm1ZfeEMlrU3LSH+nDv6rV/HpkrTKLVODZvbgyV4rJW6dAedV+m1HHQ7GNQN2v0cYA24SmyPaqkzys1Ouzokm03ulhEdDJWjdMJ46HP2N3qI+AiAIqxL0BxMjlQyw9uNnGX5EQRWIRVA1BZQjxXRgHwg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4083f613275so37550445e9.2 for ; Mon, 13 Nov 2023 07:06:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887960; x=1700492760; 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=qN+8fOi+por936xgM9ICrn7jfm+1h8lyoEZlXP5VUL8=; b=OkCna/UoCDcZbbk9kDLbMIDfHJc5mm/C2P6hhlSiJQwyv1IdOMn/pMxqxJ9JcM+boT KLUZnS/4i3u7IUC1w7rHCrntGrzExyUIorayg2iVF5SJ1Yn5XoL+9UM2XUVeegeEDQHy pR+yGxHGywVoiA905bBx2hh+McC0eojjfta7NbWjtL1WP1v6sW7Tp+gCHeD/3l+VDy3P SaxPlzHxZ7S0EmiFH5FWv55e9y4TDrHorU+j7AticJDmbPBu0ATJgoU90+mofmIZN2HF IUV/xrlI/JdhA1wxcTuaz2CAx7s4gO8Q4S4w0DzRJFIJX+fyt9wzDwJmCeSIVqsc06jE Omjg== X-Gm-Message-State: AOJu0YxLrDyfFe/A1Edm7ec2adpUK9XV7p2KUZJ3nlkH06TgAnRFURXn V9TL1TXmbOge9y/EDcRQJFHpVhWDA9E= X-Google-Smtp-Source: AGHT+IGAwRPLlNian8pLfS3noF3zTkKLUQMBYcLLWOd55WfX+zP8R2wxo7CCQqfEU+q9R2/S8+yfNw== X-Received: by 2002:a05:600c:1913:b0:408:cd96:7164 with SMTP id j19-20020a05600c191300b00408cd967164mr4756618wmq.9.1699887960542; Mon, 13 Nov 2023 07:06:00 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with UTF8SMTPSA id fm6-20020a05600c0c0600b004063d8b43e7sm14248437wmb.48.2023.11.13.07.05.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:05:59 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [FYI/pushed v4 22/25] gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro Date: Mon, 13 Nov 2023 15:04:24 +0000 Message-Id: <20231113150427.477431-23-pedro@palves.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231113150427.477431-1-pedro@palves.net> References: <20231113150427.477431-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.1 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 List-Id: 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 Reviewed-By: Andrew Burgess --- 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 c0dbd0dffea..38299e45284 100644 --- a/gdb/testsuite/lib/my-syscalls.S +++ b/gdb/testsuite/lib/my-syscalls.S @@ -21,38 +21,52 @@ #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) + .section .note.GNU-stack,"",@progbits -- 2.34.1