Skip to content

Commit

Permalink
gotls:get ret_len by register in go >1.17
Browse files Browse the repository at this point in the history
Signed-off-by: Kunhai Dai <[email protected]>
  • Loading branch information
Kunhai Dai committed Sep 14, 2024
1 parent a335b44 commit 024b026
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kern/gotls_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@ static __always_inline int gotls_read(struct pt_regs *ctx,
str = (void *)go_get_argument_by_stack(ctx, 2);
len_ptr = (void *)go_get_argument_by_stack(ctx, 3);
bpf_probe_read_kernel(&len, sizeof(len), (void *)&len_ptr);

// Read函数的返回值第一个是int类型,存放在栈里的顺序是5
ret_len_ptr = (void *)go_get_argument_by_stack(ctx, 5);
bpf_probe_read_kernel(&ret_len, sizeof(ret_len), (void *)&ret_len_ptr);
if (len <= 0) {
return 0;
}

if (is_register_abi) {
ret_len = (int)go_get_argument_by_reg(ctx, 1);
} else {
// Read函数的返回值第一个是int类型,存放在栈里的顺序是5
ret_len_ptr = (void *)go_get_argument_by_stack(ctx, 5);
bpf_probe_read_kernel(&ret_len, sizeof(ret_len), (void *)&ret_len_ptr);
}
if (ret_len <= 0 ) {
return 0;
}
Expand Down

0 comments on commit 024b026

Please sign in to comment.