Move logic to finish emulated syscalls into Task.

#603