@@ -34,20 +34,24 @@ static char *append_hex(uintptr_t d, char *buf, const char *end) {
3434 return buf;
3535}
3636
37- static void format_msg (const char *kind, uintptr_t caller, char *buf,
38- const char *end) {
37+ static void format_msg (const char *kind, uintptr_t caller,
38+ const uintptr_t *address, char *buf, const char *end) {
3939 buf = append_str (" ubsan: " , buf, end);
4040 buf = append_str (kind, buf, end);
4141 buf = append_str (" by 0x" , buf, end);
4242 buf = append_hex (caller, buf, end);
43+ if (address) {
44+ buf = append_str (" address 0x" , buf, end);
45+ buf = append_hex (*address, buf, end);
46+ }
4347 buf = append_str (" \n " , buf, end);
4448 if (buf == end)
4549 --buf; // Make sure we don't cause a buffer overflow.
4650 *buf = ' \0 ' ;
4751}
4852
4953SANITIZER_INTERFACE_WEAK_DEF (void , __ubsan_report_error, const char *kind,
50- uintptr_t caller) {
54+ uintptr_t caller, const uintptr_t *address ) {
5155 if (caller == 0 )
5256 return ;
5357 while (true ) {
@@ -80,15 +84,15 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
8084 __sanitizer::atomic_store_relaxed (&caller_pcs[sz], caller);
8185
8286 char msg_buf[128 ];
83- format_msg (kind, caller, msg_buf, msg_buf + sizeof (msg_buf));
87+ format_msg (kind, caller, address, msg_buf, msg_buf + sizeof (msg_buf));
8488 message (msg_buf);
8589 }
8690}
8791
8892SANITIZER_INTERFACE_WEAK_DEF (void , __ubsan_report_error_fatal, const char *kind,
89- uintptr_t caller) {
93+ uintptr_t caller, const uintptr_t *address ) {
9094 // Use another handlers, in case it's already overriden.
91- __ubsan_report_error (kind, caller);
95+ __ubsan_report_error (kind, caller, address );
9296}
9397
9498#if defined(__ANDROID__)
@@ -121,21 +125,39 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
121125
122126#define HANDLER_RECOVER (name, kind ) \
123127 INTERFACE void __ubsan_handle_##name##_minimal() { \
124- __ubsan_report_error (kind, GET_CALLER_PC ()); \
128+ __ubsan_report_error (kind, GET_CALLER_PC (), nullptr ); \
125129 }
126130
127131#define HANDLER_NORECOVER (name, kind ) \
128132 INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
129133 uintptr_t caller = GET_CALLER_PC (); \
130- __ubsan_report_error_fatal (kind, caller); \
134+ __ubsan_report_error_fatal (kind, caller, nullptr ); \
131135 abort_with_message (kind, caller); \
132136 }
133137
134138#define HANDLER (name, kind ) \
135139 HANDLER_RECOVER (name, kind) \
136140 HANDLER_NORECOVER(name, kind)
137141
138- HANDLER(type_mismatch, " type-mismatch" )
142+ #define HANDLER_RECOVER_PTR (name, kind ) \
143+ INTERFACE void __ubsan_handle_##name##_minimal(const uintptr_t address) { \
144+ __ubsan_report_error (kind, GET_CALLER_PC (), &address); \
145+ }
146+
147+ #define HANDLER_NORECOVER_PTR (name, kind ) \
148+ INTERFACE void __ubsan_handle_##name##_minimal_abort( \
149+ const uintptr_t address) { \
150+ uintptr_t caller = GET_CALLER_PC (); \
151+ __ubsan_report_error_fatal (kind, caller, &address); \
152+ abort_with_message (kind, caller); \
153+ }
154+
155+ // A version of a handler that takes a pointer to a value.
156+ #define HANDLER_PTR (name, kind ) \
157+ HANDLER_RECOVER_PTR (name, kind) \
158+ HANDLER_NORECOVER_PTR(name, kind)
159+
160+ HANDLER_PTR(type_mismatch, " type-mismatch" )
139161HANDLER(alignment_assumption, " alignment-assumption" )
140162HANDLER(add_overflow, " add-overflow" )
141163HANDLER(sub_overflow, " sub-overflow" )
0 commit comments