File: bpfinterp.h

package info (click to toggle)
systemtap 4.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 38,260 kB
  • sloc: cpp: 77,147; ansic: 61,828; xml: 49,277; exp: 42,244; sh: 11,046; python: 2,772; perl: 2,252; tcl: 1,305; makefile: 1,086; lisp: 105; java: 102; awk: 101; asm: 91; sed: 16
file content (91 lines) | stat: -rw-r--r-- 3,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* bpfinterp.h - SystemTap BPF interpreter
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright (C) 2016-2019 Red Hat, Inc.
 *
 */

#ifndef BPFINTERP_H
#define BPFINTERP_H 1

#include <sys/types.h>
#include <inttypes.h>
#include <linux/bpf.h>

extern "C" {
#include "libbpf.h"
}

// Required constants such as BPF_MAXFORMATLEN:
#include "../bpf-internal.h"

// Used by the transport layer and interpreter:
struct bpf_transport_context {
  // XXX: The following two fields are only used for kernel programs.
  // pmu_fd == -1 indicates context for a userspace interpreter.
  unsigned cpu;
  int pmu_fd;

  // References to global state:
  unsigned ncpus;
  bpf_map_def *map_attrs;
  std::vector<int> *map_fds;
  FILE *output_f;
  std::vector<std::string> *interned_strings;
  std::unordered_map<bpf::globals::agg_idx, bpf::globals::stats_map> *aggregates;
  // XXX: Could be refactored into a single global struct bpf_global_context.
  
  // Data for procfs probes. Multiple threads will be accessing this variable.
  // However, the procfs_lock should prevent any concurrency issues.
  std::string procfs_msg;

  // Data for an in-progress printf request:
  bool in_printf;
  int format_no;          // -- index into table of interned strings
  unsigned expected_args; // -- expected number of printf_args
  std::vector<void *> printf_args;
  std::vector<bpf::globals::perf_event_type> printf_arg_types; // either ..ARG_LONG or ..ARG_STR

  // Used to communicate if a hard error has occured.
  bool* error;

  // Store error messages for printing later on.
  std::queue<std::string> error_message;

  // TODO: Takes a lot of arguments. Refactor to be less unwieldy.
  bpf_transport_context(unsigned cpu, int pmu_fd, unsigned ncpus,
                        bpf_map_def *map_attrs,
                        std::vector<int> *map_fds,
                        FILE *output_f,
                        std::vector<std::string> *interned_strings,
                        std::unordered_map<bpf::globals::agg_idx,
                                           bpf::globals::stats_map> *aggregates,
                        bool* error)
    : cpu(cpu), pmu_fd(pmu_fd), ncpus(ncpus),
      map_attrs(map_attrs), map_fds(map_fds), output_f(output_f),
      interned_strings(interned_strings), aggregates(aggregates),
      in_printf(false), format_no(-1), expected_args(0), error(error) {}
};

enum bpf_perf_event_ret bpf_handle_transport_msg(void *buf, size_t size,
                                                 bpf_transport_context *ctx);
  
uint64_t bpf_interpret(size_t ninsns,
                       const struct bpf_insn insns[],
                       bpf_transport_context *ctx);

extern int target_pid;

#endif /* STAPRUNBPF_H */