mmap: accept non-PROT_WRITE MAP_SHARED mappings

Currently we don't accept writable file mmap()s, as there is no
system in place to guarantee dirty buffers would make it back to
disk. But we can actually accept MAP_SHARED for PROT_READ mappings,
meaning the ranges aren't writable at all (and no private copy is
made as with MAP_PRIVATE), as it turns out a fairly large class of
usage.

	. fail writable MAP_SHARED mappings at runtime
	. reduces some minix-specific patches
	. lets binutils gold build on minix without further patching

Change-Id: If2896c0a555328ac5b324afa706063fc6d86519e
This commit is contained in:
Ben Gras
2014-03-17 15:53:28 +01:00
committed by Lionel Sambuc
parent 29dca95386
commit 0b79eac642
11 changed files with 21 additions and 46 deletions

View File

@@ -2232,7 +2232,6 @@ send_data_with_mmap(int filefd, int netfd, const struct stat *st, int isdata)
(void)gettimeofday(&then, NULL);
} else
bufrem = winsize;
#if !defined(__minix)
while (1) {
mapsize = MIN(filesize - off, winsize);
if (mapsize == 0)
@@ -2244,10 +2243,14 @@ send_data_with_mmap(int filefd, int netfd, const struct stat *st, int isdata)
goto try_read;
return (SS_FILE_ERROR);
}
#ifndef __minix
(void) madvise(win, mapsize, MADV_SEQUENTIAL);
#endif
error = write_data(netfd, win, mapsize, &bufrem, &then,
isdata);
#ifndef __minix
(void) madvise(win, mapsize, MADV_DONTNEED);
#endif
munmap(win, mapsize);
if (urgflag && handleoobcmd())
return (SS_ABORTED);
@@ -2257,7 +2260,6 @@ send_data_with_mmap(int filefd, int netfd, const struct stat *st, int isdata)
}
return (SS_SUCCESS);
#endif /* !defined(__minix) */
try_read:
return (send_data_with_read(filefd, netfd, st, isdata));
}

View File

@@ -52,10 +52,6 @@ __RCSID("$NetBSD: map_object.c,v 1.52 2013/08/03 13:17:05 skrll Exp $");
#if defined(__minix)
#define MINIXVERBOSE 0
#ifndef MAP_SHARED
#define MAP_SHARED MAP_PRIVATE /* minix: MAP_SHARED should be MAP_PRIVATE */
#endif
#if MINIXVERBOSE
#include <stdio.h>
#endif

View File

@@ -61,15 +61,13 @@ __RCSID("$NetBSD: paths.c,v 1.41 2013/05/06 08:02:20 skrll Exp $");
static Search_Path *_rtld_find_path(Search_Path *, const char *, size_t);
static Search_Path **_rtld_append_path(Search_Path **, Search_Path **,
const char *, const char *, const char *);
#if !defined(__minix)
static void _rtld_process_mapping(Library_Xform **, const char *,
const char *);
#endif /* !defined(__minix) */
static char *exstrdup(const char *, const char *);
#if !defined(__minix)
static const char *getstr(const char **, const char *, const char *);
static const char *getcstr(const char **, const char *, const char *);
static const char *getword(const char **, const char *, const char *);
#if !defined(__minix)
static int matchstr(const char *, const char *, const char *);
#endif /* !defined(__minix) */
@@ -90,7 +88,6 @@ exstrdup(const char *bp, const char *ep)
return (cp);
}
#if !defined(__minix)
/*
* Like strsep(), but takes end of string and doesn't put any NUL. To
* detect empty string, compare `*p' and return value.
@@ -149,6 +146,7 @@ getword(const char **p, const char *ep, const char *delim)
return (getstr(p, ep, delim));
}
#if !defined(__minix)
/*
* Match `bp' against NUL terminated string pointed by `p'.
*/
@@ -234,7 +232,6 @@ _rtld_add_paths(const char *execname, Search_Path **path_p, const char *pathstr)
}
}
#if !defined(__minix)
/*
* Process library mappings of the form:
* <library_name> <machdep_variable> <value,...:library_name,...> ...
@@ -340,17 +337,11 @@ cleanup:
xfree(hwptr->name);
xfree(hwptr);
}
#endif /* !defined(__minix) */
void
_rtld_process_hints(const char *execname, Search_Path **path_p,
Library_Xform **lib_p, const char *fname)
{
#if defined(__minix)
/* Minix doesn't support MAP_SHARED. */
return;
#else
int fd;
char *buf, small[128];
const char *b, *ep, *ptr;
@@ -421,7 +412,6 @@ _rtld_process_hints(const char *execname, Search_Path **path_p,
if (buf != small)
(void)munmap(buf, sz);
#endif /* defined(__minix) */
}
#if !defined(__minix)