From 49d5458aaf458aaacf3250bc72cc90dc2a983497 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Wed, 24 Apr 2024 21:34:03 +0200 Subject: [PATCH] FreeBSD syscall: add wrapper for kcmp For FreeBSD 15.0-CURRENT. Will need to add for 14.1 when it is out. Mostly the same as the Linux kcmp syscall (small differences in the supported types). --- coregrind/m_syswrap/priv_syswrap-freebsd.h | 1 + coregrind/m_syswrap/syswrap-freebsd.c | 27 +++++++++++++++++++++++++++ include/vki/vki-freebsd.h | 7 +++++++ include/vki/vki-scnums-freebsd.h | 1 + 4 files changed, 36 insertions(+) diff --git a/coregrind/m_syswrap/priv_syswrap-freebsd.h b/coregrind/m_syswrap/priv_syswrap-freebsd.h index 7e8924d88..ed0889d20 100644 --- a/coregrind/m_syswrap/priv_syswrap-freebsd.h +++ b/coregrind/m_syswrap/priv_syswrap-freebsd.h @@ -573,6 +573,7 @@ DECL_TEMPLATE(freebsd, sys_membarrier) // 584 DECL_TEMPLATE(freebsd, sys_timerfd_create) // 585 DECL_TEMPLATE(freebsd, sys_timerfd_gettime) // 586 DECL_TEMPLATE(freebsd, sys_timerfd_settime) // 587 +DECL_TEMPLATE(freebsd, sys_kcmp) // 588 #endif DECL_TEMPLATE(freebsd, sys_fake_sigreturn) diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index bcd181e9d..0a937d37f 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -7138,6 +7138,32 @@ POST(sys_timerfd_settime) POST_MEM_WRITE(ARG4, sizeof(struct vki_itimerspec)); } } + +// SYS_kcmp 588 +// int kcmp(pid_t pid1, pid_t pid2, int type, uintptr_t idx1, uintptr_t idx2); +PRE(sys_kcmp) +{ + PRINT("kcmp(%ld, %ld, %ld, %" FMT_REGWORD "u, %" FMT_REGWORD "u)", + SARG1, SARG2, SARG3, ARG4, ARG5); + switch (ARG3) { + case VKI_KCMP_FILES: + case VKI_KCMP_VM: + case VKI_KCMP_SIGHAND: + /* Most of the comparison types don't look at |idx1| or |idx2|. */ + PRE_REG_READ3(int, "kcmp", + vki_pid_t, pid1, vki_pid_t, pid2, int, type); + break; + case VKI_KCMP_FILE: + case VKI_KCMP_FILEOBJ: + default: + PRE_REG_READ5(int, "kcmp", + vki_pid_t, pid1, vki_pid_t, pid2, int, type, + unsigned long, idx1, unsigned long, idx2); + break; + } +} + + #endif #undef PRE @@ -7873,6 +7899,7 @@ const SyscallTableEntry ML_(syscall_table)[] = { BSDXY(__NR_timerfd_create, sys_timerfd_create), // 585 BSDXY(__NR_timerfd_settime, sys_timerfd_settime), // 586 BSDXY(__NR_timerfd_gettime, sys_timerfd_gettime), // 587 + BSDX_(__NR_kcmp, sys_kcmp), // 588 #endif diff --git a/include/vki/vki-freebsd.h b/include/vki/vki-freebsd.h index 14b170388..77f75457d 100644 --- a/include/vki/vki-freebsd.h +++ b/include/vki/vki-freebsd.h @@ -1623,6 +1623,13 @@ struct vki_spacectl_range { #define VKI_RFSPAWN (1U<<31U) +/* kcmp() options. */ +#define VKI_KCMP_FILE 100 +#define VKI_KCMP_FILEOBJ 101 +#define VKI_KCMP_FILES 102 +#define VKI_KCMP_SIGHAND 103 +#define VKI_KCMP_VM 104 + #define VKI_CLOSE_RANGE_CLOEXEC (1<<2) //---------------------------------------------------------------------- diff --git a/include/vki/vki-scnums-freebsd.h b/include/vki/vki-scnums-freebsd.h index 344b932fa..967cd7835 100644 --- a/include/vki/vki-scnums-freebsd.h +++ b/include/vki/vki-scnums-freebsd.h @@ -687,6 +687,7 @@ #define __NR_timerfd_create 585 #define __NR_timerfd_gettime 586 #define __NR_timerfd_settime 587 +#define __NR_kcmp 588 #endif -- 2.11.4.GIT