Arceos-monolithic / Starry

An experimental modular OS written in Rust.
http://rcore-os.cn/arceos/
Apache License 2.0
12 stars 15 forks source link

简单重复调用mmap多次后, 分配地址到VA:0x8000000会出现panic #31

Closed YXalix closed 5 months ago

YXalix commented 5 months ago

以下是测试代码, 测试 arch=aarch64,

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

#define FILEPATH "/tmp/mmapped.bin"
#define NUMINTS  (1000)
#define FILESIZE (NUMINTS * sizeof(int))

int main(int argc, char *argv[])
{
    int i;
    int fd;
    int *map;  /* mmapped array of int's */

    int sz = 0;
    while (sz <= 0x8000000) {
        map = mmap(0, FILESIZE * 8, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS , -1, 0);
        sz += FILESIZE * 8;
    }
    return 0;
}

报错LOG如下

[ 20.927260 0:6 axstarry::syscall:23] [syscall] id = MMAP, args = [0, 32000, 1, 34, 18446744073709551615, 0], entry
[ 20.927676 0:6 axmem:260] [mmap] vaddr: [VA:0x0, VA:0x8000), MappingFlags(READ | USER), fixed: false, backend: false
[ 20.928142 0:6 axmem:278] find free area
[ 20.928715 0:6 axmem:283] found area [VA:0x7ffa000, VA:0x8002000)
[ 20.929233 0:6 page_table::bits64:261] failed to map fault page: VA:0x8000000(Size4K), AlreadyMapped
[ 20.929827 0:6 axruntime::lang_items:5] panicked at modules/axmem/src/area.rs:44:14:
called `Result::unwrap()` on an `Err` value: AlreadyMapped
[ 20.930625 0:6 axhal::platform::aarch64_common::psci:96] Shutting down...

能稍微帮忙解答一下吗, 非常感谢🙏

YXalix commented 5 months ago

已定位到问题, 提交了 PR: https://github.com/Arceos-monolithic/Starry/pull/33