Bug 211802 - pthread_mutexattr_setprioceiling fails with EINVAL if m_protocol != PTHREAD_PRIO_PROTECT
Summary: pthread_mutexattr_setprioceiling fails with EINVAL if m_protocol != PTHREAD_P...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-13 04:38 UTC by Enji Cooper
Modified: 2016-08-13 08:45 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer 2016-08-13 04:38:38 UTC
One of the new NetBSD tests initializes a pthread_mutexattr, then tests out priority ceiling manipulation via pthread_mutexattr_getprioceiling/pthread_mutexattr_setprioceiling . Unfortunately the test fails with EINVAL because of a check made in lib/libthr/thr_mutexattr.c:

230 int
231 _pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
232 {
233         int ret = 0;
234 
235         if (mattr == NULL || *mattr == NULL)
236                 ret = EINVAL;
237         else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
238                 ret = EINVAL;
239         else
240                 *prioceiling = (*mattr)->m_ceiling;
241 
242         return (ret);
243 }
244 
245 int
246 _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
247 {
248         int ret = 0;
249 
250         if (mattr == NULL || *mattr == NULL)
251                 ret = EINVAL;
252         else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
253                 ret = EINVAL;
254         else
255                 (*mattr)->m_ceiling = prioceiling;
256 
257         return (ret);
258 }

opengroup.org [1] and the pthread*(3) [2] manages don't state why m_protocol being set to PTHREAD_PRIO_PROTECT would cause the functions to return EINVAL.

1. https://www.freebsd.org/cgi/man.cgi?apropos=0&sektion=3&query=pthread_mutexattr&manpath=FreeBSD+7.0-current&format=html
2. http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutexattr_getprioceiling.html
Comment 1 commit-hook freebsd_committer 2016-08-13 04:46:33 UTC
A commit references this bug:

Author: ngie
Date: Sat Aug 13 04:45:40 UTC 2016
New revision: 304036
URL: https://svnweb.freebsd.org/changeset/base/304036

Log:
  Expect :mutexattr2 to fail on FreeBSD

  pthread_mutexattr_getprioceiling and pthread_mutexattr_setprioceiling
  both return EINVAL if ->m_protocol != PTHREAD_PRIO_PROTECT. The
  reasoning behind this decision isn't documented in neither the FreeBSD
  nor the OpenGroup manpages.

  Add printf's to add in debugging the issue

  PR:		211802
  Sponsored by:	EMC / Isilon Storage Division

Changes:
  projects/netbsd-tests-update-12/contrib/netbsd-tests/lib/libpthread/t_mutex.c
Comment 2 Konstantin Belousov freebsd_committer 2016-08-13 08:45:59 UTC
(In reply to commit-hook from comment #1)
They do not state because there is no value in adding banal and obvious things to the text.

Can you explain what shall be the system action when prioceiling is requested or set on non-prio protected mutexes ?