'Function pointer: physical or virtual address

When we get the address of a function (or any object, for that matter), is it the virtual address or physical address of that object??

c


Solution 1:[1]

Are you asking about pointers in general?

On most operating systems, they are logical addresses.

The operating system is responsible for translating them into physical addresses through the virtual memory and paging mechanism. This is transparent to the program. That's why a misguided program "hits the boundaries" and GPFs.

On some old systems (e.g., DOS), they would be physical, allowing you to overwrite stuff in other parts of memory.

Solution 2:[2]

Depends on the OS and at what level your code is running.

For a normal user-land program on a modern OS, you will get the virtual address.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Uri
Solution 2 Tyler McHenry