July 31, 2012
On 31-07-2012 20:30, Era Scarecrow wrote:
> On Tuesday, 31 July 2012 at 17:23:08 UTC, Maxime Chevalier wrote:
>> New to the D language here. I'm working on a tracing JIT compiler and
>> will need to allocate chunks of memory that are marked as executable.
>>
>> Is there a standard way of doing this in D, or do I need to directly
>> call into mprotect? If I'm going to be calling mprotect, what's the
>> cleanest way to do that, do I need to declare my own prototype for the
>> function and its flags, or should I write some C code that does the call?
>
>   The x86 chip it's a simple flag that the OS can set. For use with like
> UPX, the whole section is marked read, write & execute I believe (since
> it has to expand it first before it can execute the code; That is of
> course for loaded memory, not allocating...). I would say check their
> sources, may prove interesting.

UPX simply uses VirtualProtect/mprotect. It's the only way you _can_ do this in ring 3 on any OS with sane security.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
July 31, 2012
bearophile:

> DMD has a back-end that produces less efficient binaries compared
> to GDC and LDC. But DMD is more up to date (but not a lot), and
> it's the most supported, it's the reference implementation. DMD
> works well on Windows too, GDC works on Windows too. I think LDC
> doesn't work well on Windows.

An DMD doesn't support 64 bit on Windows.

Bye,
bearophile
July 31, 2012
On Tuesday, 31 July 2012 at 18:06:28 UTC, Maxime Chevalier wrote:
> How well does the D GC deal with immovable objects. Would it be a problem if I allocated many chunks of immovable data?

D's GC currently doesn't move memory at all, so this should not be a problem. If there is a chance that all references to the object in question in D-managed memory (i.e. stack, GC heap) go away, but the memory is still used, you might need to manually mark the object as live, though (see core.memory.GC.addRoot).

> Also, if you don't mind me asking, which D compiler do you guys prefer? Which one is most widely supported, most up to date?

DMD is the official reference compiler and compiles faster than the others, but is x86-only (32 bit only on Windows), and the performance of the generated code is sometimes significantly worse than with the other compilers. GDC and LDC also use the same frontend as DMD, but it usually takes them a few weeks to catch up after a new version of it is released. LDC currently doesn't work on Windows if your application uses exception handling (which most applications do).

I personally use LDC as my default compiler, but I might be biased… ;)

David
August 01, 2012
On Tuesday, 31 July 2012 at 17:23:08 UTC, Maxime Chevalier wrote:
> New to the D language here. I'm working on a tracing JIT compiler and will need to allocate chunks of memory that are marked as executable.
>
> Is there a standard way of doing this in D, or do I need to directly call into mprotect? If I'm going to be calling mprotect, what's the cleanest way to do that, do I need to declare my own prototype for the function and its flags, or should I write some C code that does the call?
>
> Thanks for your help.

Hope this helps:
http://stackoverflow.com/a/8656294/21501
1 2
Next ›   Last »