git: ba8062dc2280 - stable/14 - kinfo_vmentry: report mappings of the SysV shm segments

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 15:05:25 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=ba8062dc22805089e69a8b47e0a15c50ae35f007

commit ba8062dc22805089e69a8b47e0a15c50ae35f007
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-05 09:15:12 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-10-15 14:50:16 +0000

    kinfo_vmentry: report mappings of the SysV shm segments
    
    (cherry picked from commit d3dd6bd4039573eb74cd77da5b92e68b04296888)
---
 sys/kern/kern_proc.c | 10 ++++++++++
 sys/sys/user.h       |  1 +
 2 files changed, 11 insertions(+)

diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index b52455f140b2..d20fc0ac4e9a 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -44,6 +44,7 @@
 #include <sys/eventhandler.h>
 #include <sys/exec.h>
 #include <sys/fcntl.h>
+#include <sys/ipc.h>
 #include <sys/jail.h>
 #include <sys/kernel.h>
 #include <sys/limits.h>
@@ -62,6 +63,7 @@
 #include <sys/sbuf.h>
 #include <sys/sysent.h>
 #include <sys/sched.h>
+#include <sys/shm.h>
 #include <sys/smp.h>
 #include <sys/stack.h>
 #include <sys/stat.h>
@@ -2616,6 +2618,8 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
 	vm_offset_t addr;
 	unsigned int last_timestamp;
 	int error;
+	key_t key;
+	unsigned short seq;
 	bool guard, super;
 
 	PROC_LOCK_ASSERT(p, MA_OWNED);
@@ -2706,6 +2710,12 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
 			kve->kve_ref_count = obj->ref_count;
 			kve->kve_shadow_count = obj->shadow_count;
 			VM_OBJECT_RUNLOCK(obj);
+			if ((lobj->flags & OBJ_SYSVSHM) != 0) {
+				kve->kve_flags |= KVME_FLAG_SYSVSHM;
+				shmobjinfo(lobj, &key, &seq);
+				kve->kve_vn_fileid = key;
+				kve->kve_vn_fsid_freebsd11 = seq;
+			}
 			if (vp != NULL) {
 				vn_fullpath(vp, &fullpath, &freepath);
 				kve->kve_vn_type = vntype_to_kinfo(vp->v_type);
diff --git a/sys/sys/user.h b/sys/sys/user.h
index bd460d452bcc..70592eb44668 100644
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -516,6 +516,7 @@ struct kinfo_lockf {
 #define	KVME_FLAG_GROWS_UP	0x00000010
 #define	KVME_FLAG_GROWS_DOWN	0x00000020
 #define	KVME_FLAG_USER_WIRED	0x00000040
+#define	KVME_FLAG_SYSVSHM	0x00000080
 
 #if defined(__amd64__)
 #define	KINFO_OVMENTRY_SIZE	1168