Created
December 17, 2015 19:18
-
-
Save planrich/3fd72767812754d9104d to your computer and use it in GitHub Desktop.
ffi s390x issues, callback with non standard integral type
This file contains 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
all: | |
gcc -c ret16bit.c | |
gcc -shared ret16bit.o -o ret16bit.so | |
python test.py |
This file contains 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
#include <stdio.h> | |
#include <inttypes.h> | |
#include <string.h> | |
int test(int (*cb)(int,int), int x, int y) { | |
int i = 0; | |
// let's pollute the stack!!! | |
uint64_t * sp = (uint64_t*)__builtin_frame_address(0); | |
while (i < 3000) { | |
*(sp-(i+160/8)) = 0x0102030440302010; | |
i++; | |
} | |
return cb(x,y); | |
} |
This file contains 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 ctypes | |
import os | |
me = os.path.abspath(os.path.dirname(__file__)) | |
d = ctypes.cdll.LoadLibrary(os.path.join(me, "ret16bit.so")) | |
def callback(a, b): | |
return a+b | |
func = d.test | |
i = 1213 | |
j = 1213 | |
v = func(ctypes.CFUNCTYPE(*[ctypes.c_int16]*3)(callback), i, j) | |
assert v == (i + j), "failed! %d != %d + %d" % (v, i, j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment