aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/asm.s
diff options
context:
space:
mode:
authorDavid Lazar <lazard@golang.org>2017-03-06 14:48:36 -0500
committerDavid Lazar <lazard@golang.org>2017-03-29 17:22:08 +0000
commitee97216a1787a979911d43c0c5c582b5492a2205 (patch)
tree636c8c346cee5da888df84c5498dd2f0f984fee6 /src/runtime/asm.s
parentf3f5b10e06f6bb29731e9213dd8745a9b1857568 (diff)
downloadgo-ee97216a1787a979911d43c0c5c582b5492a2205.tar.gz
go-ee97216a1787a979911d43c0c5c582b5492a2205.zip
runtime: handle inlined calls in runtime.Callers
The `skip` argument passed to runtime.Caller and runtime.Callers should be interpreted as the number of logical calls to skip (rather than the number of physical stack frames to skip). This changes runtime.Callers to skip inlined calls in addition to physical stack frames. The result value of runtime.Callers is a slice of program counters ([]uintptr) representing physical stack frames. If the `skip` parameter to runtime.Callers skips part-way into a physical frame, there is no convenient way to encode that in the resulting slice. To avoid changing the API in an incompatible way, our solution is to store the number of skipped logical calls of the first frame in the _second_ uintptr returned by runtime.Callers. Since this number is a small integer, we encode it as a valid PC value into a small symbol called: runtime.skipPleaseUseCallersFrames For example, if f() calls g(), g() calls `runtime.Callers(2, pcs)`, and g() is inlined into f, then the frame for f will be partially skipped, resulting in the following slice: pcs = []uintptr{pc_in_f, runtime.skipPleaseUseCallersFrames+1, ...} We store the skip PC in pcs[1] instead of pcs[0] so that `pcs[i:]` will truncate the captured stack trace rather than grow it for all i. Updates #19348. Change-Id: I1c56f89ac48c29e6f52a5d085567c6d77d499cf1 Reviewed-on: https://go-review.googlesource.com/37854 Run-TryBot: David Lazar <lazard@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/asm.s')
-rw-r--r--src/runtime/asm.s21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/runtime/asm.s b/src/runtime/asm.s
index 3ddea7c055..2646172441 100644
--- a/src/runtime/asm.s
+++ b/src/runtime/asm.s
@@ -14,3 +14,24 @@ GLOBL runtime·no_pointers_stackmap(SB),RODATA, $8
GLOBL runtime·mheap_(SB), NOPTR, $0
GLOBL runtime·memstats(SB), NOPTR, $0
+
+// NaCl requires that these skips be verifiable machine code.
+#ifdef GOARCH_amd64
+#define SKIP4 BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90
+#endif
+#ifdef GOARCH_386
+#define SKIP4 BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90
+#endif
+#ifdef GOARCH_amd64p32
+#define SKIP4 BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90
+#endif
+#ifndef SKIP4
+#define SKIP4 WORD $0
+#endif
+
+#define SKIP16 SKIP4; SKIP4; SKIP4; SKIP4
+#define SKIP64 SKIP16; SKIP16; SKIP16; SKIP16
+
+// This function must be sizeofSkipFunction bytes.
+TEXT runtime·skipPleaseUseCallersFrames(SB),NOSPLIT,$0-0
+ SKIP64; SKIP64; SKIP64; SKIP64