changeset 27:523c45dfa8fb

- 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)
author cslag
date Tue, 15 Sep 2015 12:48:52 +0200
parents 32e397e1674c
children a461b6977b52
files dyncall/dyncall_call_arm32_arm.h dyncall/dyncall_call_arm32_arm_armhf.h dyncall/dyncall_call_arm32_thumb.h dyncall/dyncall_call_arm32_thumb_gas.s dyncall/dyncall_callvm_arm32_arm.c dyncall/dyncall_callvm_arm32_thumb.c
diffstat 6 files changed, 27 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- 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
 }
--- 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
 }
--- 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
 }
--- 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
-
--- 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));
 }
 
 
--- 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));
 }