При загрузке ядра ядра загрузчик должен разрешить каждый символ (функция), который используется ядром ядра.
Поскольку модули ядра недоступны при загрузке ядра ядра,ядро ядра не может напрямую использовать символы, определенные в модулях.
Однако ядро ядра может иметь указатель , который может быть инициализирован кодом модуля, когдаон загружен.Это можно рассматривать как некую процедуру регистрация :
foo.h :
// Header used by both kernel core and modules
// Register 'foo' function.
void register_foo(int (*foo)(void));
foo.c :
// compiled as a part of the kernel core
#include <foo.h>
// pointer to the registered function
static int (*foo_pointer)(void) = NULL;
// Implement the function provided by the header.
void register_foo(int (*foo)(void))
{
foo_pointer = foo;
}
// make registration function available for the module.
EXPORT_SYMBOL(register_foo);
// Calls foo function.
int call_foo(void)
{
if (foo_pointer)
return foo_pointer(); // call the registered function by pointer.
else
return 0; // in case no function is registered.
}
module.c :
// compiled as a module
#include <foo.h>
// Implement function
int foo(void)
{
return 1;
}
int __init module_init(void)
{
// register the function.
register_foo(&foo);
// ...
}