0001
0002
0003
0004
0005 #include <linux/kernel.h>
0006 #include <linux/module.h>
0007 #include <linux/kobject.h>
0008 #include <linux/init.h>
0009 #include <linux/sysfs.h>
0010
0011
0012 extern char __weak __start_BTF[];
0013 extern char __weak __stop_BTF[];
0014
0015 static ssize_t
0016 btf_vmlinux_read(struct file *file, struct kobject *kobj,
0017 struct bin_attribute *bin_attr,
0018 char *buf, loff_t off, size_t len)
0019 {
0020 memcpy(buf, __start_BTF + off, len);
0021 return len;
0022 }
0023
0024 static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {
0025 .attr = { .name = "vmlinux", .mode = 0444, },
0026 .read = btf_vmlinux_read,
0027 };
0028
0029 struct kobject *btf_kobj;
0030
0031 static int __init btf_vmlinux_init(void)
0032 {
0033 bin_attr_btf_vmlinux.size = __stop_BTF - __start_BTF;
0034
0035 if (!__start_BTF || bin_attr_btf_vmlinux.size == 0)
0036 return 0;
0037
0038 btf_kobj = kobject_create_and_add("btf", kernel_kobj);
0039 if (!btf_kobj)
0040 return -ENOMEM;
0041
0042 return sysfs_create_bin_file(btf_kobj, &bin_attr_btf_vmlinux);
0043 }
0044
0045 subsys_initcall(btf_vmlinux_init);