You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[native] Let Android know what is our reason to abort() (#9314)
[Android NDK r10c (2014)][0]:
> Added the following functions to all architectures:
> `android_set_abort_message`, `posix_fadvise`, `posix_fadvise64`,
> `pthread_gettid_np`.
There doesn't appear to be any "proper" documentation for
[`android_set_abort_message()`][1] (404), but it is *mentioned* in
the [Logging][2] documentation, e.g.
[`__android_log_call_aborter()`][3]:
> **abort_message**: an additional message supplied when aborting,
> for example this is used to call [android_set_abort_message()][1]
> in [__android_log_default_aborter()][3].
`android_set_abort_message()` allows the caller to set a text message
indicating the reason why the application is aborting its execution
using the **abort**(3) function, since the call doesn't accept any
parameters. The message is then used in the native stack trace as
well as in the application tombstone, which may be helpful for us
when reading crash reports which contain just the stack trace and no
context information.
Given the following code:
Helpers::abort_application (LOG_ASSEMBLY, "Testing abort stuff");
We will see the following logged in logcat:
F monodroid-assembly: Testing abort stuff
F monodroid-assembly: Abort at monodroid-glue.cc:825:2 ('void xamarin::android::internal::MonodroidRuntime::init_android_runtime(JNIEnv *, jclass, jobject)')
F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 8803 (XAPerfTest.net9), pid 8803 (XAPerfTest.net9)
I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstoneProto
I tombstoned: received crash request for pid 8803
I crash_dump64: performing dump of process 8803 (target tid = 8803)
F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
F DEBUG : Build fingerprint: 'google/raven/raven:14/AP2A.240805.005.F1/12043167:user/release-keys'
F DEBUG : Revision: 'MP1.0'
F DEBUG : ABI: 'arm64'
F DEBUG : Timestamp: 2024-09-24 12:00:57.245408791+0200
F DEBUG : Process uptime: 1s
F DEBUG : Cmdline: com.xamarin.XAPerfTest.net9
F DEBUG : pid: 8803, tid: 8803, name: XAPerfTest.net9 >>> com.xamarin.XAPerfTest.net9 <<<
F DEBUG : uid: 10456
F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
F DEBUG 👉: Abort message: 'Testing abort stuff'
F DEBUG : x0 0000000000000000 x1 0000000000002263 x2 0000000000000006 x3 0000007fc7ed5530
F DEBUG : x4 3139343137396262 x5 3139343137396262 x6 3139343137396262 x7 7f7f7f7f7f7f7f7f
F DEBUG : x8 00000000000000f0 x9 000000721c528350 x10 0000000000000001 x11 000000721c579170
F DEBUG : x12 0000007fc7ed3e50 x13 0000000000000088 x14 0000007fc7ed5068 x15 000000057ae2d47e
F DEBUG : x16 000000721c5dffd0 x17 000000721c5cb560 x18 0000007230490000 x19 0000000000002263
F DEBUG : x20 0000000000002263 x21 00000000ffffffff x22 0000006f69e1d7d6 x23 0000007fc7ed58a4
F DEBUG : x24 0000007fc7ed58c8 x25 0000000000000000 x26 0000000000000000 x27 b400007218a0a060
F DEBUG : x28 0000000000000000 x29 0000007fc7ed55b0
F DEBUG : lr 000000721c5628b8 sp 0000007fc7ed5510 pc 000000721c5628e4 pst 0000000000001000
The rest of stack trace is omitted for brevity.
We log the indicated message before calling `abort()`, but it also
appears on the `Abort message:` line in the stack trace; see 👉.
Messages provided to `android_set_abort_message()` appear to have an
undocumented length limit of 120 characters, so messages should
"front-load" important information.
Additionally, don't log the full path to the source file containing
the abort call, a file name is just enough.
[0]: https://developer.android.com/ndk/downloads/revision_history
[1]: https://developer.android.com/ndk/reference/set/abort-message-8h#set__abort__message_8h_1ac483b2fcb74191566f18476ce3280c9c
[2]: https://developer.android.com/ndk/reference/group/logging
[3]: https://developer.android.com/ndk/reference/group/logging#__android_log_call_aborter
auto header = static_cast<AssemblyStoreHeader*>(payload_start);
193
216
194
217
if (header->magic != ASSEMBLY_STORE_MAGIC) {
195
-
log_fatal (LOG_ASSEMBLY, "Assembly store '%s' is not a valid .NET for Android assembly store file", entry_name.get ());
196
-
Helpers::abort_application ();
218
+
Helpers::abort_application (
219
+
LOG_ASSEMBLY,
220
+
Util::monodroid_strdup_printf (
221
+
"Assembly store '%s' is not a valid .NET for Android assembly store file",
222
+
entry_name.get ()
223
+
)
224
+
);
197
225
}
198
226
199
227
if (header->version != ASSEMBLY_STORE_FORMAT_VERSION) {
200
-
log_fatal (LOG_ASSEMBLY, "Assembly store '%s' uses format version 0x%x, instead of the expected 0x%x", entry_name.get (), header->version, ASSEMBLY_STORE_FORMAT_VERSION);
201
-
Helpers::abort_application ();
228
+
Helpers::abort_application (
229
+
LOG_ASSEMBLY,
230
+
Util::monodroid_strdup_printf (
231
+
"Assembly store '%s' uses format version 0x%x, instead of the expected 0x%x",
log_fatal (LOG_ASSEMBLY, "Failed to seek to central directory position in the APK file %s. %s (result: %d; errno: %d)", apk_name, std::strerror (errno), retval, errno);
286
-
Helpers::abort_application ();
325
+
Helpers::abort_application (
326
+
LOG_ASSEMBLY,
327
+
Util::monodroid_strdup_printf (
328
+
"Failed to seek to central directory position in APK: %s. retval=%d errno=%d, File=%s",
log_fatal (LOG_ASSEMBLY, "Invalid compressed assembly descriptor at %u: no data", header->descriptor_index);
109
-
Helpers::abort_application ();
112
+
Helpers::abort_application (
113
+
LOG_ASSEMBLY,
114
+
Util::monodroid_strdup_printf (
115
+
"Invalid compressed assembly descriptor at %u: no data",
116
+
header->descriptor_index
117
+
)
118
+
);
110
119
}
111
120
112
121
if (header->uncompressed_length != cad.uncompressed_file_size) {
113
122
if (header->uncompressed_length > cad.uncompressed_file_size) {
114
-
log_fatal (LOG_ASSEMBLY, "Compressed assembly '%s' is larger than when the application was built (expected at most %u, got %u). Assemblies don't grow just like that!", name, cad.uncompressed_file_size, header->uncompressed_length);
115
-
Helpers::abort_application ();
123
+
Helpers::abort_application (
124
+
LOG_ASSEMBLY,
125
+
Util::monodroid_strdup_printf (
126
+
"Compressed assembly '%s' is larger than when the application was built (expected at most %u, got %u). Assemblies don't grow just like that!",
127
+
name,
128
+
cad.uncompressed_file_size,
129
+
header->uncompressed_length
130
+
)
131
+
);
116
132
} else {
117
133
log_debug (LOG_ASSEMBLY, "Compressed assembly '%s' is smaller than when the application was built. Adjusting accordingly.", name);
int ret = LZ4_decompress_safe (data_start, reinterpret_cast<char*>(cad.data), static_cast<int>(assembly_data_size), static_cast<int>(cad.uncompressed_file_size));
124
140
125
141
if (ret < 0) {
126
-
log_fatal (LOG_ASSEMBLY, "Decompression of assembly %s failed with code %d", name, ret);
127
-
Helpers::abort_application ();
142
+
Helpers::abort_application (
143
+
LOG_ASSEMBLY,
144
+
Util::monodroid_strdup_printf (
145
+
"Decompression of assembly %s failed with code %d",
146
+
name,
147
+
ret
148
+
)
149
+
);
128
150
}
129
151
130
152
if (static_cast<uint64_t>(ret) != cad.uncompressed_file_size) {
131
-
log_debug (LOG_ASSEMBLY, "Decompression of assembly %s yielded a different size (expected %lu, got %u)", name, cad.uncompressed_file_size, static_cast<uint32_t>(ret));
132
-
Helpers::abort_application ();
153
+
Helpers::abort_application (
154
+
LOG_ASSEMBLY,
155
+
Util::monodroid_strdup_printf (
156
+
"Decompression of assembly %s yielded a different size (expected %lu, got %u)",
if (hash_entry->descriptor_index >= assembly_store.assembly_count) {
369
-
log_fatal (LOG_ASSEMBLY, "Invalid assembly descriptor index %u, exceeds the maximum value of %u", hash_entry->descriptor_index, assembly_store.assembly_count - 1);
370
-
Helpers::abort_application ();
398
+
Helpers::abort_application (
399
+
LOG_ASSEMBLY,
400
+
Util::monodroid_strdup_printf (
401
+
"Invalid assembly descriptor index %u, exceeds the maximum value of %u",
0 commit comments