| 1 |
// Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
/** |
| 5 |
* @file |
| 6 |
* |
| 7 |
* Helpers implemented in C. |
| 8 |
* |
| 9 |
* Most drgn helpers are implemented in Python. However, there are a few that we |
| 10 |
* need internally in libdrgn, so they are implemented in C, instead. |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef DRGN_HELPERS_H |
| 14 |
#define DRGN_HELPERS_H |
| 15 |
|
| 16 |
#include <stddef.h> |
| 17 |
#include <stdint.h> |
| 18 |
|
| 19 |
#include "drgn_internal.h" |
| 20 |
|
| 21 |
struct drgn_object; |
| 22 |
struct drgn_program; |
| 23 |
|
| 24 |
struct drgn_error *linux_helper_direct_mapping_offset(struct drgn_program *prog, |
| 25 |
uint64_t *ret); |
| 26 |
|
| 27 |
struct drgn_error *linux_helper_read_vm(struct drgn_program *prog, |
| 28 |
uint64_t pgtable, uint64_t virt_addr, |
| 29 |
void *buf, size_t count); |
| 30 |
|
| 31 |
struct drgn_error *linux_helper_follow_phys(struct drgn_program *prog, |
| 32 |
uint64_t pgtable, |
| 33 |
uint64_t virt_addr, uint64_t *ret); |
| 34 |
|
| 35 |
struct drgn_error *linux_helper_per_cpu_ptr(struct drgn_object *res, |
| 36 |
const struct drgn_object *ptr, |
| 37 |
uint64_t cpu); |
| 38 |
|
| 39 |
struct drgn_error *linux_helper_cpu_curr(struct drgn_object *res, uint64_t cpu); |
| 40 |
|
| 41 |
struct drgn_error *linux_helper_idle_task(struct drgn_object *res, |
| 42 |
uint64_t cpu); |
| 43 |
|
| 44 |
struct drgn_error * |
| 45 |
linux_helper_task_thread_info(struct drgn_object *res, |
| 46 |
const struct drgn_object *task); |
| 47 |
|
| 48 |
struct drgn_error *linux_helper_task_cpu(const struct drgn_object *task, |
| 49 |
uint64_t *ret); |
| 50 |
|
| 51 |
struct drgn_error *linux_helper_task_on_cpu(const struct drgn_object *task, |
| 52 |
bool *ret); |
| 53 |
|
| 54 |
struct drgn_error * |
| 55 |
linux_helper_xa_load(struct drgn_object *res, const struct drgn_object *xa, |
| 56 |
uint64_t index); |
| 57 |
|
| 58 |
struct drgn_error *linux_helper_idr_find(struct drgn_object *res, |
| 59 |
const struct drgn_object *idr, |
| 60 |
uint64_t id); |
| 61 |
|
| 62 |
struct drgn_error *linux_helper_find_pid(struct drgn_object *res, |
| 63 |
const struct drgn_object *ns, |
| 64 |
uint64_t pid); |
| 65 |
|
| 66 |
struct drgn_error *linux_helper_pid_task(struct drgn_object *res, |
| 67 |
const struct drgn_object *pid, |
| 68 |
uint64_t pid_type); |
| 69 |
|
| 70 |
struct drgn_error *linux_helper_find_task(struct drgn_object *res, |
| 71 |
const struct drgn_object *ns, |
| 72 |
uint64_t pid); |
| 73 |
|
| 74 |
struct linux_helper_task_iterator { |
| 75 |
struct drgn_object tasks_node; |
| 76 |
struct drgn_object thread_node; |
| 77 |
uint64_t tasks_head; |
| 78 |
uint64_t thread_head; |
| 79 |
struct drgn_qualified_type task_struct_type; |
| 80 |
bool done; |
| 81 |
}; |
| 82 |
|
| 83 |
struct drgn_error * |
| 84 |
linux_helper_task_iterator_init(struct linux_helper_task_iterator *it, |
| 85 |
struct drgn_program *prog); |
| 86 |
|
| 87 |
void linux_helper_task_iterator_deinit(struct linux_helper_task_iterator *it); |
| 88 |
|
| 89 |
/** Get the next task from a @ref linux_helper_task_iterator. */ |
| 90 |
struct drgn_error * |
| 91 |
linux_helper_task_iterator_next(struct linux_helper_task_iterator *it, |
| 92 |
struct drgn_object *ret); |
| 93 |
|
| 94 |
#endif /* DRGN_HELPERS_H */ |