如何让C / C ++的内存存取类型++在Linux中 [英] how to get the memory access type in C/C++ in Linux

查看:80
本文介绍了如何让C / C ++的内存存取类型++在Linux中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/269314/is-there-a-better-way-than-parsing-proc-self-maps-to-figure-out-memory-protecti\">Is还有比分析的/ proc /自/图找出内存保护更好的办法?

我有一个指针,我想检查,如果引用的内存是否可读,可写和/或可执行文件。我怎样才能做到这一点?

I have a pointer and I want to check if the referenced memory is readable, writeable and/or executable. How can I do this?

推荐答案

您将不得不解析文件的/ proc /自/图,其中包含您的进程的内存映射,并检查其映射骗你的指针的值之内(如果有的话)。在的/ proc /自/图文件包含存储器保护(读/写/执行)。

You will have to parse the file /proc/self/maps which contains memory mappings of your process, and check which of the mappings lie within the value of your pointer (if any). The /proc/self/maps file contains the memory protection (read/write/execute).

请参阅这个问题有关地图文件的详细信息。

See this question for more info about the maps file.

这篇关于如何让C / C ++的内存存取类型++在Linux中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