Skip to content

Instantly share code, notes, and snippets.

@darkf darkf/testcase.py
Created Jan 4, 2019

Embed
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()
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
You can’t perform that action at this time.