My distro (Ubuntu 14.04.3 LTS) doesn't seem to export this reference so I can't resolve the address at module load time. I'm looking for another way to determine the address without a kernel re-compile.
I'm running as a guest under VMware Fusion on a macbook pro. Kernel is 3.13.0-74-generic.
Thanks in advance
Use
kallsyms_lookup_name
. It is defined inlinux/kallsyms.h
asUsage is trivial:
kallsyms_lookup_name
is exported for modules since kernel 2.6.33.For earlier kernels, or for find several symbols at once, generic function
kallsyms_on_each_symbol
can be used. It iterates over all symbols and calls user-specified function for them.Maybe this answer is too late for you @owenh . I am answering it for people who are looking for the same question about mem_map array. Because so far I can not find any clear answer about why mem_map can not be found. After tracing into how
pte_page
works, I record whatever I learn here.If you can not find mem_map array, it is possible because the kernel is using virtually contiguous mem_map or the sparse memory model is used, both of which do not have a physically contiguous mem_map array. Instead, it may have a
vmemmap
ormem_section
as a starting point to find all thepage struct
. This is decided by these macros (CONFIG_FLATMEM/DISCONTIGMEM/CONFIG_SPARSEMEM_VMEMMAP/CONFIG_SPARSEMEM
) ininclude/asm-generic/memory_model.h
. You can check your kernel compilation config flags using something likeIn
CONFIG_SPARSEMEM_VMEMMAP
mode, thepage struct
array starts from vmemmap, which is at a fixed location 0xffffea0000000000.While, in
CONFIG_SPARSEMEM
mode, thepage struct
array is managed through an 2-dimensional array called mem_section.In order to know how kernel uses it, we can learn from how kernel get a
page struct
of a page given apte
of a page. This macro is calledpte_page
(inarch/x86/include/asm/pgtable.h
). It transform the pte into itpfn
. Using thatpfn
, it can locate the thepage struct
either using vmemmap or mem_section. This is ininclude/asm-generic/memory_model.h
.