[RFC PATCH v2 08/15] bpf tools: Fetch calling regs to bpf arglist

From: He Kuang
Date: Sun May 24 2015 - 04:30:33 EST


For generating bpf prologue which fetches function formal parameters
when debuginfo is not provided.

Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
---
tools/lib/bpf/gen_prologue.c | 19 +++++++++++++++++++
tools/lib/bpf/libbpf.h | 2 ++
2 files changed, 21 insertions(+)

diff --git a/tools/lib/bpf/gen_prologue.c b/tools/lib/bpf/gen_prologue.c
index ca8aa1c..d25693a 100644
--- a/tools/lib/bpf/gen_prologue.c
+++ b/tools/lib/bpf/gen_prologue.c
@@ -106,3 +106,22 @@ unsigned int bpf_prologue_end(char *new_prog, int nargs)

return (char *)new_insn - new_prog;
}
+
+unsigned int bpf_prologue_formal_parameters(char *new_prog, int offset,
+ int index)
+{
+ struct bpf_insn *new_insn;
+
+ if (index >= BPF_PROLOGUE_NRARGS_MAX)
+ return 0;
+
+ new_insn = (struct bpf_insn *)new_prog;
+
+ /* load ctx to r3 */
+ if (new_prog)
+ *new_insn = BPF_LDX_MEM(BPF_DW, BPF_REG_ARG2 + index,
+ BPF_REG_ARG1, offset);
+ new_insn++;
+
+ return (char *)new_insn - new_prog;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index cf22a6a..9d6d4f7 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -72,5 +72,7 @@ unsigned int bpf_prologue_arg_deref(int offset,
int depth,
char *new_prog,
bool last);
+unsigned int bpf_prologue_formal_parameters(char *new_prog, int offset,
+ int index);

#endif
--
1.8.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/