Open Jer6y opened 4 months ago
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.
A ptrace bug in riscv linux , when tracer want to change tracee's a0 register in option PTRACE_SYSCALL to stop the tracee
PTRACE_SYSCALL
, actually , it doesn't change a0 , but it actually can change a1 ... a7 and other registersTake a look at this patch [PATCH] riscv: entry: Save a0 prior syscall_enter_from_user_mode() (kernel.org)
we need to know that where will sleep in when tracee signal self in syscall enter. take a look at file in linux /arch/riscv/kernel/traps.c
, the function do_trap_ecall_u
, every time process execute syscall will get in the function , and will be blocked in syscall_enter_from_user_mode
if it is traced for syscall enter and exit . and you will know that regs->orig_a0 is be assigned before syscall_enter_from_user_mode
. and if we use ptrace for tracer to change the register , we can't change orig_a0 , we can only change a0, because riscv ptrace USERSPACE don't support the orig_a0 change. so, actually , we can't change orig_a0 use PTRACE_SYSCALL option.
gcc code.c -o a.out
gcc test.c -o test
./a.out
a.out
fork
and setup tracee relationship between father and son father process
: take waitpid
to get tracee and use ptrace syscall
to change a0 to NULL when tracee is executing execve syscall
son process
: first claim itself can be traced
and signal self
to be trace stopped , then execute ./test
ELFtest
execve syscall
, also the envp
test
will not be excuted , but actually , ./test
works well .if(regs->orig_a0 != regs->a0 ) regs->orig_a0 = regs->a0
" at the end of the syscall_trace_enter
function in the file /kernel/entry/common.c
.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.
https://github.com/Jer6y/rv_linux_bug/assets/88422053/4f343c1e-24ab-4c78-bade-29c190f30a16
ahh just what I was looking for!
would that fix work over for https://github.com/proot-me/proot-rs as well?
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.
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
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