Convert a delegate to a function (i.e. make a thunk)

David Brown davidb at davidb.org
Thu Apr 26 20:55:54 PDT 2012


On 2012-04-25, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:

> This is like GCC's implementation of nested function pointers using
> trampolines:
>
> 	http://gcc.gnu.org/onlinedocs/gccint/Trampolines.html
>
> These nested function pointers have access to their containing lexical
> scope, even though they are just regular, non-fat pointers.
>
> Something similar can be used here, though for full-fledged D delegates
> the trampoline would need to be in executable heap memory. I believe
> nowadays heap memory is non-executable due to security concerns with
> heap overflow exploits, right? So this may require special treatment.

Gcc (at least on Linux) does a few things.  The trampoline is on
the stack, but the generated code:

  - Creates a special section

    .section .note.GNU-stack,"x", at progbits

    in the assembly that indicates to the linker that the resulting
    elf file needs to allow the stack to be executable.

  - Depending on the CPU, it may call a libgcc function
    __clear_cache.  x86 is coherent, so this isn't needed, but it is
    in the general case.

David


More information about the Digitalmars-d mailing list