#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 Bloom)

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 10/09/12 at 04:31:53 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 11/22/14 at 13:50:56 by Gedare Bloom

Description: modified (diff)
Milestone: 4.104.10.3

comment:3 Changed on 11/23/14 at 15:17:41 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 12/19/14 at 04:58:25 by Gedare Bloom

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

comment:5 Changed on 01/26/17 at 07:16:00 by Sebastian Huber

Milestone: 4.11.14.11.2

comment:6 Changed on 03/23/17 at 01:03:28 by Chris Johns

Milestone: 4.11.24.11.3

The 4.11.2 milestone is closing.

comment:7 Changed on 03/23/17 at 01:05:42 by Chris Johns

Version: 4.104.11

Move to the 4.11 branch.

comment:8 Changed on 04/03/17 at 23:16:38 by Joel Sherrill

Keywords: POSIX-Compliance added

comment:9 Changed on 02/05/18 at 05:46:43 by Chris Johns

Milestone: 4.11.3Indefinite

Requires funding.

Note: See TracTickets for help on using tickets.