Repository navigation
Expand file tree
/
Copy pathprocess.bt
More file actions
47 lines (45 loc) · 1.72 KB
/
Copy pathprocess.bt
File metadata and controls
47 lines (45 loc) · 1.72 KB
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
macro __signal(expr, is_tid)
{
import "stdlib/process/process.bpf.c";
let $sig : uint32 = 0;
if comptime (probetype != "kprobe" && probetype != "kretprobe" &&
probetype != "uprobe" && probetype != "uretprobe" &&
probetype != "usdt" && probetype != "tracepoint" &&
probetype != "profile" && probetype != "fentry" &&
probetype != "fexit" && probetype != "rawtracepoint") {
fail("%s can not be used for this probetype %s",
is_tid ? "signal_thread()" : "signal()", probetype);
}
if comptime __builtin_safe_mode {
fail("%s is unsafe. To use you need the --unsafe flag",
is_tid ? "signal_thread()" : "signal()");
} else if comptime is_literal(expr) {
if comptime is_str(expr) {
$sig = __builtin_signal_num(expr);
} else if comptime is_integer(expr) {
if comptime (expr < 1 || expr > 64) {
fail("%s accepts a string literal or an integer between 1 and 64 (inclusive)",
is_tid ? "signal_thread()" : "signal()");
} else {
$sig = (uint32)expr;
}
} else {
fail("%s accepts a string literal or a positive integer",
is_tid ? "signal_thread()" : "signal()");
}
} else if comptime (!is_integer(expr)) {
fail("%s accepts a string literal or an integer",
is_tid ? "signal_thread()" : "signal()");
} else {
$sig = (uint32)expr;
}
if ($sig == 0 || $sig > 64) {
errorf("%s expects an integer between 1 and 64 (inclusive). Got %d",
is_tid ? "signal_thread()" : "signal()", $sig);
} else {
$ret = comptime is_tid ? __signal_thread($sig) : __signal_process($sig);
if ($ret != 0) {
warnf("signal call failed with error %d", $ret);
}
}
}