Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jul 2011 05:39:18 GMT
From:      Yui NARUSE <naruse@airemix.jp>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/158755: mmap fails with addr=NULL, flags=MAP_STACK
Message-ID:  <201107100539.p6A5dIRQ034189@red.freebsd.org>
Resent-Message-ID: <201107100540.p6A5e8Vk023551@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help


>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@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107100539.p6A5dIRQ034189>