Organizing Data in Memory

layout_sections is used to decide which sections of the module are to be loaded at which positions in memory or which modules must be copied from their temporary address. The sections are split into two parts: core and init. While the first contains all code sections required during the entire run time of the module, the kernel places all initialization data and functions in a separate part that is removed when loading is completed.

Module sections are not transferred to their final memory position unless the shf_alloc flag is set in their header.16 For example, this flag is not set for sections with debugging information (produced when the gcc option -g is used) because these data need not be present in memory and can be read from the binary file if needed.

layout_sections checks whether the name of a section contains the .init string. This enables a distinction to be made between initialization code and regular code; accordingly, the start position of the section refers to the core or to the init section.

The result of layout_sections is communicated using the following elements:

□ sh_entsize in the ELF section data structure, of which there is one instance for each section, indicates the relative position of the section in the core or initialization area. If a section is not to be loaded, the value is set to ~0UL.

To then differentiate between initialization and core sections, the init_offset_mask bit (defined by (1UL << (bits_per_long-1)) )issetin sh_entsize. This stores the relative position of all init modules.

□ core_size is used to transfer the total code size that is to reside in the kernel permanently, at least until the module is unloaded. init_size totals the volumes of all sections that are required for module initialization.

Continue reading here: Transferring Data

Was this article helpful?

0 0