The branch stable/13 has been updated by kib:

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

commit db8710e2196c90a6310eada3b9cdd36d10689f74
Author:     Damjan Jovanovic <[email protected]>
AuthorDate: 2022-06-17 13:37:40 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2022-06-24 19:37:33 +0000

    struct kinfo_file changes needed for lsof to work using only usermode APIs`
    
    (cherry picked from commit 8c309d48aabf1cb469334c7716033f177a2715c0)
---
 sys/kern/kern_event.c  |  4 ++++
 sys/kern/sys_eventfd.c |  1 +
 sys/kern/sys_pipe.c    |  3 +++
 sys/kern/sys_socket.c  | 22 ++++++++++++----------
 sys/sys/user.h         | 12 ++++++++++--
 5 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 10959685fdbd..90a725b6e0f0 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -2317,8 +2317,12 @@ kqueue_close(struct file *fp, struct thread *td)
 static int
 kqueue_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc 
*fdp)
 {
+       struct kqueue *kq = fp->f_data;
 
        kif->kf_type = KF_TYPE_KQUEUE;
+       kif->kf_un.kf_kqueue.kf_kqueue_addr = (uintptr_t)kq;
+       kif->kf_un.kf_kqueue.kf_kqueue_count = kq->kq_count;
+       kif->kf_un.kf_kqueue.kf_kqueue_state = kq->kq_state;
        return (0);
 }
 
diff --git a/sys/kern/sys_eventfd.c b/sys/kern/sys_eventfd.c
index 91c045e85faf..d4aab88ab09d 100644
--- a/sys/kern/sys_eventfd.c
+++ b/sys/kern/sys_eventfd.c
@@ -342,6 +342,7 @@ eventfd_fill_kinfo(struct file *fp, struct kinfo_file *kif, 
struct filedesc *fdp
        mtx_lock(&efd->efd_lock);
        kif->kf_un.kf_eventfd.kf_eventfd_value = efd->efd_count;
        kif->kf_un.kf_eventfd.kf_eventfd_flags = efd->efd_flags;
+       kif->kf_un.kf_eventfd.kf_eventfd_addr = (uintptr_t)efd;
        mtx_unlock(&efd->efd_lock);
        return (0);
 }
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index b19fe8dbc0c0..0e19bf8ae7b4 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1591,6 +1591,9 @@ pipe_fill_kinfo(struct file *fp, struct kinfo_file *kif, 
struct filedesc *fdp)
        kif->kf_un.kf_pipe.kf_pipe_addr = (uintptr_t)pi;
        kif->kf_un.kf_pipe.kf_pipe_peer = (uintptr_t)pi->pipe_peer;
        kif->kf_un.kf_pipe.kf_pipe_buffer_cnt = pi->pipe_buffer.cnt;
+       kif->kf_un.kf_pipe.kf_pipe_buffer_in = pi->pipe_buffer.in;
+       kif->kf_un.kf_pipe.kf_pipe_buffer_out = pi->pipe_buffer.out;
+       kif->kf_un.kf_pipe.kf_pipe_buffer_size = pi->pipe_buffer.size;
        return (0);
 }
 
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index 8ac24a048093..f8857d3953d4 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -382,17 +382,19 @@ soo_fill_kinfo(struct file *fp, struct kinfo_file *kif, 
struct filedesc *fdp)
        switch (kif->kf_un.kf_sock.kf_sock_domain0) {
        case AF_INET:
        case AF_INET6:
-               if (kif->kf_un.kf_sock.kf_sock_protocol0 == IPPROTO_TCP) {
-                       if (so->so_pcb != NULL) {
-                               inpcb = (struct inpcb *)(so->so_pcb);
-                               kif->kf_un.kf_sock.kf_sock_inpcb =
-                                   (uintptr_t)inpcb->inp_ppcb;
-                               kif->kf_un.kf_sock.kf_sock_sendq =
-                                   sbused(&so->so_snd);
-                               kif->kf_un.kf_sock.kf_sock_recvq =
-                                   sbused(&so->so_rcv);
-                       }
+               if (so->so_pcb != NULL) {
+                       inpcb = (struct inpcb *)(so->so_pcb);
+                       kif->kf_un.kf_sock.kf_sock_inpcb =
+                           (uintptr_t)inpcb->inp_ppcb;
                }
+               kif->kf_un.kf_sock.kf_sock_rcv_sb_state =
+                   so->so_rcv.sb_state;
+               kif->kf_un.kf_sock.kf_sock_snd_sb_state =
+                   so->so_snd.sb_state;
+               kif->kf_un.kf_sock.kf_sock_sendq =
+                   sbused(&so->so_snd);
+               kif->kf_un.kf_sock.kf_sock_recvq =
+                   sbused(&so->so_rcv);
                break;
        case AF_UNIX:
                if (so->so_pcb != NULL) {
diff --git a/sys/sys/user.h b/sys/sys/user.h
index aa1b02ad6192..433e44c0f19e 100644
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -420,8 +420,9 @@ struct kinfo_file {
                                uint64_t        kf_pipe_addr;
                                uint64_t        kf_pipe_peer;
                                uint32_t        kf_pipe_buffer_cnt;
-                               /* Round to 64 bit alignment. */
-                               uint32_t        kf_pipe_pad0[3];
+                               uint32_t        kf_pipe_buffer_in;
+                               uint32_t        kf_pipe_buffer_out;
+                               uint32_t        kf_pipe_buffer_size;
                        } kf_pipe;
                        struct {
                                uint32_t        kf_spareint[4];
@@ -440,7 +441,14 @@ struct kinfo_file {
                        struct {
                                uint64_t        kf_eventfd_value;
                                uint32_t        kf_eventfd_flags;
+                               uint32_t        kf_eventfd_spareint[3];
+                               uint64_t        kf_eventfd_addr;
                        } kf_eventfd;
+                       struct {
+                               uint64_t        kf_kqueue_addr;
+                               int32_t         kf_kqueue_count;
+                               int32_t         kf_kqueue_state;
+                       } kf_kqueue;
                } kf_un;
        };
        uint16_t        kf_status;              /* Status flags. */

Reply via email to