# HG changeset patch # User cslag # Date 1442314132 -7200 # Node ID 523c45dfa8fb51b5e2f4a059d1ec27a63db3bea4 # Parent 32e397e1674c9bf2201cf5740e04d0cb57a935f9 - refactored arm calling conventions' callvm code, so that the code that keeps the caller from overwriting the return value on some platforms also works on OpenBSD (before we casted the function pointer to have long long as return type, to hint the caller that there is one, but that triggers an intentional SIGABRT on OpenBSD for security reasons; now the decl reflects this, directly) diff -r 32e397e1674c -r 523c45dfa8fb dyncall/dyncall_call_arm32_arm.h --- a/dyncall/dyncall_call_arm32_arm.h Sun Sep 13 16:52:53 2015 +0200 +++ b/dyncall/dyncall_call_arm32_arm.h Tue Sep 15 12:48:52 2015 +0200 @@ -50,9 +50,14 @@ ** ** - hybrid return-type call (bool ... pointer) ** +** Note the return type of this declaration is intentially of double-word size. +** On some platforms (FreeBSD/arm, Nintendo DS, ...) the compiler generates cleanup code +** in the caller (dc_callvm_call_arm32_arm) that reuses, thus overwrites r0 and r1. +** With this "hint", we preserve those registers by letting the compiler assume both +** registers are used for the return type. */ -void dcCall_arm32_arm(DCpointer target, DCpointer stackdata, DCsize size); +DClonglong dcCall_arm32_arm(DCpointer target, DCpointer stackdata, DCsize size); #ifdef __cplusplus } diff -r 32e397e1674c -r 523c45dfa8fb dyncall/dyncall_call_arm32_arm_armhf.h --- a/dyncall/dyncall_call_arm32_arm_armhf.h Sun Sep 13 16:52:53 2015 +0200 +++ b/dyncall/dyncall_call_arm32_arm_armhf.h Tue Sep 15 12:48:52 2015 +0200 @@ -35,7 +35,19 @@ extern "C" { #endif -void dcCall_arm32_armhf(DCpointer target, DCpointer stackdata, DCsize size, DCfloat* p_s16); +/* +** arm32 armhf mode calling convention calls +** +** - hybrid return-type call (bool ... pointer) +** +** Note the return type of this declaration is intentially of double-word size. +** On some platforms the compiler generates cleanup code in the caller (dyncall_callvm_arm32_arm_armhf.c's +** call()) that reuses,thus overwrites r0 and r1. +** With this "hint", we preserve those registers by letting the compiler assume both +** registers are used for the return type. +*/ + +DClonglong dcCall_arm32_armhf(DCpointer target, DCpointer stackdata, DCsize size, DCfloat* p_s16); #ifdef __cplusplus } diff -r 32e397e1674c -r 523c45dfa8fb dyncall/dyncall_call_arm32_thumb.h --- a/dyncall/dyncall_call_arm32_thumb.h Sun Sep 13 16:52:53 2015 +0200 +++ b/dyncall/dyncall_call_arm32_thumb.h Tue Sep 15 12:48:52 2015 +0200 @@ -50,13 +50,14 @@ ** ** - hybrid return-type call (bool ... pointer) ** +** Note the return type of this declaration is intentially of double-word size. +** On some platforms (FreeBSD/arm, Nintendo DS, ...) the compiler generates cleanup code +** in the caller (dc_callvm_call_arm32_thumb) that reuses, thus overwrites r0 and r1. +** With this "hint", we preserve those registers by letting the compiler assume both +** registers are used for the return type. */ -void dcCall_arm32_thumb(DCpointer target, DCpointer stackdata, DCsize size); - -/* Internally used to avoid compiler overwriting r0 and r1 in call stub */ -DClong dcCall_arm32_thumb_word (DCpointer target, DCpointer stackdata, DCsize size); -DClonglong dcCall_arm32_thumb_dword(DCpointer target, DCpointer stackdata, DCsize size); +DClonglong dcCall_arm32_thumb(DCpointer target, DCpointer stackdata, DCsize size); #ifdef __cplusplus } diff -r 32e397e1674c -r 523c45dfa8fb dyncall/dyncall_call_arm32_thumb_gas.s --- a/dyncall/dyncall_call_arm32_thumb_gas.s Sun Sep 13 16:52:53 2015 +0200 +++ b/dyncall/dyncall_call_arm32_thumb_gas.s Tue Sep 15 12:48:52 2015 +0200 @@ -83,19 +83,3 @@ mov %r13, %r7 /* Reset stack ptr. */ pop {%r4-%r7, %r15} /* Restore permanent registers and program counter. (Force a stay in THUMB in ARMv4, whether ARMv5 can return in ARM or THUMB depending on the bit 0. */ - - -/* Internally used to avoid compiler overwriting r0 and r1 in call stub */ -.globl dcCall_arm32_thumb_word - -.thumb_func -dcCall_arm32_thumb_word: - b dcCall_arm32_thumb - - -.globl dcCall_arm32_thumb_dword - -.thumb_func -dcCall_arm32_thumb_dword: - b dcCall_arm32_thumb - diff -r 32e397e1674c -r 523c45dfa8fb dyncall/dyncall_callvm_arm32_arm.c --- a/dyncall/dyncall_callvm_arm32_arm.c Sun Sep 13 16:52:53 2015 +0200 +++ b/dyncall/dyncall_callvm_arm32_arm.c Tue Sep 15 12:48:52 2015 +0200 @@ -149,11 +149,7 @@ void dc_callvm_call_arm32_arm(DCCallVM* in_self, DCpointer target) { DCCallVM_arm32_arm* self = (DCCallVM_arm32_arm*)in_self; - // This cast is needed in order for the cleanup code in the caller (this very function) to not - // overwrite and use r0 and r1, as we want to pass them back. On some platforms (FreeBSD/arm, Nintendo DS - // the compiler generates cleanup code that writes to those registers by assuming dcCall_arm32_arm didn't - // use them. - ((DClonglong(*)(DCpointer, DCpointer, DCsize))&dcCall_arm32_arm)(target, dcVecData(&self->mVecHead), dcVecSize(&self->mVecHead)); + dcCall_arm32_arm(target, dcVecData(&self->mVecHead), dcVecSize(&self->mVecHead)); } diff -r 32e397e1674c -r 523c45dfa8fb dyncall/dyncall_callvm_arm32_thumb.c --- a/dyncall/dyncall_callvm_arm32_thumb.c Sun Sep 13 16:52:53 2015 +0200 +++ b/dyncall/dyncall_callvm_arm32_thumb.c Tue Sep 15 12:48:52 2015 +0200 @@ -149,11 +149,7 @@ void dc_callvm_call_arm32_thumb(DCCallVM* in_self, DCpointer target) { DCCallVM_arm32_thumb* self = (DCCallVM_arm32_thumb*)in_self; - // This cast is needed in order for the cleanup code in the caller (this very function) to not - // overwrite and use r0 and r1, as we want to pass them back. On some platforms (FreeBSD/arm, Nintendo DS - // the compiler generates cleanup code that writes to those registers by assuming dcCall_arm32_thumb didn't - // use them. - ((DClonglong(*)(DCpointer, DCpointer, DCsize))&dcCall_arm32_thumb)(target, dcVecData(&self->mVecHead), dcVecSize(&self->mVecHead)); + dcCall_arm32_thumb(target, dcVecData(&self->mVecHead), dcVecSize(&self->mVecHead)); }