Bug 69530 - we need to implement precise exception handling
Summary: we need to implement precise exception handling
Status: REOPENED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: 2.1 CVS
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-02 23:32 UTC by Jeremy Fitzhardinge
Modified: 2020-04-12 17:49 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Fitzhardinge 2003-12-02 23:32:58 UTC
We need a mode in the codegen which allows precise exception handling.  This
means that before any instruction which could generate an exception (resulting
in SIGSEGV, SIGILL, SIGFPE or SIGBUS), we need to make sure the VCPU state is
fully up to date.

This is necessary because some programs trap the exception signals, and inspect
the machine state saved at exception time, and restart the faulting instruction
(presumably after fixing something up).
Comment 1 Dirk Mueller 2003-12-05 17:43:23 UTC
in which cases is our vcpu state not fully up to date?

are you referring to the incip hack?

Comment 2 Jeremy Fitzhardinge 2003-12-05 19:14:39 UTC
Generated code normally only stores the register state back into the baseblock at the end of each basic block.  If one of the instructions in the basic block has an exception the VCPU state will not have been updated.  If that exception's signal is caught, the handler will not see up to date state, and returning from the handler would try to restart the instruction with the wrong state.

Delayed update of the VCPU's EIP would also be a problem.

Since saving all the state back before each potentially exception-causing instruction could get expensive, this should probably be a CLO, and/or controllable by client requests.
Comment 3 Jeremy Fitzhardinge 2004-03-12 05:09:03 UTC
Bug 74298 is an example of this hitting us in practice.
Comment 4 Jeremy Fitzhardinge 2004-03-15 18:18:49 UTC
The general workaround for any code which needs precise exceptions is to use --single-step=yes.  This treats every instruction as an independent basic block.  I would expect this to have a pretty significant performance hit.
Comment 5 Johan Walles 2004-03-15 21:13:05 UTC
How about this:

First of all, don't change your codegen in any way.  When somebody registers a signal handler using sigaction(), register your own wrapper signal handler instead.  It does:
1. Update the VCPU's state using the context you receive from the kernel.
2. Call the user's signal handler with the VCPU's (now correct) context.
3. Restore the VCPU's state from whatever the user handed back to us.

I realize that since I've no clue about the internal workings of Valgrind, this may or may not be useful in any way, so I promise not to whine if you tell me the idea sucks :-).

The reason for intercepting only sigaction() is that sigaction() is the only way to register a signal handler that receives a CPU context to play with.
Comment 6 Jeremy Fitzhardinge 2004-03-15 23:17:09 UTC
The problem is that the virtual CPU state is completely, well, virtual.  At any given instruction, we don't record where the value of, say, virtual EAX currently resides, so we don't know where to pick it up from (it almost certainly isn't in the real EAX).  At the end of each basic block, we do return all the registers to well-known places, so the state is in sync then.

This only applies to signals which hit in the middle of a basic block, which limits it to synchronous exception signals (ie, SIGSEGV, SIGBUS, SIGFPE and SIGILL caused by instructions).  Async signals are all blocked, and are only processed at context switch time, which means we're definitely not in the middle of a basic block.
Comment 7 Johan Walles 2004-03-16 08:10:21 UTC
In that case, you'll need to synch before every faulting instruction just as you said.  It could have worked though :-).
Comment 8 postix 2020-01-04 16:57:57 UTC
Is this still needed?
Comment 9 Bug Janitor Service 2020-01-19 04:33:10 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 10 Bug Janitor Service 2020-02-03 04:33:16 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!
Comment 11 Tom Hughes 2020-02-03 07:07:16 UTC
Undoing KDE robot brain damage.