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

Bug: Windows execute APE with SEGV segment fault exception c0000005 at 00000000002c8cea #1345

Open
HuangShumin opened this issue Jan 2, 2025 · 4 comments
Labels
support Issues filed asking for help on using Cosmopolitan.

Comments

@HuangShumin
Copy link

HuangShumin commented Jan 2, 2025

Contact Details

[email protected]

What happened?

I installed MSYS2 and started a shell to execute any executables in https://cosmo.zip/pub/cosmos/zip/cosmos.zip, with segment fault error code 0xc0000005, take simple yes as example:

$ strace /c/bin/yes --strace
--- Process 60960 created
--- Process 60960 loaded C:\Windows\System32\ntdll.dll at 00007ff9ddef0000
--- Process 60960 loaded C:\Windows\System32\kernel32.dll at 00007ff9dd830000
--- Process 60960 loaded C:\Windows\System32\KernelBase.dll at 00007ff9db810000
--- Process 60960, exception c0000005 at 0000000000059d96
--- Process 60960 exited with status 0xc0000005
Segmentation fault

I also tried compiler in https://cosmo.zip/pub/cosmos/zip/cosmocc.zip
$ cat hello.c
// hello.c
#include <stdio.h>

int main() {
printf("hello world\n");
}

$ strace ./cosmocc hello.c -o hello
strace.exe: error creating process C:\cosmocc-3.9.7\bin\cosmocc, (error 193)

It seems cosmopolitan world won't work on my computer. Any clues?

Best Regards

Version

cosmocc (GCC) 14.1.0

What operating system are you seeing the problem on?

Windows_NT 10.0 19045

Relevant log output

$ ./cosmocc --version
cosmocc (GCC) 14.1.0
Copyright (c) 2024 Justine Alexandra Roberts Tunney
Cosmopolitan Libc and LLVM libcxx/compiler-rt are subject to non-GPL
notice licenses, e.g. ISC, MIT, etc. Your compiled programs must embed
our copyright notices. This toolchain is configured to do so by default.
Cosmopolitan comes with absolutely NO WARRANTY of any kind.
For more information, see the Cosmopolitan LICENSE files.
Copyright (C) 2022 Free Software Foundation, Inc.
This launches GNU GCC/Binutils subprocesses, which is free software; see
cosmocc's LICENSE files for source code and copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ldd ./x86_64-unknown-cosmo-cc
"CreateProcessA(NULL, argv[1], NULL, NULL, FALSE, DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS | CREATE_SUSPENDED, NULL, NULL, &si, &pi) == TRUE" failed with error code 193 in ldd64.c:138 (function: main)

./x86_64-linux-cosmo-cc
SEGV

Host Name:                 LAPTOP-RJTLHMS4
OS Name:                   Microsoft Windows 10 
OS Version:                10.0.19045 N/A Build 19045
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          N/A
Registered Organization:   N/A
Original Install Date:     2022/9/23, 12:09:30
System Boot Time:          2024/12/20, 21:38:24
System Model:              MRG-WXX
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 140 Stepping 2 GenuineIntel ~2918 Mhz
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
Total Physical Memory:     16,167 MB
Available Physical Memory: 1,370 MB
Virtual Memory: Max Size:  36,206 MB
Virtual Memory: Available: 6,319 MB
Virtual Memory: In Use:    29,887 MB
Page File Location(s):     C:\pagefile.sys
Hotfix(s):                 27 Hotfix(s) Installed.
                           [01]: KB5044020
                           [02]: KB5000736
                           [03]: KB5015684
                           [04]: KB5046613
                           [05]: KB5007273
                           [06]: KB5015895
                           [07]: KB5016705
                           [08]: KB5018506
                           [09]: KB5020372
                           [10]: KB5022924
                           [11]: KB5025315
                           [12]: KB5026879
                           [13]: KB5028318
                           [14]: KB5028380
                           [15]: KB5031539
                           [16]: KB5032392
                           [17]: KB5032907
                           [18]: KB5034224
                           [19]: KB5037018
                           [20]: KB5037240
                           [21]: KB5037995
                           [22]: KB5039336
                           [23]: KB5041579
                           [24]: KB5043935
                           [25]: KB5043130
                           [26]: KB5046823
                           [27]: KB5005260
@HuangShumin HuangShumin added the critical severity Used to report critical severity bugs (e.g. Crashing, Corrupted, Dataloss) label Jan 2, 2025
@HuangShumin HuangShumin changed the title Bug: Windows execute APE with exception c0000005 at 00000000002c8cea Bug: Windows execute APE with SEGV segment fault exception c0000005 at 00000000002c8cea Jan 2, 2025
@jart jart added support Issues filed asking for help on using Cosmopolitan. and removed critical severity Used to report critical severity bugs (e.g. Crashing, Corrupted, Dataloss) labels Jan 3, 2025
@jart
Copy link
Owner

jart commented Jan 3, 2025

Works fine for me.

image

Try running yes on the windows command prompt rather than the Cygwin shell. Cosmo isn't Cygwin so obviously it's not going to work with Cygwin's strace tool. You only need the --strace flag with Cosmo.

If it's still crashing, then run it from a folder where Windows Defender is disabled.

If it's still crashing, and strace logs nothing, then try using these yes binaries I just built at head.

For example, you can run gunzip yes.gz and then ./yes | head on the cygwin shell. It works fine for me. There's also cosmopolitan bash which you might like too. If those still crash without strace printing anything, then launch it in WinDbg and get me the instruction pointer (rip).

@HuangShumin
Copy link
Author

HuangShumin commented Jan 3, 2025

WinDbg load yes.exe:

ModLoad: 00000000`00400000 00000000`0043a000   image00000000`00400000
ModLoad: 00007ff9`ddef0000 00007ff9`de0e8000   ntdll.dll
ModLoad: 00007ff9`dd830000 00007ff9`dd8f2000   C:\Windows\System32\KERNEL32.DLL
ModLoad: 00007ff9`db810000 00007ff9`dbb0e000   C:\Windows\System32\KERNELBASE.dll
(10970.efac): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ff9`ddfc07a0 cc              int     3

Go:

0:000> g
(10970.efac): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
00000000`00023126 ??              ???

Time Travel Position stops on LdrInitializeThunk in ntdll

Time Travel Position: A:0
ntdll!LdrInitializeThunk:
00007ff9`ddf65c10 4053            push    rbx
0:000> !ttdext.tt A:0
Setting position: A:0

this is what I can provide with WinDbg so far.

@jart
Copy link
Owner

jart commented Jan 3, 2025 via email

@HuangShumin
Copy link
Author

After I click continue, then the yes.exe got segment fault exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Issues filed asking for help on using Cosmopolitan.
Projects
None yet
Development

No branches or pull requests

2 participants