Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert Linux virtual memory address to physical memory address

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to convert Linux virtual memory addresses into physical memory addresses". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and study and learn "how to convert Linux virtual memory addresses into physical memory addresses" together.

background

Modern mobile phones this SOC(system on chip), because power consumption, Modem and other functions SOC integrated a lot of core, they can also be independent systems in operation.

For example, ADSP(Application Digital Signal Processing) is a Hexagon DSP , which is a core+system that operates independently. This can not only use the dedicated core on the SOC to handle professional things, such as the ADSP mentioned above can handle audio decoding, of course, its DSP features can also handle sensor fusion algorithms, compared to general purpose processors (cortex a72 a53 a17 a9 a8 these cores) processing efficiency is higher, more power saving.

Of course, we won't solder a memory grain for it alone because of cost, it shares a portion of main memory, such as 1MB from address 0xc00000 - 0xc0100000, and the kernel (Linux running on general purpose processors) will no longer touch this memory.

However, there is also a disadvantage in sharing the same address space with multiple cores, that is, if the program has problems (wild pointers, array boundaries), it may write other core management memory space, which brings us the problem that the value of the program is inexplicably changed. In order to troubleshoot this problem, we considered converting the virtual address of the application to a physical address and performing print debug for unified analysis.

achieve

kernel added such a function/proc/self/pagemap in 2.6.25, that is, there is a pagemap in/proc of each process. By reading the contents inside, you can calculate the physical page corresponding to the current virtual address, and then add page_offset to know the physical address corresponding to the current virtual address.

Pagemap requires your app to have root privileges to use.

#include #include #include #include #include #include #include #include #include #include #include #include //Reference//https://www.kernel.org/doc/Documentation/vm/pagemap.txt #define page_map_file "/proc/self/pagemap" #define PFN_MASK ((((uint64_t)1)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report