Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
0003 
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/usdt.bpf.h>
0007 
0008 int my_pid;
0009 
0010 int usdt0_called;
0011 u64 usdt0_cookie;
0012 int usdt0_arg_cnt;
0013 int usdt0_arg_ret;
0014 
0015 SEC("usdt")
0016 int usdt0(struct pt_regs *ctx)
0017 {
0018     long tmp;
0019 
0020     if (my_pid != (bpf_get_current_pid_tgid() >> 32))
0021         return 0;
0022 
0023     __sync_fetch_and_add(&usdt0_called, 1);
0024 
0025     usdt0_cookie = bpf_usdt_cookie(ctx);
0026     usdt0_arg_cnt = bpf_usdt_arg_cnt(ctx);
0027     /* should return -ENOENT for any arg_num */
0028     usdt0_arg_ret = bpf_usdt_arg(ctx, bpf_get_prandom_u32(), &tmp);
0029     return 0;
0030 }
0031 
0032 int usdt3_called;
0033 u64 usdt3_cookie;
0034 int usdt3_arg_cnt;
0035 int usdt3_arg_rets[3];
0036 u64 usdt3_args[3];
0037 
0038 SEC("usdt//proc/self/exe:test:usdt3")
0039 int usdt3(struct pt_regs *ctx)
0040 {
0041     long tmp;
0042 
0043     if (my_pid != (bpf_get_current_pid_tgid() >> 32))
0044         return 0;
0045 
0046     __sync_fetch_and_add(&usdt3_called, 1);
0047 
0048     usdt3_cookie = bpf_usdt_cookie(ctx);
0049     usdt3_arg_cnt = bpf_usdt_arg_cnt(ctx);
0050 
0051     usdt3_arg_rets[0] = bpf_usdt_arg(ctx, 0, &tmp);
0052     usdt3_args[0] = (int)tmp;
0053 
0054     usdt3_arg_rets[1] = bpf_usdt_arg(ctx, 1, &tmp);
0055     usdt3_args[1] = (long)tmp;
0056 
0057     usdt3_arg_rets[2] = bpf_usdt_arg(ctx, 2, &tmp);
0058     usdt3_args[2] = (uintptr_t)tmp;
0059 
0060     return 0;
0061 }
0062 
0063 int usdt12_called;
0064 u64 usdt12_cookie;
0065 int usdt12_arg_cnt;
0066 u64 usdt12_args[12];
0067 
0068 SEC("usdt//proc/self/exe:test:usdt12")
0069 int BPF_USDT(usdt12, int a1, int a2, long a3, long a4, unsigned a5,
0070              long a6, __u64 a7, uintptr_t a8, int a9, short a10,
0071              short a11, signed char a12)
0072 {
0073     if (my_pid != (bpf_get_current_pid_tgid() >> 32))
0074         return 0;
0075 
0076     __sync_fetch_and_add(&usdt12_called, 1);
0077 
0078     usdt12_cookie = bpf_usdt_cookie(ctx);
0079     usdt12_arg_cnt = bpf_usdt_arg_cnt(ctx);
0080 
0081     usdt12_args[0] = a1;
0082     usdt12_args[1] = a2;
0083     usdt12_args[2] = a3;
0084     usdt12_args[3] = a4;
0085     usdt12_args[4] = a5;
0086     usdt12_args[5] = a6;
0087     usdt12_args[6] = a7;
0088     usdt12_args[7] = a8;
0089     usdt12_args[8] = a9;
0090     usdt12_args[9] = a10;
0091     usdt12_args[10] = a11;
0092     usdt12_args[11] = a12;
0093     return 0;
0094 }
0095 
0096 char _license[] SEC("license") = "GPL";