mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-25 08:37:38 +01:00
Verify that we don't call malloc when unwinding locally.
This commit is contained in:
parent
a2c27a4ab7
commit
576b59e4b1
3 changed files with 125 additions and 1 deletions
114
tests/Gtest-nomalloc.c
Normal file
114
tests/Gtest-nomalloc.c
Normal file
|
@ -0,0 +1,114 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2009 Google, Inc
|
||||
Contributed by Arun Sharma <arun.sharma@google.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <libunwind.h>
|
||||
|
||||
#define panic(args...) \
|
||||
{ fprintf (stderr, args); exit (-1); }
|
||||
|
||||
int verbose;
|
||||
int num_errors;
|
||||
int in_unwind;
|
||||
|
||||
void *
|
||||
malloc(size_t s)
|
||||
{
|
||||
static void * (*func)();
|
||||
|
||||
if(!func)
|
||||
func = (void *(*)()) dlsym(RTLD_NEXT, "malloc");
|
||||
|
||||
if (in_unwind) {
|
||||
num_errors++;
|
||||
return NULL;
|
||||
} else {
|
||||
return func(s);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_backtrace (void)
|
||||
{
|
||||
unw_word_t ip, sp;
|
||||
unw_cursor_t cursor;
|
||||
unw_context_t uc;
|
||||
int ret;
|
||||
|
||||
in_unwind = 1;
|
||||
unw_getcontext (&uc);
|
||||
if (unw_init_local (&cursor, &uc) < 0)
|
||||
panic ("unw_init_local failed!\n");
|
||||
|
||||
do
|
||||
{
|
||||
unw_get_reg (&cursor, UNW_REG_IP, &ip);
|
||||
unw_get_reg (&cursor, UNW_REG_SP, &sp);
|
||||
|
||||
ret = unw_step (&cursor);
|
||||
if (ret < 0)
|
||||
{
|
||||
++num_errors;
|
||||
}
|
||||
}
|
||||
while (ret > 0);
|
||||
in_unwind = 0;
|
||||
}
|
||||
|
||||
void
|
||||
foo3 ()
|
||||
{
|
||||
do_backtrace ();
|
||||
}
|
||||
|
||||
void
|
||||
foo2 ()
|
||||
{
|
||||
foo3 ();
|
||||
}
|
||||
|
||||
void
|
||||
foo1 ()
|
||||
{
|
||||
foo2 ();
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
foo1();
|
||||
|
||||
if (num_errors > 0)
|
||||
{
|
||||
fprintf (stderr, "FAILURE: detected %d errors\n", num_errors);
|
||||
exit (-1);
|
||||
}
|
||||
return 0;
|
||||
}
|
5
tests/Ltest-nomalloc.c
Normal file
5
tests/Ltest-nomalloc.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#define UNW_LOCAL_ONLY
|
||||
#include <libunwind.h>
|
||||
#if !defined(UNW_REMOTE_ONLY)
|
||||
#include "Gtest-nomalloc.c"
|
||||
#endif
|
|
@ -40,7 +40,8 @@ endif #ARCH_IA64
|
|||
Gtest-resume-sig Ltest-resume-sig \
|
||||
Gtest-dyn1 Ltest-dyn1 \
|
||||
test-async-sig test-flush-cache test-init-remote \
|
||||
test-mem test-setjmp test-ptrace
|
||||
test-mem test-setjmp test-ptrace \
|
||||
Ltest-nomalloc
|
||||
noinst_PROGRAMS_cdep = forker mapper test-ptrace-misc test-varargs \
|
||||
Gperf-simple Lperf-simple
|
||||
|
||||
|
@ -98,3 +99,7 @@ test_ptrace_LDADD = ../src/libunwind-ptrace.a $(LIBUNWIND)
|
|||
Ltest_concurrent_LDADD = $(LIBUNWIND) -lpthread
|
||||
Gtest_concurrent_LDADD = $(LIBUNWIND) -lpthread
|
||||
test_async_sig_LDADD = $(LIBUNWIND) -lpthread
|
||||
|
||||
LDADD += -ldl
|
||||
Ltest_nomalloc_SOURCES = Ltest-nomalloc.c
|
||||
|
||||
|
|
Loading…
Reference in a new issue