[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lightning] Memory Allocation on Mac OS X
From: |
Paulo César Pereira de Andrade |
Subject: |
Re: [Lightning] Memory Allocation on Mac OS X |
Date: |
Sun, 26 Sep 2010 20:29:55 -0300 |
2010/9/26 Noah Lavine <address@hidden>:
> Hello Lightning developers,
>
> The attached patch fixes an issue with memory allocation on Mac OS X.
> The trouble was that the test programs allocate memory for their
> functions as static variables, but in Mac OS X statically allocated
> memory is not marked as executable. This patch uses posix_memalign and
> mprotect instead, which brings the number of failed tests on my
> machine from 21 to 2.
I think most tests are somewhat bogus, and the way jit_flush_code()
works, and calls mprotect() is wrong, as it needs to adjust it to unaligned
memory, what means marking random, but on the same process, memory
as executable.
I applied your patch to my git-hub fork, but probably it should be either
added a function to allocate memory for code, or mmap should be a
better option.
This is also in my todo list for my language, for example, if one uses
a program/script, and call it again later, if the source did not change,
it could as well just read the code from a "cache file". That means it
may need to handle relocations, or, write the jit buffer as a proper
elf (or whatever) object file.
> You'll probably notice that the test has a lot of spaghetti code. That
> is because I converted the tests one by one and wasn't really thinking
> about code reuse. If you think it would be useful, though, I could
> collect the code for allocating executable memory into one function
> and put that somewhere. It might even be a good thing to add to
> Lightning itself, because presumably everyone who uses Lightning will
> need to allocate executable memory.
>
> I hope this is helpful
> Noah Lavine
Paulo