From 71a31cf4512c728040f5d7ed9270e14814bf03e0 Mon Sep 17 00:00:00 2001 From: Ali Javidi Ghasr <71215076+AliJavidiCS@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:14:20 +0330 Subject: [PATCH] Fix extracting pid form bpf_get_current_pid_tgid #35 According to `man bpf-helpers` pid is located in the lower 32 bits of the return value. Pid can be easily extracted by using an and operation with `0xFFFFFFFF` Signed-off-by: Ali Javidi Ghasr <71215076+AliJavidiCS@users.noreply.github.com> --- chapter2/hello-buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter2/hello-buffer.py b/chapter2/hello-buffer.py index 0f7a3d1..6d0bd53 100755 --- a/chapter2/hello-buffer.py +++ b/chapter2/hello-buffer.py @@ -15,7 +15,7 @@ struct data_t data = {}; char message[12] = "Hello World"; - data.pid = bpf_get_current_pid_tgid() >> 32; + data.pid = bpf_get_current_pid_tgid() & 0xFFFFFFFF; data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF; bpf_get_current_comm(&data.command, sizeof(data.command));