Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL 2 oddities #6

Closed
abl opened this issue Aug 25, 2020 · 7 comments
Closed

WSL 2 oddities #6

abl opened this issue Aug 25, 2020 · 7 comments
Labels
duplicate This issue or pull request already exists

Comments

@abl
Copy link

abl commented Aug 25, 2020

Really interesting project!

Started looking at the example under WSL 2 (Ubuntu 20.04.1 LTS) since I had that handy.

❯ make -j1 o//tool/viz/printvideo.com
MKDEPS         o//depend
PACKAGE        o//libc/stubs/stubs.a.pkg
error:package.com: check failed: 0x4480 == 0x88 (E?/err=0/errno:0/GetLastError:187 The operation completed successfully.)
make: *** [build/rules.mk:76: o//libc/stubs/stubs.a.pkg] Error 32

Running with -j8 fails with errnos 5 and 32.

WSL 2 does have a binfmt_misc set up for windows interop; disabling it with sudo sh -c 'echo 0 > /proc/sys/fs/binfmt_misc/status' allows make -j8 to succeed - deleted my clone and pulled a fresh one after disabling.

~/cosmopolitan master*
❯ o//tool/viz/printvideo.com cats.mpg
zsh: exec format error: o//tool/viz/printvideo.com

~/cosmopolitan master*
❯ file o//tool/viz/printvideo.com
o//tool/viz/printvideo.com: DOS/MBR boot sector

Re-enabling binfmt_misc afterwards gets a little farther:

~/cosmopolitan master*
❯ sudo sh -c 'echo 1 > /proc/sys/fs/binfmt_misc/status'

# The following happens regardless of answering y or n

~/cosmopolitan master*
❯ o//tool/viz/printvideo.com cats.mpg
ffplay not found; continue without audio? [yn] libc/runtime/mmap.c:143:gap > 0

Attempting to run the executable from Windows directly produces the same (lack of) output; ffplay is installed on the WSL side, fwiw.

If anything jumps out as far as what I should try/test please let me know - I've just started to trace and debug now.

@jart
Copy link
Owner

jart commented Aug 26, 2020

Try exploring the contents of ls /proc/sys/fs/binfmt_misc/ and report back. Microsoft might have installed some MZ executable shell script hook even though WSL can't run Windows binaries.

As far as playing sound is concerned, all you need to do is apt install either ffmpeg or sox. No system interface consensus exists for sound so we do it by piping raw audio into those commands.

@abl
Copy link
Author

abl commented Aug 26, 2020

Yeah, binfmt_misc is clearly part of the problem; here's the one registered definition.

❯ \cat /proc/sys/fs/binfmt_misc/WSLInterop
enabled
interpreter /tools/init
flags: F
offset 0
magic 4d5a

I had a chance to read your αpε writeup and noticed the zsh issue; sh o/tool/viz/printvideo.com cats.mpg worked with binfmt_misc on!

...then I toggled it off, and it didn't:

❯ sh o/tool/viz/printvideo.com cats.mpg
o/tool/viz/printvideo.com: 1: ELF���: not found
o/tool/viz/printvideo.com: 2: @8��@�������H�1ҽ���8���p1���׉��X�^��k������u������ގ�1�1���@���1���U��0����1�1���@t#�.�������0�1ɉ��]�ƃ�: not found
o/tool/viz/printvideo.com: 3: Syntax error: ")" unexpected

...then I toggled it back on, and it still didn't, same output.

However, o/tool/viz/printvideo.com cats.mpg now works directly in ZSH regardless of binfmt_misc status. sh -c o/tool/viz/printvideo.com cats.mpg works, bash works, running the command directly in sh/bash works.

@jart
Copy link
Owner

jart commented Aug 28, 2020

Could you try running the following command and let me know if it fixes the issue?

sudo sh -c "echo ':APE:M::MZqFpD::/bin/sh:' >/proc/sys/fs/binfmt_misc/register"

@abl
Copy link
Author

abl commented Aug 28, 2020

Registered that format:

───────┬──────────────────────────────────────────────────
       │ File: /proc/sys/fs/binfmt_misc/APE
───────┼──────────────────────────────────────────────────
   1   │ enabled
   2   │ interpreter /bin/sh
   3   │ flags:
   4   │ offset 0
   5   │ magic 4d5a71467044
───────┴──────────────────────────────────────────────────

No effect with binfmt_misc enabled/disabled.

FWIW /bin/sh is symlinked to dash?

@jart
Copy link
Owner

jart commented Aug 28, 2020

I'm having difficulties figuring out how to get binfmt_misc to work. I would recommend disabling it entirely if possible. Hopefully someone else can come along who understands it and show us how to configure it for the people who do.

@jart
Copy link
Owner

jart commented Sep 1, 2020

Another user is reporting in #2 that the one-liner workaround I posted a few comments earlier should be OK. I'm going to close out this issue. Thanks for the report!

@jart jart closed this as completed Sep 1, 2020
@jart
Copy link
Owner

jart commented Feb 27, 2021

Marking as duplicate of #2 for posterity. Thanks again for using Cosmopolitan!

@jart jart added the duplicate This issue or pull request already exists label Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants