[PATCH 2/2] mpi: make stack unwinding work at i386 mpi functions

Jussi Kivilinna jussi.kivilinna at iki.fi
Thu Apr 18 18:30:17 CEST 2019


* mpi/i386/syntax.h: Include 'config.h'.
(CFI_STARTPROC, CFI_ENDPROC, CFI_ADJUST_CFA_OFFSET, CFI_REL_OFFSET)
(CFI_RESTORE, CFI_PUSH, CFI_POP): New.
* mpi/i386/mpih-add1.S: Add CFI directives.
* mpi/i386/mpih-lshift.S: Add CFI directives.
* mpi/i386/mpih-mul1.S: Add CFI directives.
* mpi/i386/mpih-mul2.S: Add CFI directives.
* mpi/i386/mpih-mul3.S: Add CFI directives.
* mpi/i386/mpih-rshift.S: Add CFI directives.
* mpi/i386/mpih-sub1.S: Add CFI directives.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 0 files changed

diff --git a/mpi/i386/mpih-add1.S b/mpi/i386/mpih-add1.S
index 652b23218..32091f340 100644
--- a/mpi/i386/mpih-add1.S
+++ b/mpi/i386/mpih-add1.S
@@ -44,8 +44,11 @@
 	ALIGN (3)
 	.globl C_SYMBOL_NAME(_gcry_mpih_add_n)
 C_SYMBOL_NAME(_gcry_mpih_add_n:)
+	CFI_STARTPROC()
 	pushl %edi
+	CFI_PUSH(%edi)
 	pushl %esi
+	CFI_PUSH(%esi)
 
 	movl 12(%esp),%edi		/* res_ptr */
 	movl 16(%esp),%esi		/* s1_ptr */
@@ -111,6 +114,9 @@ Loop:	movl	(%esi),%eax
 	negl	%eax
 
 	popl %esi
+	CFI_POP(%esi)
 	popl %edi
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/mpih-lshift.S b/mpi/i386/mpih-lshift.S
index bf8ed9d4c..55da0678d 100644
--- a/mpi/i386/mpih-lshift.S
+++ b/mpi/i386/mpih-lshift.S
@@ -42,9 +42,13 @@
 	ALIGN (3)
 	.globl C_SYMBOL_NAME(_gcry_mpih_lshift)
 C_SYMBOL_NAME(_gcry_mpih_lshift:)
+	CFI_STARTPROC()
 	pushl	%edi
+	CFI_PUSH(%edi)
 	pushl	%esi
+	CFI_PUSH(%esi)
 	pushl	%ebx
+	CFI_PUSH(%ebx)
 
 	movl	16(%esp),%edi		/* res_ptr */
 	movl	20(%esp),%esi		/* s_ptr */
@@ -88,7 +92,11 @@ Lend:	shll	%cl,%ebx		/* compute least significant limb */
 	movl	%ebx,(%edi)		/* store it */
 
 	popl	%ebx
+	CFI_POP(%ebx)
 	popl	%esi
+	CFI_POP(%esi)
 	popl	%edi
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/mpih-mul1.S b/mpi/i386/mpih-mul1.S
index c9760ef92..9679ea622 100644
--- a/mpi/i386/mpih-mul1.S
+++ b/mpi/i386/mpih-mul1.S
@@ -49,10 +49,15 @@
 	GLOBL	C_SYMBOL_NAME(_gcry_mpih_mul_1)
 C_SYMBOL_NAME(_gcry_mpih_mul_1:)
 
+	CFI_STARTPROC()
 	INSN1(push,l	,R(edi))
+	CFI_PUSH(%edi)
 	INSN1(push,l	,R(esi))
+	CFI_PUSH(%esi)
 	INSN1(push,l	,R(ebx))
+	CFI_PUSH(%ebx)
 	INSN1(push,l	,R(ebp))
