A2 Data Types

The kernel makes a basic distinction between the following three elementary data types:

□ Standard data types as used in every C program; for example, unsigned long, void *, and char. The number of bits that these types have is not fixed by the C standard. Only various inequalities are guaranteed; for instance, unsigned long has at least as many if not more bits than int.

In terms of portability, it should be noted that the bit size of standard data types can differ between architectures.

□ Data types with a fixed number of bits. The kernel provides special integer data types with names like u32 and s16 for unsigned (u) and signed (s) integers with a predefined number of bits. The individual architectures must define the abbreviations in such a way that they can be mapped (using typedef) to corresponding elementary data types.

□ Subsystem-specific types that are never manipulated directly but always by specially written functions. Converting the data type definition is easy, because all subsystems that use any of these data types are never able to manipulate them directly but must delegate this task to the specific subsystem. Only the standard manipulation functions need to be modified; the remaining kernel parts remain unchanged.

Examples of subsystem-specific data types are pid_t for managing pids and sector_t for identifying sector numbers.

The data types with a fixed number of bits are defined in <asm-arch/types.h>.

The pre-processor constant_kernel_must always be defined before the file is linked into the kernel sources; otherwise, only data type names prefixed with a double underscore are defined (for example,_u32) to prevent overlaps with definitions in the userspace namespace.

Continue reading here: A3 Alignment

Was this article helpful?

0 0