[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2
From: |
Todd Rovito |
Subject: |
Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2 |
Date: |
Tue, 23 Feb 2010 08:47:40 -1000 |
On Tue, Feb 23, 2010 at 2:35 AM, Paolo Bonzini <address@hidden> wrote:
>> Dang, I feel like you guys almost have it solved.
>
> Possibly.
>
> First solution:
>
> codeBuffer = mmap (NULL, 4096, PROT_EXEC | PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANON, -1, 0);
>
> (Ludovic proposed "-1" as the last argument).
>
> Second solution: revert to statically allocated codeBuffer and add
>
> mprotect (((long) codeBuffer) & ~4095, 8192,
> PROT_READ | PROT_WRITE | PROT_EXEC);
>
> before invoking it.
Paolo,
Your first solution appears to be working great now! Thank you.
Here is the final code I have that is running on Mac OSX 10.6.2:
#include <stdio.h>
#include <sys/mman.h>
#include "lightning.h"
static jit_insn *codeBuffer;
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
int main()
{
codeBuffer = mmap (NULL, 4096, PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
pifi incr = (pifi) (jit_set_ip(codeBuffer).iptr);
int in;
jit_leaf(1); /* leaf 1 */
in = jit_arg_i(); /* in = arg_i */
jit_getarg_i(JIT_R0, in); /* getarg_i R0 */
jit_addi_i(JIT_RET, JIT_R0, 1); /* addi_i RET, R0, 1 */
jit_ret(); /* ret */
jit_flush_code(codeBuffer, jit_get_ip().ptr);
/* call the generated code, passing 5 as an argument */
printf("%d + 1 = %d\n", 5, incr(5));
return 0;
}
- [Lightning] failure with GNU lightning on Mac OS X 10.6.2, Todd Rovito, 2010/02/23
- [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Ludovic Courtès, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Todd Rovito, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Paolo Bonzini, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Todd Rovito, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Paolo Bonzini, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Todd Rovito, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Paolo Bonzini, 2010/02/23
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2,
Todd Rovito <=
- Re: [Lightning] Re: failure with GNU lightning on Mac OS X 10.6.2, Ludovic Courtès, 2010/02/24