#2078 assigned defect

sys/features.h ill-defines _POSIX_MEMLOCK and _POSIX_MEMLOCK_RANGE

Reported by: strauman Owned by: Joel Sherrill
Priority: normal Milestone: Indefinite
Component: tool/newlib Version: 4.11
Severity: normal Keywords: POSIX-Compliance
Cc: Blocked By:
Blocking:

Description (last modified by Gedare)

According to the linux manpage (I don't have access to a posix standard ATM):

On POSIX systems on which mlock() and munlock() are available,

_POSIX_MEMLOCK_RANGE is defined in <unistd.h> and the number of bytes
in a page can be determined from the constant PAGESIZE (if defined) in
<limits.h> or by calling sysconf(_SC_PAGESIZE).

On POSIX systems on which mlockall() and munlockall() are available,
_POSIX_MEMLOCK is defined in <unistd.h> to a value greater than 0.
(See also sysconf(3).)

However, newlib's sys/feature.h defines

#ifdef rtems
...
#define _POSIX_MEMLOCK 1
#define _POSIX_MEMLOCK_RANGE 1
#define _POSIX_MEMORY_PROTECTION 1
...
#endif

which is wrong since RTEMS does *not* implement mlock nor mlockall. BTW:
the definition of _POSIX_MEMORY_PROTECTION also seems fishy.

Change History (9)

comment:1 Changed on Oct 9, 2012 at 4:31:53 AM by Ralf Corsepius

Replying to comment:0:

According to the linux manpage (I don't have access to a posix standard ATM):

POSIX can be found here: http://pubs.opengroup.org/onlinepubs/9699919799/

On POSIX systems on which mlock() and munlock() are available,

_POSIX_MEMLOCK_RANGE is defined in <unistd.h> and the number of bytes
in a page can be determined from the constant PAGESIZE (if defined) in
<limits.h> or by calling sysconf(_SC_PAGESIZE).

On POSIX systems on which mlockall() and munlockall() are available,
_POSIX_MEMLOCK is defined in <unistd.h> to a value greater than 0.
(See also sysconf(3).)

Well, ... this is the Linux interpretation of POSIX.
As I understand the POSIX standard (c.f. above) it doesn't mandate this specific interpretation, but leaves more room for interpretation.

However, newlib's sys/feature.h defines

#ifdef rtems
...
#define _POSIX_MEMLOCK 1
#define _POSIX_MEMLOCK_RANGE 1
#define _POSIX_MEMORY_PROTECTION 1
...
#endif

which is wrong since RTEMS does *not* implement mlock nor mlockall.

Good catch - I agreed, newlib should not define these for RTEMS.
Could you please submit a patch to upstream newlib?

BTW:
the definition of _POSIX_MEMORY_PROTECTION also seems fishy.

Could you please file a separate bug for this issue, otherwise it's not unlikely it will get lost?

comment:2 Changed on Nov 22, 2014 at 1:50:56 PM by Gedare

Description: modified (diff)
Milestone: 4.104.10.3

comment:3 Changed on Nov 23, 2014 at 3:17:41 PM by Joel Sherrill

Milestone: 4.10.34.11
Version: unknown4.10

We should not tinker with newlib for a 4.10.x release unless critical. Moving milestone and changing filed against.

comment:4 Changed on Dec 19, 2014 at 4:58:25 AM by Gedare

Description: modified (diff)
Milestone: 4.114.11.1
Owner: changed from Ralf Corsepius to Joel Sherrill
Status: newassigned

comment:5 Changed on Jan 26, 2017 at 7:16:00 AM by Sebastian Huber

Milestone: 4.11.14.11.2

comment:6 Changed on Mar 23, 2017 at 1:03:28 AM by Chris Johns

Milestone: 4.11.24.11.3

The 4.11.2 milestone is closing.

comment:7 Changed on Mar 23, 2017 at 1:05:42 AM by Chris Johns

Version: 4.104.11

Move to the 4.11 branch.

comment:8 Changed on Apr 3, 2017 at 11:16:38 PM by Joel Sherrill

Keywords: POSIX-Compliance added

comment:9 Changed on Feb 5, 2018 at 5:46:43 AM by Chris Johns

Milestone: 4.11.3Indefinite

Requires funding.

Note: See TracTickets for help on using tickets.