pf2 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -2
  3. data/Cargo.lock +650 -0
  4. data/Cargo.toml +3 -0
  5. data/README.md +110 -13
  6. data/Rakefile +8 -0
  7. data/crates/backtrace-sys2/.gitignore +1 -0
  8. data/crates/backtrace-sys2/Cargo.toml +9 -0
  9. data/crates/backtrace-sys2/build.rs +48 -0
  10. data/crates/backtrace-sys2/src/lib.rs +5 -0
  11. data/crates/backtrace-sys2/src/libbacktrace/.gitignore +15 -0
  12. data/crates/backtrace-sys2/src/libbacktrace/Isaac.Newton-Opticks.txt +9286 -0
  13. data/crates/backtrace-sys2/src/libbacktrace/LICENSE +29 -0
  14. data/crates/backtrace-sys2/src/libbacktrace/Makefile.am +623 -0
  15. data/crates/backtrace-sys2/src/libbacktrace/Makefile.in +2666 -0
  16. data/crates/backtrace-sys2/src/libbacktrace/README.md +36 -0
  17. data/crates/backtrace-sys2/src/libbacktrace/aclocal.m4 +864 -0
  18. data/crates/backtrace-sys2/src/libbacktrace/alloc.c +167 -0
  19. data/crates/backtrace-sys2/src/libbacktrace/allocfail.c +136 -0
  20. data/crates/backtrace-sys2/src/libbacktrace/allocfail.sh +104 -0
  21. data/crates/backtrace-sys2/src/libbacktrace/atomic.c +113 -0
  22. data/crates/backtrace-sys2/src/libbacktrace/backtrace-supported.h.in +66 -0
  23. data/crates/backtrace-sys2/src/libbacktrace/backtrace.c +129 -0
  24. data/crates/backtrace-sys2/src/libbacktrace/backtrace.h +189 -0
  25. data/crates/backtrace-sys2/src/libbacktrace/btest.c +501 -0
  26. data/crates/backtrace-sys2/src/libbacktrace/compile +348 -0
  27. data/crates/backtrace-sys2/src/libbacktrace/config/enable.m4 +38 -0
  28. data/crates/backtrace-sys2/src/libbacktrace/config/lead-dot.m4 +31 -0
  29. data/crates/backtrace-sys2/src/libbacktrace/config/libtool.m4 +7436 -0
  30. data/crates/backtrace-sys2/src/libbacktrace/config/ltoptions.m4 +369 -0
  31. data/crates/backtrace-sys2/src/libbacktrace/config/ltsugar.m4 +123 -0
  32. data/crates/backtrace-sys2/src/libbacktrace/config/ltversion.m4 +23 -0
  33. data/crates/backtrace-sys2/src/libbacktrace/config/lt~obsolete.m4 +98 -0
  34. data/crates/backtrace-sys2/src/libbacktrace/config/multi.m4 +68 -0
  35. data/crates/backtrace-sys2/src/libbacktrace/config/override.m4 +117 -0
  36. data/crates/backtrace-sys2/src/libbacktrace/config/unwind_ipinfo.m4 +37 -0
  37. data/crates/backtrace-sys2/src/libbacktrace/config/warnings.m4 +227 -0
  38. data/crates/backtrace-sys2/src/libbacktrace/config.guess +1700 -0
  39. data/crates/backtrace-sys2/src/libbacktrace/config.h.in +182 -0
  40. data/crates/backtrace-sys2/src/libbacktrace/config.sub +1885 -0
  41. data/crates/backtrace-sys2/src/libbacktrace/configure +15740 -0
  42. data/crates/backtrace-sys2/src/libbacktrace/configure.ac +613 -0
  43. data/crates/backtrace-sys2/src/libbacktrace/dwarf.c +4402 -0
  44. data/crates/backtrace-sys2/src/libbacktrace/edtest.c +120 -0
  45. data/crates/backtrace-sys2/src/libbacktrace/edtest2.c +43 -0
  46. data/crates/backtrace-sys2/src/libbacktrace/elf.c +7443 -0
  47. data/crates/backtrace-sys2/src/libbacktrace/fileline.c +407 -0
  48. data/crates/backtrace-sys2/src/libbacktrace/filenames.h +52 -0
  49. data/crates/backtrace-sys2/src/libbacktrace/filetype.awk +13 -0
  50. data/crates/backtrace-sys2/src/libbacktrace/install-debuginfo-for-buildid.sh.in +65 -0
  51. data/crates/backtrace-sys2/src/libbacktrace/install-sh +501 -0
  52. data/crates/backtrace-sys2/src/libbacktrace/instrumented_alloc.c +114 -0
  53. data/crates/backtrace-sys2/src/libbacktrace/internal.h +389 -0
  54. data/crates/backtrace-sys2/src/libbacktrace/libtool.m4 +7436 -0
  55. data/crates/backtrace-sys2/src/libbacktrace/ltmain.sh +8636 -0
  56. data/crates/backtrace-sys2/src/libbacktrace/ltoptions.m4 +369 -0
  57. data/crates/backtrace-sys2/src/libbacktrace/ltsugar.m4 +123 -0
  58. data/crates/backtrace-sys2/src/libbacktrace/ltversion.m4 +23 -0
  59. data/crates/backtrace-sys2/src/libbacktrace/lt~obsolete.m4 +98 -0
  60. data/crates/backtrace-sys2/src/libbacktrace/macho.c +1355 -0
  61. data/crates/backtrace-sys2/src/libbacktrace/missing +215 -0
  62. data/crates/backtrace-sys2/src/libbacktrace/mmap.c +331 -0
  63. data/crates/backtrace-sys2/src/libbacktrace/mmapio.c +110 -0
  64. data/crates/backtrace-sys2/src/libbacktrace/move-if-change +83 -0
  65. data/crates/backtrace-sys2/src/libbacktrace/mtest.c +410 -0
  66. data/crates/backtrace-sys2/src/libbacktrace/nounwind.c +66 -0
  67. data/crates/backtrace-sys2/src/libbacktrace/pecoff.c +957 -0
  68. data/crates/backtrace-sys2/src/libbacktrace/posix.c +104 -0
  69. data/crates/backtrace-sys2/src/libbacktrace/print.c +92 -0
  70. data/crates/backtrace-sys2/src/libbacktrace/read.c +110 -0
  71. data/crates/backtrace-sys2/src/libbacktrace/simple.c +108 -0
  72. data/crates/backtrace-sys2/src/libbacktrace/sort.c +108 -0
  73. data/crates/backtrace-sys2/src/libbacktrace/state.c +72 -0
  74. data/crates/backtrace-sys2/src/libbacktrace/stest.c +137 -0
  75. data/crates/backtrace-sys2/src/libbacktrace/test-driver +148 -0
  76. data/crates/backtrace-sys2/src/libbacktrace/test_format.c +55 -0
  77. data/crates/backtrace-sys2/src/libbacktrace/testlib.c +234 -0
  78. data/crates/backtrace-sys2/src/libbacktrace/testlib.h +110 -0
  79. data/crates/backtrace-sys2/src/libbacktrace/ttest.c +161 -0
  80. data/crates/backtrace-sys2/src/libbacktrace/unittest.c +92 -0
  81. data/crates/backtrace-sys2/src/libbacktrace/unknown.c +65 -0
  82. data/crates/backtrace-sys2/src/libbacktrace/xcoff.c +1606 -0
  83. data/crates/backtrace-sys2/src/libbacktrace/xztest.c +508 -0
  84. data/crates/backtrace-sys2/src/libbacktrace/zstdtest.c +523 -0
  85. data/crates/backtrace-sys2/src/libbacktrace/ztest.c +541 -0
  86. data/ext/pf2/Cargo.toml +25 -0
  87. data/ext/pf2/build.rs +3 -0
  88. data/ext/pf2/extconf.rb +6 -1
  89. data/ext/pf2/src/backtrace.rs +126 -0
  90. data/ext/pf2/src/lib.rs +15 -0
  91. data/ext/pf2/src/profile.rs +65 -0
  92. data/ext/pf2/src/profile_serializer.rs +204 -0
  93. data/ext/pf2/src/ringbuffer.rs +152 -0
  94. data/ext/pf2/src/ruby_init.rs +74 -0
  95. data/ext/pf2/src/sample.rs +66 -0
  96. data/ext/pf2/src/siginfo_t.c +5 -0
  97. data/ext/pf2/src/signal_scheduler/configuration.rs +31 -0
  98. data/ext/pf2/src/signal_scheduler/timer_installer.rs +199 -0
  99. data/ext/pf2/src/signal_scheduler.rs +311 -0
  100. data/ext/pf2/src/timer_thread_scheduler.rs +319 -0
  101. data/ext/pf2/src/util.rs +30 -0
  102. data/lib/pf2/cli.rb +1 -1
  103. data/lib/pf2/reporter.rb +48 -16
  104. data/lib/pf2/version.rb +1 -1
  105. data/lib/pf2.rb +20 -5
  106. metadata +128 -5
  107. data/ext/pf2/pf2.c +0 -246
