函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\bpf\btf.c Create Date:2022-07-27 14:39:06
首页 Copyright©Brick

3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
int btf_distill_func_proto(struct bpf_verifier_log *log,
               struct btf *btf,
               const struct btf_type *func,
               const char *tname,
               struct btf_func_model *m)
{
    const struct btf_param *args;
    const struct btf_type *t;
    u32 i, nargs;
    int ret;
 
    if (!func) {
        /* BTF function prototype doesn't match the verifier types.
         * Fall back to 5 u64 args.
         */
        for (i = 0; i < 5; i++)
            m->arg_size[i] = 8;
        m->ret_size = 8;
        m->nr_args = 5;
        return 0;
    }
    args = (const struct btf_param *)(func + 1);
    nargs = btf_type_vlen(func);
    if (nargs >= MAX_BPF_FUNC_ARGS) {
        bpf_log(log,
            "The function %s has %d arguments. Too many.\n",
            tname, nargs);
        return -EINVAL;
    }
    ret = __get_type_size(btf, func->type, &t);
    if (ret < 0) {
        bpf_log(log,
            "The function %s return type %s is unsupported.\n",
            tname, btf_kind_str[BTF_INFO_KIND(t->info)]);
        return -EINVAL;
    }
    m->ret_size = ret;
 
    for (i = 0; i < nargs; i++) {
        ret = __get_type_size(btf, args[i].type, &t);
        if (ret < 0) {
            bpf_log(log,
                "The function %s arg%d type %s is unsupported.\n",
                tname, i, btf_kind_str[BTF_INFO_KIND(t->info)]);
            return -EINVAL;
        }
        m->arg_size[i] = ret;
    }
    m->nr_args = nargs;
    return 0;
}