Closed trungnt2910 closed 1 year ago
Is there any way to see verbose logs of how Cosmopolitan detects the OS? Reading through the codebase, I see that Cosmopolitan implements syscalls as some kind of optimized form of assembly that is platform-specific, for example this. I wonder if these assembly calls are routed through blink or executed directly on the host's system. If the latter is true, this is a huge problem for Haiku, since while it conforms to POSIX, it has a very different way of exposing kernel functionality.
When you're running a Cosmopolitan binary, you can use the --strace
and --ftrace
flags to see what it's doing. For example, system call tracing looks like:
master jart@nightmare:~/blink$ o//blink/blink third_party/cosmo/2/a64l_test.com --strace |& head
SYS 24060 259'931 bell system five system call support 309 magnums loaded on gnu/systemd
SYS 24060 625'384 mprotect(0x700000000000, 16'384, 0) → 0
SYS 24060 763'952 mmap(0x700000000000, 65'536, PROT_READ|PROT_WRITE, MAP_STACK|MAP_ANONYMOUS, -1, 0) → 0x700000000000 (65'536 bytes total)
SYS 24060 1'321'726 getenv("TMPDIR") → NULL
SYS 24060 1'487'868 sigaction(SIGXCPU, {.sa_handler=&403c1f}, [NULL]) → 0
SYS 24060 1'537'816 sigaction(SIGXFSZ, {.sa_handler=&403c02}, [NULL]) → 0
SYS 24060 1'640'749 getcwd(0x473280, 1'024) → "/home/jart/blink"
SYS 24060 1'827'178 openat(AT_FDCWD, "/home/jart/blink/third_party/cosmo/2/a64l_test.com", 0, 0) → 3
SYS 24060 1'891'552 getfiledescriptorsize(3) → 299'008
SYS 24060 1'965'276 mmap(0, 299'008, PROT_READ, MAP_SHARED, 3, 0) → 0x100080040000 (458'752 bytes total)
When a Cosmopolitan binary issues a system call under Blink, it goes through Blink's OpSyscall
. Guest binaries have no way of interfacing the host system without going through that opcode. If you want to learn more about how Cosmopolitan works, read https://justine.lol/ape.html and visit our Discord https://discord.gg/nMvdGvyz where I can answer fine grained questions in real time.
Oh one more thing. My "Size Optimization Tricks" blog post has a section that deep dives into how APE platform detection works. https://justine.lol/sizetricks/#elf
This PR tracks the patches made for
blink
to be built on HaikuOS and additional work to be done formake check
to work on Haiku.Currently, these tests are still failing:
Most of these tests fail at some
syscall
. In the best case, it fails with a weirderrno
, in other cases, with aud2
"Undefined instruction" error in the JIT, as mentioned in #35.Is there any way to see verbose logs of how Cosmopolitan detects the OS? Reading through the codebase, I see that Cosmopolitan implements
syscall
s as some kind of optimized form of assembly that is platform-specific, for example this. I wonder if these assembly calls are routed throughblink
or executed directly on the host's system. If the latter is true, this is a huge problem for Haiku, since while it conforms to POSIX, it has a very different way of exposing kernel functionality.Also, this PR, while focusing on support for Haiku, has some other patches that are not Haiku-specific too.