Linuxloadablemodule mechanism and Inspiration

Source: Internet
Author: User
Linuxloadablemodule mechanism and inspiration-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1, EXPORT_SYMBOL

EXPORT_SYMBOL (my_pub_func );
In the pre-compilation phase, it will be parsed:
Extern void * _ crc_my_pub_func _ attribute _ (weak ));
Static const unsigned long _ kcrctab_my_pub_func _ attribute _ (_ used _) _ attribute _ (section ("_ kcrctl """), unused) = (unsigned long) & __ crc_my_pub_func;
Static const char _ kstrtab_my_pub_func [] _ attribute _ (section ("_ ksymtab_strings") = "my_pub_func ";
Static const struct kernel_symbol _ ksymtab_my_pub_func _ attribute _ (_ used _) _ attribute _ (section ("_ ksymtab """), unused) = {(unsigned long) & my_pub_func, _ kstrtab_my_pub_func };

Obviously _ ksymtab_my_pub_func stores the address and Symbol Information of my_pub_func. The address corresponding to this symbol
It will only be confirmed after insmod;
_ Ksymtab_my_pub_func is linked to _ ksymtab section ,__ all content in the ksymtab section constitutes
Kernel "Export" symbol table, which is used in insmod.

2,/proc/kallsyms
Cat/proc/kallsyms prints the current symbol table of the kernel, for example:
...
D8834a24 t snd_free_sgbuf_pages [snd_page_alloc]
C0180d7a U create_proc_entry [snd_page_alloc]
D88341d8 T snd_dma_free_pages [snd_page_alloc]
C013d858 U _ get_free_pages [snd_page_alloc]
D8834ab5 t snd_malloc_sgbuf_pages [snd_page_alloc]
C014f906 U kmem_cache_alloc [snd_page_alloc]
C01_dcd U dma_alloc_coherent [snd_page_alloc]
...
The first column is the address of the symbol in the kernel address space; the second column is the symbol attribute, which is expressed in lower case.
Local symbols. uppercase indicates the global symbol. For more information, see man nm. The third column indicates the symbol string.

3. What do I need to do with insmod module_name.ko?
(1) memory needs to be allocated to allocate the symbols contained in the module to the kernel address space;
2), parse the external symbols called in this module from the kernel symbol table, and use the resolved real address
Replace the symbolic address.

4. Some Inspiration
The kernel-loaded module mechanism is similar to the dynamic link mechanism, but the idea is very simple. Some embedded
System (such as mp3/mp4/cell phone System) RAM space is very limited, and smaller SDRAM facilitates
Reduce power consumption and improve product competitiveness, and these products have unlimited external storage requirements (generally
Integrates large-capacity nand flash, which is determined by product features). At the same time, such systems need to be integrated.
More and more functions, but these functions are often run independently, which is suitable for some functional modules.
It is block-based and loaded to the system memory when needed, and unmounted when not needed.
Inspired by the module loading mechanism, it is easy to implement a mechanism similar to dynamic link, saving system memory.
This mechanism is easy to operate in some simple embedded environments (such as ucos
System.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.