From 7ad0ae7f42f3e208431ab66a9032dc9549f978d0 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 10 Oct 2017 11:44:05 -0700 Subject: [PATCH] arm: zext return value parameters The closure function (invoked as closure->fun in ffi_closure_XXX_inner) will only populate the actual number of bytes for the true return type, which may be a character. This leaves garbage on the stack when the assembly closure function (i.e. ffi_closure_XXX) reads the return value off of the stack into r0 as a 4-byte value. ffi_closure_XXX always leaves room for at least 4 bytes here, so we can safely set them to 0. Otherwise, if there is garbage in any of these bytes, these end up in r0 and in the returned value as well. --- src/arm/ffi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/arm/ffi.c b/src/arm/ffi.c index b4fb5b69..12ce04ac 100644 --- a/src/arm/ffi.c +++ b/src/arm/ffi.c @@ -419,6 +419,11 @@ ffi_prep_incoming_args_SYSV (ffi_cif *cif, void *rvalue, rvalue = *(void **) argp; argp += 4; } + else + { + if (cif->rtype->size && cif->rtype->size < 4) + **(int32_t **) rvalue = 0; + } for (i = 0, n = cif->nargs; i < n; i++) {