Subject: lib/7564: MAP_FAILED not defined (for mmap)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <quichem@merit.edu>
List: netbsd-bugs
Date: 05/12/1999 08:36:25
>Number:         7564
>Category:       lib
>Synopsis:       MAP_FAILED not defined (for mmap)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 12 08:35:01 1999
>Last-Modified:
>Originator:     mukesh agrawal
>Organization:
merit network
>Release:        1.3.3
>Environment:
NetBSD smock 1.3.3 NetBSD 1.3.3 (SMOCK) #2: Thu Feb  4 17:14:06 EST 1999     wfs@smock:/usr/src/sys/arch/i386/compile/SMOCK i386

>Description:
mmap is supposed to return MAP_FAILED if it can't perform the mapping.
MAP_FAILED is supposed to be defined in /usr/include/sys/mman.h
(according to Single Unix Spec v2). but it isn't. from looking at the
Solaris and FreeBSD headers, it looks like it should _probably_ be
defined as ((void *) -1).
>How-To-Repeat:
the following won't compile

#include <sys/types.h>
#include <sys/mman.h>

int main() {
	if (mmap(0, 1024, PROT_READ, MAP_SHARED, 3, 0) == MAP_FAILED) {
		exit(1);
	}
}
>Fix:
this fixes the compile problem, but i don't know that it's the
right answer. (i don't know if -1 can be a valid return from mmap.)

in /usr/include/sys/mman.h, add

#define MAP_FAILED ((void *) -1)

>Audit-Trail:
>Unformatted: