162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __TRACE_HELPER_H
362306a36Sopenharmony_ci#define __TRACE_HELPER_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <bpf/libbpf.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define __ALIGN_MASK(x, mask)	(((x)+(mask))&~(mask))
862306a36Sopenharmony_ci#define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a)-1)
962306a36Sopenharmony_ci
1062306a36Sopenharmony_cistruct ksym {
1162306a36Sopenharmony_ci	long addr;
1262306a36Sopenharmony_ci	char *name;
1362306a36Sopenharmony_ci};
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciint load_kallsyms(void);
1662306a36Sopenharmony_ciint load_kallsyms_refresh(void);
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct ksym *ksym_search(long key);
1962306a36Sopenharmony_cilong ksym_get_addr(const char *name);
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/* open kallsyms and find addresses on the fly, faster than load + search. */
2262306a36Sopenharmony_ciint kallsyms_find(const char *sym, unsigned long long *addr);
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_civoid read_trace_pipe(void);
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cissize_t get_uprobe_offset(const void *addr);
2762306a36Sopenharmony_cissize_t get_rel_offset(uintptr_t addr);
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciint read_build_id(const char *path, char *build_id, size_t size);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#endif
32