This is exactly how Windows' device drivers work. What you are asking for is the same functionality be extended to userland programs.
The primary problem for this is proof generation. Programming paradigms where proofs are easy to generate would be too limiting. So, although we gain security, our flexibility is tarnished.