运行`make qemu`得到错误:`qemu_mprotect__osdep: mprotect failed: Permission denied`

问题描述

我正在尝试在 ma​​c m1 上进行 mit6.828 实验。安装riscv-tool-chain后,我尝试运行make qemu,它似乎是用来启动内核的,但一开始我收到了这个错误:

mkfs/mkfs fs.img README user/xargstest.sh user/_cat user/_echo user/_forktest user/_grep user/_init user/_kill user/_ln user/_ls user/_mkdir user/_rm user/_sh user/_stressfs user/_usertests user/_wc user/_zombie user/_cowtest user/_uthread user/_call user/_testsh user/_kalloctest user/_bcachetest user/_alloctest user/_bigfile
nmeta 46 (boot,super,log blocks 30 inode blocks 13,bitmap blocks 1) blocks 1954 total 2000
balloc: first 766 blocks have been allocated
balloc: write bitmap block at sector 45
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 1 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
Could not allocate dynamic translator buffer
make: *** [qemu] Error 1

所以我从github克隆了qemu reposiroty以获取源代码,并检查版本为v5.1.0,然后我应用此链接pathch中提到的补丁link

配置运行如下:

 ./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"`

makemake install 看起来运行良好,但是当我在实验室中再次执行 make qemu 时,又出现了另一个错误,我仍然没有找到如何解决这个问题:>

qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -drive file=fs.img,bus=virtio-mmio-bus.0
qemu-system-riscv64: qemu_mprotect__osdep: mprotect failed: Permission denied
**
ERROR:/Users/rezero/Desktop/6.828-note/qemus/qemu-5.1.0/tcg/tcg.c:733:tcg_region_init: assertion failed: (!rc)
Bail out! ERROR:/Users/rezero/Desktop/6.828-note/qemus/qemu-5.1.0/tcg/tcg.c:733:tcg_region_init: assertion failed: (!rc)
make: *** [qemu] Abort trap: 6

解决方法

我尝试了很多次,因为我对 qemu 和 macos 不熟悉。 我得到了:

# modify /etc/paths 
/usr/bin
/bin
/usr/local/bin
/usr/sbin
/sbin

# modify .zshrc
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$HOME/bin:/usr/local/bin:$PATH"
export PATH="$PATH:/usr/local/opt/riscv-gnu-toolchain/bin"

仍然不知道发生了什么,但在我应用如下两个补丁后,事情似乎奏效了。 (确保在iterm上关闭Rosetta模式,仍然使用qemu 5.1.0)

patch1 你可以下载并cd到qemu目录然后像这样命令:patch -p1 < ../patch/v2-tcg-Fix-execution-on-Apple-Silicon.patch

patch2 只有两行,打开osdep.c文件修改即可。

应用上述补丁后,运行配置:

./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"

make & make install

然后就成功了,内核可以启动了。

,

@Rezero 按照你的步骤,你编译的时候遇到过这样的错误:

 CC      hw/display/virtio-gpu-3d.o
hw/display/virtio-gpu-3d.c:149:41: error: variable has incomplete type 'struct virgl_renderer_resource_info'
    struct virgl_renderer_resource_info info;
                                        ^
hw/display/virtio-gpu-3d.c:149:12: note: forward declaration of 'struct virgl_renderer_resource_info'
    struct virgl_renderer_resource_info info;
           ^
hw/display/virtio-gpu-3d.c:167:15: error: implicit declaration of function 'virgl_renderer_resource_get_info' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...