Created
January 4, 2019 13:59
-
-
Save darkf/2f3ca05f581786ee536a631f4ed86468 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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