Lines Matching refs:shm
64 struct shm_obj *shm; in shm_obj_find() local
66 SYS_DLIST_FOR_EACH_CONTAINER(&shm_list, shm, node) { in shm_obj_find()
67 if (shm->hash == key) { in shm_obj_find()
68 return shm; in shm_obj_find()
75 static void shm_obj_add(struct shm_obj *shm) in shm_obj_add() argument
77 sys_dlist_init(&shm->node); in shm_obj_add()
78 sys_dlist_append(&shm_list, &shm->node); in shm_obj_add()
81 static void shm_obj_remove(struct shm_obj *shm) in shm_obj_remove() argument
83 sys_dlist_remove(&shm->node); in shm_obj_remove()
84 if (shm->size > 0) { in shm_obj_remove()
88 if (arch_page_phys_get(shm->mem, &phys) == 0) { in shm_obj_remove()
89 k_mem_unmap(shm->mem, ROUND_UP(shm->size, _page_size)); in shm_obj_remove()
92 k_free(shm->mem); in shm_obj_remove()
95 k_free(shm); in shm_obj_remove()
98 static int shm_fstat(struct shm_obj *shm, struct stat *st) in shm_fstat() argument
102 st->st_size = shm->size; in shm_fstat()
107 static int shm_ftruncate(struct shm_obj *shm, off_t length) in shm_ftruncate() argument
117 if (shm->size != 0) { in shm_ftruncate()
137 shm->mem = virt; in shm_ftruncate()
138 shm->size = length; in shm_ftruncate()
143 static off_t shm_lseek(struct shm_obj *shm, off_t offset, int whence, size_t cur) in shm_lseek() argument
155 addend = shm->size; in shm_lseek()
176 static int shm_mmap(struct shm_obj *shm, void *addr, size_t len, int prot, int flags, off_t off, in shm_mmap() argument
184 ((off & (_page_size - 1)) != 0) || ((len + off) > shm->size)) { in shm_mmap()
194 if (shm->mem == NULL) { in shm_mmap()
204 *virt = shm->mem + off; in shm_mmap()
209 static ssize_t shm_rw(struct shm_obj *shm, void *buf, size_t size, bool is_write, size_t offset) in shm_rw() argument
211 if (offset >= shm->size) { in shm_rw()
214 size = MIN(size, shm->size - offset); in shm_rw()
219 memcpy(&shm->mem[offset], buf, size); in shm_rw()
221 memcpy(buf, &shm->mem[offset], size); in shm_rw()
240 struct shm_obj *shm = obj; in shm_close() local
242 shm->refs -= (shm->refs > 0) ? 1 : 0; in shm_close()
243 if (shm->unlinked && (shm->refs == 0)) { in shm_close()
244 shm_obj_remove(shm); in shm_close()
252 struct shm_obj *shm = obj; in shm_ioctl() local
260 return shm_lseek(shm, offset, whence, cur); in shm_ioctl()
270 return shm_mmap(shm, addr, len, prot, flags, off, maddr); in shm_ioctl()
277 return shm_fstat(shm, st); in shm_ioctl()
282 return shm_ftruncate(shm, length); in shm_ioctl()
303 struct shm_obj *shm; in shm_open() local
339 shm = shm_obj_find(key); in shm_open()
340 if ((shm != NULL) && shm->unlinked) { in shm_open()
347 if ((shm != NULL) && excl) { in shm_open()
353 if (shm == NULL) { in shm_open()
354 shm = k_calloc(1, sizeof(*shm)); in shm_open()
355 if (shm == NULL) { in shm_open()
361 shm->hash = key; in shm_open()
362 shm_obj_add(shm); in shm_open()
364 } else if (shm == NULL) { in shm_open()
369 ++shm->refs; in shm_open()
370 zvfs_finalize_typed_fd(fd, shm, &shm_vtable, ZVFS_MODE_IFSHM); in shm_open()
378 struct shm_obj *shm; in shm_unlink() local
387 shm = shm_obj_find(key); in shm_unlink()
388 if ((shm == NULL) || shm->unlinked) { in shm_unlink()
393 shm->unlinked = true; in shm_unlink()
394 if (shm->refs == 0) { in shm_unlink()
395 shm_obj_remove(shm); in shm_unlink()