From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gAdlCaRRhGT3ViMAWB0awg (envelope-from ) for ; Sat, 10 Jun 2023 06:34:12 -0400 Received: by simark.ca (Postfix, from userid 112) id 2466E1E0D6; Sat, 10 Jun 2023 06:34:12 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=HecCfjpn; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9D14E1E0D6 for ; Sat, 10 Jun 2023 06:34:11 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5E333856604 for ; Sat, 10 Jun 2023 10:34:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5E333856604 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686393250; bh=AcqwZ3Uz2TB0TEotTcDbNOQnBuy057AZzTJEYVh62gY=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HecCfjpnbW6adfj+sDgzhQz3fKUW/xX9uzUZpNMYrBWzx6oNz5SQ1Gy4GUsHxoaUN 2G1CD8i/2/bimR5HanFAqVsztIEHMCLKtk4Ut+Y9VT5bMBk1N50GNPyyRmJnC9/WRJ 4OPvoJN0MqpLoeRxDhMr5c5YhTYaOtcecKbFqGxA= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E62AD385841E for ; Sat, 10 Jun 2023 10:33:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E62AD385841E Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-373-NMmuwIkmNRecagLts4SqXg-1; Sat, 10 Jun 2023 06:33:32 -0400 X-MC-Unique: NMmuwIkmNRecagLts4SqXg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f42bcef2acso10789975e9.2 for ; Sat, 10 Jun 2023 03:33:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686393211; x=1688985211; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AcqwZ3Uz2TB0TEotTcDbNOQnBuy057AZzTJEYVh62gY=; b=YQ2kSN/b9oHxXdGbwwOZLgn7kaBvBCc75NixvMuP8pXip5Owx9PoH0wrUXGKP9ze4z +X/Xi+MZH8XV9Iyqd6Dgd+QvQOH2RwmJ5EL4BiQ9Ea98+eMMdzjx7YIP6A7dkDbyWlv9 t1KOjRfnZJvTeuIoMKwjY5F7fTU4wNtP3qF8ttfbu+cDgUIew9UEVYX6mz486BrxMAhN dkpGpnAOcqXdJFZ5jfRq24yq2FF565vX/rjcWr5LKEnBzlLxyQHlm8eZmQFKdQHfDe/l 7bY2umYKve51P2q6SEa3QY0GD/9vWPhwUPFUfJHddElY/dPL6RAP5p7mMBL8iYsPEzmF uZ/Q== X-Gm-Message-State: AC+VfDypypQgGeAt4lrmQwIsuaY302QY2GuqMytIHNTjVzg9lVDxRLnq 3z6dUqYbHnV2kbBRbf1mcB8Upy93r63kT6tGWtNAvTVUQlX6r4qXSl2aFG1bOrpqMTiORE1uRwI iZNpwt86Useldm9st629q6Rpqf+3GSQ== X-Received: by 2002:a05:600c:2246:b0:3f7:e70c:8ea4 with SMTP id a6-20020a05600c224600b003f7e70c8ea4mr2549179wmm.34.1686393211366; Sat, 10 Jun 2023 03:33:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BSwtvOjLv6/qQEw6ZhfEpprzVBhtRzbxtW56viemdPBrf8FQXZu8Pz+cADdeNS7XZsY451A== X-Received: by 2002:a05:600c:2246:b0:3f7:e70c:8ea4 with SMTP id a6-20020a05600c224600b003f7e70c8ea4mr2549171wmm.34.1686393211071; Sat, 10 Jun 2023 03:33:31 -0700 (PDT) Received: from localhost (92.40.218.124.threembb.co.uk. [92.40.218.124]) by smtp.gmail.com with ESMTPSA id l15-20020a05600c1d0f00b003f1978bbcd6sm6293760wms.3.2023.06.10.03.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jun 2023 03:33:30 -0700 (PDT) To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCH 26/31] gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro In-Reply-To: <20221212203101.1034916-27-pedro@palves.net> References: <20221212203101.1034916-1-pedro@palves.net> <20221212203101.1034916-27-pedro@palves.net> Date: Sat, 10 Jun 2023 11:33:29 +0100 Message-ID: <87fs6zy5c6.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Pedro Alves writes: > 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. LGTM. Reviewed-By: Andrew Burgess Thanks, Andrew > > 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 7f06f9c398b..6fb53624f31 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.36.0