English 中文(简体)
毫米:不允许的行动
原标题:mmap: Operation not permitted
  • 时间:2011-11-21 14:47:40
  •  标签:
  • c
  • linux

我正试图在用户空间使用微粒,读一下从肉体开始的记忆。 它包含所有物理页。 这台机器是1 386台,运行3台。

这部法典就是这样:

....

//define page size
//
#define PAGE_SIZE 0x1000 //4096 bytes
#define PAGE_MASK (PAGE_SIZE - 1)

....

  /* open /dev/mem file*/
  if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
        printf("/dev/mem could not be opened.
");
    perror("open");
        exit(1);
  } else {
    printf("/dev/mem opened.
");
  }

  /* Map one page */
  printf(" mem_map is at physical addr: 0x%x
", mem_map_phy_addr);

  map_base = mmap(0, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, (mem_map_phy_addr & ~PAGE_MASK)); //mem_map_phy_addr is at 0x356f2000

  if(map_base == (void *) -1) {
    printf("Memory map failed. err num = %d
",errno);
    perror("mmap"); //failed here
  } else {
    printf("Memory mapped at address %p.
", map_base);
  }

I ran this as a root. The output is:

/dev/mem opened.
 mem_map is at physical addr: 0x356f2000
Memory map failed. err num = 1
mmap: Operation not permitted

我肯定会把这一问题推向我/etc/sysctl.conf的档案,并添加以下内容:

vm.mmap_min_addr = 0

但这也不可行。

Anyone knows why mem_map operation like this is not permitted and how I can get around it?

感谢。

最佳回答

能够编成<>CONFIG_STRICT_DEV MEM/code>。 这是防止用户空间在1MB(IIRC)上空获得(可能敏感)物理记忆的一种安全特征。 你们也许能够用精炼的炉.灭.。

问题回答

我在试图用闪光在APU2c4委员会(APU2c4)上,使用A Archlav时,也遇到了同样的问题。

在我的系统中,如果使用自制的纸浆,则我别无选择。

我通过制定<条码>iomem来解决这个问题。 缩略语 Grub:

# /boot/grub/grub.cfg
linux   /boot/vmlinuz-linux iomem=relaxed

当然,这一解决办法是boot。

Reference:
https://www.reddit.com/r/libreboot/comments/6wvyry/flashrom_failures_to_access/
https://www.flashrom.org/FAQ
https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签