Bug 158755 - [libc] mmap fails with addr=NULL, flags=MAP_STACK
Summary: [libc] mmap fails with addr=NULL, flags=MAP_STACK
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-10 06:40 UTC by naruse
Modified: 2018-05-20 23:51 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description naruse 2011-07-10 06:40:07 UTC
FreeBSD's mmap supports MAP_STACK as flags.
But when addr is NULL it won't find any suitable addr and try to use addr:0 and fails.

Note that manpage has following description and without MAP_STACK it find unallocated space and use it.

"If addr is zero, an address will be selected by the system.  The actual starting address of the region is returned."

How-To-Repeat: Run following program. Both mmap should success but on FreeBSD 8.2 first one fails.

#include <sys/mman.h>
#include <stdio.h>
#include <errno.h>
int main (void) {
        void *ptr;
        errno = 0;
        ptr = mmap((void *)0, 1, PROT_READ | PROT_WRITE, MAP_STACK, -1, 0);
        printf("addr=0: ptr=%p, errno=%d\n", ptr, errno);
        errno = 0;
        ptr = mmap((void *)1, 1, PROT_READ | PROT_WRITE, MAP_STACK, -1, 0);
        printf("addr=1: ptr=%p, errno=%d\n", ptr, errno);
        return 0;
}
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:51:20 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"