File: data_source.c

package info (click to toggle)
bpftrace 0.24.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,496 kB
  • sloc: cpp: 60,982; ansic: 10,952; python: 953; yacc: 665; sh: 536; lex: 295; makefile: 22
file content (176 lines) | stat: -rw-r--r-- 2,785 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
struct Foo1 {
  int a;
  char b;
  long c;
};

struct Foo2 {
  int a;
  union {
    struct Foo1 f;
    struct {
      char g;
    };
  };
};

struct Foo3 {
  struct Foo1 *foo1;
  const volatile struct Foo2 *restrict foo2;
};

struct Foo3 foo3;

struct Foo4 {
  int pid;
  int pgid;
  unsigned int : 12; // padding
  unsigned int a : 8;
  unsigned int b : 1;
  unsigned int c : 3;
  unsigned int d : 20;
};

struct Foo3 *func_1(int a,
                    struct Foo1 *foo1,
                    struct Foo2 *foo2,
                    struct Foo3 *foo3,
                    struct Foo4 *foo4)
{
  return 0;
}

struct Foo3 *func_2(int a, int *b, struct Foo1 *foo1)
{
  return 0;
}

// __attribute__((noinline)) is needed due to a LLDB/GCC compatibility bug
struct Foo3 *__attribute__((noinline)) func_3(int a, int *b, struct Foo1 *foo1)
{
  return 0;
}

struct FirstFieldsAreAnonUnion {
  union {
    int a;
    int b;
  };
  int c;
};

struct FirstFieldsAreAnonUnion first_fields_anon_union;

struct Arrays {
  int int_arr[4];
  char char_arr[8];
  void *ptr_arr[2];
  int multi_dim[3][2];
  int zero[0];
  int flexible[];
};
struct Arrays arrays;

struct Arrays *func_arrays(struct Arrays *arr)
{
  return 0;
}

struct ArrayWithCompoundData {
  struct Foo3 *data[2];
};

void func_array_with_compound_data(struct ArrayWithCompoundData *arr)
{
}

struct task_struct {
  int pid;
  int pgid;
};

struct file {
  int ino;
};

struct vm_area_struct {
  unsigned long vm_start;
  unsigned long vm_end;
};

struct bpf_iter__task {
  struct task_struct *task;
};

struct bpf_iter__task_file {
  struct task_struct *task;
  struct file *file;
};

struct bpf_iter__task_vma {
  struct task_struct *task;
  struct vm_area_struct *vma;
};

int bpf_iter_task()
{
  return 0;
}

int bpf_iter_task_file()
{
  return 0;
}

int bpf_iter_task_vma()
{
  return 0;
}

// kfunc definitions
struct bpf_map {};
long bpf_map_sum_elem_count(const struct bpf_map *map)
{
  return 0;
}
_Bool bpf_session_is_return()
{
  return 1;
}

long __probestub_event_rt(void *__data, long first_real_arg)
{
  return first_real_arg;
}

struct sock {
  int cookie;
};

void tcp_shutdown(struct sock *sk, int how)
{
}

// kernel percpu variables
__attribute__((section(".data..percpu"))) unsigned long process_counts;

// Make sure all new mocked kernel functions are called in this main (below)
// so they don't get optimzed away
int main(void)
{
  struct bpf_iter__task iter_task;
  struct bpf_iter__task_file iter_task_file;
  struct bpf_iter__task_vma iter_task_vma;
  struct bpf_map bpf_map;
  struct sock sk;

  func_1(0, 0, 0, 0, 0);

  bpf_iter_task();
  bpf_iter_task_file();
  bpf_iter_task_vma();
  bpf_map_sum_elem_count(&bpf_map);
  __probestub_event_rt((void *)&bpf_map, 1);
  tcp_shutdown(&sk, 0);
  return 0;
}