From nobody Thu Jan 04 10:44:19 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 4T5NW75qdNz56K8R; Thu, 4 Jan 2024 10:44:19 +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 4T5NW74Mz5z4yjN; Thu, 4 Jan 2024 10:44:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704365059; 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=T+gTeITV39sM1Nq0lx5n5yZbaJ7XyFXIYj7s9IQfkg0=; b=frNnAIZcG/dZNqaeqatWbA9jezqiSqxSidkxXAW5IoAS8ECjOK9H/2zP7XXTivlEofuq29 HQU9qAeGLX8GzB73vB7Lkvq0VLssaTK7df5u6Oa5WEjmfRJOoPCP+SB/NKeZjs+NghJCo9 uILULy32F6WbrOG7KIc4LWRxnkEOzxdDZLuqTk3czu06Kp+bSo+MSFGRYMH2EHYDUyHuX6 PQzLSd+gZvWZlqUmhD4SS6vWNI8jN62Gs3+aoaOhKg49ydBVMyiYmY05AVcFagZPwUmGi9 He/4HSEpA3SyX0dfKNjHW99KfSdr1zxVzVGuZ8i7ltEEyW0PZpmUKigKXBxgtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704365059; 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=T+gTeITV39sM1Nq0lx5n5yZbaJ7XyFXIYj7s9IQfkg0=; b=LfAvB3Gg/rLCrifiaFmFrm+0DNHgFILmz1UhWyURtsscaZ2sOfMj7EbTd1uNw2b5eWDT3m pRiOliQ8m9YZtbi8NHdpqSAiR7A5hYSbF8RXuhXCR/CfBPkBq9j0DhuDvMW+pZ9PRqr4S3 9WyCfeXMOI0s5W79BvJZQ2H/rrFzoElYfRAJYT+TRUV0OEMmzXPBh3ccxem1TBE6YdowQL +w7Ug8JHR07O+J5OYRZFrbw149tHA9byKxZPGV2LgCHfACNOm73DHpaWr9zadI5msaVf/6 mh0PI/CObndcaoYqOxW0LeLa648BpraMpXjASfIWLa3Ag6odnTJHok44ypsJrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704365059; a=rsa-sha256; cv=none; b=H5FxMqLS/FSNLtEXG1sQ4Hi4wD/YPkZ3fhyPs4nMIW/dXxsmHmY/BHd1mXumxsJUs3XDH/ hcwT9v7e7iOfyhNiCXgAt72IPgaUWn/S/dQQV23Xf8CYBvsnf+g3Fe+4xzMhLHUOa+XHWt zwAE0tisGkX2m+xf5zALaC9wOGtWOt1GBbHIauc7I++RIm/u6nVJPnhV9vxsrXnpda6/FV JonfwpXVRFh89lP8z6XCUQW7eoebi/hnKSo6vXPAXZ3iVrANpDIVH5neaiWbnt7KRzak1C cPdyPFEz9S0tyAPD73V8yseHeRZY/DwqfO0Fc9nnEGPsxkvmxSe+gB6bEanKxA== 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 4T5NW72t6bz1Pb2; Thu, 4 Jan 2024 10:44:19 +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 404AiJfG047051; Thu, 4 Jan 2024 10:44:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 404AiJpY047048; Thu, 4 Jan 2024 10:44:19 GMT (envelope-from git) Date: Thu, 4 Jan 2024 10:44:19 GMT Message-Id: <202401041044.404AiJpY047048@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 0eccb45979a8 - main - libthr: thr_attr.c: EINVAL, not ENOTSUP, on invalid arguments 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0eccb45979a8ee3129e11b638ebc4cfa00942b80 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=0eccb45979a8ee3129e11b638ebc4cfa00942b80 commit 0eccb45979a8ee3129e11b638ebc4cfa00942b80 Author: Olivier Certner AuthorDate: 2023-11-24 21:21:16 +0000 Commit: Olivier Certner CommitDate: 2024-01-04 10:42:08 +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 --- 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;