xref: /linux/kernel/configs.c (revision 2b089bf8d19c66f70ae3b2d2d101be1ae49bfe24)
1*2b089bf8SThomas Huth // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * kernel/configs.c
41da177e4SLinus Torvalds  * Echo the kernel .config file used to build the kernel
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Copyright (C) 2002 Khalid Aziz <khalid_aziz@hp.com>
7f4b09ebcSAdrian Bunk  * Copyright (C) 2002 Randy Dunlap <rdunlap@xenotime.net>
81da177e4SLinus Torvalds  * Copyright (C) 2002 Al Stone <ahs3@fc.hp.com>
91da177e4SLinus Torvalds  * Copyright (C) 2002 Hewlett-Packard Company
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <linux/kernel.h>
131da177e4SLinus Torvalds #include <linux/module.h>
141da177e4SLinus Torvalds #include <linux/proc_fs.h>
151da177e4SLinus Torvalds #include <linux/seq_file.h>
161da177e4SLinus Torvalds #include <linux/init.h>
177c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds /*
2013610aa9SMasahiro Yamada  * "IKCFG_ST" and "IKCFG_ED" are used to extract the config data from
2113610aa9SMasahiro Yamada  * a binary kernel image or a module. See scripts/extract-ikconfig.
221da177e4SLinus Torvalds  */
2313610aa9SMasahiro Yamada asm (
2413610aa9SMasahiro Yamada "	.pushsection .rodata, \"a\"		\n"
2513610aa9SMasahiro Yamada "	.ascii \"IKCFG_ST\"			\n"
2613610aa9SMasahiro Yamada "	.global kernel_config_data		\n"
2713610aa9SMasahiro Yamada "kernel_config_data:				\n"
2813610aa9SMasahiro Yamada "	.incbin \"kernel/config_data.gz\"	\n"
2913610aa9SMasahiro Yamada "	.global kernel_config_data_end		\n"
3013610aa9SMasahiro Yamada "kernel_config_data_end:			\n"
3113610aa9SMasahiro Yamada "	.ascii \"IKCFG_ED\"			\n"
3213610aa9SMasahiro Yamada "	.popsection				\n"
3313610aa9SMasahiro Yamada );
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #ifdef CONFIG_IKCONFIG_PROC
361da177e4SLinus Torvalds 
3713610aa9SMasahiro Yamada extern char kernel_config_data;
3813610aa9SMasahiro Yamada extern char kernel_config_data_end;
3913610aa9SMasahiro Yamada 
401da177e4SLinus Torvalds static ssize_t
411da177e4SLinus Torvalds ikconfig_read_current(struct file *file, char __user *buf,
421da177e4SLinus Torvalds 		      size_t len, loff_t * offset)
431da177e4SLinus Torvalds {
4485badbdfSAkinobu Mita 	return simple_read_from_buffer(buf, len, offset,
4513610aa9SMasahiro Yamada 				       &kernel_config_data,
4613610aa9SMasahiro Yamada 				       &kernel_config_data_end -
4713610aa9SMasahiro Yamada 				       &kernel_config_data);
481da177e4SLinus Torvalds }
491da177e4SLinus Torvalds 
5015ad7cdcSHelge Deller static const struct file_operations ikconfig_file_ops = {
511da177e4SLinus Torvalds 	.owner = THIS_MODULE,
521da177e4SLinus Torvalds 	.read = ikconfig_read_current,
536038f373SArnd Bergmann 	.llseek = default_llseek,
541da177e4SLinus Torvalds };
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds static int __init ikconfig_init(void)
571da177e4SLinus Torvalds {
581da177e4SLinus Torvalds 	struct proc_dir_entry *entry;
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds 	/* create the current config file */
61c33fff0aSDenis V. Lunev 	entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
62c33fff0aSDenis V. Lunev 			    &ikconfig_file_ops);
631da177e4SLinus Torvalds 	if (!entry)
641da177e4SLinus Torvalds 		return -ENOMEM;
651da177e4SLinus Torvalds 
6613610aa9SMasahiro Yamada 	proc_set_size(entry, &kernel_config_data_end - &kernel_config_data);
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds 	return 0;
691da177e4SLinus Torvalds }
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds static void __exit ikconfig_cleanup(void)
721da177e4SLinus Torvalds {
73c74c120aSAlexey Dobriyan 	remove_proc_entry("config.gz", NULL);
741da177e4SLinus Torvalds }
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds module_init(ikconfig_init);
771da177e4SLinus Torvalds module_exit(ikconfig_cleanup);
781da177e4SLinus Torvalds 
79626a0312SStephen Boyd #endif /* CONFIG_IKCONFIG_PROC */
80626a0312SStephen Boyd 
811da177e4SLinus Torvalds MODULE_LICENSE("GPL");
821da177e4SLinus Torvalds MODULE_AUTHOR("Randy Dunlap");
831da177e4SLinus Torvalds MODULE_DESCRIPTION("Echo the kernel .config file used to build the kernel");
84