From nobody Fri Jan 14 18:10:37 2022 X-Original-To: dev-commits-src-branches@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 BFBC719433B2; Fri, 14 Jan 2022 18:10:39 +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 4Jb8VP5VVwz4pbx; Fri, 14 Jan 2022 18:10:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642183837; 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=pfj7Rrzowrm1wb2Fm1G3R3fj8N1lnxkqNkTzMrekHEs=; b=UlXeqcuA534AhLCNJiIb03l1AUzGd4fx5gEEhK3+SwfWKlPO/FUy8IQFKTRhtTiT0zO/Jj SYt6Oy0PrXG3rZzhIL3Eahxs7nqRRW4o82uAShtlqHaHE2abgdNX/41RjcQ4IWs4YQqNx1 28+A48x8QFwlqjKAREg9MnrN61l0g+M3/6gEUZDAj2kGxv46YYY1TxKRs+6Zyrfy11AqYG XPTJaW66tQslJyTHTZZRQR19sX7XWaCZSIdWjBbhjhCiIA1myt5NmtEnoyrFkW/NkVD9qe UBijIdeYqSrctKoY5oR9U1iY0wANBQsSXirOwV/lHLDXviQzJkhDTAovPZiqNA== 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 33D6E185A0; Fri, 14 Jan 2022 18:10:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20EIAbJq096590; Fri, 14 Jan 2022 18:10:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EIAbZq096589; Fri, 14 Jan 2022 18:10:37 GMT (envelope-from git) Date: Fri, 14 Jan 2022 18:10:37 GMT Message-Id: <202201141810.20EIAbZq096589@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 8c709f30a184 - stable/13 - sched_get/setaffinity(): try to be more compatible with Linux List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8c709f30a18466527e52e3b081a69fd2b99b6a19 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642183837; 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=pfj7Rrzowrm1wb2Fm1G3R3fj8N1lnxkqNkTzMrekHEs=; b=RoAFLXsc1oh0f5JnUskmi744XwblUrkiKIC8MwLuRPlba2/e4VTgmr7b+pZY5fGVVbeQlU 7CIrX8tTMUhVdiWwRvmaizYlx61mitmJRdkdY1vJORtbmw4jLis1huNIKN9+8K2wrXtbmJ KDsaVzO+uOZwHX2gmPmTPH/t6C0LRosD5F6JRDDOMUrvqrbuZuRyeySkK+s2YBrtJPX7Kv zS7H3GJ9FmEfuWdxOGxvs5rSgaH+bMuWq6W4vS4SqYs8Mo2j9oCltWalljK++tvxQ5lPz6 iOAjcMRlHdy0Nt0pEnMjxyakZqg7e7lqcHPI7+FoZRjBhYlKULD7Fh7TabIwKQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642183837; a=rsa-sha256; cv=none; b=ivMabuIw1FPAS7/JhIGJG/jqGPkdRzLl4skfqD+DcTsJpTaswT1tDKVY161R0hzZsablU+ BXmc3I+Xg6bgE9aCHpSx9wZOL45koQXF1v2LDzRwuhlGOf+n7CohycjMP9JlJsA2f2+uS/ OUeCD1yN2hLJenkA+x0vBq9CL8dTprKNeGN6fszF2u9QnNrRRCcIhshAn3OtkL/9MUzgZt BL/KXA+GN551g/kIrUm/pRl4pRCpCZaWrWoePYX8lppMBv5K4gnj0Rzk3SSna/mjj8m/6g 9tpoNddJiU8aoHJyT6CRBv5QOfsLbPMlvFJE9azo/fXO8KQBxDIl7DiNb2jd2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8c709f30a18466527e52e3b081a69fd2b99b6a19 commit 8c709f30a18466527e52e3b081a69fd2b99b6a19 Author: Konstantin Belousov AuthorDate: 2022-01-02 22:11:49 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-14 16:17:31 +0000 sched_get/setaffinity(): try to be more compatible with Linux (cherry picked from commit d9cacbf4b010d96dbfe96a09259972a95c675f26) --- lib/libc/gen/sched_getaffinity.c | 20 ++++++++++++++++++++ lib/libc/gen/sched_setaffinity.c | 13 ++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c index 2ae8c5b763a3..7d345eb82a3b 100644 --- a/lib/libc/gen/sched_getaffinity.c +++ b/lib/libc/gen/sched_getaffinity.c @@ -26,11 +26,31 @@ * SUCH DAMAGE. */ +#include #include +#include int sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset) { + /* + * Be more Linux-compatible: + * - return EINVAL in passed size is less than size of cpuset_t + * in advance, instead of ERANGE from the syscall + * - if passed size is larger than the size of cpuset_t, be + * permissive by claming it back to sizeof(cpuset_t) and + * zeroing the rest. + */ + if (cpusetsz < sizeof(cpuset_t)) { + errno = EINVAL; + return (-1); + } + if (cpusetsz > sizeof(cpuset_t)) { + memset((char *)cpuset + sizeof(cpuset_t), 0, + cpusetsz - sizeof(cpuset_t)); + cpusetsz = sizeof(cpuset_t); + } + return (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid == 0 ? -1 : pid, cpusetsz, cpuset)); } diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c index 52fc6d4bc811..91ab2a401bda 100644 --- a/lib/libc/gen/sched_setaffinity.c +++ b/lib/libc/gen/sched_setaffinity.c @@ -26,11 +26,22 @@ * SUCH DAMAGE. */ +#include #include +#include int sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset) { + cpuset_t c; + + if (cpusetsz > sizeof(cpuset_t)) { + errno = EINVAL; + return (-1); + } else { + memset(&c, 0, sizeof(c)); + memcpy(&c, cpuset, cpusetsz); + } return (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, - pid == 0 ? -1 : pid, cpusetsz, cpuset)); + pid == 0 ? -1 : pid, sizeof(cpuset_t), &c)); }