complete write_shmem function