运行`make qemu`得到错误:`qemu_mprotect__osdep:mprotect失败:权限被拒绝`



我正在mac 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 repository以获得源代码,并将版本检查为v5.1.0,然后我从这个链接提到的这个链接路径应用补丁

配置运行方式如下:

./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,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,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 with:

./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]

这是macOS 11.2 mprotect错误,您可以修改qemu/tcg/tcg.c修复它,查看https://gitlab.com/qemu-project/qemu/-/commit/c118881ee607dcac

最新更新