def alloc(map_size): """Allocate memory. This is intended to be used by the JIT, so the memory has the executable bit set and gets allocated internally in case of a sandboxed process. """ from errno import ENOMEM from rpython.rlib import debug if _CYGWIN: # XXX: JIT memory should be using mmap MAP_PRIVATE with # PROT_EXEC but Cygwin's fork() fails. mprotect() # cannot be used, but seems to be unnecessary there. res = c_malloc_safe(map_size) if res == rffi.cast(PTR, 0): raise MemoryError return res res = alloc_hinted(rffi.cast(PTR, hint.pos), map_size) if res == rffi.cast(PTR, -1): # some systems (some versions of OS/X?) complain if they # are passed a non-zero address. Try again. res = alloc_hinted(rffi.cast(PTR, 0), map_size) if res == rffi.cast(PTR, -1): # ENOMEM simply raises MemoryError, but other errors are fatal if rposix.get_saved_errno() != ENOMEM: debug.fatalerror_notb( "Got an unexpected error trying to allocate some " "memory for the JIT (tried to do mmap() with " "PROT_EXEC|PROT_READ|PROT_WRITE). This can be caused " "by a system policy like PAX. You need to find how " "to work around the policy on your system.") raise MemoryError else: hint.pos += map_size return res
def tuple_realize(space, py_obj): """ Creates the tuple in the interpreter. The PyTupleObject must not be modified after this call. We check that it does not contain any NULLs at this point (which would correspond to half-broken W_TupleObjects). """ py_tup = rffi.cast(PyTupleObject, py_obj) l = py_tup.c_ob_size p = py_tup.c_ob_item items_w = [None] * l for i in range(l): w_item = from_ref(space, p[i]) if w_item is None: fatalerror_notb( "Fatal error in cpyext, CPython compatibility layer: " "converting a PyTupleObject into a W_TupleObject, " "but found NULLs as items") items_w[i] = w_item w_obj = space.newtuple(items_w) track_reference(space, py_obj, w_obj) return w_obj