I have searched the answer to my question for hours, to no avail.
My question: I want to define a variable that can be accessed(w/r)(shared) by the two files in linux kernel: source/arch/x86/kvm/x86.c
and source/kernel/sched/core.c
.
My failed attempt: I tried to use export_symbol
to define a global var in x86.c
. But the compile error message says:
the var is undefined reference
Is there any other solution? I am new to linux kernel programming. Thanks in advance.
When you use want to use a global variable in kernel modules, you should use the EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() or EXPORT_SYMBOL_GPL_FUTURE(): Eg:
int myvar;
EXPORT_SYMBOL(myvar);
you should then use
extern int myvar
in the other file where you want to use it, before you use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With