From: "Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>
To: DJ Delorie <dj@redhat.com>
Cc: libffi-discuss@sourceware.org
Subject: Re: [RFC PATCH v3 2/5] x86: Support for Static Trampolines
Date: Thu, 28 Jan 2021 17:25:03 -0600 [thread overview]
Message-ID: <78a00ccd-3724-2a2d-3c59-f4a2b7a309cd@linux.microsoft.com> (raw)
In-Reply-To: <xnv9bgg0z0.fsf@greed.delorie.com>
On 1/28/21 4:17 PM, DJ Delorie wrote:
> "Madhavan T. Venkataraman" <madvenka@linux.microsoft.com> writes:
>>> Extern, but local to this port, yes?
>>
>> Yes. So, is this declaration acceptable?
>
> Yup!
Great.
>
>>>> + /* Initialize the dynamic trampoline. */
>>>
>>> Should these new APIs be inside #if FFI_EXEC_STATIC_TRAMP ?
>>>
>>
>> Strictly speaking, these should be inside that ifdef. I did it this
>> way to avoid too many ifdefs in the code. If you prefer I put them
>> inside the ifdefs, I will do it. I will try to minimize the number of
>> ifdefs somehow.
>
> No, it's ok, I was just worried that if ffi_tramp_is_present was in an
> #ifdef any callers would be too - but as you noted in another email,
> there's always a ffi_tramp_is_present even if it always returns false.
>
ok.
>>> This hack to detect CET should be replaced by the logic in ffitarget.h,
>>> or add a #define CET_ENABLED to ffitarget.h
>>>
>>
>> So, _CET_ENDBR for x64 is either defined as:
>>
>> If CET is present:
>> #define _CET_ENDBR endbr64
>> Otherwise:
>> #define _CET_ENDBR
>>
>> So, it is always defined. So, I cannot do something like:
>
> I was thinking of the conditionals in src/x86/ffitarget.h:
>
> #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
> && defined(__CET__)
>
> Obviously you'd omit the __ASSEMBLER__ one ;-)
So, the definition is like this:
#if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
&& defined(__CET__)
# include <cet.h>
# define _CET_NOTRACK notrack
#else
# define _CET_ENDBR
# define _CET_NOTRACK
#endif
Where we include cet.h, CET_ENDBR may still be defined either
as endbr64 or empty depending on __CET__ & 1 being non-zero or
zero, right?
So, would something like this work?
#if !defined(GENERATE_LIBFFI_MAP) && defined(__CET__)
# include <cet.h>
# if (__CET__ & 1) != 0
# define ENDBR_PRESENT
# endif
# define _CET_NOTRACK notrack
#else
# define _CET_ENDBR
# define _CET_NOTRACK
#endif
Then, I can do:
#ifdef ENDBR_PRESENT
blah blah
>
> If you duplicate the ffitarget.h logic you get the same results.
>
>>> Copies first argument to %r10, discards return address and arg - closure
>>> will return to whoever called it's caller. I'm not sure how this works,
>>> which means *at least* a comment needs to be here ;-)
>>>
>> The target code in this case is the alt entry point.
>>
>> This is what the alt code is doing:
>> - load the data (closure) address in r10
>> - discard the original value of r10 saved on the stack
>> since we are using r10 we don't need its original value
>> - restore the stack back to what it was when the static trampoline was
>> invoked.
>
> These kinds of short notes should be useful inline comments in the assembler:
>
> movq 8(%rsp), %r10 /* load closure */
>
I will add this.
>> I could add a small comment saying "see comment above trampoline_code_table".
>> Is that acceptable?
>
> That would be good too :-)
>
I will add this as well.
Thanks!
Madhavan
next prev parent reply other threads:[~2021-01-28 23:25 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1ef5c7e1c9a6ebb140a476ba555ec955681f4fba>
2021-01-15 18:46 ` [RFC PATCH v3 0/5] Libffi " madvenka
2021-01-15 18:46 ` [RFC PATCH v3 1/5] " madvenka
2021-01-27 3:31 ` DJ Delorie
2021-01-27 21:51 ` Madhavan T. Venkataraman
2021-01-27 22:15 ` DJ Delorie
2021-01-27 22:43 ` Madhavan T. Venkataraman
2021-01-15 18:46 ` [RFC PATCH v3 2/5] x86: Support for " madvenka
2021-01-27 3:31 ` DJ Delorie
2021-01-28 21:59 ` Madhavan T. Venkataraman
2021-01-28 22:17 ` DJ Delorie
2021-01-28 23:25 ` Madhavan T. Venkataraman [this message]
2021-01-29 2:09 ` DJ Delorie
2021-01-29 2:38 ` Madhavan T. Venkataraman
2021-01-29 2:48 ` DJ Delorie
2021-01-29 3:24 ` Madhavan T. Venkataraman
2021-01-29 6:07 ` DJ Delorie
2021-02-01 19:46 ` DJ Delorie
2021-01-15 18:46 ` [RFC PATCH v3 3/5] i386: " madvenka
2021-01-15 18:46 ` [RFC PATCH v3 4/5] arm64: " madvenka
2021-01-15 18:46 ` [RFC PATCH v3 5/5] arm: " madvenka
2021-01-26 23:41 ` [RFC PATCH v3 0/5] Libffi " Anthony Green
2021-01-27 17:20 ` Madhavan T. Venkataraman
2021-01-27 18:00 ` Anthony Green
2021-01-27 19:45 ` Madhavan T. Venkataraman
2021-01-28 14:21 ` Anthony Green
2021-01-28 17:01 ` Madhavan T. Venkataraman
2021-02-05 18:20 ` Madhavan T. Venkataraman
2021-02-05 18:46 ` Anthony Green
2021-02-05 19:38 ` Madhavan T. Venkataraman
2021-02-07 16:09 ` Madhavan T. Venkataraman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78a00ccd-3724-2a2d-3c59-f4a2b7a309cd@linux.microsoft.com \
--to=madvenka@linux.microsoft.com \
--cc=dj@redhat.com \
--cc=libffi-discuss@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).