1*8269e767SBrooks Davis.\" SPDX-License-Identifier: BSD-2-Clause 2*8269e767SBrooks Davis.\" 3*8269e767SBrooks Davis.\" Copyright (c) 2024 The FreeBSD Foundation 4*8269e767SBrooks Davis.\" 5*8269e767SBrooks Davis.\" This documentation was written by 6*8269e767SBrooks Davis.\" Mark Johnston <markj@FreeBSD.org> under sponsorship 7*8269e767SBrooks Davis.\" from the FreeBSD Foundation. 8*8269e767SBrooks Davis.\" 9*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 10*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 11*8269e767SBrooks Davis.\" are met: 12*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 13*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 14*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 15*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 16*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 17*8269e767SBrooks Davis.\" 18*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 19*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 22*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*8269e767SBrooks Davis.\" SUCH DAMAGE. 29*8269e767SBrooks Davis.\" 30*8269e767SBrooks Davis.Dd January 23, 2024 31*8269e767SBrooks Davis.Dt KCMP 2 32*8269e767SBrooks Davis.Os 33*8269e767SBrooks Davis.Sh NAME 34*8269e767SBrooks Davis.Nm kcmp 35*8269e767SBrooks Davis.Nd compare two kernel objects 36*8269e767SBrooks Davis.Sh LIBRARY 37*8269e767SBrooks Davis.Lb libc 38*8269e767SBrooks Davis.Sh SYNOPSIS 39*8269e767SBrooks Davis.In unistd.h 40*8269e767SBrooks Davis.Ft int 41*8269e767SBrooks Davis.Fn kcmp "pid_t pid1" "pid_t pid2" "int type" "uintptr_t idx1" "uintptr_t idx2" 42*8269e767SBrooks Davis.Sh DESCRIPTION 43*8269e767SBrooks DavisThe 44*8269e767SBrooks Davis.Nm 45*8269e767SBrooks Davissystem call allows the caller to determine whether the two processes with 46*8269e767SBrooks DavisPIDs 47*8269e767SBrooks Davis.Fa pid1 48*8269e767SBrooks Davisand 49*8269e767SBrooks Davis.Fa pid2 50*8269e767SBrooks Davisreference the same kernel object. 51*8269e767SBrooks DavisThe 52*8269e767SBrooks Davis.Fa type 53*8269e767SBrooks Davisparameter specifies the type of object, and 54*8269e767SBrooks Davis.Fa idx1 55*8269e767SBrooks Davisand 56*8269e767SBrooks Davis.Fa idx2 57*8269e767SBrooks Davisare identifiers which refer to some object in the context of process 58*8269e767SBrooks Davis.Fa pid1 59*8269e767SBrooks Davisand 60*8269e767SBrooks Davis.Fa pid2 , 61*8269e767SBrooks Davisrespectively. 62*8269e767SBrooks Davis.Pp 63*8269e767SBrooks DavisThe following values for 64*8269e767SBrooks Davis.Fa type 65*8269e767SBrooks Davismay be specified: 66*8269e767SBrooks Davis.Bl -tag -width KCMP_FILE 67*8269e767SBrooks Davis.It Dv KCMP_FILE 68*8269e767SBrooks DavisCompare two file descriptions referred to by file descriptors 69*8269e767SBrooks Davis.Fa idx1 70*8269e767SBrooks Davisand 71*8269e767SBrooks Davis.Fa idx2 . 72*8269e767SBrooks DavisThey may be equivalent if, for example, one of the descriptors was 73*8269e767SBrooks Daviscreated by applying 74*8269e767SBrooks Davis.Xr dup 2 75*8269e767SBrooks Davisto the other descriptor. 76*8269e767SBrooks Davis.It Dv KCMP_FILEOBJ 77*8269e767SBrooks DavisPerform a 78*8269e767SBrooks Davis.Dq deep comparison 79*8269e767SBrooks Davisof the file descriptions referred to by file descriptors 80*8269e767SBrooks Davis.Fa idx1 81*8269e767SBrooks Davisand 82*8269e767SBrooks Davis.Fa idx2 . 83*8269e767SBrooks DavisThis tests whether the underlying object referred to by the file descriptions 84*8269e767SBrooks Davisis the same. 85*8269e767SBrooks DavisFor example, if the same filesystem path is opened twice, the kernel will create 86*8269e767SBrooks Davistwo separate file descriptions to back the two file descriptors, but they will 87*8269e767SBrooks Davisrefer to the same underlying object, a 88*8269e767SBrooks Davis.Xr vnode 9 . 89*8269e767SBrooks DavisWhen compared using the 90*8269e767SBrooks Davis.Dv KCMP_FILE 91*8269e767SBrooks Davistype, these descriptors will be different, but using the 92*8269e767SBrooks Davis.Dv KCMP_FILEOBJ 93*8269e767SBrooks Davistype, they will be equal (assuming that the path was not unlinked in between 94*8269e767SBrooks Davisthe two opens). 95*8269e767SBrooks Davis.It Dv KCMP_FILES 96*8269e767SBrooks DavisDetermine whether the two processes share the same file descriptor table. 97*8269e767SBrooks DavisThis will be the case if one of the processes was created by 98*8269e767SBrooks Davis.Xr rfork 2 99*8269e767SBrooks Daviswithout specifying the 100*8269e767SBrooks Davis.Dv RFFDG 101*8269e767SBrooks Davisflag. 102*8269e767SBrooks DavisThe 103*8269e767SBrooks Davis.Fa idx1 104*8269e767SBrooks Davisand 105*8269e767SBrooks Davis.Fa idx2 106*8269e767SBrooks Davisparameters are ignored. 107*8269e767SBrooks Davis.It Dv KCMP_SIGHAND 108*8269e767SBrooks DavisDetermine whether the two processes share the same signal handler table. 109*8269e767SBrooks DavisThis will be the case if one of the processes was created using the 110*8269e767SBrooks Davis.Dv RFSIGSHARE 111*8269e767SBrooks Davisflag to 112*8269e767SBrooks Davis.Xr rfork 2 . 113*8269e767SBrooks DavisThe 114*8269e767SBrooks Davis.Fa idx1 115*8269e767SBrooks Davisand 116*8269e767SBrooks Davis.Fa idx2 117*8269e767SBrooks Davisparameters are ignored. 118*8269e767SBrooks Davis.It Dv KCMP_VM 119*8269e767SBrooks DavisDetermine whether the two processes share a virtual memory address space. 120*8269e767SBrooks DavisThis may be the case if one of the processes created the other using 121*8269e767SBrooks Davis.Xr vfork 2 122*8269e767SBrooks Davisor 123*8269e767SBrooks Davis.Xr rfork 2 124*8269e767SBrooks Daviswith the 125*8269e767SBrooks Davis.Dv RFMEM 126*8269e767SBrooks Davisflag. 127*8269e767SBrooks DavisThe 128*8269e767SBrooks Davis.Fa idx1 129*8269e767SBrooks Davisand 130*8269e767SBrooks Davis.Fa idx2 131*8269e767SBrooks Davisparameters are ignored. 132*8269e767SBrooks Davis.El 133*8269e767SBrooks DavisThe caller of 134*8269e767SBrooks Davis.Nm 135*8269e767SBrooks Davismust have permission to debug both processes, otherwise the system call 136*8269e767SBrooks Daviswill fail. 137*8269e767SBrooks Davis.Sh RETURN VALUES 138*8269e767SBrooks DavisIf 139*8269e767SBrooks Davis.Fa idx1 140*8269e767SBrooks Davisand 141*8269e767SBrooks Davis.Fa idx2 142*8269e767SBrooks Davisrefer to the same object, 143*8269e767SBrooks Davis.Nm 144*8269e767SBrooks Davisreturns 0. 145*8269e767SBrooks DavisIf the object referred to by 146*8269e767SBrooks Davis.Fa pid1 147*8269e767SBrooks Davisand 148*8269e767SBrooks Davis.Fa idx1 149*8269e767SBrooks Davisis less or greater than the object referred to by 150*8269e767SBrooks Davis.Fa pid2 151*8269e767SBrooks Davisand 152*8269e767SBrooks Davis.Fa idx2 , 153*8269e767SBrooks Davis.Nm 154*8269e767SBrooks Davisreturns the values 1 and 2, respectively. 155*8269e767SBrooks DavisThe order is defined internally by the kernel and is stable until the system 156*8269e767SBrooks Davisreboots. 157*8269e767SBrooks DavisIf the two objects cannot be compared for some reason, 158*8269e767SBrooks Davis.Nm 159*8269e767SBrooks Davisreturns 3. 160*8269e767SBrooks DavisFor example, if 161*8269e767SBrooks Davis.Fa type 162*8269e767SBrooks Davisis 163*8269e767SBrooks Davis.Dv KCMP_FILEOBJ 164*8269e767SBrooks Davisand 165*8269e767SBrooks Davis.Fa idx1 166*8269e767SBrooks Davisand 167*8269e767SBrooks Davis.Fa idx2 168*8269e767SBrooks Davisare different descriptor types, e.g., a socket and a file, then 169*8269e767SBrooks Davis.Nm 170*8269e767SBrooks Daviswill return 3. 171*8269e767SBrooks Davis.Pp 172*8269e767SBrooks DavisIf an error occurs, the value -1 is returned and the global variable 173*8269e767SBrooks Davis.Va errno 174*8269e767SBrooks Davisis set to indicate the error. 175*8269e767SBrooks Davis.Sh ERRORS 176*8269e767SBrooks Davis.Nm 177*8269e767SBrooks Davismay fail with the following errors: 178*8269e767SBrooks Davis.Bl -tag -width Er 179*8269e767SBrooks Davis.It Bq Er ENODEV 180*8269e767SBrooks Davis.Dv KCMP_FILEOBJ 181*8269e767SBrooks Daviswas specified and 182*8269e767SBrooks Davis.Fa idx1 183*8269e767SBrooks Davisrefers to a file descriptor which does not implement a comparison operator. 184*8269e767SBrooks Davis.It Bq Er EINVAL 185*8269e767SBrooks DavisThe value of 186*8269e767SBrooks Davis.Fa type 187*8269e767SBrooks Davisis invalid. 188*8269e767SBrooks Davis.It Bq Er EBADF 189*8269e767SBrooks DavisOne of the file descriptors referred to by 190*8269e767SBrooks Davis.Fa idx1 191*8269e767SBrooks Davisor 192*8269e767SBrooks Davis.Fa idx2 193*8269e767SBrooks Davisis not valid. 194*8269e767SBrooks Davis.It Bq Er ESRCH 195*8269e767SBrooks DavisOne of the processes referred to by 196*8269e767SBrooks Davis.Fa pid1 197*8269e767SBrooks Davisor 198*8269e767SBrooks Davis.Fa pid2 199*8269e767SBrooks Davisdoes not exist or is not visible (e.g., due to jail restrictions). 200*8269e767SBrooks Davis.It Bq Er EPERM 201*8269e767SBrooks DavisThe caller does not have permission to access one of the processes referred to 202*8269e767SBrooks Davisby 203*8269e767SBrooks Davis.Fa pid1 204*8269e767SBrooks Davisor 205*8269e767SBrooks Davis.Fa pid2 . 206*8269e767SBrooks Davis.El 207*8269e767SBrooks Davis.Sh SEE ALSO 208*8269e767SBrooks Davis.Xr dup 2 , 209*8269e767SBrooks Davis.Xr fcntl 2 , 210*8269e767SBrooks Davis.Xr fork 2 , 211*8269e767SBrooks Davis.Xr rfork 2 , 212*8269e767SBrooks Davis.Xr vfork 2 213*8269e767SBrooks Davis.Sh STANDARDS 214*8269e767SBrooks DavisThe 215*8269e767SBrooks Davis.Nm 216*8269e767SBrooks Davissystem call originated in Linux. 217*8269e767SBrooks DavisThis implementation aims to be source-compatible with the Linux implementation. 218*8269e767SBrooks Davis.Fx 219*8269e767SBrooks Davisimplements only a subset of the possible values for 220*8269e767SBrooks Davis.Fa type 221*8269e767SBrooks Davissupported in Linux. 222*8269e767SBrooks DavisMore values may be added in the future. 223*8269e767SBrooks DavisThe 224*8269e767SBrooks Davis.Dv KCMP_FILEOBJ 225*8269e767SBrooks Davistype is a FreeBSD extension. 226*8269e767SBrooks Davis.Sh HISTORY 227*8269e767SBrooks DavisThe 228*8269e767SBrooks Davis.Nm 229*8269e767SBrooks Davisfunction was introduced in 230*8269e767SBrooks Davis.Fx 14.1 . 231