|
2 | 2 |
|
3 | 3 | #include "bits.h" |
4 | 4 | #include "snmalloc/ds_core/defines.h" |
| 5 | +#include "snmalloc/ds_core/tid.h" |
5 | 6 | #include "snmalloc/stl/array.h" |
6 | 7 | #include "snmalloc/stl/type_traits.h" |
7 | 8 | #include "snmalloc/stl/utility.h" |
@@ -339,6 +340,38 @@ namespace snmalloc |
339 | 340 | } |
340 | 341 | }; |
341 | 342 |
|
| 343 | + /** |
| 344 | + * Report a fatal error via a PAL-specific error reporting mechanism. This |
| 345 | + * takes a format string and a set of arguments. The format string indicates |
| 346 | + * the remaining arguments with "{}". This could be extended later to |
| 347 | + * support indexing fairly easily, if we ever want to localise these error |
| 348 | + * messages. |
| 349 | + * |
| 350 | + * The following are supported as arguments: |
| 351 | + * |
| 352 | + * - Characters (`char`), printed verbatim. |
| 353 | + * - Strings Literals (`const char*` or `const char[]`), printed verbatim. |
| 354 | + * - Raw pointers (void*), printed as hex strings. |
| 355 | + * - Integers (convertible to `size_t`), printed as hex strings. |
| 356 | + * |
| 357 | + * These types should be sufficient for allocator-related error messages. |
| 358 | + */ |
| 359 | + template<size_t BufferSize, typename... Args> |
| 360 | + [[noreturn]] inline void report_fatal_error(Args... args) |
| 361 | + { |
| 362 | + MessageBuilder<BufferSize> msg{stl::forward<Args>(args)...}; |
| 363 | + error(msg.get_message()); |
| 364 | + } |
| 365 | + |
| 366 | + template<size_t BufferSize, typename... Args> |
| 367 | + inline void message(Args... args) |
| 368 | + { |
| 369 | + MessageBuilder<BufferSize> msg{stl::forward<Args>(args)...}; |
| 370 | + MessageBuilder<BufferSize> msg_tid{ |
| 371 | + "{}: {}", debug_get_tid(), msg.get_message()}; |
| 372 | + message_impl(msg_tid.get_message()); |
| 373 | + } |
| 374 | + |
342 | 375 | /** |
343 | 376 | * Convenience type that has no fields / methods. |
344 | 377 | */ |
|
0 commit comments