freebsd-src icon indicating copy to clipboard operation
freebsd-src copied to clipboard

linprocfs: Add support for proc/sysvipc/{msg,sem,shm}

Open ricardobranco777 opened this issue 9 months ago • 0 comments

Add support for proc/sysvipc/{msg,sem,shm}

Tracking in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=278812

To build:

  1. cd /sys/modules/linprocfs
  2. make && doas make install && doas cp -f /boot/modules/linprocfs.ko /boot/kernel/
  3. doas kldxref /boot/kernel/
  4. doas umount -a -t linprocfs
  5. doas kldunload -v linprocfs
  6. doas kldload -v linprocfs
  7. doas mount -t linprocfs linprocfs /compat/linux/proc/

How I tested it (needs ipcmk from the util-linux package):

$ ipcmk --shmem 128K
Shared memory id: 131072

$ cat /compat/linux/proc/sysvipc/shm 
       key      shmid perms                  size  cpid  lpid nattch   uid   gid  cuid  cgid      atime      dtime      ctime                   rss                  swap
-264176145     131072  4644                131072 39330     0      0  1000  1000  1000  1000          0          0 1714846976                    -1                    -1

$ ipcmk --semaphore 7 
Semaphore id: 196608

$ cat /compat/linux/proc/sysvipc/sem
       key      semid perms      nsems   uid   gid  cuid  cgid      otime      ctime
1038146433     196608  1644          7  1000  1000  1000  1000          0 1714847009

$ ipcmk --queue
Message queue id: 131072

$ cat /compat/linux/proc/sysvipc/msg
       key      msqid perms      cbytes       qnum lspid lrpid   uid   gid  cuid  cgid      stime      rtime      ctime
 756788372     131072   644           0          0     0     0  1000  1000  1000  1000          0          0 1714847025

$ ipcs -a
Message Queues:
T           ID          KEY MODE        OWNER    GROUP    CREATOR  CGROUP                 CBYTES                 QNUM               QBYTES        LSPID        LRPID STIME    RTIME    CTIME
q       131072    756788372 --rw-r--r-- ricardo  ricardo  ricardo  ricardo             0            0                 2048            0            0 no-entry no-entry 20:23:45

Shared Memory:
T           ID          KEY MODE        OWNER    GROUP    CREATOR  CGROUP         NATTCH        SEGSZ         CPID         LPID ATIME    DTIME    CTIME
m       131072   -264176145 --rw-r--r-- ricardo  ricardo  ricardo  ricardo             0       131072        39330            0 no-entry no-entry 20:22:56

Semaphores:
T           ID          KEY MODE        OWNER    GROUP    CREATOR  CGROUP          NSEMS OTIME    CTIME
s       196608   1038146433 --rw-r--r-- ricardo  ricardo  ricardo  ricardo             7 no-entry 20:23:29

The filtering is the same as done by ipcs:

  • msg: https://github.com/freebsd/freebsd-src/blob/main/usr.bin/ipcs/ipcs.c#L215
  • shm: https://github.com/freebsd/freebsd-src/blob/main/usr.bin/ipcs/ipcs.c#L247
  • sem: https://github.com/freebsd/freebsd-src/blob/main/usr.bin/ipcs/ipcs.c#L276

Format string adapted from:

  • shm: https://github.com/torvalds/linux/blob/master/ipc/shm.c#L1857
  • sem: https://github.com/torvalds/linux/blob/master/ipc/sem.c#L2468
  • msg: https://github.com/torvalds/linux/blob/master/ipc/msg.c#L1349

ricardobranco777 avatar May 04 '24 18:05 ricardobranco777