From nobody Thu Jan 18 21:10:14 2024 X-Original-To: dev-commits-src-all@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 4TGFkv052Tz570hQ; Thu, 18 Jan 2024 21:10:15 +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 4TGFkt5r1gz4jG2; Thu, 18 Jan 2024 21:10:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705612214; 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=jyb1PS6QLsgLtE7GEtny7k1fm+KZpjr/M99je1raGSs=; b=ryc8YQp0+Kn8NSkJnbXkRA9cKYUC93FwCDe6pqtrqnIaVj3sz33bn/qZ64BQS3hoA11BXs 566TDOu6mAg6Hw8qnqS13Dy6WByeUEZGCASKCJLGWrCHqJja5KbJApzoU1qXG1hKk11eIA r5j2Qf1CEEYSVZl//vTqeMhSjlDFdLaNUIz1HmWwoQVHD0vvI0uSRCkf0Nvs0EHpHsnr6r HTDy60dfVklBgXe9iFXoanKXOfJhRgZ9YMd/OET5+uuoVmMux9jdI+QTp0cm+DRgoJR2p3 DH4frgmVoWEiVBhmc2+ciXlVzy389LgUPTOBiWQfr4lagXRK+zCVFOaTU4UU2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705612214; 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=jyb1PS6QLsgLtE7GEtny7k1fm+KZpjr/M99je1raGSs=; b=qqyakasGd+F3oTVOlxBdamnbrPhzCO/NbMdC/SJrc3EClUm0w71K0Q2+oRfQ0wwokrvP4b MU6hAt97cGUscaghH7VtyPFeTwTQm/pZUjGm0mXtKWUh+EntG9EBI6gvue2hniqKgIzN8K M3+9b4R569SfsO22mt6tyZweuPYca+SwPa1xRKfwlPAVUFwQ7vRe+8n8in+CoaXnDBEUZe t5COEbyiJBfHwXlgDQBK1s+Qrr9Ic+o/GYOYgTw5ZA1OCKNJILRhPSoz7QiEdgZbEMjLVb /IGljCyw++q2BORqzb3OWuHsDB6fWBfXVA1Lloi2xtLNisACaXFCvxfMtN6KEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705612214; a=rsa-sha256; cv=none; b=STC2/TAkulMtFPPqKPIfpJ7qmMk5irgb2+0ClnrQjNCemLAOtY5ApihRYcuEC5DNC5SqGd 8VdLdhvwRborngVuOFm6B5LH9Mo0/VnOpYffxNyMSNkuDxlcSPoAsGGgyq7ki/AcF7Kf67 ouZHr3qrwH+EJ0aW6/suYVT6vfD5RQv+erR1B44U85pBuvtw3KLvrGYKNEbO2AqrIqPQUA c5szrOOuDOhhDq87gMTSTSALvKitmI1rh6lUU7ZcY6t5lpWelGidScis/IBPtKii1pA+V5 K6xeUCsist7tTtJKbZzsYhVN3jZKzRDlrzhxnBTAWHc/Fu9flZ5owFT161bL2w== 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 4TGFkt4wFyzNPt; Thu, 18 Jan 2024 21:10:14 +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 40ILAEQr060070; Thu, 18 Jan 2024 21:10:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40ILAEvt060066; Thu, 18 Jan 2024 21:10:14 GMT (envelope-from git) Date: Thu, 18 Jan 2024 21:10:14 GMT Message-Id: <202401182110.40ILAEvt060066@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: 8d97e469dee9 - stable/13 - libthr: thr_attr.c: EINVAL, not ENOTSUP, on invalid arguments List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/13 X-Git-Reftype: branch X-Git-Commit: 8d97e469dee9db347a6cf433ac7e4d40f36d2c48 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=8d97e469dee9db347a6cf433ac7e4d40f36d2c48 commit 8d97e469dee9db347a6cf433ac7e4d40f36d2c48 Author: Olivier Certner AuthorDate: 2023-11-24 21:21:16 +0000 Commit: Olivier Certner CommitDate: 2024-01-18 21:09:43 +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) Approved by: markj (mentor) --- 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;