Skip to content

Instantly share code, notes, and snippets.



Created Jan 4, 2019
What would you like to do?
import mmap
import cffi
ffi = cffi.FFI()
ffi.cdef("struct test { int x; };")
ref = None
def alloc():
global ref
mem = mmap.mmap(-1, 0x1000, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE)
# Uncomment this to keep mem alive
#ref = mem
return ffi.cast("struct test *", ffi.from_buffer(mem))
def main():
test = alloc()
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.