Startup and Configuration¶
Configuration data and startup code for the kernel.
-
void
kernel_init
(void)¶ Initializes scheduler and creates main and idle task.
-
container_of
( PTR, TYPE, MEMBER)¶ Returns the container of a pointer to a member.
1
((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER)))
For a struct
TYPE
with a memberMEMBER
, given a pointerPTR
toTYPE::MEMBER
this function returns a pointer to the instance ofTYPE
.E.g. for
struct my_struct_t { ...; something_t n; ... } my_struct;
,&my_struct == container_of(&my_struct.n, struct my_struct_t, n)
.Parameters
PTR: pointer to a member TYPE: a type name (a struct or union), container of PTR MEMBER: name of the member of TYPE which PTR points to Return values
- Pointer to the container of PTR.
-
NORETURN
¶ The NORETURN keyword tells the compiler to assume that the function cannot return.
-
CONST
¶ A function declared as CONST is
kernel_defines.h::PURE
and also not allowed to examine global memory.I.e. a CONST function cannot even dereference a pointer parameter.
-
PURE
¶ The function has no effects except the return value and its return value depends only on the parameters and/or global variables.
Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be.
-
UNREACHABLE
()¶ Tell the compiler that this line of code cannot be reached.
1
do { /* nothing */ } while (1)
Most useful in junction with
kernel_defines.h::NORETURN
. Use this if the compiler cannot tell that e.g. an assembler instruction causes a longjmp, or a write causes a reboot.
-
ALIGN_OF
( T)¶ Calculate the minimal alignment for type T.
1
(offsetof(struct { char c; T t; }, t))
Parameters
T: Type to examine Return values
- The minimal alignment of T.
-
BUILD_BUG_ON
( condition)¶ Forces a compilation error if condition is true.
1
((void)sizeof(char[1 - 2 * !!(condition)]))
This trick is only needed if the condition can’t be evaluated before compile time (i.e. sizeof(sometype_t) < 42 ) For more details on this see for example: https://git.kernel.org/pub/scm/linux/kernel/git/stable/ linux-stable.git/tree/include/linux/bug.h
Parameters
condition: A condition that will be evaluated at compile time