@@ -0,0 +1,167 @@
1
+ /* alloc.c -- Memory allocation without mmap.
2
+ Copyright (C) 2012-2021 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 <stdlib.h>
37
+ #include <sys/types.h>
38
+
39
+ #include "backtrace.h"
40
+ #include "internal.h"
41
+
42
+ /* Allocation routines to use on systems that do not support anonymous
43
+ mmap. This implementation just uses malloc, which means that the
44
+ backtrace functions may not be safely invoked from a signal
45
+ handler. */
46
+
47
+ /* Allocate memory like malloc. If ERROR_CALLBACK is NULL, don't
48
+ report an error. */
49
+
50
+ void *
51
+ backtrace_alloc (struct backtrace_state *state ATTRIBUTE_UNUSED,
52
+ size_t size, backtrace_error_callback error_callback,
53
+ void *data)
54
+ {
55
+ void *ret;
56
+
57
+ ret = malloc (size);
58
+ if (ret == NULL)
59
+ {
60
+ if (error_callback)
61
+ error_callback (data, "malloc", errno);
62
+ }
63
+ return ret;
64
+ }
65
+
66
+ /* Free memory. */
67
+
68
+ void
69
+ backtrace_free (struct backtrace_state *state ATTRIBUTE_UNUSED,
70
+ void *p, size_t size ATTRIBUTE_UNUSED,
71
+ backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
72
+ void *data ATTRIBUTE_UNUSED)
73
+ {
74
+ free (p);
75
+ }
76
+
77
+ /* Grow VEC by SIZE bytes. */
78
+
79
+ void *
80
+ backtrace_vector_grow (struct backtrace_state *state ATTRIBUTE_UNUSED,
81
+ size_t size, backtrace_error_callback error_callback,
82
+ void *data, struct backtrace_vector *vec)
83
+ {
84
+ void *ret;
85
+
86
+ if (size > vec->alc)
87
+ {
88
+ size_t alc;
89
+ void *base;
90
+
91
+ if (vec->size == 0)
92
+ alc = 32 * size;
93
+ else if (vec->size >= 4096)
94
+ alc = vec->size + 4096;
95
+ else
96
+ alc = 2 * vec->size;
97
+
98
+ if (alc < vec->size + size)
99
+ alc = vec->size + size;
100
+
101
+ base = realloc (vec->base, alc);
102
+ if (base == NULL)
103
+ {
104
+ error_callback (data, "realloc", errno);
105
+ return NULL;
106
+ }
107
+
108
+ vec->base = base;
109
+ vec->alc = alc - vec->size;
110
+ }
111
+
112
+ ret = (char *) vec->base + vec->size;
113
+ vec->size += size;
114
+ vec->alc -= size;
115
+ return ret;
116
+ }
117
+
118
+ /* Finish the current allocation on VEC. */
119
+
120
+ void *
121
+ backtrace_vector_finish (struct backtrace_state *state,
122
+ struct backtrace_vector *vec,
123
+ backtrace_error_callback error_callback,
124
+ void *data)
125
+ {
126
+ void *ret;
127
+
128
+ /* With this allocator we call realloc in backtrace_vector_grow,
129
+ which means we can't easily reuse the memory here. So just
130
+ release it. */
131
+ if (!backtrace_vector_release (state, vec, error_callback, data))
132
+ return NULL;
133
+ ret = vec->base;
134
+ vec->base = NULL;
135
+ vec->size = 0;
136
+ vec->alc = 0;
137
+ return ret;
138
+ }
139
+
140
+ /* Release any extra space allocated for VEC. */
141
+
142
+ int
143
+ backtrace_vector_release (struct backtrace_state *state ATTRIBUTE_UNUSED,
144
+ struct backtrace_vector *vec,
145
+ backtrace_error_callback error_callback,
146
+ void *data)
147
+ {
148
+ vec->alc = 0;
149
+
150
+ if (vec->size == 0)
151
+ {
152
+ /* As of C17, realloc with size 0 is marked as an obsolescent feature, use
153
+ free instead. */
154
+ free (vec->base);
155
+ vec->base = NULL;
156
+ return 1;
157
+ }
158
+
159
+ vec->base = realloc (vec->base, vec->size);
160
+ if (vec->base == NULL)
161
+ {
162
+ error_callback (data, "realloc", errno);
163
+ return 0;
164
+ }
165
+
166
+ return 1;
167
+ }
@@ -0,0 +1,136 @@
1
+ /* allocfail.c -- Test for libbacktrace library
2
+ Copyright (C) 2018-2021 Free Software Foundation, Inc.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ (1) Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ (2) Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in
13
+ the documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ (3) The name of the author may not be used to
17
+ endorse or promote products derived from this software without
18
+ specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ POSSIBILITY OF SUCH DAMAGE. */
31
+
32
+ #include <assert.h>
33
+ #include <stdio.h>
34
+ #include <stdlib.h>
35
+ #include <string.h>
36
+ #include <unistd.h>
37
+
38
+ #include "filenames.h"
39
+
40
+ #include "backtrace.h"
41
+ #include "backtrace-supported.h"
42
+
43
+ #include "testlib.h"
44
+
45
+ extern uint64_t get_nr_allocs (void);
46
+ extern void set_fail_at_alloc (uint64_t);
47
+ extern int at_fail_alloc_p (void);
48
+
49
+ static int test1 (void) __attribute__ ((noinline, unused));
50
+ static int f2 (int) __attribute__ ((noinline));
51
+ static int f3 (int, int) __attribute__ ((noinline));
52
+
53
+ static unsigned callback_errors = 0;
54
+
55
+ static void
56
+ error_callback_full (void *vdata ATTRIBUTE_UNUSED,
57
+ const char *msg ATTRIBUTE_UNUSED,
58
+ int errnum ATTRIBUTE_UNUSED)
59
+ {
60
+ if (at_fail_alloc_p ())
61
+ {
62
+ set_fail_at_alloc (0);
63
+ return;
64
+ }
65
+
66
+ callback_errors++;
67
+ }
68
+
69
+ static int
70
+ callback_full (void *vdata ATTRIBUTE_UNUSED, uintptr_t pc ATTRIBUTE_UNUSED,
71
+ const char *filename ATTRIBUTE_UNUSED,
72
+ int lineno ATTRIBUTE_UNUSED,
73
+ const char *function ATTRIBUTE_UNUSED)
74
+ {
75
+
76
+ return 0;
77
+ }
78
+
79
+ static int
80
+ test1 (void)
81
+ {
82
+ return f2 (__LINE__) + 1;
83
+ }
84
+
85
+ static int
86
+ f2 (int f1line)
87
+ {
88
+ return f3 (f1line, __LINE__) + 2;
89
+ }
90
+
91
+ static int
92
+ f3 (int f1line ATTRIBUTE_UNUSED, int f2line ATTRIBUTE_UNUSED)
93
+ {
94
+ int i;
95
+
96
+ i = backtrace_full (state, 0, callback_full, error_callback_full, NULL);
97
+
98
+ if (i != 0)
99
+ {
100
+ fprintf (stderr, "test1: unexpected return value %d\n", i);
101
+ ++failures;
102
+ }
103
+
104
+ if (callback_errors)
105
+ ++failures;
106
+
107
+ return failures;
108
+ }
109
+
110
+ /* Run all the tests. */
111
+
112
+ int
113
+ main (int argc, char **argv)
114
+ {
115
+ uint64_t fail_at = 0;
116
+
117
+ if (argc == 2)
118
+ {
119
+ fail_at = atoi (argv[1]);
120
+ set_fail_at_alloc (fail_at);
121
+ }
122
+
123
+ state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
124
+ error_callback_full, NULL);
125
+ if (state == NULL)
126
+ exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
127
+
128
+ #if BACKTRACE_SUPPORTED
129
+ test1 ();
130
+ #endif
131
+
132
+ if (argc == 1)
133
+ fprintf (stderr, "%llu\n", (long long unsigned) get_nr_allocs ());
134
+
135
+ exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
136
+ }
@@ -0,0 +1,104 @@
1
+ #!/bin/sh
2
+
3
+ # allocfail.sh -- Test for libbacktrace library.
4
+ # Copyright (C) 2018-2021 Free Software Foundation, Inc.
5
+
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are
8
+ # met:
9
+
10
+ # (1) Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+
13
+ # (2) Redistributions in binary form must reproduce the above copyright
14
+ # notice, this list of conditions and the following disclaimer in
15
+ # the documentation and/or other materials provided with the
16
+ # distribution.
17
+
18
+ # (3) The name of the author may not be used to
19
+ # endorse or promote products derived from this software without
20
+ # specific prior written permission.
21
+
22
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23
+ # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+
34
+ set -e
35
+
36
+ if [ ! -f ./allocfail ]; then
37
+ # Hard failure.
38
+ exit 99
39
+ fi
40
+
41
+ allocs=$(./allocfail 2>&1)
42
+ if [ "$allocs" = "" ]; then
43
+ # Hard failure.
44
+ exit 99
45
+ fi
46
+
47
+ # This generates the following output:
48
+ # ...
49
+ # $ allocfail.sh
50
+ # allocs: 80495
51
+ # Status changed to 0 at 1
52
+ # Status changed to 1 at 3
53
+ # Status changed to 0 at 11
54
+ # Status changed to 1 at 12
55
+ # Status changed to 0 at 845
56
+ # ...
57
+ #
58
+ # We have status 0 for an allocation failure at:
59
+ # - 1 because backtrace_create_state handles failure robustly
60
+ # - 2 because the fail switches backtrace_full to !can_alloc mode.
61
+ # - 11 because failure of elf_open_debugfile_by_buildid does not generate an
62
+ # error callback beyond the one for the allocation failure itself.
63
+
64
+ echo "allocs: $allocs"
65
+
66
+ step=1
67
+ i=1
68
+ passes=0
69
+ prev_status=-1
70
+ while [ $i -le $allocs ]; do
71
+ if ./allocfail $i >/dev/null 2>&1; status=$?; then
72
+ true
73
+ fi
74
+ if [ $status -gt 1 ]; then
75
+ echo "Unallowed fail found: $i"
76
+ # Failure.
77
+ exit 1
78
+ fi
79
+
80
+ # The test-case would run too long if we would excercise all allocs.
81
+ # So, run with step 1 initially, and increase the step once we have 10
82
+ # subsequent passes, and drop back to step 1 once we encounter another
83
+ # failure. This takes ~2.6 seconds on an i7-6600U CPU @ 2.60GHz.
84
+ if [ $status -eq 0 ]; then
85
+ passes=$(($passes + 1))
86
+ if [ $passes -ge 10 ]; then
87
+ step=$((step * 10))
88
+ passes=0
89
+ fi
90
+ elif [ $status -eq 1 ]; then
91
+ passes=0
92
+ step=1
93
+ fi
94
+
95
+ if [ $status -ne $prev_status ]; then
96
+ echo "Status changed to $status at $i"
97
+ fi
98
+ prev_status=$status
99
+
100
+ i=$(($i + $step))
101
+ done
102
+
103
+ # Success.
104
+ exit 0
@@ -0,0 +1,113 @@
1
+ /* atomic.c -- Support for atomic functions if not present.
2
+ Copyright (C) 2013-2021 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 <sys/types.h>
36
+
37
+ #include "backtrace.h"
38
+ #include "backtrace-supported.h"
39
+ #include "internal.h"
40
+
41
+ /* This file holds implementations of the atomic functions that are
42
+ used if the host compiler has the sync functions but not the atomic
43
+ functions, as is true of versions of GCC before 4.7. */
44
+
45
+ #if !defined (HAVE_ATOMIC_FUNCTIONS) && defined (HAVE_SYNC_FUNCTIONS)
46
+
47
+ /* Do an atomic load of a pointer. */
48
+
49
+ void *
50
+ backtrace_atomic_load_pointer (void *arg)
51
+ {
52
+ void **pp;
53
+ void *p;
54
+
55
+ pp = (void **) arg;
56
+ p = *pp;
57
+ while (!__sync_bool_compare_and_swap (pp, p, p))
58
+ p = *pp;
59
+ return p;
60
+ }
61
+
62
+ /* Do an atomic load of an int. */
63
+
64
+ int
65
+ backtrace_atomic_load_int (int *p)
66
+ {
67
+ int i;
68
+
69
+ i = *p;
70
+ while (!__sync_bool_compare_and_swap (p, i, i))
71
+ i = *p;
72
+ return i;
73
+ }
74
+
75
+ /* Do an atomic store of a pointer. */
76
+
77
+ void
78
+ backtrace_atomic_store_pointer (void *arg, void *p)
79
+ {
80
+ void **pp;
81
+ void *old;
82
+
83
+ pp = (void **) arg;
84
+ old = *pp;
85
+ while (!__sync_bool_compare_and_swap (pp, old, p))
86
+ old = *pp;
87
+ }
88
+
89
+ /* Do an atomic store of a size_t value. */
90
+
91
+ void
92
+ backtrace_atomic_store_size_t (size_t *p, size_t v)
93
+ {
94
+ size_t old;
95
+
96
+ old = *p;
97
+ while (!__sync_bool_compare_and_swap (p, old, v))
98
+ old = *p;
99
+ }
100
+
101
+ /* Do an atomic store of a int value. */
102
+
103
+ void
104
+ backtrace_atomic_store_int (int *p, int v)
105
+ {
106
+ size_t old;
107
+
108
+ old = *p;
109
+ while (!__sync_bool_compare_and_swap (p, old, v))
110
+ old = *p;
111
+ }
112
+
113
+ #endif
@@ -0,0 +1,66 @@
1
+ /* backtrace-supported.h.in -- Whether stack backtrace is supported.
2
+ Copyright (C) 2012-2021 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
+ /* The file backtrace-supported.h.in is used by configure to generate
34
+ the file backtrace-supported.h. The file backtrace-supported.h may
35
+ be #include'd to see whether the backtrace library will be able to
36
+ get a backtrace and produce symbolic information. */
37
+
38
+
39
+ /* BACKTRACE_SUPPORTED will be #define'd as 1 if the backtrace library
40
+ should work, 0 if it will not. Libraries may #include this to make
41
+ other arrangements. */
42
+
43
+ #define BACKTRACE_SUPPORTED @BACKTRACE_SUPPORTED@
44
+
45
+ /* BACKTRACE_USES_MALLOC will be #define'd as 1 if the backtrace
46
+ library will call malloc as it works, 0 if it will call mmap
47
+ instead. This may be used to determine whether it is safe to call
48
+ the backtrace functions from a signal handler. In general this
49
+ only applies to calls like backtrace and backtrace_pcinfo. It does
50
+ not apply to backtrace_simple, which never calls malloc. It does
51
+ not apply to backtrace_print, which always calls fprintf and
52
+ therefore malloc. */
53
+
54
+ #define BACKTRACE_USES_MALLOC @BACKTRACE_USES_MALLOC@
55
+
56
+ /* BACKTRACE_SUPPORTS_THREADS will be #define'd as 1 if the backtrace
57
+ library is configured with threading support, 0 if not. If this is
58
+ 0, the threaded parameter to backtrace_create_state must be passed
59
+ as 0. */
60
+
61
+ #define BACKTRACE_SUPPORTS_THREADS @BACKTRACE_SUPPORTS_THREADS@
62
+
63
+ /* BACKTRACE_SUPPORTS_DATA will be #defined'd as 1 if the backtrace_syminfo
64
+ will work for variables. It will always work for functions. */
65
+
66
+ #define BACKTRACE_SUPPORTS_DATA @BACKTRACE_SUPPORTS_DATA@