[pypy-dev] Help with asmmemmgr.py:_copy_to_raw_memory()

Armin Rigo armin.rigo at gmail.com
Wed Oct 13 01:28:34 EDT 2021


Hi,

On Wed, 13 Oct 2021 at 04:08, M A <teammember0x01 at gmail.com> wrote:
> Hi guys. I am having a problem with a function called _copy_to_raw_memory() in the file rpython/jit/backend/llsupport/asmmemmgr.py. After building PyPy there is always a crash in this function. Here is a partial backtrace I captured:
>
> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x104100000)
>     frame #0: 0x0000000100c3a8b4 libpypy-c.dylib`pypy_g_InstrBuilder__copy_to_raw_memory + 268
>   * frame #1: 0x0000000100bfec98 libpypy-c.dylib`pypy_g_InstrBuilder_copy_to_raw_memory + 40
>     frame #2: 0x0000000100c3efd4 libpypy-c.dylib`pypy_g_InstrBuilder_materialize + 232
>     frame #3: 0x0000000100c047e4 libpypy-c.dylib`pypy_g_AssemblerARM64__build_failure_recovery + 1208
>     frame #4: 0x0000000100c3b5ec libpypy-c.dylib`pypy_g_BaseAssembler_setup_once + 80
>     frame #5: 0x0000000100d31668 libpypy-c.dylib`pypy_g_compile_and_run_once___rpython_jit_metainterp_ji_29 + 364
>     frame #6: 0x0000000100cd3ed4 libpypy-c.dylib`pypy_g_bound_reached__star_4_8 + 740
>     frame #7: 0x0000000100b66510 libpypy-c.dylib`pypy_g_portal_29 + 104
>     frame #8: 0x0000000100ca7804 libpypy-c.dylib`pypy_g_ll_portal_runner__pypy_objspace_std_typeobject_W_1 + 344
>
>
> With the help of print() statements I was able to find the exact line that was causing the problem. It is this:
>
> dst[j] = block.data[j]
>
> I have tried printing the values for these variables but that doesn't compile. I can't be sure the two variables are set correctly. Using type() on these two variables also doesn't compile. Even comparing the two variables to None doesn't work. How can I figure out what is wrong with this code? Please let me know if you need more information. Thank you.

This is the function that copies the generated machine code into the
special memory area that was allocated to be read-write-executable.
What is likely occurring here is that on your particular machine, when
we ask the OS to get a read-write-executable piece of memory, it
doesn't do that.  But instead of returning an error, it returns a
valid page of memory that is apparently not writeable.  Then the
process crashes like you have found while trying to write to it.

You need to look up if your OS imposes strange non-POSIX requirements
on the process.  Maybe
https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon
is a good starting point.


A bientôt,

Armin Rigo


More information about the pypy-dev mailing list