Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Provide kernel headers useful to build tracing programs
0004  * such as for running eBPF tracing tools.
0005  *
0006  * (Borrowed code from kernel/configs.c)
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/module.h>
0011 #include <linux/kobject.h>
0012 #include <linux/init.h>
0013 
0014 /*
0015  * Define kernel_headers_data and kernel_headers_data_end, within which the
0016  * compressed kernel headers are stored. The file is first compressed with xz.
0017  */
0018 
0019 asm (
0020 "   .pushsection .rodata, \"a\"     \n"
0021 "   .global kernel_headers_data     \n"
0022 "kernel_headers_data:               \n"
0023 "   .incbin \"kernel/kheaders_data.tar.xz\" \n"
0024 "   .global kernel_headers_data_end     \n"
0025 "kernel_headers_data_end:           \n"
0026 "   .popsection             \n"
0027 );
0028 
0029 extern char kernel_headers_data;
0030 extern char kernel_headers_data_end;
0031 
0032 static ssize_t
0033 ikheaders_read(struct file *file,  struct kobject *kobj,
0034            struct bin_attribute *bin_attr,
0035            char *buf, loff_t off, size_t len)
0036 {
0037     memcpy(buf, &kernel_headers_data + off, len);
0038     return len;
0039 }
0040 
0041 static struct bin_attribute kheaders_attr __ro_after_init = {
0042     .attr = {
0043         .name = "kheaders.tar.xz",
0044         .mode = 0444,
0045     },
0046     .read = &ikheaders_read,
0047 };
0048 
0049 static int __init ikheaders_init(void)
0050 {
0051     kheaders_attr.size = (&kernel_headers_data_end -
0052                   &kernel_headers_data);
0053     return sysfs_create_bin_file(kernel_kobj, &kheaders_attr);
0054 }
0055 
0056 static void __exit ikheaders_cleanup(void)
0057 {
0058     sysfs_remove_bin_file(kernel_kobj, &kheaders_attr);
0059 }
0060 
0061 module_init(ikheaders_init);
0062 module_exit(ikheaders_cleanup);
0063 
0064 MODULE_LICENSE("GPL v2");
0065 MODULE_AUTHOR("Joel Fernandes");
0066 MODULE_DESCRIPTION("Echo the kernel header artifacts used to build the kernel");