1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-07-02 13:41:46 +02:00
Commit graph

110 commits

Author SHA1 Message Date
Konstantin Belousov 752ce15c4f Preliminary version of freebsd syscall unwinder 2010-03-08 19:45:54 +02:00
Konstantin Belousov 89e1df2d32 Fix _UI_siglongjmp_cont name 2010-03-08 15:55:29 +02:00
Konstantin Belousov 0f1c0f5f66 Fix resume. 2010-03-08 15:51:39 +02:00
Konstantin Belousov 43ed5b3e56 Add required assembler magic. 2010-03-08 00:57:50 +02:00
Konstantin Belousov 093855f12a Remove unneeded includes of sys/types.h 2010-03-08 00:25:22 +02:00
Konstantin Belousov 53095e6b3e Code for resume 2010-03-07 23:43:07 +02:00
Konstantin Belousov c64723835c Support walk over freebsd sigframes 2010-03-07 21:53:01 +02:00
Konstantin Belousov d0d5f9979b Correct rsp offset 2010-03-07 21:20:43 +02:00
Konstantin Belousov 200147d0f2 Handle fpu state 2010-03-06 23:22:46 +02:00
Konstantin Belousov 62218e10eb Provide proper offsets for gregs in freebsd ucontext. Note that fp regs are not handled. 2010-03-06 22:33:11 +02:00
Konstantin Belousov 81f2de0083 Add implementation of unw_is_signal_frame for freebsd. 2010-03-06 18:08:44 +02:00
Konstantin Belousov 1ba7599250 Add FreeBSD stub. 2010-03-06 17:54:51 +02:00
Konstantin Belousov 3eabce18b1 Include sys/types.h when needed. 2010-03-06 16:43:39 +02:00
Konstantin Belousov c7ffca11ae FreeBSD way to name registers. 2010-03-06 16:35:32 +02:00
Arun Sharma 3468a6b33d Change MS_SYNC to MS_ASYNC
Hopefully this makes the address validation a bit cheaper.
2010-02-23 10:35:47 -08:00
Paul Pluzhnikov 0cf76ed0b5 Check for NULL when validating addresses
This is rather on the obvious side.

While doing strace on an executable using libunwind, I noticed a
lot of:

  msync(0, 1, MS_SYNC) = -1 ENOMEM (Cannot allocate memory)

Since we know that the first page isn't mapped (or at least doesn't
contain the data we are looking for), we can eliminate all such
msync calls.

Tested on Linux/x86_64 with no regressions.
2009-12-01 13:59:45 -08:00
Arun Sharma 491d576529 Fix compiler warnings on x86_64 2009-10-16 14:01:50 -07:00
Paul Pluzhnikov 84d4150668 Allow caller to block signals.
Greetings,

We use libunwind just for stack traces (I suspect many others do as well).

The use pattern is:

