Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Kernel - why a function's address in System.map is one byte preceding its address as seen in real time?

In linux kernel source code, added this lines in tasklet_action code:

printk("tasklet_action = %p\n" , *tasklet_action);
printk("tasklet_action = %p\n" , &tasklet_action);
printk("tasklet_action = %p\n" , tasklet_action);

In the output I get:

tasklet_action = c03441a1
tasklet_action = c03441a1
tasklet_action = c03441a1

But when searching it in the system.map file the tasklet_action address is at c03441a0 so there is an offset of 1 byte.

  • Why do I have this offset?
  • Is it always an one byte offset?
like image 986
0x90 Avatar asked Jan 02 '13 10:01

0x90


People also ask

Why is kernel mapped to the same address space as processes?

The reason why kernel is mapped into userspace is mostly performance-related. Kernel can also set own different page table at any time to access physical memory it wants, but that would also trash all caches and degrade performance dramatically.

How kernel uses the address space?

The kernel address space is statically mapped into the address space. The top 1 GB of the user's space is reserved for system elements while the bottom 1 GB holds the user code, data, stack, and heap.

What is memory mapping in Linux?

Memory mapping is one of the most interesting features of a Unix system. From a driver's point of view, the memory-mapping facility allows direct memory access to a user space device. To assign a mmap() operation to a driver, the mmap field of the device driver's struct file_operations must be implemented.

What is the address where the kernel starts?

The TEXT_OFFSET is a small, typically 32KB area above the kernel RAM in both physical and virtual memory space. The location of the kernel in the physical RAM at 0x10000000 is just an example, this can be on any even 16MB boundary.


1 Answers

My guess is that you are running on ARM in Thumb mode, or on some other architecture that uses the bottom bit of the function pointer to indicate which mode to run in.

If so, the answer is that your function really is located at the address in the system.map.

The value you get at run time is the location and the mode.

Instructions, on these kinds of architectures, always must be 2- or 4-byte aligned, which would leave the bottom bit always zero. When the architecture grew an extra mode the designers made use of the 'wasted' bit to encode the mode. It's clever, but confusing, and not just for you: a lot of software, like debuggers, broke in many nasty ways when this was first invented.

The concept is particularly confusing for x86 programmers who are used to variable-length instructions with any random alignment.

like image 95
ams Avatar answered Oct 01 '22 23:10

ams