From nobody Wed Jan 24 14:43:03 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TKmsM53Crz587sG; Wed, 24 Jan 2024 14:43:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TKmsM4cTQz4jKq; Wed, 24 Jan 2024 14:43:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706107383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YsOunRQdzi+AMzA9iARS0SNTevZl9SzYoVANgX38RME=; b=cgOdQ8cFO7TUuY0UuvIzBD2SwqgMpsJ3ABJpQQ/Y+N4JRg0AdzhmtG1xDx4haE53zngH65 vTmRmuFPGJDddO4ApTU56qbEai3dq5X4y5qCrhOH6+4izV3ll2A0nj0jjOzpHEUI4icteB y5ISUz0VAo8hpRAOabdx8lKP6cLi0TH6UT6DG8sdFclwAVVs/wVfwB8lthmFjGGKz1Tgvy 0Ug6MHxww3JKTF2oQi/CLiYxa7AIKuQLtqElmA4Ei0KiSRUSvz9wD4UMgV1JJ29pN+1vPZ c+k3lXfAeKFIxyhQpYeQmR213PrcTY1WFV7peEotxJmxD+tmXBfV0dXvD0zs8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706107383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YsOunRQdzi+AMzA9iARS0SNTevZl9SzYoVANgX38RME=; b=ZkJjE1OgATahzu+paYXOGvbJ8QPZ4DKpCkqib0CvtmN3otnsSXhjwxLLDPY3Y/3vILvERC xxZGlWZ3kPWzy4LwkmeWKJWEV09gFIvI+2VxXX/iMOgb2jgxlvlI4s6kLU2wCYkq7+dVGx /wqXjujFddTKomRjuGqRcGlOaQbP/xop+napZcYFRq0k/6MAsttRUPjal5GGhS8qbOlYm9 fnAsp7sNJzyeyZtl6fiiGjz/2fqUBpNgRGesIaPOz+ucDFyjL/hy/QRd6/C0rvrdN2AA+P qadAfwHg4wTuWYxz+039MWDaP2iDKYrGzxsqILNSykyr9cQfvTI2K1cXgBxS0Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706107383; a=rsa-sha256; cv=none; b=WYToBsCOWLDH4V3syE4/kmOyU/NG85oiNcILME5fG0MsX5SrakbEP0TnwQprC4RT85TuIf 6sHYjcykHjlC10pTT7mA2np3FqahnppXddxyagYLRmqTz5byucjcVE9bZM9IXH8qBmAgmL xXI6B9hB1hEazK+DaY18pu/Ks3J/dnm3mr0oXKm9/vHaUkkIz1PZmYo9QPNDk0GaNWstb2 //u9oX0iqRuXLt83NaYZbiH8NyJEeH061d05KGq8L3zGWqJvmazxXPSNrCZ+kX9jDD1js9 KmhaHaAkQ1ET5rLoKn8a7HO1WwkqOHclBRxCYDL0/V6k+cLgN002SLfplnSIdg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TKmsM3jZPzJN9; Wed, 24 Jan 2024 14:43:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40OEh3tg098822; Wed, 24 Jan 2024 14:43:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40OEh3b4098819; Wed, 24 Jan 2024 14:43:03 GMT (envelope-from git) Date: Wed, 24 Jan 2024 14:43:03 GMT Message-Id: <202401241443.40OEh3b4098819@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: af0d437dd31f - main - kcmp: Add a manual page List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: af0d437dd31f71726f7eb5e9aca9fbd374a8277a Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=af0d437dd31f71726f7eb5e9aca9fbd374a8277a commit af0d437dd31f71726f7eb5e9aca9fbd374a8277a Author: Mark Johnston AuthorDate: 2024-01-24 14:41:31 +0000 Commit: Mark Johnston CommitDate: 2024-01-24 14:42:15 +0000 kcmp: Add a manual page Reviewed by: kib, emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D43562 --- lib/libc/sys/Makefile.inc | 1 + lib/libc/sys/kcmp.2 | 230 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+) diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 4137699bb741..b533443f96b2 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -215,6 +215,7 @@ MAN+= abort2.2 \ ioctl.2 \ issetugid.2 \ jail.2 \ + kcmp.2 \ kenv.2 \ kill.2 \ kldfind.2 \ diff --git a/lib/libc/sys/kcmp.2 b/lib/libc/sys/kcmp.2 new file mode 100644 index 000000000000..5491e09b918b --- /dev/null +++ b/lib/libc/sys/kcmp.2 @@ -0,0 +1,230 @@ +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2024 The FreeBSD Foundation +.\" +.\" This documentation was written by +.\" Mark Johnston under sponsorship +.\" from the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd January 23, 2024 +.Dt KCMP 2 +.Os +.Sh NAME +.Nm kcmp +.Nd compare two kernel objects +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn kcmp "pid_t pid1" "pid_t pid2" "int type" "uintptr_t idx1" "uintptr_t idx2" +.Sh DESCRIPTION +The +.Nm +system call allows the caller to determine whether the two processes with +PIDs +.Fa pid1 +and +.Fa pid2 +reference the same kernel object. +The +.Fa type +parameter specifies the type of object, and +.Fa idx1 +and +.Fa idx2 +are identifiers which refer to some object in the context of process +.Fa pid1 +and +.Fa pid2 , +respectively. +.Pp +The following values for +.Fa type +may be specified: +.Bl -tag -width KCMP_FILE +.It Dv KCMP_FILE +Compare two file descriptions referred to by file descriptors +.Fa idx1 +and +.Fa idx2 . +They may be equivalent if, for example, one of the descriptors was +created by applying +.Xr dup 2 +to the other descriptor. +.It Dv KCMP_FILEOBJ +Perform a +.Dq deep comparison +of the file descriptions referred to by file descriptors +.Fa idx1 +and +.Fa idx2 . +This tests whether the underlying object referred to by the file descriptions +is the same. +For example, if the same filesystem path is opened twice, the kernel will create +two separate file descriptions to back the two file descriptors, but they will +refer to the same underlying object, a +.Xr vnode 9 . +When compared using the +.Dv KCMP_FILE +type, these descriptors will be different, but using the +.Dv KCMP_FILEOBJ +type, they will be equal (assuming that the path was not unlinked in between +the two opens). +.It Dv KCMP_FILES +Determine whether the two processes share the same file descriptor table. +This will be the case if one of the processes was created by +.Xr rfork 2 +without specifying the +.Dv RFFDG +flag. +The +.Fa idx1 +and +.Fa idx2 +parameters are ignored. +.It Dv KCMP_SIGHAND +Determine whether the two processes share the same signal handler table. +This will be the case if one of the processes was created using the +.Dv RFSIGSHARE +flag to +.Xr rfork 2 . +The +.Fa idx1 +and +.Fa idx2 +parameters are ignored. +.It Dv KCMP_VM +Determine whether the two processes share a virtual memory address space. +This may be the case if one of the processes created the other using +.Xr vfork 2 +or +.Xr rfork 2 +with the +.Dv RFMEM +flag. +The +.Fa idx1 +and +.Fa idx2 +parameters are ignored. +.El +The caller of +.Nm +must have permission to debug both processes, otherwise the system call +will fail. +.Sh RETURN VALUES +If +.Fa idx1 +and +.Fa idx2 +refer to the same object, +.Nm +returns 0. +If the object referred to by +.Fa pid1 +and +.Fa idx1 +is less or greater than the object referred to by +.Fa pid2 +and +.Fa idx2 , +.Nm +returns the values 1 and 2, respectively. +The order is defined internally by the kernel and is stable until the system +reboots. +If the two objects cannot be compared for some reason, +.Nm +returns 3. +For example, if +.Fa type +is +.Dv KCMP_FILEOBJ +and +.Fa idx1 +and +.Fa idx2 +are different descriptor types, e.g., a socket and a file, then +.Nm +will return 3. +.Pp +If an error occurs, the value -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Nm +may fail with the following errors: +.Bl -tag -width Er +.It Bq Er ENODEV +.Dv KCMP_FILEOBJ +was specified and +.Fa idx1 +refers to a file descriptor which does not implement a comparison operator. +.It Bq Er EINVAL +The value of +.Fa type +is invalid. +.It Bq Er EBADF +One of the file descriptors referred to by +.Fa idx1 +or +.Fa idx2 +is not valid. +.It Bq Er ESRCH +One of the processes referred to by +.Fa pid1 +or +.Fa pid2 +does not exist or is not visible (e.g., due to jail restrictions). +.It Bq Er EPERM +The caller does not have permission to access one of the processes referred to +by +.Fa pid1 +or +.Fa pid2 . +.El +.Sh SEE ALSO +.Xr dup 2 , +.Xr fcntl 2 , +.Xr fork 2 , +.Xr rfork 2 , +.Xr vfork 2 +.Sh STANDARDS +The +.Nm +system call originated in Linux. +This implementation aims to be source-compatible with the Linux implementation. +.Fx +implements only a subset of the possible values for +.Fa type +supported in Linux. +More values may be added in the future. +The +.Dv KCMP_FILEOBJ +type is a FreeBSD extension. +.Sh HISTORY +The +.Nm +function was introduced in +.Fx 14.1 .