我已经为这个问题苦苦挣扎了好几天。为了提供一些上下文,我不是代码的作者,它使用 Windows API 来访问串行端口,我通过以下方式在 macOS 上编译并运行它:
make CC="$(brew --prefix mingw-w64)/bin/x86_64-w64-mingw32-gcc" -j$(nproc) && wine64 emul.exe
问题是Apple Silicon上出现页面错误
wine: Unhandled page fault on read access to 0000000000000050 at address 000000017005C815 (thread 0024), starting debugger...
我用
-fsanitize=address
在 Windows 上重新编译它,没有任何问题。不幸的是,由于 mingw64 基于 gcc,我没有这个选项。
我能做些什么来为我提供一些有关问题的信息、我可以使用的任何标志或工具吗?
理论上,这段代码是 ANSI C,在 gcc 中使用 -Wall 编译不会给我任何警告。
下面的错误是Wine64给我的。
Unhandled exception: page fault on read access to 0x0000000000000050 in 64-bit code (0x0000017005c815).
Register dump:
rip:000000017005c815 rsp:000000000021fc70 rbp:0000000000000000 eflags:00000283 ( - -- I S - - -C)
rax:00000002283071c0 rbx:0000000000000000 rcx:0000000000000030 rdx:0000000000000000
rsi:0000000000000030 rdi:0000000000000000 r8:0000000000000000 r9:ffffffffffffffff r10:00000001400087bd
r11:0000000000000202 r12:0000000000340ef0 r13:0000000000000000 r14:0000000000000000 r15:0000000000000000
Stack dump:
0x0000000021fc70: 000000000000001a ffffffffffffffff
0x0000000021fc80: 00000000000007e7 000000010000000b
0x0000000021fc90: 0000000000000000 00000002282a3636
0x0000000021fca0: 0000000b00000002 000000000000001e
0x0000000021fcb0: 0000000b000007e7 000000000000001b
0x0000000021fcc0: 00000000001e0212 0000000000000008
0x0000000021fcd0: 0000000000000039 0000000000c91338
0x0000000021fce0: 000000000021fd20 0000000140005adc
0x0000000021fcf0: 0000000100000009 0000000140015448
0x0000000021fd00: 0000000140015429 ffffffffffffffff
0x0000000021fd10: 000000000021fd50 0000000040002bf2
0x0000000021fd20: 000000000021fd50 0000000140007a95
Backtrace:
=>0 0x0000017005c815 in ntdll (+0x5c815) (0000000000000000)
1 0x000002282a3636 in msvcrt (+0x23636) (0000000000000000)
2 0x00000140005adc in emul (+0x5adc) (0x0000000021fd20)
3 0x00000140007a95 in emul (+0x7a95) (0x0000000021fd50)
4 0x0000014000151f in emul (+0x151f) (0x0000000021fd80)
5 0x00000140001467 in emul (+0x1467) (0x0000000021fdb0)
6 0x000001400012ee in emul (+0x12ee) (0x00000000c91330)
7 0x00000140001406 in emul (+0x1406) (0000000000000000)
8 0x0000007b627fe9 in kernel32 (+0x27fe9) (0000000000000000)
9 0x0000017005d668 in ntdll (+0x5d668) (0000000000000000)
0x0000017005c815 ntdll+0x5c815: cmpq $0,0x00000000000020 <wine-loader>+0x20(%rcx)
Modules:
Module Address Debug info Name (12 modules)
ELF 0000000000000000-0000000000005000 Stabs <wine-loader>
ELF 0000000068036000-000000006803a000 Deferred <wine-loader>
ELF 00000000680be000-000000006816f000 Deferred ntdll.so
PE 000000007b000000-000000007b298000 Deferred kernelbase
PE 000000007b600000-000000007b65d000 Export kernel32
PE 000000007d400000-000000007d405000 Deferred wine64-preloader
PE 0000000140000000-0000000140077000 Dwarf-5 emul
PE 0000000170000000-00000001700a1000 Export ntdll
PE 0000000228280000-000000022831b000 Export msvcrt
PE 00007ff815f8c000-00007ff815fc8000 Deferred libsystem_kernel.dylib
PE 00007ff815fc7000-00007ff815fd3000 Deferred libsystem_pthread.dylib
PE 00007ff815ff7000-00007ff816003000 Deferred libsystem_platform.dylib
Threads:
process tid prio name (all IDs are in hex)
00000020 (D) Z:\opt\workspace\project\emulator\emul.exe
00000024 0 <==
00000100 0
00000104 0 wine_threadpool_timer_queue
00000110 0
00000038 services.exe
0000003c 0
00000040 0 wine_rpcrt4_server
0000004c 0 wine_rpcrt4_io
00000070 0 wine_rpcrt4_io
0000009c 0 wine_rpcrt4_io
000000b4 0 wine_rpcrt4_io
000000d8 0 wine_rpcrt4_io
00000044 winedevice.exe
00000048 0
00000054 0
00000058 0 wine_sechost_service
0000005c 0
00000060 0
00000064 0
000000c0 0
00000118 0 wine_threadpool_worker
00000068 winedevice.exe
0000006c 0
00000074 0
00000078 0 wine_sechost_service
0000007c 0
00000080 0
00000084 0
00000088 0
0000008c explorer.exe
00000090 0
000000c4 0
000000c8 0 wine_rpcrt4_server
00000094 plugplay.exe
00000098 0
000000a0 0
000000a4 0 wine_sechost_service
000000a8 0 wine_rpcrt4_server
000000ac svchost.exe
000000b0 0
000000b8 0
000000bc 0 wine_sechost_service
000000d0 rpcss.exe
000000d4 0
000000e0 0
000000e4 0 wine_sechost_service
000000e8 0 wine_rpcrt4_server
000000ec 0 wine_rpcrt4_server
000000f0 0 wine_rpcrt4_io
000000f8 conhost.exe
000000fc 0
System information:
Wine build: wine-8.0.1
Platform: x86_64
Version: Windows 7
Host system: Darwin
Host version: 23.1.0
经过一番调查,我发现 fopen 调用失败并返回 NULL,这就是问题的根本原因。