+	CFI_PUSH(%ebp)
 
 	INSN2(mov,l	,R(res_ptr),MEM_DISP(esp,20))
 	INSN2(mov,l	,R(s1_ptr),MEM_DISP(esp,24))
@@ -77,8 +82,13 @@ Loop:
 	INSN2(mov,l	,R(eax),R(ebx))
 
 	INSN1(pop,l	,R(ebp))
+	CFI_POP(%ebp)
 	INSN1(pop,l	,R(ebx))
+	CFI_POP(%ebx)
 	INSN1(pop,l	,R(esi))
+	CFI_POP(%esi)
 	INSN1(pop,l	,R(edi))
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/mpih-mul2.S b/mpi/i386/mpih-mul2.S
index 9794e1108..fe4129c43 100644
--- a/mpi/i386/mpih-mul2.S
+++ b/mpi/i386/mpih-mul2.S
@@ -50,10 +50,15 @@
 	GLOBL	C_SYMBOL_NAME(_gcry_mpih_addmul_1)
 C_SYMBOL_NAME(_gcry_mpih_addmul_1:)
 
+	CFI_STARTPROC()
 	INSN1(push,l	,R(edi))
+	CFI_PUSH(%edi)
 	INSN1(push,l	,R(esi))
+	CFI_PUSH(%esi)
 	INSN1(push,l	,R(ebx))
+	CFI_PUSH(%ebx)
 	INSN1(push,l	,R(ebp))
+	CFI_PUSH(%ebp)
 
 	INSN2(mov,l	,R(res_ptr),MEM_DISP(esp,20))
 	INSN2(mov,l	,R(s1_ptr),MEM_DISP(esp,24))
@@ -79,8 +84,13 @@ Loop:
 	INSN2(mov,l	,R(eax),R(ebx))
 
 	INSN1(pop,l	,R(ebp))
+	CFI_POP(%ebp)
 	INSN1(pop,l	,R(ebx))
+	CFI_POP(%ebx)
 	INSN1(pop,l	,R(esi))
+	CFI_POP(%esi)
 	INSN1(pop,l	,R(edi))
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/mpih-mul3.S b/mpi/i386/mpih-mul3.S
index 6df201763..87577d54c 100644
--- a/mpi/i386/mpih-mul3.S
+++ b/mpi/i386/mpih-mul3.S
@@ -50,10 +50,15 @@
 	GLOBL	C_SYMBOL_NAME(_gcry_mpih_submul_1)
 C_SYMBOL_NAME(_gcry_mpih_submul_1:)
 
+	CFI_STARTPROC()
 	INSN1(push,l	,R(edi))
+	CFI_PUSH(%edi)
 	INSN1(push,l	,R(esi))
+	CFI_PUSH(%esi)
 	INSN1(push,l	,R(ebx))
+	CFI_PUSH(%ebx)
 	INSN1(push,l	,R(ebp))
+	CFI_PUSH(%ebp)
 
 	INSN2(mov,l	,R(res_ptr),MEM_DISP(esp,20))
 	INSN2(mov,l	,R(s1_ptr),MEM_DISP(esp,24))
@@ -79,8 +84,13 @@ Loop:
 	INSN2(mov,l	,R(eax),R(ebx))
 
 	INSN1(pop,l	,R(ebp))
+	CFI_POP(%ebp)
 	INSN1(pop,l	,R(ebx))
+	CFI_POP(%ebx)
 	INSN1(pop,l	,R(esi))
+	CFI_POP(%esi)
 	INSN1(pop,l	,R(edi))
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/mpih-rshift.S b/mpi/i386/mpih-rshift.S
index 2920e55d8..35a8201f3 100644
--- a/mpi/i386/mpih-rshift.S
+++ b/mpi/i386/mpih-rshift.S
@@ -43,9 +43,13 @@
 	ALIGN (3)
 	.globl C_SYMBOL_NAME(_gcry_mpih_rshift)
 C_SYMBOL_NAME(_gcry_mpih_rshift:)
