Remove functions depending on each other, cleanup internal errno in shm_common, remove various unnecessary includes.