termux / proot

An chroot-like implementation using ptrace.
https://wiki.termux.com/wiki/PRoot
Other
745 stars 161 forks source link

ptrace(PEEKDATA): I/O error when trying to run box86 on aarch64 PRoot #213

Closed WheezyE closed 2 years ago

WheezyE commented 2 years ago

Problem description This might be a pretty niche case, but I'm trying to run box86 on an aarch64 Debian bullseye PRoot (installed with proot-distro). I'm running into...

~ $ proot-distro login --isolated --shared-tmp debian
root@localhost:~# sudo su - user
user@localhost:~$ DISPLAY=:1 WINEARCH=win32 /usr/local/bin/box86 /home/user/wine/bin/wine wineboot
Box86 with Dynarec v0.2.5 16b8657a built on Jan 16 2022 15:27:51
Box86 with Dynarec v0.2.5 16b8657a built on Jan 16 2022 15:27:51
Box86 with Dynarec v0.2.5 16b8657a built on Jan 16 2022 15:27:51
proot warning: ptrace(PEEKDATA): I/O error
wine client error:0: sendmsg: Bad address
user@localhost:~$

Also happens without --isolated or --shared-tmp flags.

Full disclosure: I have gotten box86 working on a 32-bit (armhf) Termux install, but not on a 64-bit (aarch64) Termux install yet. I'm honestly not sure if it's Termux's fault that this isn't working, or if it's because I'm trying to run :armhf multi-arch libraries that box86 needs. I just don't know where to ask for help.

EDIT: Box64 does work on this same aarch64 proot, just not box86. I've seen people making chroots to run box86 on aarch64 systems, but I would like to run both box86 and box64 side-by-side on the same aarch64 proot (box86 & box64 do run side-by-side on other aarch64 linux systems using multi-arch).

Box86 is not detected unless I run these commands (also see commented lines in the script):

sudo dpkg --add-architecture armhf && sudo apt update
sudo apt install libc6:armhf libncurses5:armhf libstdc++6:armhf -y #magic command that makes box86 run on aarch64 https://github.com/ptitSeb/box86/issues/465

But this seems to cause the error.

Steps to reproduce Install Termux on Android, then run this experimental script that runs box64/wine64 on Debian aarch64 PRoot. Then install libc6:armhf (see above) to get aarch64 to detect box86.

Expected behavior Wine should boot a 32-bit environment and send video output to the XServer XSDL Android app

Additional information

Application version:
0.117
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages.termux.org/apt/termux-main/ stable main
# science-repo (sources.list.d/science.list)
deb https://termux.mentality.rip/termux-science science stable
# game-repo (sources.list.d/game.list)
deb https://termux.mentality.rip/termux-games games stable
Updatable packages:
apt/stable 2.3.14 aarch64 [upgradable from: 2.3.13-4]
libexpat/stable 2.4.3 aarch64 [upgradable from: 2.4.2]
libtirpc/stable 1.3.2-1 aarch64 [upgradable from: 1.3.2]
proot-distro/stable 2.9.5 all [upgradable from: 2.9.4]
termux-tools/stable 0.156 all [upgradable from: 0.155]
Android version:
9
Kernel build information:              
Linux localhost 4.4.146+ #1 SMP PREEMPT Sat Apr 24 02:53:11 UTC 2021 aarch64 Android
Device manufacturer:
Amazon
Device model:
KFTRWI

Here's a verbose output from:

~ $ PROOT_VERBOSE=9 proot-distro login --isolated --shared-tmp debian
root@localhost:~# sudo su - user
user@localhost:~$ DISPLAY=:1 WINEARCH=win32 /usr/local/bin/box86 /home/user/wine/bin/wine wineboot

VERBOSE.txt

michalbednarski commented 2 years ago

Looks like you could work around this issue for now by making local PRoot build this condition always false (if (0)): https://github.com/termux/proot/blob/17e72681bccd7a2424b99196c0daa9f059ff352a/src/extension/fake_id0/sendmsg.c#L55