GetStackTrace(void** result, int max_depth)
{
...
  unw_getcontext(&uc);
  unw_init_local(&cursor, &uc);

  while (n < max_depth) {
    if (unw_get_reg(&cursor, UNW_REG_IP, (unw_word_t *) &ip) < 0) {
      break;
    }
    result[n++] = ip;
    if (unw_step(&cursor) <= 0) {
      break;
    }
  }

Given this usage, it is quite convenient for us to block signals (or
prevent signal handlers from re-entering libunwind by other means) at the
"top level", which makes most of the sigprocmask calls performed by
libunwind itself unneccessary.

The second patch in this series adds a configure option which removes most
of the sigprocmask calls.

Attached patch is a preliminary for it -- consolidating all of the
"sigprocmask; mutex_lock;" sequences into lock_acquire and "mutex_unlock;
sigprocmask;" sequences into lock_release.

Thanks,
--
Paul Pluzhnikov

commit 402d15b123d54a7669db7cf17a76dd315094e472
Author: Paul Pluzhnikov <ppluzhnikov@google.com>
Date:   Mon Sep 21 10:18:28 2009 -0700

    Replace "sigprocmask + mutext_lock" with a single lock_acquire.
    Likewise, replace "mutext_unlock + sigprocmask" with lock_release.
2009-09-25 09:35:31 -07:00
Arun Sharma ef29eade44 This patch eliminates one system call per unwind by not using the
getcontext in libc.

Also cleanup the namespace (check-name-space passes on x86_64 now).
Replace uses of offsets.h with ucontext_i.h.
Rename _x86_64_setcontext to _Ux86_64_setcontext.

TBD: Add CFI annotations for get/setcontext.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2008-06-16 14:42:16 -06:00
Arun Sharma 649f1fb344 [X86-64] For local unwinding, we have a defence mechanism against
bad/missing unwind information, which could result in libunwind
dereferencing bad pointers. This mechanism is based on msync(2) system
call and significantly reduces the chances of a bad pointer
dereference in libunwind.

The original idea was to turn this mechanism on only when necessary
i.e. libunwind didn't find proper unwind information for a IP.

There are a couple of problems in the current implementation.

* The flag is global and is modified without locking
* The flag isn't reset when starting a new unwind

The attached patch makes ->validate a per-thread setting by moving it
into struct cursor from unw_local_addr_space and resets it to false
when starting a new unwind. As a result, cursor->as_arg points to the
cursor itself instead of the ucontext (for the local case).

This was found to reduce the number of msync() system calls from an
application using libunwind significantly.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2008-06-16 14:35:53 -06:00
Paul Pluzhnikov bb9d3dc689 [X86-64] Fix the pattern used to match signal frames.
The current pattern is too restrictive and doesn't work well on
modern glibcs.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2008-04-16 08:05:49 -06:00
Jan Kratochvil 57e5696463 Mark Wielaard <mwielaard@redhat.com> writes:
On some systems executable stacks are denied. Since libunwind and the
tests don't actually need executable stacks this patch marks all
assembly files as not needing it.

The original patch comes from frysk:

2007-04-05  Jan Kratochvil  <jan.kratochvil@redhat.com>

    * src/hppa/getcontext.S, src/hppa/setcontext.S, src/hppa/siglongjmp.S,
    src/ia64/Ginstall_cursor.S, src/ia64/Linstall_cursor.S,
    src/ia64/dyn_info_list.S, src/ia64/getcontext.S, src/ia64/longjmp.S,
    src/ia64/setjmp.S, src/ia64/siglongjmp.S, src/ia64/sigsetjmp.S,
    src/ppc64/longjmp.S, src/ppc64/siglongjmp.S, src/x86/longjmp.S,
    src/x86/siglongjmp.S, src/x86_64/longjmp.S, src/x86_64/setcontext.S,
    src/x86_64/siglongjmp.S: Stack should be non-executable, for SELinux.

I added a couple more markers for new files in current libunwind.

Before this patch you would get the following on selinux enabled
systems without allow_exec_stack: error while loading shared
libraries:

libunwind.so.7: cannot enable executable stack as shared object
	requires: Permission denied

After the patch that error disappears and all test results are similar
to the results on systems without executable stack protection.
2007-10-01 08:35:01 -06:00
David Mosberger-Tang e6b9f350f7 Introduce a tdep_get_func_addr_hook() in the ELF lookup_symbol()
routine and add address-space argument.  This is needed because on
PPC64, a the function-name symbol refers to a function descriptor
(unlike, for example, on ia64, where the @fptr() operator is needed to
refer to a function descriptor).  Thus, in order to look up the name
of a function, we need to dereference the function descriptor.  To
make matters more "interesting", the function descriptors are normally
resolved by the dynamic linker, so we can't get their values from the
ELF file.  Instead, we have to read them from the running image, hence
the need for the address-space argument.
2007-08-22 13:02:09 -06:00
David Mosberger-Tang 5c95d139df Cleanup some files from previous patch and rerurn autoconf tools. 2007-08-06 19:59:28 -06:00
Arun Sharma 3afd613545 [X86-64]: Instead of auto-generating _u_context_i.h, hardcode the
necessary offsets in offsets.h as is done for other
	  platforms.  This fixes cross-builds.
2007-08-06 19:58:12 -06:00
Arun Sharma 497b987043 Add gen-offsets to the Makefile
This is so that the source file gets distributed and _ucontext_i.h is
generated properly on the target machine.

Signed-off-by: Arun Sharma <arun.sharma@google.com>
2007-04-10 20:18:56 -06:00
Arun Sharma 31440e9796 Make libunwind pass C++ exceptions correctly
When libunwind is linked with a C++ program that throws exceptions,
the exception that's thrown is passed in %rax. However, libc's
setcontext clears %rax, causing problems.

This patch implements a setcontext that doesn't clobber rax.

TBD: Add dwarf CFI annotations

Signed-off-by: Arun Sharma <arun.sharma@google.com>
2007-04-05 20:40:41 -06:00
David Mosberger-Tang 62bacfcf1f [x86-64] Minor reformatting for GNU-style and use memset() in lieu of bzero(). 2006-08-10 21:34:31 -06:00
Arun Sharma (अरुण) 795529eee3 [x86-64] Add a known good address cache.
This improves the performance of Lperf-simple from 500ns to 195ns
on the avg.

Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-08-10 21:30:01 -06:00
Arun Sharma 8297866bd4 [x86-64] (unw_step): Further refine handling of functions without unwind-info.
CFA should be incremented by 16 in the hope that the previous frame
may have valid unwind info.

Also increase the default frame pointer recognition heuristic from 4k
to 16k.

Signed-off-by: Andrey Veskov <Andrey.Veskov@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 22:06:48 -06:00
Arun Sharma 06d2ffa41a [x86-64] (unw_step): Improve handling of functions which lack unwind info.
If following the frame-chain leads to a frame >= 4KB away, we conclude that
the frame-pointer isn't really valid.
2006-07-26 22:04:40 -06:00
Arun Sharma 7c0907634d [x86-64] (unw_is_signal_frame): If access mem fails, it's not a signal frame. 2006-07-26 21:58:27 -06:00
Arun Sharma 527225e492 [x86-64] Make a best effort at validating pointers before dereferencing them.
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 21:46:39 -06:00
Arun Sharma 00db7f752a Implement a ip -> dwarf_reg_state cache.
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 21:18:49 -06:00
David Mosberger-Tang 6daeeac60a Revert "Initial revision"
This reverts e6446885f4 commit.
2006-07-26 14:53:49 -06:00
David Mosberger-Tang ca69fee8bb Merge ../libunwind-v0.98
Conflicts:

	include/dwarf_i.h
	include/x86/jmpbuf.h
	include/x86_64/jmpbuf.h
	src/hppa/init.h
	src/mi/Gget_fpreg.c
	src/mi/Gset_fpreg.c
	src/mi/strerror.c
2006-07-25 21:41:43 -06:00
hp.com!davidm d9e100753f Include "libunwind_i.h" instead of "tdep.h".
(Logical change 1.294)
2005-05-20 09:48:08 +00:00
hp.com!davidm 07b01ad205 Include "libunwind_i.h" instead of "tdep.h" and "internal.h".
(Logical change 1.294)
2005-05-20 09:48:08 +00:00
mostang.com!davidm 7fbb8a9593 Adjust for sigset_t to intrmask_t renaming.
(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm 17bf4d0af8 (unw_step): If dwarf_step() fails and the frame doesn't look like
a signal-trampoline, assume that it's a PLT stub.
	If non-DWARF stepping fails to change IP and CFA, declare
	it a bad frame.

2004/11/23 16:59:56-08:00 mostang.com!davidm
(unw_step): Also print IP as part of the function-trace.

2004/11/23 16:17:37-08:00 mostang.com!davidm
(unw_step): When dwarf_step() fails on a signal-frame, fill in all
	the known locations because dwarf_step() fails on older
	kernels which don't export the kernel vDSO even though every-
	thing else may be providing proper DWARF unwind-info.

2004/10/25 17:43:57+02:00 homeip.net!davidm
Add Debug statement for return-value.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm 7ac9665fd3 (unw_get_proc_info): Don't freak out if dwarf_make_proc_info() fails.
Unfortunately, it must fail for current versions of libc
	since they fail to provide unwind-info for _start() and
	_dl_start().

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm b1b84400b9 (tdep_uc_addr): Define as HIDDEN.
(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm e3180d47a0 (UC_MCONTEXT_{R8-R15,RDI,RSI,RBX,RDX,RAX,RCX}: New macros.
(Logical change 1.290)
2005-05-03 09:13:17 +00:00
hp.com!davidm e6446885f4 Initial revision 2005-05-03 09:13:17 +00:00
hp.com!davidm 516f759229 Fix two typos which kept things from building on x86-64 and other
platforms.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
hp.com!davidm df5acdd24a Fix missing NELEMS -> ARRAY_SIZE adjustment.
(Logical change 1.290)
2005-05-03 09:13:17 +00:00
hp.com!davidm a9cad72ed4 (x86_64_local_resume): Fix missing "H" typo.
2004/11/30 22:44:47-08:00 mostang.com!davidm
(my_rt_sigreturn): New function.
(x86_64_local_resume): Use my_rt_sigreturn().  The normal sigreturn()
	does nothing (returns with an error).

2004/11/23 18:01:09-08:00 mostang.com!davidm
(x86_64_local_resume): Provide a minimal implementation (a la x86).
(establish_machine_state): Fix off-by-one error.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
hp.com!davidm 555bae8aa3 (tdep_access_reg): When writing RAX/RDX, update eh_args[] and
eh_valid_mask instead.  When reading and the corresponding
	eh_valid_mask bit is set, read from eh_args[] instead.

2004/11/17 02:43:39-08:00 mostang.com!davidm
(tdep_access_reg): Treat UNW_X86_64_RSP exactly like UNW_X86_64_CFA.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
hp.com!davidm 081c41d8a6 (common_init): Don't forget to initialize sigcontext_format and
sigcontext_addr.

2004/11/17 02:43:39-08:00 mostang.com!davidm
(common_init): Don't forget to clear c->dwarf members args_size,
	ret_addr_column, pi_valid, and pi_is_dynamic.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
hp.com!davidm 5b20c6e082 (Logical change 1.290) 2005-05-03 09:13:17 +00:00
mostang.com!davidm caa528e1e8 Add dummy implementation of _UI_longjmp_cont().
(Logical change 1.268)
2004-09-09 16:26:15 +00:00
com[davidm]!masbock e09e6ce1ad x86-64: fix unw_get_proc_info()
(Logical change 1.260)
2004-08-31 13:59:37 +00:00
hp.com!davidm f576cce748 Drop debug-level for function-trace to 1.
(Logical change 1.257)
2004-08-26 10:02:46 +00:00
homeip.net!davidm 6058013abe (unw_step): If dwarf_step() fails, fall back on using the frame-chain.
In theory, this may not be needed.  In practice, I find that
	Red Hat Enterprise Linux AS release 3, the _start() routine has
	no unwind-info, but we need to be able to unwind into this
	routine to find the end-of-frame-chain marker (RBP == 0).

(Logical change 1.253)
2004-08-20 11:23:15 +00:00
homeip.net!davidm be2bed2712 (tdep_access_reg): If c->dwarf.cfa_is_sp is set, treat UNW_X86_64_RSP
as a read-only alias of CFA.

(Logical change 1.253)
2004-08-20 11:23:15 +00:00
homeip.net!davidm 51ef1210e8 Include ucontext_i.h.
(unw_step): Fixup signal-frame-skipping code so it can be cross-compiled.

(Logical change 1.251)
2004-08-19 14:00:14 +00:00
homeip.net!davidm 43425a9beb (Logical change 1.251) 2004-08-19 14:00:14 +00:00
homeip.net!davidm c0603a8ebc Initial revision 2004-08-19 14:00:14 +00:00
ibm.com!masbock a766efd844 (Logical change 1.249) 2004-08-19 13:39:10 +00:00
ibm.com!masbock 58e37267be Initial revision 2004-08-19 13:39:10 +00:00