Skip to content

Instantly share code, notes, and snippets.

@planrich
Created December 17, 2015 19:18
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 planrich/3fd72767812754d9104d to your computer and use it in GitHub Desktop.
Save planrich/3fd72767812754d9104d to your computer and use it in GitHub Desktop.
ffi s390x issues, callback with non standard integral type
all:
gcc -c ret16bit.c
gcc -shared ret16bit.o -o ret16bit.so
python test.py
#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);
}
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