+	CFI_STARTPROC()
 	pushl	%edi
+	CFI_PUSH(%edi)
 	pushl	%esi
+	CFI_PUSH(%esi)
 	pushl	%ebx
+	CFI_PUSH(%ebx)
 
 	movl	16(%esp),%edi		/* wp */
 	movl	20(%esp),%esi		/* up */
@@ -67,7 +71,7 @@ C_SYMBOL_NAME(_gcry_mpih_rshift:)
 	movl	%ebx,%eax
 
 	ALIGN (3)
-Loop2:	 movl	 (%esi,%edx,4),%ebx	 /* load next higher limb */
+Loop2:	movl	 (%esi,%edx,4),%ebx	/* load next higher limb */
 	shrdl	%cl,%ebx,%eax		/* compute result limb */
 	movl	%eax,(%edi,%edx,4)	/* store it */
 	incl	%edx
@@ -91,7 +95,11 @@ Lend2:	shrl	%cl,%ebx		/* compute most significant limb */
 	movl	%ebx,(%edi)		/* store it */
 
 	popl	%ebx
+	CFI_POP(%ebx)
 	popl	%esi
+	CFI_POP(%esi)
 	popl	%edi
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/mpih-sub1.S b/mpi/i386/mpih-sub1.S
index f447f7a66..501c4a9fd 100644
--- a/mpi/i386/mpih-sub1.S
+++ b/mpi/i386/mpih-sub1.S
@@ -45,8 +45,11 @@
 	ALIGN (3)
 	.globl C_SYMBOL_NAME(_gcry_mpih_sub_n)
 C_SYMBOL_NAME(_gcry_mpih_sub_n:)
+	CFI_STARTPROC()
 	pushl %edi
+	CFI_PUSH(%edi)
 	pushl %esi
+	CFI_PUSH(%esi)
 
 	movl 12(%esp),%edi		/* res_ptr */
 	movl 16(%esp),%esi		/* s1_ptr */
@@ -112,6 +115,9 @@ Loop:	movl	(%esi),%eax
 	negl	%eax
 
 	popl %esi
+	CFI_POP(%esi)
 	popl %edi
+	CFI_POP(%edi)
 	ret
+	CFI_ENDPROC()
 
diff --git a/mpi/i386/syntax.h b/mpi/i386/syntax.h
index 39ede988f..9101585a8 100644
--- a/mpi/i386/syntax.h
+++ b/mpi/i386/syntax.h
@@ -26,6 +26,30 @@
  *	 to avoid revealing of sensitive data due to paging etc.
  */
 
+#include <config.h>
+
+#ifdef HAVE_GCC_ASM_CFI_DIRECTIVES
+# define CFI_STARTPROC()            .cfi_startproc
+# define CFI_ENDPROC()              .cfi_endproc
+# define CFI_ADJUST_CFA_OFFSET(off) .cfi_adjust_cfa_offset off
+# define CFI_REL_OFFSET(reg,off)    .cfi_rel_offset reg, off
+# define CFI_RESTORE(reg)           .cfi_restore reg
+
+# define CFI_PUSH(reg) \
+	CFI_ADJUST_CFA_OFFSET(4); CFI_REL_OFFSET(reg, 0)
+# define CFI_POP(reg) \
+	CFI_ADJUST_CFA_OFFSET(-4); CFI_RESTORE(reg)
+#else
+# define CFI_STARTPROC()
+# define CFI_ENDPROC()
+# define CFI_ADJUST_CFA_OFFSET(off)
+# define CFI_REL_OFFSET(reg,off)
+# define CFI_RESTORE(reg)
+
+# define CFI_PUSH(reg)
+# define CFI_POP(reg)
+#endif
+
 #undef ALIGN
 
 #if defined (BSD_SYNTAX) || defined (ELF_SYNTAX)




More information about the Gcrypt-devel mailing list