authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-25 19:10:11+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-25 19:10:11+02:00
log54db36cd88835ed6b9d9584d9568e9aa72e41480
treefa69c82ecc88148f9a2126db0bc8c0239a8d0caf
parent37b05742ff1544bccf7c8ae9b12c6707a5a54df2

std: Fix backtraces on sparcv9

Flush all the register windows to stack before starting the stack walk, we may otherwise try to read garbage and crash and burn. Add a few comptime annotations to debloat some functions.

1 files changed, 11 insertions(+), 4 deletions(-)

lib/std/debug.zig+11-4
......@@ -336,6 +336,13 @@ pub const StackIterator = struct {
336336 fp: usize,
337337
338338 pub fn init(first_address: ?usize, fp: ?usize) StackIterator {
339 if (builtin.arch == .sparcv9) {
340 // Flush all the register windows on stack.
341 asm volatile (
342 \\ flushw
343 ::: "memory");
344 }
345
339346 return StackIterator{
340347 .first_address = first_address,
341348 .fp = fp orelse @frameAddress(),
......@@ -343,18 +350,18 @@ pub const StackIterator = struct {
343350 }
344351
345352 // Offset of the saved BP wrt the frame pointer.
346 const fp_offset = if (builtin.arch.isRISCV())
353 const fp_offset = if (comptime builtin.arch.isRISCV())
347354 // On RISC-V the frame pointer points to the top of the saved register
348355 // area, on pretty much every other architecture it points to the stack
349356 // slot where the previous frame pointer is saved.
350357 2 * @sizeOf(usize)
351 else if (builtin.arch.isSPARC())
358 else if (comptime builtin.arch.isSPARC())
352359 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
353360 14 * @sizeOf(usize)
354361 else
355362 0;
356363
357 const fp_bias = if (builtin.arch.isSPARC())
364 const fp_bias = if (comptime builtin.arch.isSPARC())
358365 // On SPARC frame pointers are biased by a constant.
359366 2047
360367 else
......@@ -380,7 +387,7 @@ pub const StackIterator = struct {
380387 }
381388
382389 fn next_internal(self: *StackIterator) ?usize {
383 const fp = if (builtin.arch.isSPARC())
390 const fp = if (comptime builtin.arch.isSPARC())
384391 // On SPARC the offset is positive. (!)
385392 math.add(usize, self.fp, fp_offset) catch return null
386393 else