diff options
author | marcus <marcus> | 2003-09-24 22:13:56 +0000 |
---|---|---|
committer | marcus <marcus> | 2003-09-24 22:13:56 +0000 |
commit | 90aa62ee1de3c45182d9bfd87acf9c03ede9cdfc (patch) | |
tree | f5fd8566bfacbc1d92dc979ceb5e44767e23517a | |
parent | e7d323d1f64c14e25f2aa673bc0d00495c785287 (diff) |
2003-09-24 Marcus Brinkmann <marcus@gnu.org>
* mmap.c: New file.
* Makefile.am (physmem_SOURCES): Add mmap.c.
* malloc-wrap.c (LACKS_SYS_MMAN_H, mmap, munmap, PROT_READ,
PROT_WRITE, MAP_PRIVATE, MAP_ANONYMOUS, MUNMAP_FAILURE): Remove
macros.
* zalloc.c (panic): Remove macro.
-rw-r--r-- | physmem/ChangeLog | 8 | ||||
-rw-r--r-- | physmem/Makefile.am | 2 | ||||
-rw-r--r-- | physmem/malloc-wrap.c | 12 | ||||
-rw-r--r-- | physmem/mmap.c | 53 | ||||
-rw-r--r-- | physmem/zalloc.c | 1 |
5 files changed, 63 insertions, 13 deletions
diff --git a/physmem/ChangeLog b/physmem/ChangeLog index edab5c1..b0a427e 100644 --- a/physmem/ChangeLog +++ b/physmem/ChangeLog @@ -1,3 +1,11 @@ +2003-09-24 Marcus Brinkmann <marcus@gnu.org> + + * mmap.c: New file. + * Makefile.am (physmem_SOURCES): Add mmap.c. + * malloc-wrap.c (LACKS_SYS_MMAN_H, mmap, munmap, PROT_READ, + PROT_WRITE, MAP_PRIVATE, MAP_ANONYMOUS, MUNMAP_FAILURE): Remove + macros. + 2003-09-22 Marcus Brinkmann <marcus@gnu.org> * Makefile.am (AM_CPPFLAGS, physmem_CFLAGS): Removed. diff --git a/physmem/Makefile.am b/physmem/Makefile.am index 1962ac8..fd1979e 100644 --- a/physmem/Makefile.am +++ b/physmem/Makefile.am @@ -29,7 +29,7 @@ physmem_CPPFLAGS = -I$(top_builddir)/include \ physmem_SOURCES = $(ARCH_SOURCES) \ output.h output.c \ - zalloc.h zalloc.c malloc-wrap.c \ + zalloc.h zalloc.c mmap.c malloc-wrap.c \ physmem.h physmem.c # Doug Lea's malloc is included by malloc-wrap.c. diff --git a/physmem/malloc-wrap.c b/physmem/malloc-wrap.c index 5197941..9371b2d 100644 --- a/physmem/malloc-wrap.c +++ b/physmem/malloc-wrap.c @@ -1,4 +1,4 @@ -/* malloc-wrap.c: Doug Lea's malloc for the physical memory server. +/* malloc-wrap.c - Doug Lea's malloc for the physical memory server. Copyright (C) 2003 Free Software Foundation, Inc. Written by Marcus Brinkmann. @@ -34,7 +34,6 @@ #define __STD_C 1 #define LACKS_UNISTD_H #define LACKS_SYS_PARAM_H -#define LACKS_SYS_MMAN_H #define LACKS_FCNTL_H /* We want to use optimized versions of memset and memcpy. */ @@ -44,20 +43,11 @@ #define MORECORE(x) MORECORE_FAILURE #define HAVE_MMAP 1 #define HAVE_MREMAP 0 -#define MUNMAP_FAILURE (-1) #define MMAP_CLEARS 1 #define malloc_getpagesize l4_min_page_size () -#define mmap(addr, size, p, f, fd, o) (zalloc (size) ?: MUNMAP_FAILURE) -#define munmap(addr, size) (zfree ((l4_word_t) addr, size), 0) #define MMAP_AS_MORECORE_SIZE (16 * malloc_getpagesize) #define DEFAULT_MMAP_THRESHOLD (4 * malloc_getpagesize) -/* These values don't really matter in mmap emulation */ -#define MAP_PRIVATE 1 -#define MAP_ANONYMOUS 2 -#define PROT_READ 1 -#define PROT_WRITE 2 - /* Suppress debug output in mstats(). */ #define fprintf(...) diff --git a/physmem/mmap.c b/physmem/mmap.c new file mode 100644 index 0000000..c54a7d2 --- /dev/null +++ b/physmem/mmap.c @@ -0,0 +1,53 @@ +/* mmap.c - A simple mmap for anonymous memory allocations in physmem. + Copyright (C) 2003 Free Software Foundation, Inc. + Written by Marcus Brinkmann. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#include <sys/mman.h> + +#include "output.h" +#include "zalloc.h" + + +void * +mmap (void *address, size_t length, int protect, int flags, + int filedes, off_t offset) +{ + if (address) + panic ("mmap called with non-zero ADDRESS"); + if (flags != (MAP_PRIVATE | MAP_ANONYMOUS)) + panic ("mmap called with invalid flags"); + if (protect != (PROT_READ | PROT_WRITE)) + panic ("mmap called with invalid protection"); + + /* At this point, we can safely ignore FILEDES and OFFSET. */ + return (((void *) zalloc (length)) ?: (void *) -1); +} + + +int +munmap (void *addr, size_t length) +{ + zfree ((l4_word_t) addr, length); + return 0; +} diff --git a/physmem/zalloc.c b/physmem/zalloc.c index d595d99..96fddbc 100644 --- a/physmem/zalloc.c +++ b/physmem/zalloc.c @@ -27,7 +27,6 @@ #include "zalloc.h" -#define panic(...) do { printf (__VA_ARGS__); l4_sleep (l4_never); } while (0) #ifndef NDEBUG #define DODEBUG(level, func) \ |