Skip to content

Commit 88c5b58

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents a63fd59 + d3d32f4 commit 88c5b58

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#include "sanitizer_common/sanitizer_atomic.h"
22

3-
#include <stdlib.h>
43
#include <stdint.h>
4+
#include <stdlib.h>
55
#include <string.h>
66
#include <unistd.h>
77

88
#ifdef KERNEL_USE
99
extern "C" void ubsan_message(const char *msg);
1010
static void message(const char *msg) { ubsan_message(msg); }
1111
#else
12-
static void message(const char *msg) {
13-
(void)write(2, msg, strlen(msg));
14-
}
12+
static void message(const char *msg) { (void)write(2, msg, strlen(msg)); }
1513
#endif
1614

1715
static const int kMaxCallerPcs = 20;
@@ -62,16 +60,18 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
6260
uintptr_t p;
6361
for (unsigned i = 0; i < sz; ++i) {
6462
p = __sanitizer::atomic_load_relaxed(&caller_pcs[i]);
65-
if (p == 0) break; // Concurrent update.
63+
if (p == 0)
64+
break; // Concurrent update.
6665
if (p == caller)
6766
return;
6867
}
69-
if (p == 0) continue; // FIXME: yield?
68+
if (p == 0)
69+
continue; // FIXME: yield?
7070
}
7171

7272
if (!__sanitizer::atomic_compare_exchange_strong(
7373
&caller_pcs_sz, &sz, sz + 1, __sanitizer::memory_order_seq_cst))
74-
continue; // Concurrent update! Try again from the start.
74+
continue; // Concurrent update! Try again from the start.
7575

7676
if (sz == kMaxCallerPcs) {
7777
message("ubsan: too many errors\n");
@@ -85,6 +85,12 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
8585
}
8686
}
8787

88+
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error_fatal, const char *kind,
89+
uintptr_t caller) {
90+
// Use another handlers, in case it's already overriden.
91+
__ubsan_report_error(kind, caller);
92+
}
93+
8894
#if defined(__ANDROID__)
8995
extern "C" __attribute__((weak)) void android_set_abort_message(const char *);
9096
static void abort_with_message(const char *kind, uintptr_t caller) {
@@ -121,7 +127,7 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
121127
#define HANDLER_NORECOVER(name, kind) \
122128
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
123129
uintptr_t caller = GET_CALLER_PC(); \
124-
__ubsan_report_error(kind, caller); \
130+
__ubsan_report_error_fatal(kind, caller); \
125131
abort_with_message(kind, caller); \
126132
}
127133

compiler-rt/test/ubsan_minimal/TestCases/override-callback.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | FileCheck %s
1+
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 2>&1 | FileCheck %s
2+
// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=all %s -o %t && not --crash %run %t 2>&1 | FileCheck %s --check-prefixes=FATAL
3+
24
#include <stdint.h>
35
#include <stdio.h>
46
#include <stdlib.h>
@@ -9,7 +11,12 @@ void __ubsan_report_error(const char *kind, uintptr_t caller) {
911
fprintf(stderr, "CUSTOM_CALLBACK: %s\n", kind);
1012
}
1113

14+
void __ubsan_report_error_fatal(const char *kind, uintptr_t caller) {
15+
fprintf(stderr, "FATAL_CALLBACK: %s\n", kind);
16+
}
17+
1218
int main(int argc, const char **argv) {
1319
int32_t t0 = (~((uint32_t)0));
1420
// CHECK: CUSTOM_CALLBACK: implicit-conversion
21+
// FATAL: FATAL_CALLBACK: implicit-conversion
1522
}

0 commit comments

Comments
 (0)