1
/* libunwind - a platform-independent unwind library
2
Copyright (C) 2011 Google, Inc
3
Contributed by Paul Pluzhnikov <ppluzhnikov@google.com>
5
Permission is hereby granted, free of charge, to any person obtaining
6
a copy of this software and associated documentation files (the
7
"Software"), to deal in the Software without restriction, including
8
without limitation the rights to use, copy, modify, merge, publish,
9
distribute, sublicense, and/or sell copies of the Software, and to
10
permit persons to whom the Software is furnished to do so, subject to
11
the following conditions:
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1
24
#define UNW_LOCAL_ONLY
2
25
#include <libunwind.h>
3
#if !defined(UNW_REMOTE_ONLY)
4
#include "Gtest-nocalloc.c"
33
#define panic(args...) \
34
{ fprintf (stderr, args); exit (-1); }
41
calloc(size_t n, size_t s)
43
static void * (*func)(size_t, size_t);
46
/* In glibc, dlsym() calls calloc. Calling dlsym(RTLD_NEXT, "calloc") here
47
causes infinite recursion. Instead, we simply use it by its other
49
extern void *__libc_calloc(size_t, size_t);
51
func = &__libc_calloc;
54
func = dlsym(RTLD_NEXT, "calloc");
68
static void * (*func)(size_t);
71
func = dlsym(RTLD_NEXT, "malloc");
84
const int num_levels = 100;
88
unw_backtrace(pc, num_levels);
115
/* Create (and leak) 100 TSDs, then call backtrace()
116
and check that it doesn't call malloc()/calloc(). */
117
for (i = 0; i < 100; ++i) {
119
if (pthread_key_create (&key, NULL))
120
panic ("FAILURE: unable to create key %d\n", i);
122
/* Call backtrace right after thread creation,
123
* where we are sure that we're not inside malloc */
125
num_mallocs = num_callocs = 0;
127
num_errors = num_mallocs + num_callocs;
131
"FAILURE: detected %d error%s (malloc: %d, calloc: %d)\n",
132
num_errors, num_errors > 1 ? "s" : "",
133
num_mallocs, num_callocs);