1 // SPDX-License-Identifier: GPL-2.0
10 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
11 struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
12 struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
14 static void unwind__register_ops(struct map_groups *mg,
15 struct unwind_libunwind_ops *ops)
17 mg->unwind_libunwind_ops = ops;
20 int unwind__prepare_access(struct map_groups *mg, struct map *map,
24 enum dso_type dso_type;
25 struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
28 if (!dwarf_callchain_users)
32 pr_debug("unwind: thread map already set, dso=%s\n",
39 /* env->arch is NULL for live-mode (i.e. perf top) */
40 if (!mg->machine->env || !mg->machine->env->arch)
43 dso_type = dso__type(map->dso, mg->machine);
44 if (dso_type == DSO__TYPE_UNKNOWN)
47 arch = perf_env__arch(mg->machine->env);
49 if (!strcmp(arch, "x86")) {
50 if (dso_type != DSO__TYPE_64BIT)
51 ops = x86_32_unwind_libunwind_ops;
52 } else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
53 if (dso_type == DSO__TYPE_64BIT)
54 ops = arm64_unwind_libunwind_ops;
58 pr_err("unwind: target platform=%s is not supported\n", arch);
62 unwind__register_ops(mg, ops);
64 err = mg->unwind_libunwind_ops->prepare_access(mg);
66 *initialized = err ? false : true;
70 void unwind__flush_access(struct map_groups *mg)
72 if (!dwarf_callchain_users)
75 if (mg->unwind_libunwind_ops)
76 mg->unwind_libunwind_ops->flush_access(mg);
79 void unwind__finish_access(struct map_groups *mg)
81 if (!dwarf_callchain_users)
84 if (mg->unwind_libunwind_ops)
85 mg->unwind_libunwind_ops->finish_access(mg);
88 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
89 struct thread *thread,
90 struct perf_sample *data, int max_stack)
92 if (thread->mg->unwind_libunwind_ops)
93 return thread->mg->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);