proot-me / proot

chroot, mount --bind, and binfmt_misc without privilege/setup for Linux
https://proot-me.github.io
GNU General Public License v2.0
1.96k stars 369 forks source link

riscv: add riscv arch support #375

Open Jer6y opened 4 months ago

Jer6y commented 4 months ago

add riscv arch support

Why does using -O0 result in fewer test case failures compared to using -O2 on openEuler RISCV? I am not certain of the reason, but it may be related to some issues with the compiler optimizations.

The porting effectiveness test can be found at the link https://github.com/Jer6y/rv_linux_bug, which also describes a bug related to ptrace on RISCV Linux that has not yet been fixed. However, it is possible to perform some rather rudimentary operations locally to temporarily correct the ptrace issue.

368

Jer6y commented 4 months ago

README Summary

This is a brief readme introduction on how to properly run and operate proot on openEuler RISCV 23.09. Before compiling and running, there is a bug with RISCV Linux ptrace that needs to be addressed.

Bug summary

A ptrace bug in riscv linux , when tracer want to change tracee's a0 register in option PTRACE_SYSCALL to stop the tracee

Bug descrption

Bug analysis

Bug Reproduction

compile code.c and test.c in riscv linux

gcc code.c -o a.out
gcc test.c -o test

put a.out test in the same directory

execute a.out

./a.out

what do "a.out" and "test" do ?

hot to fix bug

simple way to support ptrace and run proot

testcase for riscv proot

I employed a temporary solution by recompiling the openEuler kernel locally, and this is the result of my proot test cases.

https://github.com/Jer6y/rv_linux_bug/assets/88422053/578bf9f6-5227-4c63-a282-eb4ae1af23da

Compared to running on x86, there were 7 additional failures.

This could be due to the ptrace still having bugs, or it might be that the ported code requires further improvement.

use proot on openEuler riscv to chroot

https://github.com/Jer6y/rv_linux_bug/assets/88422053/4f343c1e-24ab-4c78-bade-29c190f30a16

Kreijstal commented 4 months ago

ahh just what I was looking for!

would that fix work over for https://github.com/proot-me/proot-rs as well?

Jer6y commented 2 months ago

ahh just what I was looking for!

would that fix work over for https://github.com/proot-me/proot-rs as well?

I'm sorry that I'm not so familiar with Rust. Perhaps in the future, I will support rust proot, possibly when RISC-V mobile phones come out.

lrzlin commented 2 months ago

Why does using -O0 result in fewer test case failures compared to using -O2 on openEuler RISCV? I am not certain of the reason, but it may be related to some issues with the compiler optimizations.

Maybe you should trying add $cc in SYSCALL macro's clobber list and make result from =r to +r.

Ref: riscv nolibc header https://github.com/torvalds/linux/blob/master/tools/include/nolibc/arch-riscv.h