Skip to content

Instantly share code, notes, and snippets.

@darkf
Created January 4, 2019 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkf/2f3ca05f581786ee536a631f4ed86468 to your computer and use it in GitHub Desktop.
Save darkf/2f3ca05f581786ee536a631f4ed86468 to your computer and use it in GitHub Desktop.
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()
print(test.x)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment