18
18
#include " PThreadMutex.h"
19
19
#include " SysSignal.h"
20
20
#include < cerrno>
21
+ #include < inttypes.h>
21
22
#include < sys/ptrace.h>
22
23
#include < sys/types.h>
23
24
25
+ static void AppendExceptionData (std::vector<mach_exception_data_type_t > &out,
26
+ mach_exception_data_t data,
27
+ mach_msg_type_number_t count) {
28
+ mach_exception_data_type_t buf;
29
+ for (mach_msg_type_number_t i = 0 ; i < count; ++i) {
30
+ // The input Data we receive need not be aligned correctly.
31
+ // Perform an unaligned copy by pretending we're dealing with
32
+ // a char* buffer. This is required to work around UBSAN/ASAN
33
+ // "misaligned address" errors.
34
+ auto *src = reinterpret_cast <char *>(data + i);
35
+ memcpy (&buf, src, sizeof (mach_exception_data_type_t ));
36
+ out.push_back (buf);
37
+ }
38
+ }
39
+
24
40
// Routine mach_exception_raise
25
41
extern " C" kern_return_t
26
42
catch_mach_exception_raise (mach_port_t exception_port, mach_port_t thread,
@@ -95,20 +111,16 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
95
111
mach_exception_data_t exc_data,
96
112
mach_msg_type_number_t exc_data_count) {
97
113
if (DNBLogCheckLogBit (LOG_EXCEPTIONS)) {
98
- std::vector<uint64_t > exc_datas;
99
- uint64_t tmp;
100
- for (unsigned i = 0 ; i < exc_data_count; ++i) {
101
- // Perform an unaligned copy.
102
- memcpy (&tmp, &exc_data[i], sizeof (uint64_t ));
103
- exc_datas.push_back (tmp);
104
- }
114
+ std::vector<mach_exception_data_type_t > exc_datas;
115
+ AppendExceptionData (exc_datas, exc_data, exc_data_count);
105
116
DNBLogThreaded (" ::%s ( exc_port = 0x%4.4x, thd_port = 0x%4.4x, tsk_port = "
106
- " 0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { 0x%llx, "
107
- " 0x%llx })" ,
117
+ " 0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { 0x%" PRIx64
118
+ " , "
119
+ " 0x%" PRIx64 " })" ,
108
120
__FUNCTION__, exc_port, thread_port, task_port, exc_type,
109
121
MachException::Name (exc_type), exc_data_count,
110
- (uint64_t )( exc_data_count > 0 ? exc_datas[0 ] : 0xBADDBADD ),
111
- (uint64_t )( exc_data_count > 1 ? exc_datas[1 ] : 0xBADDBADD ));
122
+ (exc_data_count > 0 ? exc_datas[0 ] : 0xBADDBADD ),
123
+ (exc_data_count > 1 ? exc_datas[1 ] : 0xBADDBADD ));
112
124
}
113
125
g_message->exc_type = 0 ;
114
126
g_message->exc_data .clear ();
@@ -117,7 +129,7 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
117
129
g_message->task_port = task_port;
118
130
g_message->thread_port = thread_port;
119
131
g_message->exc_type = exc_type;
120
- g_message->AppendExceptionData ( exc_data, exc_data_count);
132
+ AppendExceptionData ( g_message->exc_data , exc_data, exc_data_count);
121
133
return KERN_SUCCESS;
122
134
} else if (!MachTask::IsValid (g_message->task_port )) {
123
135
// Our original exception port isn't valid anymore check for a SIGTRAP
@@ -129,7 +141,7 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
129
141
g_message->task_port = task_port;
130
142
g_message->thread_port = thread_port;
131
143
g_message->exc_type = exc_type;
132
- g_message->AppendExceptionData ( exc_data, exc_data_count);
144
+ AppendExceptionData ( g_message->exc_data , exc_data, exc_data_count);
133
145
return KERN_SUCCESS;
134
146
}
135
147
}
0 commit comments