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.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 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=1686393214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AcqwZ3Uz2TB0TEotTcDbNOQnBuy057AZzTJEYVh62gY=; b=bpxGUl9Wg//ppZtbTH+JfJQuPek9doRwBV2s3vkCcaDRJ1Z/mrU6xwXXIkpaTDQlQpCtQJ uP30t0vk5RqMfvGP2xbU6YbAqmh/W7HHMDQUBrIn7nkkT43HX9RPKwqy1Y1g97FlYkqYkb 9L8JVycmH+cN5b4WxUrB5ruiw7B6pMQ= 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) From: Andrew Burgess 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-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,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: 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