(This code doesn't properly handle 32-bit on 64-bit sendmsg() (which proot normally fixes for fake-uid SCM_CREDENTIALS, though looks like in this case message didn't have SCM_CREDENTIALS so disabling this functionality should just work in this case, although I hadn't got whole wine running to fully test that, please report if this fixes issue)

WheezyE commented 2 years ago

Thank you for the reply and apologies for the delay: I finally got some time to work on this today.

I forked Termux/PRoot, made that change to sendmsg.c, installed a fresh Termux, then installed make, git, and gcc (and other tools) with the help of this stackexchange (first and last comment there). I was then able to make && make install my patched PRoot, then ran my install script again. Then I installed those multi-arch libraries again (see steps above).

I think I built PRoot correctly (though am not 100% sure - though I couldn't access proot until I did make install so I'm pretty sure I'm using the proot I built), but am still getting the same error. I'll post a verbose output here too

EDIT: Here's that output and log

user@localhost:~$ DISPLAY=:1 WINEARCH=win32 /usr/local/bin/box86 /home/user/wine/bin/wine wineboot
Box86 with Dynarec v0.2.5 50ca38d4 built on Jan 22 2022 22:34:23
Box86 with Dynarec v0.2.5 50ca38d4 built on Jan 22 2022 22:34:23
Dynarec for ARM64, with extension: ASIMD AES CRC32 PMULL PageSize:4096
Box64 with Dynarec v0.1.7 40de393 built on Jan 22 2022 22:15:26
Using default BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/
Using default BOX64_PATH: ./:bin/
Counted 30 Env var
Looking for /home/user/wine/bin/wineserver
Using native(wrapped) libc.so.6
Using native(wrapped) ld-linux-x86-64.so.2
Using native(wrapped) libpthread.so.0
Using native(wrapped) librt.so.1
proot warning: ptrace(PEEKDATA): I/O error
wine client error:0: sendmsg: Bad address

VERBOSE_patch1.txt

EDIT2: Here's a comparison of before the patch

proot info: vpid 12: sysenter start: sendmsg(0x4, 0xef718ab0, 0x0, 0x0, 0x6319f050, 0xf019327d) = 0x4 [0xffc111f0, 1]
proot warning: ptrace(PEEKDATA): I/O error
proot info: vpid 12: sysenter end: void(0xfffffff2, 0xef718ab0, 0x0, 0x0, 0x6319f050, 0xf019327d) = 0xfffffff2 [0xffc111f0, 1]
wine client error:0: sendmsg: Bad address
proot info: vpid 12: exited with status 1

And after the patch (if I did it correctly)

proot info: vpid 13: sysenter start: sendmsg(0x4, 0xf5ca3ab0, 0x0, 0x0, 0x6319f050, 0xf671e27d) = 0x4 [0xffbe1860, 1]
proot warning: ptrace(PEEKDATA): I/O error
proot info: vpid 13: sysenter end: void(0xfffffff2, 0xf5ca3ab0, 0x0, 0x0, 0x6319f050, 0xf671e27d) = 0xfffffff2 [0xffbe1860, 1]
wine client error:0: sendmsg: Bad address
proot info: vpid 13: exited with status 1
michalbednarski commented 2 years ago

I've pushed actual AArch32 implementation for SCM_CREDENTIALS handling and was able to get to wine cmd to work (for graphical apps it looks like I didn't have all libraries installed, anyway there are no sendmsg nor Bad address errors)

michalbednarski commented 2 years ago

Also just pushed update to apt repo as proot 5.1.107-53 (Now on https://packages-cf.termux.org and should soon propagate to other mirrors)

WheezyE commented 2 years ago

That did it!!! Incredible! Screenshot_20220123-131857 This is notepad++ (x86) being run on box86 on AArch64 Debian PRoot on Termux aarch64

I also had to install these other :armhf multiarch dependencies inside the Debian PRoot to get box86 to run wine 32-bit wine

sudo dpkg --add-architecture armhf && sudo apt update
sudo apt install libc6:armhf libncurses5:armhf libstdc++6:armhf -y
sudo apt install libfontconfig1:armhf libmpg123-0:armhf libcups2:armhf libncurses6:armhf libfreetype6:armhf -y
sudo apt install libxcb1:armhf libxext6:armhf -y
sudo apt install libxinerama1:armhf libxxf86vm1:armhf libxrender1:armhf libxcomposite1:armhf libxi6:armhf libxcursor1:armhf -y 
sudo apt install libxrandr2:armhf -y

Thank you for your hard work! I'll close this issue and keep fine-tuning AnBox86_64.sh

WheezyE commented 2 years ago

I can also confirm that box64 still works as well (it needed libcups2 reinstalled for some reason, but it works) and that I can switch back and forth between box86/wine & box64/wine64 over and over again now.

sudo apt install libcups2 -y
DISPLAY=:1 /usr/local/bin/box64 /home/user/wine/bin/wine64 /home/user/npp64/notepad++.exe

DISPLAY=:1 WINEARCH=win32 WINEPREFIX=~/.wine32/ /usr/local/bin/box86 /home/user/wine/bin/wine /home/user/npp32/notepad++.exe