[DTrace-devel] [PATCH 4/6 v2] Add macro to access stack slots past the register spill area
Kris Van Hees
kris.van.hees at oracle.com
Fri Mar 11 06:26:18 UTC 2022
The DT_TRAMP_SP9n) macro has been renamed to DT_TRAMP_SP_SLOT(n) for
consistency with the new DT_STK_SP_SLOT(n) macro. DT_STK_SP is new
and refers to the location of a "stack pointer" that holds the address
of a DT_STK_SP_SLOT.
This patch also removes the SCRATCH_* macros because they are obsolete.
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Eugene Loh <eugene.loh at oracle.com
---
libdtrace/dt_cg.c | 6 +++++
libdtrace/dt_dctx.h | 33 ++++++++++++++----------
libdtrace/dt_prov_dtrace.c | 16 ++++++------
test/unittest/codegen/tst.stack_layout.r | 21 ++++++++-------
test/utils/print-stack-layout.c | 7 +++--
5 files changed, 47 insertions(+), 36 deletions(-)
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 5300c9f6..1cb06ef7 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -515,9 +515,15 @@ dt_cg_prologue(dt_pcb_t *pcb, dt_node_t *pred)
* char *buf; // (%r9 = reserved reg for buf)
*
* // stdw [%fp + DT_STK_DCTX], %r1
+ * // mov %r0, %fp
+ * // add %r0, DT_STK_SP_BASE
+ * // stdw [%fp + DT_STK_SP], %r0
*/
TRACE_REGSET("Prologue: Begin");
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_FP, DT_STK_DCTX, BPF_REG_1));
+ emit(dlp, BPF_MOV_REG(BPF_REG_0, BPF_REG_FP));
+ emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, DT_STK_SP_BASE));
+ emit(dlp, BPF_STORE(BPF_DW, BPF_REG_FP, DT_STK_SP, BPF_REG_0));
/*
* buf = dctx->buf; // lddw %r0, [%fp + DT_STK_DCTX]
diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
index f6c7f301..d45720d7 100644
--- a/libdtrace/dt_dctx.h
+++ b/libdtrace/dt_dctx.h
@@ -109,13 +109,13 @@ typedef struct dt_dctx {
* -16, -24, -32, etc. -- that is, negative multiples of sizeof(uint64_t).
*
* +----------------+
- * SP(n) | |
+ * SP_SLOT(n) | |
* +----------------+
* | ... |
* +----------------+
- * SP(1) | |
+ * SP_SLOT(1) | |
* +----------------+
- * SP_BASE = SP(0) | |
+ * SP_BASE = SP_SLOT(0) | |
* +----------------+
* DCTX | DTrace Context |
* +----------------+
@@ -124,7 +124,7 @@ typedef struct dt_dctx {
#define DT_STK_SLOT_SZ ((int16_t)sizeof(uint64_t))
#define DT_TRAMP_SP_BASE (DT_STK_BASE - DCTX_SIZE - DT_STK_SLOT_SZ)
-#define DT_TRAMP_SP(n) (DT_TRAMP_SP_BASE - (n) * DT_STK_SLOT_SZ)
+#define DT_TRAMP_SP_SLOT(n) (DT_TRAMP_SP_BASE - (n) * DT_STK_SLOT_SZ)
/*
* DTrace clause functions can use all BPF registers except for the %fp (frame
@@ -142,24 +142,29 @@ typedef struct dt_dctx {
* -16, -24, -32, etc. -- that is, negative multiples of sizeof(uint64_t).
*
* +----------------+
- * SCRATCH_BASE | Scratch Memory |
- * +----------------+
- * SPILL(n) | %r8 | (n = DT_STK_NREGS - 1 = 8)
- * +----------------+
* | ... |
* +----------------+
- * SPILL(1) | %r1 |
- * +----------------+
- * SPILL_BASE = SPILL(0) | %r0 |
+ * SP_BASE = SP_SLOT(0) | |<--+
+ * +----------------+ |
+ * SPILL(n) | %r8 | (n = DT_STK_NREGS - 1 = 8)
+ * +----------------+ |
+ * | ... | |
+ * +----------------+ |
+ * SPILL(1) | %r1 | |
+ * +----------------+ |
+ * SPILL_BASE = SPILL(0) | %r0 | |
+ * +----------------+ |
+ * SP | +------------+ (initial value)
* +----------------+
* DCTX | Ptr to dctx |
* +----------------+
*/
#define DT_STK_DCTX (DT_STK_BASE - DT_STK_SLOT_SZ)
-#define DT_STK_SPILL_BASE (DT_STK_DCTX - DT_STK_SLOT_SZ)
+#define DT_STK_SP (DT_STK_DCTX - DT_STK_SLOT_SZ)
+#define DT_STK_SPILL_BASE (DT_STK_SP - DT_STK_SLOT_SZ)
#define DT_STK_SPILL(n) (DT_STK_SPILL_BASE - (n) * DT_STK_SLOT_SZ)
-#define DT_STK_SCRATCH_BASE (-MAX_BPF_STACK)
-#define DT_STK_SCRATCH_SZ (MAX_BPF_STACK + DT_STK_SPILL(DT_STK_NREGS - 1))
+#define DT_STK_SP_BASE DT_STK_SPILL(DT_STK_NREGS)
+#define DT_STK_SP_SLOT(n) (DT_STK_SP_BASE - (n) * DT_STK_SLOT_SZ)
#endif /* _DT_DCTX_H */
diff --git a/libdtrace/dt_prov_dtrace.c b/libdtrace/dt_prov_dtrace.c
index 57a5783c..a7fc2cf5 100644
--- a/libdtrace/dt_prov_dtrace.c
+++ b/libdtrace/dt_prov_dtrace.c
@@ -128,30 +128,30 @@ static void trampoline(dt_pcb_t *pcb)
/*
* key = DT_STATE_(BEGANON|ENDEDON);
- * // stw [%fp + DT_TRAMP_SP(0)],
+ * // stw [%fp + DT_TRAMP_SP_SLOT(0)],
* // DT_STATE_(BEGANON|ENDEDON)
* val = bpf_get_smp_processor_id();
* // call bpf_get_smp_processor_id
- * // stw [%fp + DT_TRAMP_SP(1)], %r0
+ * // stw [%fp + DT_TRAMP_SP_SLOT(1)], %r0
* bpf_map_update_elem(state, &key, &val, BPF_ANY);
* // lddw %r1, &state
* // mov %r2, %fp
- * // add %r2, DT_TRAMP_SP(0)
+ * // add %r2, DT_TRAMP_SP_SLOT(0)
* // mov %r3, %fp
- * // add %r3, DT_TRAMP_SP(1)
+ * // add %r3, DT_TRAMP_SP_SLOT(1)
* // mov %r4, BPF_ANY
* // call bpf_map_update_elem
*/
dt_ident_t *state = dt_dlib_get_map(pcb->pcb_hdl, "state");
- emit(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_FP, DT_TRAMP_SP(0), key));
+ emit(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_FP, DT_TRAMP_SP_SLOT(0), key));
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_smp_processor_id));
- emit(dlp, BPF_STORE(BPF_W, BPF_REG_FP, DT_TRAMP_SP(1), BPF_REG_0));
+ emit(dlp, BPF_STORE(BPF_W, BPF_REG_FP, DT_TRAMP_SP_SLOT(1), BPF_REG_0));
dt_cg_xsetx(dlp, state, DT_LBL_NONE, BPF_REG_1, state->di_id);
emit(dlp, BPF_MOV_REG(BPF_REG_2, BPF_REG_FP));
- emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, DT_TRAMP_SP(0)));
+ emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, DT_TRAMP_SP_SLOT(0)));
emit(dlp, BPF_MOV_REG(BPF_REG_3, BPF_REG_FP));
- emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, DT_TRAMP_SP(1)));
+ emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, DT_TRAMP_SP_SLOT(1)));
emit(dlp, BPF_MOV_IMM(BPF_REG_4, BPF_ANY));
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_map_update_elem));
diff --git a/test/unittest/codegen/tst.stack_layout.r b/test/unittest/codegen/tst.stack_layout.r
index af2a4aad..ce047255 100644
--- a/test/unittest/codegen/tst.stack_layout.r
+++ b/test/unittest/codegen/tst.stack_layout.r
@@ -1,12 +1,13 @@
Base: 0
dctx: -8
-%r0: -16
-%r1: -24
-%r2: -32
-%r3: -40
-%r4: -48
-%r5: -56
-%r6: -64
-%r7: -72
-%r8: -80
-scratch: -81 .. -512
+sp: -16
+%r0: -24
+%r1: -32
+%r2: -40
+%r3: -48
+%r4: -56
+%r5: -64
+%r6: -72
+%r7: -80
+%r8: -88
+sp-base: -96
diff --git a/test/utils/print-stack-layout.c b/test/utils/print-stack-layout.c
index cdab8914..efc3bf67 100644
--- a/test/utils/print-stack-layout.c
+++ b/test/utils/print-stack-layout.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -13,6 +13,7 @@ int main(void)
{
printf("Base: % 4d\n", DT_STK_BASE);
printf("dctx: % 4d\n", DT_STK_DCTX);
+ printf("sp: % 4d\n", DT_STK_SP);
printf("%%r0: % 4d\n", DT_STK_SPILL(0));
printf("%%r1: % 4d\n", DT_STK_SPILL(1));
printf("%%r2: % 4d\n", DT_STK_SPILL(2));
@@ -22,8 +23,6 @@ int main(void)
printf("%%r6: % 4d\n", DT_STK_SPILL(6));
printf("%%r7: % 4d\n", DT_STK_SPILL(7));
printf("%%r8: % 4d\n", DT_STK_SPILL(8));
- printf("scratch: % 4d .. % 4d\n",
- DT_STK_SCRATCH_BASE + DT_STK_SCRATCH_SZ - 1,
- DT_STK_SCRATCH_BASE);
+ printf("sp-base: % 4d\n", DT_STK_SP_SLOT(0));
exit(0);
}
--
2.34.1
More information about the DTrace-devel
mailing list