[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210301174749.1269154-4-swboyd@chromium.org>
Date: Mon, 1 Mar 2021 09:47:45 -0800
From: Stephen Boyd <swboyd@...omium.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...nel.org>,
Alexei Starovoitov <ast@...nel.org>,
Jessica Yu <jeyu@...nel.org>,
Evan Green <evgreen@...omium.org>,
Hsin-Yi Wang <hsinyi@...omium.org>
Subject: [PATCH 3/7] buildid: Add API to parse build ID out of buffer
Add an API that can parse the build ID in hex string form out of a
buffer to support printing a kernel module's build ID.
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Alexei Starovoitov <ast@...nel.org>
Cc: Jessica Yu <jeyu@...nel.org>
Cc: Evan Green <evgreen@...omium.org>
Cc: Hsin-Yi Wang <hsinyi@...omium.org>
Signed-off-by: Stephen Boyd <swboyd@...omium.org>
---
include/linux/buildid.h | 1 +
lib/buildid.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/buildid.h b/include/linux/buildid.h
index dd134a96a87c..f5a5b920d18c 100644
--- a/include/linux/buildid.h
+++ b/include/linux/buildid.h
@@ -10,6 +10,7 @@
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
__u32 *size);
+int build_id_parse_buf(const void *buf, char *build_id, u32 buf_size);
const char *vmlinux_build_id(void);
#endif
diff --git a/lib/buildid.c b/lib/buildid.c
index 57daf928b133..4e1d7c51dc5f 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -165,6 +165,26 @@ static void build_id2hex(char *dst, const unsigned char *src, __u32 size)
dst[2 * size] = '\0';
}
+/**
+ * build_id_parse_buf - Get build ID in hex string format from elf section note
+ * @buf: Elf note section(s) to parse
+ * @build_id: Build ID in hex string format parsed from @buf
+ * @buf_size: Size of @buf in bytes
+ *
+ * Return: 0 on success, -EINVAL otherwise
+ */
+int build_id_parse_buf(const void *buf, char *build_id, u32 buf_size)
+{
+ unsigned char build_id_buf[BUILD_ID_SIZE_MAX];
+ __u32 size;
+ int ret;
+
+ ret = parse_build_id_buf(build_id_buf, &size, buf, buf_size);
+ if (!ret)
+ build_id2hex(build_id, build_id_buf, size);
+
+ return ret;
+}
/**
* vmlinux_build_id - Get the running kernel's build-id in hex string format
*
--
https://chromeos.dev
Powered by blists - more mailing lists