git: 64de7b789b3d - stable/14 - posix shm: add shm_get_path(9)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 15 Oct 2024 15:05:34 UTC
The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=64de7b789b3d9fb03dfac93fa8c3ba6fa27bcd82 commit 64de7b789b3d9fb03dfac93fa8c3ba6fa27bcd82 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-10-07 01:44:49 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-10-15 14:50:17 +0000 posix shm: add shm_get_path(9) (cherry picked from commit bda73e441f2576de5ad00856d758354c299a3f75) --- sys/kern/uipc_shm.c | 31 +++++++++++++++++++++++++++++++ sys/sys/mman.h | 1 + 2 files changed, 32 insertions(+) diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c index 52a569931b01..8334d7eb3264 100644 --- a/sys/kern/uipc_shm.c +++ b/sys/kern/uipc_shm.c @@ -2196,3 +2196,34 @@ sys_shm_open2(struct thread *td, struct shm_open2_args *uap) return (kern_shm_open2(td, uap->path, uap->flags, uap->mode, uap->shmflags, NULL, uap->name)); } + +int +shm_get_path(struct vm_object *obj, char *path, size_t sz) +{ + struct shmfd *shmfd; + int error; + + error = 0; + shmfd = NULL; + sx_slock(&shm_dict_lock); + VM_OBJECT_RLOCK(obj); + if ((obj->flags & OBJ_POSIXSHM) == 0) { + error = EINVAL; + } else { + if (obj->type == shmfd_pager_type) + shmfd = obj->un_pager.swp.swp_priv; + else if (obj->type == OBJT_PHYS) + shmfd = obj->un_pager.phys.phys_priv; + if (shmfd == NULL) { + error = ENXIO; + } else { + strlcpy(path, shmfd->shm_path == NULL ? "anon" : + shmfd->shm_path, sz); + } + } + if (error != 0) + path[0] = '\0'; + VM_OBJECT_RUNLOCK(obj); + sx_sunlock(&shm_dict_lock); + return (error); +} diff --git a/sys/sys/mman.h b/sys/sys/mman.h index 7eb38a5f59d0..36973b941e61 100644 --- a/sys/sys/mman.h +++ b/sys/sys/mman.h @@ -310,6 +310,7 @@ void shm_drop(struct shmfd *shmfd); int shm_dotruncate(struct shmfd *shmfd, off_t length); bool shm_largepage(struct shmfd *shmfd); void shm_remove_prison(struct prison *pr); +int shm_get_path(struct vm_object *obj, char *path, size_t sz); extern struct fileops shm_ops;