Created
November 3, 2020 04:16
-
-
Save soasme/a2a0c75fba9a00ac5dc8596a4322c47a 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
| from cffi import FFI | |
| ffi = FFI() | |
| ffi.cdef(""" | |
| void *malloc(size_t size); | |
| #define CLONE_NEWNS 0x00020000 | |
| #define CLONE_NEWCGROUP 0x02000000 | |
| #define CLONE_NEWUTS 0x04000000 | |
| #define CLONE_NEWIPC 0x08000000 | |
| #define CLONE_NEWNET 0x40000000 | |
| #define CLONE_NEWUSER 0x10000000 | |
| #define CLONE_NEWPID 0x20000000 | |
| #define CLONE_NEWTIME 0x00000080 | |
| int clone(int (*fn)(void *), void *stack, int flags, void *arg, ...); | |
| typedef struct { | |
| unsigned char r, g, b; | |
| } pixel_t; | |
| """) | |
| C = ffi.dlopen(None) | |
| print('CLONE_NEWNS', C.CLONE_NEWNS) | |
| @ffi.callback("int(void *)") | |
| def child(arg): | |
| pixel = ffi.cast("pixel_t *", arg) | |
| print("child arg", pixel.r, pixel.g, pixel.b) | |
| return 0 | |
| stack = C.malloc(1024*1024) | |
| print('malloc(1024*1024)', stack) | |
| arg = ffi.new("pixel_t*") | |
| arg.r = 0 | |
| arg.g = 0 | |
| arg.b = 0 | |
| ret = C.clone(child, stack+1024*1024, C.CLONE_NEWNS, ffi.cast("void *", arg)) | |
| print('clone(child)', ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment