pf2 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +11 -0
- data/Rakefile +9 -2
- data/doc/development.md +11 -0
- data/examples/mandelbrot.rb +69 -0
- data/examples/mandelbrot_ractor.rb +77 -0
- data/ext/pf2/build.rs +7 -0
- data/ext/pf2/src/ruby_c_api_helper.c +6 -0
- data/ext/pf2/src/serialization/profile.rs +1 -0
- data/ext/pf2/src/serialization/serializer.rs +4 -0
- data/ext/pf2/src/signal_scheduler.rs +1 -1
- data/ext/pf2/src/util.rs +2 -1
- data/ext/pf2c/backtrace_state.c +10 -0
- data/ext/pf2c/backtrace_state.h +10 -0
- data/ext/pf2c/configuration.c +90 -0
- data/ext/pf2c/configuration.h +23 -0
- data/ext/pf2c/extconf.rb +21 -0
- data/ext/pf2c/pf2.c +17 -0
- data/ext/pf2c/pf2.h +8 -0
- data/ext/pf2c/ringbuffer.c +74 -0
- data/ext/pf2c/ringbuffer.h +24 -0
- data/ext/pf2c/sample.c +70 -0
- data/ext/pf2c/sample.h +22 -0
- data/ext/pf2c/serializer.c +377 -0
- data/ext/pf2c/serializer.h +58 -0
- data/ext/pf2c/session.c +344 -0
- data/ext/pf2c/session.h +51 -0
- data/lib/pf2/cli.rb +33 -2
- data/lib/pf2/reporter/annotate.rb +101 -0
- data/lib/pf2/reporter/firefox_profiler.rb +1 -1
- data/lib/pf2/reporter/firefox_profiler_ser2.rb +308 -0
- data/lib/pf2/reporter.rb +2 -0
- data/lib/pf2/version.rb +1 -1
- data/vendor/libbacktrace/.gitignore +5 -0
- data/vendor/libbacktrace/Isaac.Newton-Opticks.txt +9286 -0
- data/vendor/libbacktrace/LICENSE +29 -0
- data/vendor/libbacktrace/Makefile.am +708 -0
- data/vendor/libbacktrace/Makefile.in +2820 -0
- data/vendor/libbacktrace/README.md +46 -0
- data/vendor/libbacktrace/aclocal.m4 +864 -0
- data/vendor/libbacktrace/alloc.c +167 -0
- data/vendor/libbacktrace/allocfail.c +136 -0
- data/vendor/libbacktrace/allocfail.sh +104 -0
- data/vendor/libbacktrace/atomic.c +113 -0
- data/vendor/libbacktrace/backtrace-supported.h.in +66 -0
- data/vendor/libbacktrace/backtrace.c +129 -0
- data/vendor/libbacktrace/backtrace.h +189 -0
- data/vendor/libbacktrace/btest.c +517 -0
- data/vendor/libbacktrace/compile +348 -0
- data/vendor/libbacktrace/config/enable.m4 +38 -0
- data/vendor/libbacktrace/config/lead-dot.m4 +31 -0
- data/vendor/libbacktrace/config/libtool.m4 +7545 -0
- data/vendor/libbacktrace/config/ltoptions.m4 +369 -0
- data/vendor/libbacktrace/config/ltsugar.m4 +123 -0
- data/vendor/libbacktrace/config/ltversion.m4 +23 -0
- data/vendor/libbacktrace/config/lt~obsolete.m4 +98 -0
- data/vendor/libbacktrace/config/multi.m4 +68 -0
- data/vendor/libbacktrace/config/override.m4 +117 -0
- data/vendor/libbacktrace/config/unwind_ipinfo.m4 +37 -0
- data/vendor/libbacktrace/config/warnings.m4 +227 -0
- data/vendor/libbacktrace/config.guess +1700 -0
- data/vendor/libbacktrace/config.h.in +185 -0
- data/vendor/libbacktrace/config.sub +1885 -0
- data/vendor/libbacktrace/configure +15952 -0
- data/vendor/libbacktrace/configure.ac +642 -0
- data/vendor/libbacktrace/dwarf.c +4593 -0
- data/vendor/libbacktrace/edtest.c +120 -0
- data/vendor/libbacktrace/edtest2.c +43 -0
- data/vendor/libbacktrace/elf.c +7471 -0
- data/vendor/libbacktrace/fileline.c +407 -0
- data/vendor/libbacktrace/filenames.h +52 -0
- data/vendor/libbacktrace/filetype.awk +13 -0
- data/vendor/libbacktrace/install-debuginfo-for-buildid.sh.in +65 -0
- data/vendor/libbacktrace/install-sh +501 -0
- data/vendor/libbacktrace/instrumented_alloc.c +114 -0
- data/vendor/libbacktrace/internal.h +428 -0
- data/vendor/libbacktrace/ltmain.sh +8636 -0
- data/vendor/libbacktrace/macho.c +1361 -0
- data/vendor/libbacktrace/missing +215 -0
- data/vendor/libbacktrace/mmap.c +331 -0
- data/vendor/libbacktrace/mmapio.c +110 -0
- data/vendor/libbacktrace/move-if-change +83 -0
- data/vendor/libbacktrace/mtest.c +410 -0
- data/vendor/libbacktrace/nounwind.c +66 -0
- data/vendor/libbacktrace/pecoff.c +1123 -0
- data/vendor/libbacktrace/posix.c +104 -0
- data/vendor/libbacktrace/print.c +117 -0
- data/vendor/libbacktrace/read.c +110 -0
- data/vendor/libbacktrace/simple.c +108 -0
- data/vendor/libbacktrace/sort.c +108 -0
- data/vendor/libbacktrace/state.c +72 -0
- data/vendor/libbacktrace/stest.c +137 -0
- data/vendor/libbacktrace/test-driver +148 -0
- data/vendor/libbacktrace/test_format.c +55 -0
- data/vendor/libbacktrace/testlib.c +234 -0
- data/vendor/libbacktrace/testlib.h +110 -0
- data/vendor/libbacktrace/ttest.c +161 -0
- data/vendor/libbacktrace/unittest.c +92 -0
- data/vendor/libbacktrace/unknown.c +65 -0
- data/vendor/libbacktrace/xcoff.c +1617 -0
- data/vendor/libbacktrace/xztest.c +508 -0
- data/vendor/libbacktrace/zstdtest.c +523 -0
- data/vendor/libbacktrace/ztest.c +541 -0
- metadata +122 -3
@@ -0,0 +1,215 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
# Common wrapper for a few potentially missing GNU programs.
|
3
|
+
|
4
|
+
scriptversion=2013-10-28.13; # UTC
|
5
|
+
|
6
|
+
# Copyright (C) 1996-2014 Free Software Foundation, Inc.
|
7
|
+
# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
|
8
|
+
|
9
|
+
# This program is free software; you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation; either version 2, or (at your option)
|
12
|
+
# any later version.
|
13
|
+
|
14
|
+
# This program is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
|
22
|
+
# As a special exception to the GNU General Public License, if you
|
23
|
+
# distribute this file as part of a program that contains a
|
24
|
+
# configuration script generated by Autoconf, you may include it under
|
25
|
+
# the same distribution terms that you use for the rest of that program.
|
26
|
+
|
27
|
+
if test $# -eq 0; then
|
28
|
+
echo 1>&2 "Try '$0 --help' for more information"
|
29
|
+
exit 1
|
30
|
+
fi
|
31
|
+
|
32
|
+
case $1 in
|
33
|
+
|
34
|
+
--is-lightweight)
|
35
|
+
# Used by our autoconf macros to check whether the available missing
|
36
|
+
# script is modern enough.
|
37
|
+
exit 0
|
38
|
+
;;
|
39
|
+
|
40
|
+
--run)
|
41
|
+
# Back-compat with the calling convention used by older automake.
|
42
|
+
shift
|
43
|
+
;;
|
44
|
+
|
45
|
+
-h|--h|--he|--hel|--help)
|
46
|
+
echo "\
|
47
|
+
$0 [OPTION]... PROGRAM [ARGUMENT]...
|
48
|
+
|
49
|
+
Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
|
50
|
+
to PROGRAM being missing or too old.
|
51
|
+
|
52
|
+
Options:
|
53
|
+
-h, --help display this help and exit
|
54
|
+
-v, --version output version information and exit
|
55
|
+
|
56
|
+
Supported PROGRAM values:
|
57
|
+
aclocal autoconf autoheader autom4te automake makeinfo
|
58
|
+
bison yacc flex lex help2man
|
59
|
+
|
60
|
+
Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
|
61
|
+
'g' are ignored when checking the name.
|
62
|
+
|
63
|
+
Send bug reports to <bug-automake@gnu.org>."
|
64
|
+
exit $?
|
65
|
+
;;
|
66
|
+
|
67
|
+
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
|
68
|
+
echo "missing $scriptversion (GNU Automake)"
|
69
|
+
exit $?
|
70
|
+
;;
|
71
|
+
|
72
|
+
-*)
|
73
|
+
echo 1>&2 "$0: unknown '$1' option"
|
74
|
+
echo 1>&2 "Try '$0 --help' for more information"
|
75
|
+
exit 1
|
76
|
+
;;
|
77
|
+
|
78
|
+
esac
|
79
|
+
|
80
|
+
# Run the given program, remember its exit status.
|
81
|
+
"$@"; st=$?
|
82
|
+
|
83
|
+
# If it succeeded, we are done.
|
84
|
+
test $st -eq 0 && exit 0
|
85
|
+
|
86
|
+
# Also exit now if we it failed (or wasn't found), and '--version' was
|
87
|
+
# passed; such an option is passed most likely to detect whether the
|
88
|
+
# program is present and works.
|
89
|
+
case $2 in --version|--help) exit $st;; esac
|
90
|
+
|
91
|
+
# Exit code 63 means version mismatch. This often happens when the user
|
92
|
+
# tries to use an ancient version of a tool on a file that requires a
|
93
|
+
# minimum version.
|
94
|
+
if test $st -eq 63; then
|
95
|
+
msg="probably too old"
|
96
|
+
elif test $st -eq 127; then
|
97
|
+
# Program was missing.
|
98
|
+
msg="missing on your system"
|
99
|
+
else
|
100
|
+
# Program was found and executed, but failed. Give up.
|
101
|
+
exit $st
|
102
|
+
fi
|
103
|
+
|
104
|
+
perl_URL=http://www.perl.org/
|
105
|
+
flex_URL=http://flex.sourceforge.net/
|
106
|
+
gnu_software_URL=http://www.gnu.org/software
|
107
|
+
|
108
|
+
program_details ()
|
109
|
+
{
|
110
|
+
case $1 in
|
111
|
+
aclocal|automake)
|
112
|
+
echo "The '$1' program is part of the GNU Automake package:"
|
113
|
+
echo "<$gnu_software_URL/automake>"
|
114
|
+
echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
|
115
|
+
echo "<$gnu_software_URL/autoconf>"
|
116
|
+
echo "<$gnu_software_URL/m4/>"
|
117
|
+
echo "<$perl_URL>"
|
118
|
+
;;
|
119
|
+
autoconf|autom4te|autoheader)
|
120
|
+
echo "The '$1' program is part of the GNU Autoconf package:"
|
121
|
+
echo "<$gnu_software_URL/autoconf/>"
|
122
|
+
echo "It also requires GNU m4 and Perl in order to run:"
|
123
|
+
echo "<$gnu_software_URL/m4/>"
|
124
|
+
echo "<$perl_URL>"
|
125
|
+
;;
|
126
|
+
esac
|
127
|
+
}
|
128
|
+
|
129
|
+
give_advice ()
|
130
|
+
{
|
131
|
+
# Normalize program name to check for.
|
132
|
+
normalized_program=`echo "$1" | sed '
|
133
|
+
s/^gnu-//; t
|
134
|
+
s/^gnu//; t
|
135
|
+
s/^g//; t'`
|
136
|
+
|
137
|
+
printf '%s\n' "'$1' is $msg."
|
138
|
+
|
139
|
+
configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
|
140
|
+
case $normalized_program in
|
141
|
+
autoconf*)
|
142
|
+
echo "You should only need it if you modified 'configure.ac',"
|
143
|
+
echo "or m4 files included by it."
|
144
|
+
program_details 'autoconf'
|
145
|
+
;;
|
146
|
+
autoheader*)
|
147
|
+
echo "You should only need it if you modified 'acconfig.h' or"
|
148
|
+
echo "$configure_deps."
|
149
|
+
program_details 'autoheader'
|
150
|
+
;;
|
151
|
+
automake*)
|
152
|
+
echo "You should only need it if you modified 'Makefile.am' or"
|
153
|
+
echo "$configure_deps."
|
154
|
+
program_details 'automake'
|
155
|
+
;;
|
156
|
+
aclocal*)
|
157
|
+
echo "You should only need it if you modified 'acinclude.m4' or"
|
158
|
+
echo "$configure_deps."
|
159
|
+
program_details 'aclocal'
|
160
|
+
;;
|
161
|
+
autom4te*)
|
162
|
+
echo "You might have modified some maintainer files that require"
|
163
|
+
echo "the 'autom4te' program to be rebuilt."
|
164
|
+
program_details 'autom4te'
|
165
|
+
;;
|
166
|
+
bison*|yacc*)
|
167
|
+
echo "You should only need it if you modified a '.y' file."
|
168
|
+
echo "You may want to install the GNU Bison package:"
|
169
|
+
echo "<$gnu_software_URL/bison/>"
|
170
|
+
;;
|
171
|
+
lex*|flex*)
|
172
|
+
echo "You should only need it if you modified a '.l' file."
|
173
|
+
echo "You may want to install the Fast Lexical Analyzer package:"
|
174
|
+
echo "<$flex_URL>"
|
175
|
+
;;
|
176
|
+
help2man*)
|
177
|
+
echo "You should only need it if you modified a dependency" \
|
178
|
+
"of a man page."
|
179
|
+
echo "You may want to install the GNU Help2man package:"
|
180
|
+
echo "<$gnu_software_URL/help2man/>"
|
181
|
+
;;
|
182
|
+
makeinfo*)
|
183
|
+
echo "You should only need it if you modified a '.texi' file, or"
|
184
|
+
echo "any other file indirectly affecting the aspect of the manual."
|
185
|
+
echo "You might want to install the Texinfo package:"
|
186
|
+
echo "<$gnu_software_URL/texinfo/>"
|
187
|
+
echo "The spurious makeinfo call might also be the consequence of"
|
188
|
+
echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
|
189
|
+
echo "want to install GNU make:"
|
190
|
+
echo "<$gnu_software_URL/make/>"
|
191
|
+
;;
|
192
|
+
*)
|
193
|
+
echo "You might have modified some files without having the proper"
|
194
|
+
echo "tools for further handling them. Check the 'README' file, it"
|
195
|
+
echo "often tells you about the needed prerequisites for installing"
|
196
|
+
echo "this package. You may also peek at any GNU archive site, in"
|
197
|
+
echo "case some other package contains this missing '$1' program."
|
198
|
+
;;
|
199
|
+
esac
|
200
|
+
}
|
201
|
+
|
202
|
+
give_advice "$1" | sed -e '1s/^/WARNING: /' \
|
203
|
+
-e '2,$s/^/ /' >&2
|
204
|
+
|
205
|
+
# Propagate the correct exit status (expected to be 127 for a program
|
206
|
+
# not found, 63 for a program that failed due to version mismatch).
|
207
|
+
exit $st
|
208
|
+
|
209
|
+
# Local variables:
|
210
|
+
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
211
|
+
# time-stamp-start: "scriptversion="
|
212
|
+
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
213
|
+
# time-stamp-time-zone: "UTC"
|
214
|
+
# time-stamp-end: "; # UTC"
|
215
|
+
# End:
|
@@ -0,0 +1,331 @@
|
|
1
|
+
/* mmap.c -- Memory allocation with mmap.
|
2
|
+
Copyright (C) 2012-2024 Free Software Foundation, Inc.
|
3
|
+
Written by Ian Lance Taylor, Google.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are
|
7
|
+
met:
|
8
|
+
|
9
|
+
(1) Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in
|
14
|
+
the documentation and/or other materials provided with the
|
15
|
+
distribution.
|
16
|
+
|
17
|
+
(3) The name of the author may not be used to
|
18
|
+
endorse or promote products derived from this software without
|
19
|
+
specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
22
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
23
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
25
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
26
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
28
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
29
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
30
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
POSSIBILITY OF SUCH DAMAGE. */
|
32
|
+
|
33
|
+
#include "config.h"
|
34
|
+
|
35
|
+
#include <errno.h>
|
36
|
+
#include <string.h>
|
37
|
+
#include <stdlib.h>
|
38
|
+
#include <unistd.h>
|
39
|
+
#include <sys/types.h>
|
40
|
+
#include <sys/mman.h>
|
41
|
+
|
42
|
+
#include "backtrace.h"
|
43
|
+
#include "internal.h"
|
44
|
+
|
45
|
+
#ifndef HAVE_DECL_GETPAGESIZE
|
46
|
+
extern int getpagesize (void);
|
47
|
+
#endif
|
48
|
+
|
49
|
+
/* Memory allocation on systems that provide anonymous mmap. This
|
50
|
+
permits the backtrace functions to be invoked from a signal
|
51
|
+
handler, assuming that mmap is async-signal safe. */
|
52
|
+
|
53
|
+
#ifndef MAP_ANONYMOUS
|
54
|
+
#define MAP_ANONYMOUS MAP_ANON
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#ifndef MAP_FAILED
|
58
|
+
#define MAP_FAILED ((void *)-1)
|
59
|
+
#endif
|
60
|
+
|
61
|
+
/* A list of free memory blocks. */
|
62
|
+
|
63
|
+
struct backtrace_freelist_struct
|
64
|
+
{
|
65
|
+
/* Next on list. */
|
66
|
+
struct backtrace_freelist_struct *next;
|
67
|
+
/* Size of this block, including this structure. */
|
68
|
+
size_t size;
|
69
|
+
};
|
70
|
+
|
71
|
+
/* Free memory allocated by backtrace_alloc. */
|
72
|
+
|
73
|
+
static void
|
74
|
+
backtrace_free_locked (struct backtrace_state *state, void *addr, size_t size)
|
75
|
+
{
|
76
|
+
/* Just leak small blocks. We don't have to be perfect. Don't put
|
77
|
+
more than 16 entries on the free list, to avoid wasting time
|
78
|
+
searching when allocating a block. If we have more than 16
|
79
|
+
entries, leak the smallest entry. */
|
80
|
+
|
81
|
+
if (size >= sizeof (struct backtrace_freelist_struct))
|
82
|
+
{
|
83
|
+
size_t c;
|
84
|
+
struct backtrace_freelist_struct **ppsmall;
|
85
|
+
struct backtrace_freelist_struct **pp;
|
86
|
+
struct backtrace_freelist_struct *p;
|
87
|
+
|
88
|
+
c = 0;
|
89
|
+
ppsmall = NULL;
|
90
|
+
for (pp = &state->freelist; *pp != NULL; pp = &(*pp)->next)
|
91
|
+
{
|
92
|
+
if (ppsmall == NULL || (*pp)->size < (*ppsmall)->size)
|
93
|
+
ppsmall = pp;
|
94
|
+
++c;
|
95
|
+
}
|
96
|
+
if (c >= 16)
|
97
|
+
{
|
98
|
+
if (size <= (*ppsmall)->size)
|
99
|
+
return;
|
100
|
+
*ppsmall = (*ppsmall)->next;
|
101
|
+
}
|
102
|
+
|
103
|
+
p = (struct backtrace_freelist_struct *) addr;
|
104
|
+
p->next = state->freelist;
|
105
|
+
p->size = size;
|
106
|
+
state->freelist = p;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
/* Allocate memory like malloc. If ERROR_CALLBACK is NULL, don't
|
111
|
+
report an error. */
|
112
|
+
|
113
|
+
void *
|
114
|
+
backtrace_alloc (struct backtrace_state *state,
|
115
|
+
size_t size, backtrace_error_callback error_callback,
|
116
|
+
void *data)
|
117
|
+
{
|
118
|
+
void *ret;
|
119
|
+
int locked;
|
120
|
+
struct backtrace_freelist_struct **pp;
|
121
|
+
size_t pagesize;
|
122
|
+
size_t asksize;
|
123
|
+
void *page;
|
124
|
+
|
125
|
+
ret = NULL;
|
126
|
+
|
127
|
+
/* If we can acquire the lock, then see if there is space on the
|
128
|
+
free list. If we can't acquire the lock, drop straight into
|
129
|
+
using mmap. __sync_lock_test_and_set returns the old state of
|
130
|
+
the lock, so we have acquired it if it returns 0. */
|
131
|
+
|
132
|
+
if (!state->threaded)
|
133
|
+
locked = 1;
|
134
|
+
else
|
135
|
+
locked = __sync_lock_test_and_set (&state->lock_alloc, 1) == 0;
|
136
|
+
|
137
|
+
if (locked)
|
138
|
+
{
|
139
|
+
for (pp = &state->freelist; *pp != NULL; pp = &(*pp)->next)
|
140
|
+
{
|
141
|
+
if ((*pp)->size >= size)
|
142
|
+
{
|
143
|
+
struct backtrace_freelist_struct *p;
|
144
|
+
|
145
|
+
p = *pp;
|
146
|
+
*pp = p->next;
|
147
|
+
|
148
|
+
/* Round for alignment; we assume that no type we care about
|
149
|
+
is more than 8 bytes. */
|
150
|
+
size = (size + 7) & ~ (size_t) 7;
|
151
|
+
if (size < p->size)
|
152
|
+
backtrace_free_locked (state, (char *) p + size,
|
153
|
+
p->size - size);
|
154
|
+
|
155
|
+
ret = (void *) p;
|
156
|
+
|
157
|
+
break;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
if (state->threaded)
|
162
|
+
__sync_lock_release (&state->lock_alloc);
|
163
|
+
}
|
164
|
+
|
165
|
+
if (ret == NULL)
|
166
|
+
{
|
167
|
+
/* Allocate a new page. */
|
168
|
+
|
169
|
+
pagesize = getpagesize ();
|
170
|
+
asksize = (size + pagesize - 1) & ~ (pagesize - 1);
|
171
|
+
page = mmap (NULL, asksize, PROT_READ | PROT_WRITE,
|
172
|
+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
173
|
+
if (page == MAP_FAILED)
|
174
|
+
{
|
175
|
+
if (error_callback)
|
176
|
+
error_callback (data, "mmap", errno);
|
177
|
+
}
|
178
|
+
else
|
179
|
+
{
|
180
|
+
size = (size + 7) & ~ (size_t) 7;
|
181
|
+
if (size < asksize)
|
182
|
+
backtrace_free (state, (char *) page + size, asksize - size,
|
183
|
+
error_callback, data);
|
184
|
+
|
185
|
+
ret = page;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
return ret;
|
190
|
+
}
|
191
|
+
|
192
|
+
/* Free memory allocated by backtrace_alloc. */
|
193
|
+
|
194
|
+
void
|
195
|
+
backtrace_free (struct backtrace_state *state, void *addr, size_t size,
|
196
|
+
backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
|
197
|
+
void *data ATTRIBUTE_UNUSED)
|
198
|
+
{
|
199
|
+
int locked;
|
200
|
+
|
201
|
+
/* If we are freeing a large aligned block, just release it back to
|
202
|
+
the system. This case arises when growing a vector for a large
|
203
|
+
binary with lots of debug info. Calling munmap here may cause us
|
204
|
+
to call mmap again if there is also a large shared library; we
|
205
|
+
just live with that. */
|
206
|
+
if (size >= 16 * 4096)
|
207
|
+
{
|
208
|
+
size_t pagesize;
|
209
|
+
|
210
|
+
pagesize = getpagesize ();
|
211
|
+
if (((uintptr_t) addr & (pagesize - 1)) == 0
|
212
|
+
&& (size & (pagesize - 1)) == 0)
|
213
|
+
{
|
214
|
+
/* If munmap fails for some reason, just add the block to
|
215
|
+
the freelist. */
|
216
|
+
if (munmap (addr, size) == 0)
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
/* If we can acquire the lock, add the new space to the free list.
|
222
|
+
If we can't acquire the lock, just leak the memory.
|
223
|
+
__sync_lock_test_and_set returns the old state of the lock, so we
|
224
|
+
have acquired it if it returns 0. */
|
225
|
+
|
226
|
+
if (!state->threaded)
|
227
|
+
locked = 1;
|
228
|
+
else
|
229
|
+
locked = __sync_lock_test_and_set (&state->lock_alloc, 1) == 0;
|
230
|
+
|
231
|
+
if (locked)
|
232
|
+
{
|
233
|
+
backtrace_free_locked (state, addr, size);
|
234
|
+
|
235
|
+
if (state->threaded)
|
236
|
+
__sync_lock_release (&state->lock_alloc);
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
/* Grow VEC by SIZE bytes. */
|
241
|
+
|
242
|
+
void *
|
243
|
+
backtrace_vector_grow (struct backtrace_state *state,size_t size,
|
244
|
+
backtrace_error_callback error_callback,
|
245
|
+
void *data, struct backtrace_vector *vec)
|
246
|
+
{
|
247
|
+
void *ret;
|
248
|
+
|
249
|
+
if (size > vec->alc)
|
250
|
+
{
|
251
|
+
size_t pagesize;
|
252
|
+
size_t alc;
|
253
|
+
void *base;
|
254
|
+
|
255
|
+
pagesize = getpagesize ();
|
256
|
+
alc = vec->size + size;
|
257
|
+
if (vec->size == 0)
|
258
|
+
alc = 16 * size;
|
259
|
+
else if (alc < pagesize)
|
260
|
+
{
|
261
|
+
alc *= 2;
|
262
|
+
if (alc > pagesize)
|
263
|
+
alc = pagesize;
|
264
|
+
}
|
265
|
+
else
|
266
|
+
{
|
267
|
+
alc *= 2;
|
268
|
+
alc = (alc + pagesize - 1) & ~ (pagesize - 1);
|
269
|
+
}
|
270
|
+
base = backtrace_alloc (state, alc, error_callback, data);
|
271
|
+
if (base == NULL)
|
272
|
+
return NULL;
|
273
|
+
if (vec->base != NULL)
|
274
|
+
{
|
275
|
+
memcpy (base, vec->base, vec->size);
|
276
|
+
backtrace_free (state, vec->base, vec->size + vec->alc,
|
277
|
+
error_callback, data);
|
278
|
+
}
|
279
|
+
vec->base = base;
|
280
|
+
vec->alc = alc - vec->size;
|
281
|
+
}
|
282
|
+
|
283
|
+
ret = (char *) vec->base + vec->size;
|
284
|
+
vec->size += size;
|
285
|
+
vec->alc -= size;
|
286
|
+
return ret;
|
287
|
+
}
|
288
|
+
|
289
|
+
/* Finish the current allocation on VEC. */
|
290
|
+
|
291
|
+
void *
|
292
|
+
backtrace_vector_finish (
|
293
|
+
struct backtrace_state *state ATTRIBUTE_UNUSED,
|
294
|
+
struct backtrace_vector *vec,
|
295
|
+
backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
|
296
|
+
void *data ATTRIBUTE_UNUSED)
|
297
|
+
{
|
298
|
+
void *ret;
|
299
|
+
|
300
|
+
ret = vec->base;
|
301
|
+
vec->base = (char *) vec->base + vec->size;
|
302
|
+
vec->size = 0;
|
303
|
+
return ret;
|
304
|
+
}
|
305
|
+
|
306
|
+
/* Release any extra space allocated for VEC. */
|
307
|
+
|
308
|
+
int
|
309
|
+
backtrace_vector_release (struct backtrace_state *state,
|
310
|
+
struct backtrace_vector *vec,
|
311
|
+
backtrace_error_callback error_callback,
|
312
|
+
void *data)
|
313
|
+
{
|
314
|
+
size_t size;
|
315
|
+
size_t alc;
|
316
|
+
size_t aligned;
|
317
|
+
|
318
|
+
/* Make sure that the block that we free is aligned on an 8-byte
|
319
|
+
boundary. */
|
320
|
+
size = vec->size;
|
321
|
+
alc = vec->alc;
|
322
|
+
aligned = (size + 7) & ~ (size_t) 7;
|
323
|
+
alc -= aligned - size;
|
324
|
+
|
325
|
+
backtrace_free (state, (char *) vec->base + aligned, alc,
|
326
|
+
error_callback, data);
|
327
|
+
vec->alc = 0;
|
328
|
+
if (vec->size == 0)
|
329
|
+
vec->base = NULL;
|
330
|
+
return 1;
|
331
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
/* mmapio.c -- File views using mmap.
|
2
|
+
Copyright (C) 2012-2024 Free Software Foundation, Inc.
|
3
|
+
Written by Ian Lance Taylor, Google.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are
|
7
|
+
met:
|
8
|
+
|
9
|
+
(1) Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in
|
14
|
+
the documentation and/or other materials provided with the
|
15
|
+
distribution.
|
16
|
+
|
17
|
+
(3) The name of the author may not be used to
|
18
|
+
endorse or promote products derived from this software without
|
19
|
+
specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
22
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
23
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
25
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
26
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
28
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
29
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
30
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
POSSIBILITY OF SUCH DAMAGE. */
|
32
|
+
|
33
|
+
#include "config.h"
|
34
|
+
|
35
|
+
#include <errno.h>
|
36
|
+
#include <sys/types.h>
|
37
|
+
#include <sys/mman.h>
|
38
|
+
#include <unistd.h>
|
39
|
+
|
40
|
+
#include "backtrace.h"
|
41
|
+
#include "internal.h"
|
42
|
+
|
43
|
+
#ifndef HAVE_DECL_GETPAGESIZE
|
44
|
+
extern int getpagesize (void);
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#ifndef MAP_FAILED
|
48
|
+
#define MAP_FAILED ((void *)-1)
|
49
|
+
#endif
|
50
|
+
|
51
|
+
/* This file implements file views and memory allocation when mmap is
|
52
|
+
available. */
|
53
|
+
|
54
|
+
/* Create a view of SIZE bytes from DESCRIPTOR at OFFSET. */
|
55
|
+
|
56
|
+
int
|
57
|
+
backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
|
58
|
+
int descriptor, off_t offset, uint64_t size,
|
59
|
+
backtrace_error_callback error_callback,
|
60
|
+
void *data, struct backtrace_view *view)
|
61
|
+
{
|
62
|
+
size_t pagesize;
|
63
|
+
unsigned int inpage;
|
64
|
+
off_t pageoff;
|
65
|
+
void *map;
|
66
|
+
|
67
|
+
if ((uint64_t) (size_t) size != size)
|
68
|
+
{
|
69
|
+
error_callback (data, "file size too large", 0);
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
|
73
|
+
pagesize = getpagesize ();
|
74
|
+
inpage = offset % pagesize;
|
75
|
+
pageoff = offset - inpage;
|
76
|
+
|
77
|
+
size += inpage;
|
78
|
+
size = (size + (pagesize - 1)) & ~ (pagesize - 1);
|
79
|
+
|
80
|
+
map = mmap (NULL, size, PROT_READ, MAP_PRIVATE, descriptor, pageoff);
|
81
|
+
if (map == MAP_FAILED)
|
82
|
+
{
|
83
|
+
error_callback (data, "mmap", errno);
|
84
|
+
return 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
view->data = (char *) map + inpage;
|
88
|
+
view->base = map;
|
89
|
+
view->len = size;
|
90
|
+
|
91
|
+
return 1;
|
92
|
+
}
|
93
|
+
|
94
|
+
/* Release a view read by backtrace_get_view. */
|
95
|
+
|
96
|
+
void
|
97
|
+
backtrace_release_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
|
98
|
+
struct backtrace_view *view,
|
99
|
+
backtrace_error_callback error_callback,
|
100
|
+
void *data)
|
101
|
+
{
|
102
|
+
union {
|
103
|
+
const void *cv;
|
104
|
+
void *v;
|
105
|
+
} const_cast;
|
106
|
+
|
107
|
+
const_cast.cv = view->base;
|
108
|
+
if (munmap (const_cast.v, view->len) < 0)
|
109
|
+
error_callback (data, "munmap", errno);
|
110
|
+
}
|