From nobody Thu Jan 18 21:08:46 2024 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 4TGFjB31N5z570Vy; Thu, 18 Jan 2024 21:08:46 +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 4TGFjB23Sdz4hKp; Thu, 18 Jan 2024 21:08:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705612126; 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=fkoOORrE0Orq/MubvCMcAd1vHZmXqb7ob/Q/Ygutoq8=; b=IaOD4HWS0HZ7bGlqFzchLDE7mAKocLVw4fD0J9uXaE7sux5iNTUlpLtAtcqCcrghtohiF7 vmHDu9Strkxt/nKFTpmpr7gP8ryRtZp9lcpgc87vmT/hnlv45AgmRPcY4UVlxY3smA16cA gi+kMn2kfv7NBaz3VoOfWgA6GdOmYvkhF+8w4pjCNPe9X48rHsK44XzepgVAwiWu3Q+p9l Vgu7yBpP+IOlcM3TM25QWFLxgKmyDYbDzziydu5zDR9IaQ9OO7Dmt3aYCRp4hSOwpm/oHU Db5LPm8hEIc3gLX8xSVb9hDG1VJcOdZngUhz1OxSeq9A3TNELaX5lJb+ULoalA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705612126; 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=fkoOORrE0Orq/MubvCMcAd1vHZmXqb7ob/Q/Ygutoq8=; b=gmnsf6kn0qwOBtDsWXyECz21qLCJ9Sv7XUQAnxy7xIxe8mNOLtVS33Ljq134Xwskz4XURe YQgowNucYYIRkqehBY+hRPCGaefpOMZLUbrqoi3hVoVjKt+Z1GNSQEYwi8pRFomU1gmOzd 4oKz9Qsnml5MJ2JRAPqp4JmuXjC77edHNeLOuzZTp3AqTXRMuYDyU0hBmWzXt/afwtQuoN 0kBbeVf53cUV58z5ew9xkMvVms10m/3gd/iSJjqqZtbb18g/PU8u8kVmeQHiwMtgYm9SAR +ZGgJOIcJ9C1nbaxGNYed28e8BLCAPXZ3K2vBmraI9NqnBzNaK85putTD3jgMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705612126; a=rsa-sha256; cv=none; b=EAZFSXMq48FiqK1DIF6qWFwcKy8UgRP9agRWjYNgplLF8fSKwlwy0T/Znjj2ZpX0/wkOeZ CjQwf3K8ZpgCJ5aN/hAXi4BttvhOqn5WzwsLQYH8hERJq7zYoo0kj1TfrNdwuXpla35mhE 7Ekz52Swaxj6o4hLfLgUpsOa+h0Nhxi5df4eP2wstANPMhGYxM25+IVkCjtL5JahXirg0X /cZJbPAId3/Yt2sjL/QixUqnUkUrG6ElLd5RXR1UGEOSaVjI+OZ6G/vSOZA1pNX40MSRRs +2vBxUm9RRBwLjk++LGxuDwayrZt3804Abto4LY4NByWolU3VvCloUjoWmbafg== 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 4TGFjB171VzMxd; Thu, 18 Jan 2024 21:08:46 +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 40IL8k8o053157; Thu, 18 Jan 2024 21:08:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40IL8k8E053155; Thu, 18 Jan 2024 21:08:46 GMT (envelope-from git) Date: Thu, 18 Jan 2024 21:08:46 GMT Message-Id: <202401182108.40IL8k8E053155@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 6ae07a0424c3 - stable/14 - libthr: thr_attr.c: EINVAL, not ENOTSUP, on invalid arguments 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 6ae07a0424c328148e63b46fc7d5eaeeeaa6e28a Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=6ae07a0424c328148e63b46fc7d5eaeeeaa6e28a commit 6ae07a0424c328148e63b46fc7d5eaeeeaa6e28a Author: Olivier Certner AuthorDate: 2023-11-24 21:21:16 +0000 Commit: Olivier Certner CommitDate: 2024-01-18 21:07:53 +0000 libthr: thr_attr.c: EINVAL, not ENOTSUP, on invalid arguments On first read, POSIX may seem ambiguous about the return code for some scheduling-related pthread functions on invalid arguments. But a more thorough reading and a bit of standards archeology strongly suggests that this case should be handled by EINVAL and that ENOTSUP is reserved for implementations providing only part of the functionality required by the POSIX option POSIX_PRIORITY_SCHEDULING (e.g., if an implementation doesn't support SCHED_FIFO, it should return ENOTSUP on a call to, e.g., sched_setscheduler() with 'policy' SCHED_FIFO). This reading is supported by the second sentence of the very definition of ENOTSUP, as worded in CAE/XSI Issue 5 and POSIX Issue 6: "The implementation does not support this feature of the Realtime Feature Group.", and the fact that an additional ENOTSUP case was added to pthread_setschedparam() in Issue 6, which introduces SCHED_SPORADIC, saying that pthread_setschedparam() may return it when attempting to dynamically switch to SCHED_SPORADIC on systems that doesn't support that. glibc, illumos and NetBSD also support that reading by always returning EINVAL, and OpenBSD as well, since it always returns EINVAL but the corresponding code has a comment suggesting returning ENOTSUP for SCHED_FIFO and SCHED_RR, which it effectively doesn't support. Additionally, always returning EINVAL fixes inconsistencies where EINVAL would be returned on some out-of-range values and ENOTSUP on others. Reviewed by: markj Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D43006 (cherry picked from commit 0eccb45979a8ee3129e11b638ebc4cfa00942b80) --- lib/libthr/thread/thr_attr.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/libthr/thread/thr_attr.c b/lib/libthr/thread/thr_attr.c index decbcb949167..0ccc31b22c13 100644 --- a/lib/libthr/thread/thr_attr.c +++ b/lib/libthr/thread/thr_attr.c @@ -380,13 +380,11 @@ int _thr_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit) { - if (attr == NULL || *attr == NULL) + if (attr == NULL || *attr == NULL || + (sched_inherit != PTHREAD_INHERIT_SCHED && + sched_inherit != PTHREAD_EXPLICIT_SCHED)) return (EINVAL); - if (sched_inherit != PTHREAD_INHERIT_SCHED && - sched_inherit != PTHREAD_EXPLICIT_SCHED) - return (ENOTSUP); - (*attr)->sched_inherit = sched_inherit; return (0); } @@ -400,18 +398,15 @@ _thr_attr_setschedparam(pthread_attr_t * __restrict attr, { int policy; - if (attr == NULL || *attr == NULL) + if (attr == NULL || *attr == NULL || param == NULL) return (EINVAL); - if (param == NULL) - return (ENOTSUP); - policy = (*attr)->sched_policy; if (policy == SCHED_FIFO || policy == SCHED_RR) { if (param->sched_priority < _thr_priorities[policy-1].pri_min || param->sched_priority > _thr_priorities[policy-1].pri_max) - return (ENOTSUP); + return (EINVAL); } else { /* * Ignore it for SCHED_OTHER now, patches for glib ports @@ -432,10 +427,9 @@ int _thr_attr_setschedpolicy(pthread_attr_t *attr, int policy) { - if (attr == NULL || *attr == NULL) + if (attr == NULL || *attr == NULL || + policy < SCHED_FIFO || policy > SCHED_RR) return (EINVAL); - if (policy < SCHED_FIFO || policy > SCHED_RR) - return (ENOTSUP); (*attr)->sched_policy = policy; (*attr)->prio = _thr_priorities[policy-1].pri_default;