MPS issue job004006

TitleCVM postmortem debugging support is not properly integrated into the MPS
Assigned userRichard Brooksby
DescriptionChangelist 190660 [1] contains various extensions to the MPS for CVM that have been implemented in the CVM source tree, but which need incorporating properly into the MPS.
AnalysisInspection of the CVM sources shows that the following functions are called:

* mps_unsafe_unprotect
* mps_is_arena_lock_held
* mps_enter_fatal_mode

The extensions support debugging. The requirement here is to be able to safely debug the system when the MPS is active. In particular (since CVM is a JIT compiler that stores its compiled code on the heap) in order to decode the stack, the debugger needs access to memory which may be protected by the MPS. This causes the debugger to hit a protected page, which re-enters the MPS via the MPS's vectored exception handler, which fails because the arena lock is already held.

Accordingly, there is a call mps_enter_fatal_mode(arena) which (i) releases the arena lock if held; (ii) removes protection from pages managed by the MPS if any; (iii) removes the MPS's vectored exception handler.

Justification for (i): you might want to be able to call MPS functions like mps_addr_pool or whatever from the debugger, and these would need to take the arena lock.

Justification for (ii): debugger needs to be able to decode the stack on Win64; you need to be able to look at memory from the debugger.

(iii) seems like a bad idea (it doesn't handle multiple arenas gracefully, and it's hard to implement on other platforms). Better would be to remove the arena from the global ring of arenas. This would mean that it would no longer be consulted by ArenaAccess.

DL suggests that it would also be a good idea to stop the arena from starting new traces, or progressing any active traces. (But see mpscvm.c -- there's a call to mps_arena_clamp in mps_enter_fatal_mode that has been commented out for some reason.)

See also job003911, job003951.
How foundinspection
Created byRichard Brooksby
Created on2016-04-18 15:42:16
Last modified byGareth Rees
Last modified on2016-09-13 17:32:07
History2016-04-18 RB Created.
2016-09-06 GDR Analysis.


Change Effect Date User Description
192365 closed 2016-09-13 17:32:07 Gareth Rees Merge branch/2016-09-06/job004006.