Bug 9025 – core.thread.Fiber seems to crash on Win64

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2012-11-14T09:19:00Z
Last change time
2012-11-15T00:43:10Z
Assigned to
nobody
Creator
turkeyman

Comments

Comment #0 by turkeyman — 2012-11-14T09:19:15Z
It seems core.thread.Fiber doesn't work under the new DMD for win64. Crashes on call(), in fiber_switchcontext(), access violation, looks like an alignment problem, since the pointer is valid. fiber_switchContext: 000007FEE25509E0 push rbp 000007FEE25509E1 mov rbp,rsp 000007FEE25509E4 push rbx 000007FEE25509E5 push r12 000007FEE25509E7 push r13 000007FEE25509E9 push r14 000007FEE25509EB push r15 000007FEE25509ED push qword ptr gs:[fiber_switchContext+15h (7FEE25509F5h)] *** CRASH*** +15h? does 'push qword' support reading from unaligned addresses like that? 000007FEE25509F5 push qword ptr gs:[fiber_switchContext+25h (7FEE2550A05h)] 000007FEE25509FD push qword ptr gs:[fiber_switchContext+35h (7FEE2550A15h)] 000007FEE2550A05 mov qword ptr [rdi],rsp 000007FEE2550A08 mov rsp,rsi 000007FEE2550A0B pop qword ptr gs:[fiber_switchContext+43h (7FEE2550A23h)] 000007FEE2550A13 pop qword ptr gs:[fiber_switchContext+43h (7FEE2550A23h)] 000007FEE2550A1B pop qword ptr gs:[fiber_switchContext+43h (7FEE2550A23h)] 000007FEE2550A23 pop r15 000007FEE2550A25 pop r14 000007FEE2550A27 pop r13 000007FEE2550A29 pop r12 000007FEE2550A2B pop rbx 000007FEE2550A2C pop rbp 000007FEE2550A2D pop rcx 000007FEE2550A2E jmp rcx
Comment #1 by bugzilla — 2012-11-14T13:56:02Z
qword means 4 bytes, and you can't push 4 bytes in 64 bit mode. Only 8 bytes.
Comment #2 by bugzilla — 2012-11-15T00:01:38Z
(In reply to comment #1) > qword means 4 bytes, and you can't push 4 bytes in 64 bit mode. Only 8 bytes. Aggh, that's wrong. The source code is in src/core/thread.d, and looks like: ---------------------------------------------- // save current stack state push RBP; mov RBP, RSP; push RBX; push R12; push R13; push R14; push R15; push qword ptr GS:[0]; push qword ptr GS:[8]; push qword ptr GS:[16]; // store oldp mov [RDI], RSP; // load newp to begin context switch mov RSP, RSI; // load saved state from new stack pop qword ptr GS:[16]; pop qword ptr GS:[8]; pop qword ptr GS:[0]; pop R15; pop R14; pop R13; pop R12; pop RBX; pop RBP; // 'return' to complete switch pop RCX; jmp RCX; ---------------------------------------- So, if you could disassemble the code, it should be GS:[0], but I suspect the assembler made it an offset from the program counter. To fix, xor RAX,RAX push qword ptr GS:[RAX] push qwork ptr GS:8[RAX] ... etc. ...
Comment #3 by bugzilla — 2012-11-15T00:03:49Z
Confirmed, the [RIP] addressing mode is the problem.
Comment #4 by github-bugzilla — 2012-11-15T00:42:35Z