#195 infinite SIGFPE loop on integer-div-by-zero.

v1.0 (example)
closed-fixed
nobody
crt (84)
5
2010-11-25
2010-09-21
Pawel Sikora
No

hi,
please compile following testcase and run.

int main()
{
volatile int x = 0;
x /= x;
return 0;
}

Reading symbols from X:\src\eh-test\eh-test/main64.exe...done.
(gdb) r
Starting program: X:\src\eh-test\eh-test/main64.exe
[New Thread 1124.0xbb8]

Program received signal SIGFPE, Arithmetic exception.
0x0000000000401762 in main () at main.cpp:4
4 x /= x;
(gdb) c
Continuing.

Program received signal SIGFPE, Arithmetic exception.
0x0000000000401762 in main () at main.cpp:4
4 x /= x;
(gdb)
Continuing.

Program received signal SIGFPE, Arithmetic exception.
0x0000000000401762 in main () at main.cpp:4
4 x /= x;
(gdb) disassemble
Dump of assembler code for function main():
0x0000000000401740 <+0>: push %rbp
0x0000000000401741 <+1>: mov %rsp,%rbp
0x0000000000401744 <+4>: sub $0x40,%rsp
0x0000000000401748 <+8>: callq 0x4024c0 <__main>
0x000000000040174d <+13>: movl $0x0,-0x4(%rbp)
0x0000000000401754 <+20>: mov -0x4(%rbp),%eax
0x0000000000401757 <+23>: mov -0x4(%rbp),%edx
0x000000000040175a <+26>: mov %edx,-0x14(%rbp)
0x000000000040175d <+29>: mov %eax,%edx
0x000000000040175f <+31>: sar $0x1f,%edx
=> 0x0000000000401762 <+34>: idivl -0x14(%rbp)
0x0000000000401765 <+37>: mov %eax,-0x4(%rbp)
0x0000000000401768 <+40>: mov $0x0,%eax
0x000000000040176d <+45>: leaveq
0x000000000040176e <+46>: retq
End of assembler dump.

as you can see it throws SEH on idiv and mingw SEH handler in crtexe.c/crt_handler.c
returns back to 'idiv' opcode via EXCEPTION_CONTINUE_EXECUTION and we get
execption again.

probably mingw handler should return EXCEPTION_EXECUTE_HANDLER and allow
windows to terminate process instead of warming cpu ;)

Discussion

  • Kai Tietz
    Kai Tietz
    2010-11-25

    • status: open --> closed-fixed
     
  • Kai Tietz
    Kai Tietz
    2010-11-25

    Sorry, I have missed to report that fix. On trunk fixed in crt_handler.c