Split out syscall-executing logic to make upcoming changes to task execution state simpler.

Looks big and scary, but it's just splitting some code into its own function and normalizing formatting a bit.  On the road to #293.