@@ -233,6 +233,40 @@ MOZ_NoReturn(int aLine) {
233
233
234
234
#else
235
235
236
+ // This function causes the process to crash by writing the line number
237
+ // specified in the `aLine` parameter to the address provide by `aAddress`.
238
+ // The store is implemented as volatile assembly code to ensure it's always
239
+ // included in the output and always executed. This does not apply to ASAN
240
+ // builds where we use __builtin_trap() instead, as an illegal access would
241
+ // trip ASAN's checks.
242
+ # if !defined(MOZ_ASAN)
243
+ static inline void MOZ_CrashSequence (void * aAddress, intptr_t aLine) {
244
+ # if defined(__i386__) || defined(__x86_64__)
245
+ asm volatile (
246
+ " mov %1, (%0);\n " // Write the line number to the crashing address
247
+ : // no output registers
248
+ : " r" (aAddress), " r" (aLine));
249
+ # elif defined(__arm__) || defined(__aarch64__)
250
+ asm volatile (
251
+ " str %1,[%0];\n " // Write the line number to the crashing address
252
+ : // no output registers
253
+ : " r" (aAddress), " r" (aLine));
254
+ # elif defined(__riscv)
255
+ asm volatile (
256
+ " sw %1,0(%0);\n " // Write the line number to the crashing address
257
+ : // no output registers
258
+ : " r" (aAddress), " r" (aLine));
259
+ # else
260
+ # warning \
261
+ " Unsupported architecture, replace the code below with assembly suitable to crash the process"
262
+ asm volatile (" " ::: " memory" );
263
+ *((volatile int *)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */
264
+ # endif
265
+ }
266
+ # else
267
+ # define MOZ_CrashSequence (x, y ) __builtin_trap()
268
+ # endif
269
+
236
270
/*
237
271
* MOZ_CRASH_WRITE_ADDR is the address to be used when performing a forced
238
272
* crash. NULL is preferred however if for some reason NULL cannot be used
@@ -250,16 +284,16 @@ MOZ_NoReturn(int aLine) {
250
284
# endif
251
285
252
286
# ifdef __cplusplus
253
- # define MOZ_REALLY_CRASH (line ) \
254
- do { \
255
- *(( volatile int *) MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \
256
- MOZ_NOMERGE ::abort (); \
287
+ # define MOZ_REALLY_CRASH (line ) \
288
+ do { \
289
+ MOZ_CrashSequence ( MOZ_CRASH_WRITE_ADDR, line); \
290
+ MOZ_NOMERGE ::abort (); \
257
291
} while (false )
258
292
# else
259
- # define MOZ_REALLY_CRASH (line ) \
260
- do { \
261
- *(( volatile int *) MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \
262
- MOZ_NOMERGE abort (); \
293
+ # define MOZ_REALLY_CRASH (line ) \
294
+ do { \
295
+ MOZ_CrashSequence ( MOZ_CRASH_WRITE_ADDR, line); \
296
+ MOZ_NOMERGE abort (); \
263
297
} while (false )
264
298
# endif
265
299
#endif
0 commit comments