kern/158755: mmap fails with addr=NULL, flags=MAP_STACK

Yui NARUSE naruse at airemix.jp
Sun Jul 10 05:40:08 UTC 2011


>Number:         158755
>Category:       kern
>Synopsis:       mmap fails with addr=NULL, flags=MAP_STACK
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 10 05:40:07 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Yui NARUSE
>Release:        8.2
>Organization:
>Environment:
FreeBSD windy.airemix.net 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011     root at mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
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;
}
>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list