The aboveCodeIt is often used in the kernel. "_ attribute _" and "_ Section _" are keywords of the GCC compiler.
The above sectionProgramA Method for initializing a module is provided:
1. If a kernel module needs to be initialized when the system is started, you only need to call "module_init (Function
) "The GCC compiler will put the pointer of this function into a specific code segment (". initcall. init "code segment) when compiling the code );
2. When Linux is started, after the first kernel thread is generated, the do_initcils () function is called. initcall. the first address of the init code segment starts to call the initialization function one by one (there is no parameter for the system-defined initialization function );
From the two steps above, we can see that Linux uses the powerful functions of the GCC compiler to make initialization of modules simple and does not need to be registered in a special place, you only need to call "module_init (
Function) "This code can complete the work. GCC can decide whether to compile to the kernel or compile as a loaded Module Based on the Compilation options.
All source files of network code are stored in the "/net" directory. The core sub-directory under this directory is the core module, including the packet cache, neighbor table, device management, and other sub-modules. "Ethernet" sub-directory implementation 802.3
MAC layer features. The "IPv4" sub-directory implements the TCP/IP protocol, and the "IPv6" sub-directory implements the IPv6 protocol. Other subdirectories are unique in Linux.