总线错误:10时扫描地址空间在c



我正在尝试扫描地址空间以找到具有读/写权限的内存块。每个页面检查一个地址是可以接受的,因为每个页面都有相同的权限。我知道我应该得到分段错误:11当试图写一块内存,我不应该能够。这种情况发生在我试图访问更高的地址时,但是当我在较低的部分时,比如0x00000100,我得到总线错误:10。

注意:代码是用-m32标志编译的,所以它模拟了一个32位的机器。

同时注意:在调用chunk_list函数之前,chunk_list的内存已经被malloc了

我复制了下面的代码:
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include "memchunk.h" 

int get_mem_layout (struct memchunk *chunk_list, int size)
{
//grab the page size
long page = sysconf(_SC_PAGESIZE);
printf("The page size for this system is %ld bytesn", page);
//page size is 4069 bytes
//test printing the number of words on a page
long words = page / 4;  
printf("Which works out to %ld words per pagen", words);
//works out to 1024 words a page
//1024 = 0x400
//create the addy pointer
    //start will be used after bus error: 10 is solved
void *start;
char * currAddy;
currAddy = (char*)0x01000000;
//someplace to store the addy to write to
//char * testWrite;

//looping through the first size pages
int i;
for(i = 0; i < size; i++){
    //chunk start - wrong addy being written just testing
    chunk_list[i].start = currAddy;
    printf("addy is %pn",currAddy);
    sleep(1);
    //try and write to the current addy
    //testWrite = currAddy;
    //*testWrite = 'a';
    *currAddy = '1';

    //+= 0x400 to get to next page
    currAddy += 0x400;
}

//while loop here for all the addys - not there yet because still dealing with bus error: 10
return 0;

}

任何帮助都将非常感激。我还在代码中注释了一些其他尝试,但仍然会在内存空间的下部产生总线错误:10。

编辑:我将使用信号处理segfault。我知道如何处理segfault,所以有一种方法来处理总线错误:10使用信号,以及?

读取或写入未映射的内存被认为会导致总线故障。要发现内存是否存在,请为segfault安装一个处理程序以做出相应的反应。

在Linux SE(安全增强)进程中,程序部分在随机位置加载,以阻止病毒能够依赖稳定的地址。

在大多数虚拟内存系统中,非映射空间通常从地址0开始,因此试图解引用NULL指针或基于NULL指针的结构会导致异常。在20世纪80年代,空白空间通常是64K到256K。在现代体系结构中,16M是检测基于null的访问的合理选择。

在许多虚拟内存系统中,有一个系统调用来获取每个进程映射的内存位置。Linux操作系统下,检查/proc/self/maps的内容

最新更新