-Mostly copy and paste from the prctl version with some individual changes. Next up: Testing. Former-commit-id: 19a4f90255
19a4f90255