You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix mapping of integer overflow in division to managed exception #4138
area-PAL-coreclronly for closed issuesbugin-prThere is an active PR which will close this issue when it is mergedos-linuxLinux OS (any supported distro)
Linux linux integer overflow during division to the same signal code as division by zero in some cases, the si_signo is SIGFPE and the si_code is FPE_INTDIV and so we generate division by zero exception instead of integer overflow.
It seems that we will need to check the failing instruction code, find the divisor value and check if it is zero. Based on that we would either return EXCEPTION_INT_DIVIDE_BY_ZERO or EXCEPTION_INT_OVERFLOW.
The code we had is not complete. It doesn't handle memory operands. We need to add support for those since two tests in System.Dynamic.Runtime.Tests are failing due to division overflow reported as division by zero for memory operands.
What happens if the contents of the memory operand is modified by another thread after the exception is thrown? Would IsDivByZeroAnIntegerOverflow check lead to the wrong exception being thrown?
You are right, it would (if we extended the current verification to the memory operands).
But there seems to be no other way to find out whether a division by zero or integer overflow happened.
Another bad issue could happen in case the memory of the target operand got unmapped from the address space by another thread before we had a chance to check.
I am still investigating if there is an alternative way to figure out the difference.
An alternative approach to solve the issue would be to make jitter issue zero check for the divisor before the actual division and throw the div by zero in that case explicitly. That way, we could convert all hardware exceptions with code EXCEPTION_INT_DIVIDE_BY_ZERO to EXCEPTION_INT_OVERFLOW.
Btw, Windows do the same thing as I was originally suggesting - decode the instruction, find the address of the operand and read its value. So it seems that unless we want to perform the check before every division, we don't have other option.
So it seems that unless we want to perform the check before every division, we don't have other option.
It looks like the x86 JIT forces the divisor into a register if it's not a local, I wonder if that's just a coincidence or it was done on purpose. RyuJIT doesn't do it but I supposed it could be modified to do it. Though I'm not sure if it's worth the trouble, this situation should be rare.
area-PAL-coreclronly for closed issuesbugin-prThere is an active PR which will close this issue when it is mergedos-linuxLinux OS (any supported distro)
Activity
janvorli commentedon Apr 16, 2015
We actually do the same thing for OSX here:
https://github.com/dotnet/coreclr/blob/master/src/pal/src/exception/machexception.cpp#L647
So we should be able to reuse the IsDivByZeroAnIntegerOverflow function.
janvorli commentedon Apr 16, 2015
The code we had is not complete. It doesn't handle memory operands. We need to add support for those since two tests in System.Dynamic.Runtime.Tests are failing due to division overflow reported as division by zero for memory operands.
mikedn commentedon Apr 16, 2015
What happens if the contents of the memory operand is modified by another thread after the exception is thrown? Would IsDivByZeroAnIntegerOverflow check lead to the wrong exception being thrown?
janvorli commentedon Apr 16, 2015
You are right, it would (if we extended the current verification to the memory operands).
But there seems to be no other way to find out whether a division by zero or integer overflow happened.
Another bad issue could happen in case the memory of the target operand got unmapped from the address space by another thread before we had a chance to check.
I am still investigating if there is an alternative way to figure out the difference.
An alternative approach to solve the issue would be to make jitter issue zero check for the divisor before the actual division and throw the div by zero in that case explicitly. That way, we could convert all hardware exceptions with code
EXCEPTION_INT_DIVIDE_BY_ZEROtoEXCEPTION_INT_OVERFLOW.janvorli commentedon Apr 16, 2015
Btw, Windows do the same thing as I was originally suggesting - decode the instruction, find the address of the operand and read its value. So it seems that unless we want to perform the check before every division, we don't have other option.
mikedn commentedon Apr 16, 2015
It looks like the x86 JIT forces the divisor into a register if it's not a local, I wonder if that's just a coincidence or it was done on purpose. RyuJIT doesn't do it but I supposed it could be modified to do it. Though I'm not sure if it's worth the trouble, this situation should be rare.
janvorli commentedon Apr 18, 2015
Fixed by dotnet/coreclr#737