* Finds segment either by shmid if is_shmid is true, or by segnum if * is_shmid is false. */
| 227 | * is_shmid is false. |
| 228 | */ |
| 229 | static struct shmid_kernel * |
| 230 | shm_find_segment(struct prison *rpr, int arg, bool is_shmid) |
| 231 | { |
| 232 | struct shmid_kernel *shmseg; |
| 233 | int segnum; |
| 234 | |
| 235 | segnum = is_shmid ? IPCID_TO_IX(arg) : arg; |
| 236 | if (segnum < 0 || segnum >= shmalloced) |
| 237 | return (NULL); |
| 238 | shmseg = &shmsegs[segnum]; |
| 239 | if ((shmseg->u.shm_perm.mode & SHMSEG_ALLOCATED) == 0 || |
| 240 | (!shm_allow_removed && |
| 241 | (shmseg->u.shm_perm.mode & SHMSEG_REMOVED) != 0) || |
| 242 | (is_shmid && shmseg->u.shm_perm.seq != IPCID_TO_SEQ(arg)) || |
| 243 | shm_prison_cansee(rpr, shmseg) != 0) |
| 244 | return (NULL); |
| 245 | return (shmseg); |
| 246 | } |
| 247 | |
| 248 | static void |
| 249 | shm_deallocate_segment(struct shmid_kernel *shmseg) |
no test coverage detected