Bug 158755

Summary: [libc] mmap fails with addr=NULL, flags=MAP_STACK
Product: Base System Reporter: naruse
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me CC: koobs
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

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"