summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJameson Nash <vtjnash@gmail.com>2022-04-25 18:30:37 -0400
committerDave Watson <dade.watson@gmail.com>2022-05-22 11:10:44 -0700
commit0c4484911dcaa47af09da3a717a66ab98dc7f7a8 (patch)
tree433b34c181e661e759ed3cc7e94e0d11a3908a2f /src
parent7eb6f72ff22a8db41800a317d331750982f75296 (diff)
downloadlibunwind-0c4484911dcaa47af09da3a717a66ab98dc7f7a8.tar.gz
avoid leaking registers across sigreturn
Mostly just relevant for fp registers, which are frequently mostly just ignored otherwise.
Diffstat (limited to 'src')
-rw-r--r--src/aarch64/Gstep.c5
-rw-r--r--src/arm/Gos-freebsd.c5
-rw-r--r--src/arm/Gos-linux.c5
-rw-r--r--src/loongarch64/Gstep.c5
-rw-r--r--src/mips/Gstep.c5
-rw-r--r--src/riscv/Gstep.c3
-rw-r--r--src/s390x/Gstep.c3
-rw-r--r--src/sh/Gstep.c5
-rw-r--r--src/tilegx/Gis_signal_frame.c3
-rw-r--r--src/x86/Gos-freebsd.c3
-rw-r--r--src/x86/Gos-linux.c8
-rw-r--r--src/x86_64/Gos-freebsd.c5
-rw-r--r--src/x86_64/Gos-solaris.c4
13 files changed, 48 insertions, 11 deletions
diff --git a/src/aarch64/Gstep.c b/src/aarch64/Gstep.c
index 92e2a666..5e9e63ce 100644
--- a/src/aarch64/Gstep.c
+++ b/src/aarch64/Gstep.c
@@ -55,7 +55,7 @@ static int
aarch64_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
- int ret;
+ int i, ret;
unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
struct dwarf_loc sp_loc = DWARF_LOC (sp_addr, 0);
@@ -82,6 +82,9 @@ aarch64_handle_signal_frame (unw_cursor_t *cursor)
c->frame_info.frame_type = UNW_AARCH64_FRAME_SIGRETURN;
c->frame_info.cfa_reg_offset = sc_addr - sp_addr;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/arm/Gos-freebsd.c b/src/arm/Gos-freebsd.c
index a1069223..1566a813 100644
--- a/src/arm/Gos-freebsd.c
+++ b/src/arm/Gos-freebsd.c
@@ -38,7 +38,7 @@ HIDDEN int
arm_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
- int ret, fmt;
+ int i, ret, fmt;
unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
struct dwarf_loc sp_loc = DWARF_LOC (sp_addr, 0);
@@ -70,6 +70,9 @@ arm_handle_signal_frame (unw_cursor_t *cursor)
c->frame_info.frame_type = UNW_ARM_FRAME_SIGRETURN;
c->frame_info.cfa_reg_offset = sc_addr - sp_addr;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/arm/Gos-linux.c b/src/arm/Gos-linux.c
index 260e086f..19703030 100644
--- a/src/arm/Gos-linux.c
+++ b/src/arm/Gos-linux.c
@@ -33,7 +33,7 @@ HIDDEN int
arm_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
- int ret;
+ int i, ret;
unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
struct dwarf_loc sp_loc = DWARF_LOC (sp_addr, 0);
@@ -93,6 +93,9 @@ arm_handle_signal_frame (unw_cursor_t *cursor)
c->frame_info.frame_type = UNW_ARM_FRAME_SIGRETURN;
c->frame_info.cfa_reg_offset = sc_addr - sp_addr;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/loongarch64/Gstep.c b/src/loongarch64/Gstep.c
index 5743694b..221cc4f1 100644
--- a/src/loongarch64/Gstep.c
+++ b/src/loongarch64/Gstep.c
@@ -33,7 +33,7 @@ loongarch64_handle_signal_frame (unw_cursor_t *cursor)
struct cursor *c = (struct cursor *) cursor;
unw_word_t sc_addr, sp_addr = c->dwarf.cfa;
unw_word_t ra, fp;
- int ret;
+ int i, ret;
if (unw_is_signal_frame (cursor)) {
sc_addr = sp_addr + LINUX_SF_TRAMP_SIZE + sizeof (siginfo_t) +
@@ -51,6 +51,9 @@ loongarch64_handle_signal_frame (unw_cursor_t *cursor)
c->sigcontext_pc = c->dwarf.ip;
c->sigcontext_format = LOONGARCH64_SCF_LINUX_RT_SIGFRAME;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/mips/Gstep.c b/src/mips/Gstep.c
index 79fea71f..3706cfc2 100644
--- a/src/mips/Gstep.c
+++ b/src/mips/Gstep.c
@@ -32,7 +32,7 @@ mips_handle_signal_frame (unw_cursor_t *cursor)
struct cursor *c = (struct cursor *) cursor;
unw_word_t sc_addr, sp_addr = c->dwarf.cfa;
unw_word_t ra, fp;
- int ret;
+ int i, ret;
switch (unw_is_signal_frame (cursor)) {
case 1:
@@ -51,6 +51,9 @@ mips_handle_signal_frame (unw_cursor_t *cursor)
c->sigcontext_addr = sc_addr;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor. */
c->dwarf.loc[UNW_MIPS_R0] = DWARF_LOC (sc_addr + LINUX_SC_R0_OFF, 0);
c->dwarf.loc[UNW_MIPS_R1] = DWARF_LOC (sc_addr + LINUX_SC_R1_OFF, 0);
diff --git a/src/riscv/Gstep.c b/src/riscv/Gstep.c
index 5126b0ef..28687a8f 100644
--- a/src/riscv/Gstep.c
+++ b/src/riscv/Gstep.c
@@ -53,6 +53,9 @@ riscv_handle_signal_frame (unw_cursor_t *cursor)
return -UNW_EUNSPEC;
#endif
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/s390x/Gstep.c b/src/s390x/Gstep.c
index 0b79580b..c6b64417 100644
--- a/src/s390x/Gstep.c
+++ b/src/s390x/Gstep.c
@@ -64,6 +64,9 @@ s390x_handle_signal_frame (unw_cursor_t *cursor)
c->sigcontext_addr = sc_addr;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/sh/Gstep.c b/src/sh/Gstep.c
index 60d7ec2b..2c6a96c5 100644
--- a/src/sh/Gstep.c
+++ b/src/sh/Gstep.c
@@ -31,7 +31,7 @@ static int
sh_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
- int ret;
+ int i, ret;
unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
struct dwarf_loc sp_loc = DWARF_LOC (sp_addr, 0);
@@ -63,6 +63,9 @@ sh_handle_signal_frame (unw_cursor_t *cursor)
c->sigcontext_addr = sc_addr;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/tilegx/Gis_signal_frame.c b/src/tilegx/Gis_signal_frame.c
index 5452c2cb..eea00e47 100644
--- a/src/tilegx/Gis_signal_frame.c
+++ b/src/tilegx/Gis_signal_frame.c
@@ -96,6 +96,9 @@ tilegx_handle_signal_frame (unw_cursor_t *cursor)
C_ABI_SAVE_AREA_SIZE;
sc_addr = c->sigcontext_addr + LINUX_UC_MCONTEXT_OFF;
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
/* Update the dwarf cursor.
Set the location of the registers to the corresponding addresses of the
uc_mcontext / sigcontext structure contents. */
diff --git a/src/x86/Gos-freebsd.c b/src/x86/Gos-freebsd.c
index 1b251d02..28e6722a 100644
--- a/src/x86/Gos-freebsd.c
+++ b/src/x86/Gos-freebsd.c
@@ -124,6 +124,9 @@ x86_handle_signal_frame (unw_cursor_t *cursor)
return 0;
}
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
c->dwarf.loc[EIP] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EIP_OFF, 0);
c->dwarf.loc[ESP] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_ESP_OFF, 0);
c->dwarf.loc[EAX] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EAX_OFF, 0);
diff --git a/src/x86/Gos-linux.c b/src/x86/Gos-linux.c
index d448dce7..0908e3a1 100644
--- a/src/x86/Gos-linux.c
+++ b/src/x86/Gos-linux.c
@@ -73,7 +73,7 @@ HIDDEN int
x86_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
- int ret;
+ int i, ret;
/* c->esp points at the arguments to the handler. Without
SA_SIGINFO, the arguments consist of a signal number
@@ -123,6 +123,9 @@ x86_handle_signal_frame (unw_cursor_t *cursor)
return 0;
}
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
c->dwarf.loc[EAX] = DWARF_LOC (sc_addr + LINUX_SC_EAX_OFF, 0);
c->dwarf.loc[ECX] = DWARF_LOC (sc_addr + LINUX_SC_ECX_OFF, 0);
c->dwarf.loc[EDX] = DWARF_LOC (sc_addr + LINUX_SC_EDX_OFF, 0);
@@ -130,9 +133,6 @@ x86_handle_signal_frame (unw_cursor_t *cursor)
c->dwarf.loc[EBP] = DWARF_LOC (sc_addr + LINUX_SC_EBP_OFF, 0);
c->dwarf.loc[ESI] = DWARF_LOC (sc_addr + LINUX_SC_ESI_OFF, 0);
c->dwarf.loc[EDI] = DWARF_LOC (sc_addr + LINUX_SC_EDI_OFF, 0);
- c->dwarf.loc[EFLAGS] = DWARF_NULL_LOC;
- c->dwarf.loc[TRAPNO] = DWARF_NULL_LOC;
- c->dwarf.loc[ST0] = DWARF_NULL_LOC;
c->dwarf.loc[EIP] = DWARF_LOC (sc_addr + LINUX_SC_EIP_OFF, 0);
c->dwarf.loc[ESP] = DWARF_LOC (sc_addr + LINUX_SC_ESP_OFF, 0);
diff --git a/src/x86_64/Gos-freebsd.c b/src/x86_64/Gos-freebsd.c
index aa6a4b43..e8f04381 100644
--- a/src/x86_64/Gos-freebsd.c
+++ b/src/x86_64/Gos-freebsd.c
@@ -92,7 +92,7 @@ x86_64_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
unw_word_t ucontext;
- int ret;
+ int i, ret;
if (c->sigcontext_format == X86_64_SCF_FREEBSD_SIGFRAME)
{
@@ -108,6 +108,9 @@ x86_64_handle_signal_frame (unw_cursor_t *cursor)
return ret;
}
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
c->dwarf.loc[RAX] = DWARF_LOC (ucontext + UC_MCONTEXT_GREGS_RAX, 0);
c->dwarf.loc[RDX] = DWARF_LOC (ucontext + UC_MCONTEXT_GREGS_RDX, 0);
c->dwarf.loc[RCX] = DWARF_LOC (ucontext + UC_MCONTEXT_GREGS_RCX, 0);
diff --git a/src/x86_64/Gos-solaris.c b/src/x86_64/Gos-solaris.c
index 75258d61..a9957ba8 100644
--- a/src/x86_64/Gos-solaris.c
+++ b/src/x86_64/Gos-solaris.c
@@ -51,6 +51,7 @@ x86_64_handle_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
unw_word_t ucontext = c->dwarf.cfa + sizeof (struct sigframe);
+ int i;
if (c->sigcontext_format != X86_64_SCF_SOLARIS_SIGFRAME)
return -UNW_EBADFRAME;
@@ -69,6 +70,9 @@ x86_64_handle_signal_frame (unw_cursor_t *cursor)
return ret;
}
+ for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
+ c->dwarf.loc[i] = DWARF_NULL_LOC;
+
c->dwarf.loc[RAX] = DWARF_LOC (ucontext + UC_MCONTEXT_GREGS_RAX, 0);
c->dwarf.loc[RDX] = DWARF_LOC (ucontext + UC_MCONTEXT_GREGS_RDX, 0);
c->dwarf.loc[RCX] = DWARF_LOC (ucontext + UC_MCONTEXT_GREGS_RCX, 0);