@@ -124,6 +124,13 @@ int probe_stack(struct pt_regs* ctx) {
124124 return 0 ;
125125}
126126
127+ struct {
128+ __uint (type , BPF_MAP_TYPE_HASH );
129+ __type (key , u32 );
130+ __type (value , u32 );
131+ __uint (max_entries , MAX_WATCH_PROC_COUNT );
132+ } watch_proc_map SEC (".maps" );
133+
127134// raw_tracepoint hook
128135
129136struct {
@@ -139,10 +146,6 @@ typedef struct point_arg_t {
139146} point_arg ;
140147
141148#define MAX_POINT_ARG_COUNT 6
142- // typedef struct point_args_t {
143- // u32 count;
144- // point_arg_t point_args[MAX_POINT_ARG_COUNT];
145- // } point_args;
146149
147150typedef struct syscall_point_args_t {
148151 // u32 nr;
@@ -151,13 +154,6 @@ typedef struct syscall_point_args_t {
151154 point_arg point_arg_ret ;
152155} syscall_point_args ;
153156
154- // struct {
155- // __uint(type, BPF_MAP_TYPE_HASH);
156- // __type(key, u32);
157- // __type(value, struct point_args_t);
158- // __uint(max_entries, 512);
159- // } point_args_map SEC(".maps");
160-
161157// syscall_point_args_map 的 key 就是 nr
162158struct {
163159 __uint (type , BPF_MAP_TYPE_HASH );
@@ -166,17 +162,6 @@ struct {
166162 __uint (max_entries , 512 );
167163} syscall_point_args_map SEC (".maps" );
168164
169- // struct arg_ret_mask_t {
170- // u32 ret_mask;
171- // };
172-
173- // struct {
174- // __uint(type, BPF_MAP_TYPE_HASH);
175- // __type(key, u32);
176- // __type(value, struct arg_ret_mask_t);
177- // __uint(max_entries, 512);
178- // } arg_ret_mask_map SEC(".maps");
179-
180165// syscall过滤配置
181166struct syscall_filter_t {
182167 u32 is_32bit ;
@@ -255,6 +240,34 @@ static __always_inline u32 read_args(program_data_t p, struct point_arg_t* point
255240 return next_arg_index ;
256241}
257242
243+ SEC ("raw_tracepoint/sched_process_fork" )
244+ int tracepoint__sched__sched_process_fork (struct bpf_raw_tracepoint_args * ctx )
245+ {
246+ long ret = 0 ;
247+ program_data_t p = {};
248+ if (!init_program_data (& p , ctx ))
249+ return 0 ;
250+
251+ struct task_struct * parent = (struct task_struct * ) ctx -> args [0 ];
252+ struct task_struct * child = (struct task_struct * ) ctx -> args [1 ];
253+
254+ // 为了实现仅指定单个pid时 能追踪其产生的子进程的相关系统调用 设计如下
255+ // 维护一个 map
256+ // - 其 key 为进程 pid
257+ // - 其 value 为其父进程 pid
258+ // 逻辑如下
259+ // 当进入此处后,先获取进程本身信息,然后通过自己的父进程 pid 去 map 中取出对应的value
260+ // 如果没有取到则说明这个进程不是要追踪的进程
261+ // 取到了,则说明这个是之前产生的进程,然后向map存入进程信息 key 就是进程本身 pid 而 value则是父进程pid
262+ // 那么最开始的 pid 从哪里来呢 答案是从首次通过 sys_enter 的过滤之后 向该map存放第一个key value
263+ // 1. parent_child_map => {}
264+ // 2. 出现第一个通过 sys_enter 处的过滤的进程,则更新map -> parent_child_map => {12345: 12345}
265+ // 3. sched_process_fork 获取进程的父进程信息,检查map,发现父进程存在其中,则更新map -> parent_child_map => {12345: 12345, 22222: 12345}
266+ // 4. sys_enter/sys_exit 有限次遍历 parent_child_map 取出key逐个比较当前进程的pid
267+ // 待实现...
268+ return 0 ;
269+ }
270+
258271SEC ("raw_tracepoint/sys_enter" )
259272int raw_syscalls_sys_enter (struct bpf_raw_tracepoint_args * ctx ) {
260273
0 commit comments