lightning
[Top][All Lists]
Advanced

[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 01:01:45 -1000

2010/2/23 Ludovic Courtès <address@hidden>:
> Hi,
>
> Todd Rovito <address@hidden> writes:
>
>> This GDB was configured as "x86_64-apple-darwin"...Reading symbols for
>
> [...]
>
>> Program received signal EXC_BAD_ACCESS, Could not access memory.
>> Reason: KERN_PROTECTION_FAILURE at address: 0x0000000100001100
>> 0x0000000100001100 in codeBuffer ()
>
> Could it be that Darwin clears the execution bit on data segments?
>
> You could try allocating ‘codeBuffer’ like this:
>
>  codeBuffer = mmap (NULL, 1024, PROT_EXEC | PROT_READ | PROT_WRITE,
>                     MAP_PRIVATE | MAP_ANONYMOUS, -1, -1);

Ludo,
  Thanks for the help, I think you got me much closer.  Here is the
code with your changes:

   #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, 1024, PROT_EXEC | PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANON, -1, -1);

       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;
     }

And here are the results I got in gdb:
gdb incrGNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18
20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for
shared libraries .. done

(gdb) run
Starting program: /Users/rovitotv/prog/lightning/test/incr
Reading symbols for shared libraries +. done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffffffffffff
0x0000000100000bde in main () at incr.c:19
19             jit_leaf(1);                     /*      leaf  1             */
(gdb)


It is still crashing.  I really have no idea what I am doing, but
thank you for the help.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]