From 02081e4b62ae09d8cb09b9f03c362af22b816e3f Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Sat, 16 Jul 2011 03:11:10 +0200 Subject: [PATCH] rename mmap() and munmap() . it's a good extra interface to have but doesn't meet standardised functionality . applications (in pkgsrc) find it and expect full functionality the minix mmap doesn't offter . on the whole probably better to hide these functions (mmap and friends) until they are grown up; the base system can use the new minix_* names --- commands/mdocml/main.c | 4 ++++ commands/patch/inp.c | 8 ++++++++ drivers/memory/memory.c | 6 +++--- include/sys/mman.h | 6 +++--- lib/csu/i386-aout/crtso.S | 4 ++-- lib/libc/ansi/malloc-debug.c | 3 +++ lib/libc/other/namespace.h | 3 +++ lib/libc/posix/_mmap.c | 12 ++++++------ lib/libc/syscall/mmap.S | 6 +++--- lib/libc/syscall/munmap.S | 12 ++++++------ lib/libsys/alloc_util.c | 6 +++--- lib/nbsd_libc/cdb/cdbr.c | 9 ++++++--- lib/nbsd_libc/citrus/citrus_mmap.c | 7 +++++-- lib/nbsd_libc/db/recno/rec_close.c | 4 ++++ lib/nbsd_libc/include/namespace.h | 3 --- lib/nbsd_libc/nls/catclose.c | 4 ++++ lib/nbsd_libc/nls/catopen.c | 13 ++++++++++--- lib/nbsd_libc/stdlib/malloc.c | 5 +++++ lib/nbsd_libc/sys-minix/mmap.c | 9 +++------ nbsd_include/sys/mman.h | 8 +++++--- servers/ipc/shm.c | 4 ++-- servers/pm/utility.c | 16 ++++++++-------- servers/rs/memory.c | 20 ++++++++++---------- 23 files changed, 106 insertions(+), 66 deletions(-) diff --git a/commands/mdocml/main.c b/commands/mdocml/main.c index fb497d3bd..ae5c8b902 100644 --- a/commands/mdocml/main.c +++ b/commands/mdocml/main.c @@ -644,9 +644,13 @@ fdesc(struct curparse *curp) roff_reset(roff); if (ln.buf) free(ln.buf); +#ifdef __minix + assert(!with_mmap); +#else if (with_mmap) munmap(blk.buf, blk.sz); else +#endif free(blk.buf); return; diff --git a/commands/patch/inp.c b/commands/patch/inp.c index ecbeabb87..e104cb122 100644 --- a/commands/patch/inp.c +++ b/commands/patch/inp.c @@ -102,7 +102,11 @@ re_input(void) free(i_ptr); i_ptr = NULL; if (i_womp != NULL) { +#ifndef __minix munmap(i_womp, i_size); +#else + free(i_womp); +#endif i_womp = NULL; } } else { @@ -139,7 +143,11 @@ reallocate_lines(size_t *lines_allocated) new_size = *lines_allocated * 3 / 2; p = realloc(i_ptr, (new_size + 2) * sizeof(char *)); if (p == NULL) { /* shucks, it was a near thing */ +#ifndef __minix munmap(i_womp, i_size); +#else + free(i_womp); +#endif i_womp = NULL; free(i_ptr); i_ptr = NULL; diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index c38a4b837..4863ce2c4 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -407,7 +407,7 @@ message *m_ptr; if(vlen % PAGE_SIZE) { vlen -= vlen % PAGE_SIZE; } - munmap((void *) vaddr, vlen); + minix_munmap((void *) vaddr, vlen); m_geom[IMGRD_DEV].dv_base= cvul64(0); m_geom[IMGRD_DEV].dv_size= cvul64(0); m_vaddrs[IMGRD_DEV] = 0; @@ -465,7 +465,7 @@ message *m_ptr; /* pointer to control message */ panic("huge old ramdisk"); } size = ex64lo(dv->dv_size); - munmap((void *) m_vaddrs[dev], size); + minix_munmap((void *) m_vaddrs[dev], size); m_vaddrs[dev] = (vir_bytes) NULL; } @@ -474,7 +474,7 @@ message *m_ptr; /* pointer to control message */ #endif /* Try to allocate a piece of memory for the RAM disk. */ - if((mem = mmap(NULL, ramdev_size, PROT_READ|PROT_WRITE, + if((mem = minix_mmap(NULL, ramdev_size, PROT_READ|PROT_WRITE, MAP_PREALLOC|MAP_ANON, -1, 0)) == MAP_FAILED) { printf("MEM: failed to get memory for ramdisk\n"); return(ENOMEM); diff --git a/include/sys/mman.h b/include/sys/mman.h index 5040ff7e4..7317ea606 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -25,9 +25,9 @@ /* mmap() error return */ #define MAP_FAILED ((void *)-1) -_PROTOTYPE( void *mmap, (void *, size_t, int, int, int, off_t)); -_PROTOTYPE( int munmap, (void *, size_t)); -_PROTOTYPE( int munmap_text, (void *, size_t)); +_PROTOTYPE( void *minix_mmap, (void *, size_t, int, int, int, off_t)); +_PROTOTYPE( int minix_munmap, (void *, size_t)); +_PROTOTYPE( int minix_munmap_text, (void *, size_t)); _PROTOTYPE( void *vm_remap, (endpoint_t d, endpoint_t s, void *da, void *sa, size_t si)); _PROTOTYPE( int vm_unmap, (endpoint_t endpt, void *addr)); diff --git a/lib/csu/i386-aout/crtso.S b/lib/csu/i386-aout/crtso.S index 6f17bee97..f46dc2593 100644 --- a/lib/csu/i386-aout/crtso.S +++ b/lib/csu/i386-aout/crtso.S @@ -91,7 +91,7 @@ __minix_unmapzero: /* unmap 0-page code */ push $I386_PAGE_SIZE push $crtso - call _munmap_text /* unmap_text(crtso, I386_PAGE_SIZE) */ + call _minix_munmap_text /* unmap_text(crtso, I386_PAGE_SIZE) */ add $8, %esp #ifdef __ACK__ @@ -103,7 +103,7 @@ __minix_unmapzero: /* unmap 0-page data */ push $I386_PAGE_SIZE push $romstart - call _munmap /* munmap(romstart, I386_PAGE_SIZE) */ + call _minix_munmap /* munmap(romstart, I386_PAGE_SIZE) */ add $8, %esp #endif diff --git a/lib/libc/ansi/malloc-debug.c b/lib/libc/ansi/malloc-debug.c index cb572cf34..2a32bbfd4 100644 --- a/lib/libc/ansi/malloc-debug.c +++ b/lib/libc/ansi/malloc-debug.c @@ -10,6 +10,9 @@ #include #include +#define mmap minix_mmap +#define munmap minix_munmap + #include "malloc-debug.h" #if 0 diff --git a/lib/libc/other/namespace.h b/lib/libc/other/namespace.h index 628da34cd..4831f2a0f 100644 --- a/lib/libc/other/namespace.h +++ b/lib/libc/other/namespace.h @@ -155,6 +155,9 @@ #define system _system #define tcdrain _tcdrain #define wait _wait +#define minix_mmap _minix_mmap +#define minix_munmap _minix_munmap +#define minix_munmap_text _minix_munmap_text #endif #endif /* _NAMESPACE_H_ */ diff --git a/lib/libc/posix/_mmap.c b/lib/libc/posix/_mmap.c index 26e2164d7..8497fddc4 100644 --- a/lib/libc/posix/_mmap.c +++ b/lib/libc/posix/_mmap.c @@ -1,8 +1,8 @@ #define _SYSTEM 1 #include -#define mmap _mmap -#define munmap _munmap -#define munmap_text _munmap_text +#define minix_mmap _minix_mmap +#define minix_munmap _minix_munmap +#define minix_munmap_text _minix_munmap_text #define vm_remap _vm_remap #define vm_unmap _vm_unmap #define vm_getphys _vm_getphys @@ -12,7 +12,7 @@ #include #include -PUBLIC void *mmap(void *addr, size_t len, int prot, int flags, +PUBLIC void *minix_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { message m; @@ -34,7 +34,7 @@ PUBLIC void *mmap(void *addr, size_t len, int prot, int flags, return (void *) m.VMM_RETADDR; } -PUBLIC int munmap(void *addr, size_t len) +PUBLIC int minix_munmap(void *addr, size_t len) { message m; @@ -45,7 +45,7 @@ PUBLIC int munmap(void *addr, size_t len) } -PUBLIC int munmap_text(void *addr, size_t len) +PUBLIC int minix_munmap_text(void *addr, size_t len) { message m; diff --git a/lib/libc/syscall/mmap.S b/lib/libc/syscall/mmap.S index d8afedad8..364c6eba0 100644 --- a/lib/libc/syscall/mmap.S +++ b/lib/libc/syscall/mmap.S @@ -1,6 +1,6 @@ #include -IMPORT(_mmap) -ENTRY(mmap) - jmp _C_LABEL(_mmap) +IMPORT(_minix_mmap) +ENTRY(minix_mmap) + jmp _C_LABEL(_minix_mmap) diff --git a/lib/libc/syscall/munmap.S b/lib/libc/syscall/munmap.S index 5ca046694..c7708251c 100644 --- a/lib/libc/syscall/munmap.S +++ b/lib/libc/syscall/munmap.S @@ -1,10 +1,10 @@ #include -IMPORT(_munmap) -ENTRY(munmap) - jmp _C_LABEL(_munmap) +IMPORT(_minix_munmap) +ENTRY(minix_munmap) + jmp _C_LABEL(_minix_munmap) -IMPORT(_munmap_text) -ENTRY(munmap_text) - jmp _C_LABEL(_munmap_text) +IMPORT(_minix_munmap_text) +ENTRY(minix_munmap_text) + jmp _C_LABEL(_minix_munmap_text) diff --git a/lib/libsys/alloc_util.c b/lib/libsys/alloc_util.c index 40e906c12..03db92f13 100644 --- a/lib/libsys/alloc_util.c +++ b/lib/libsys/alloc_util.c @@ -33,12 +33,12 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) if(flags & AC_ALIGN64K) mmapflags |= MAP_ALIGN64K; - /* First try to get memory with mmap. This is guaranteed + /* First try to get memory with minix_mmap. This is guaranteed * to be page-aligned, and we can tell VM it has to be * pre-allocated and contiguous. */ errno = 0; - buf = (vir_bytes) mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0); + buf = (vir_bytes) minix_mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0); /* If that failed, maybe we're not running in paged mode. * If that's the case, ENXIO will be returned. @@ -74,6 +74,6 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) int free_contig(void *addr, size_t len) { - return munmap(addr, len); + return minix_munmap(addr, len); } diff --git a/lib/nbsd_libc/cdb/cdbr.c b/lib/nbsd_libc/cdb/cdbr.c index 07300d4e3..90f1c526d 100644 --- a/lib/nbsd_libc/cdb/cdbr.c +++ b/lib/nbsd_libc/cdb/cdbr.c @@ -123,15 +123,14 @@ cdbr_open(const char *path, int flags) cdbr->mmap_size = (size_t)sb.st_size; #ifdef __minix - cdbr->mmap_base = mmap(NULL, cdbr->mmap_size, PROT_READ, MAP_ANON, -1, (off_t)0); - if (cdbr->mmap_base == MAP_FAILED) { + if(!(cdbr->mmap_base = malloc(cdbr->mmap_size))) { free(cdbr); return NULL; } if (read(fd, cdbr->mmap_base, cdbr->mmap_size) != cdbr->mmap_size) { - munmap(cdbr->mmap_base, cdbr->mmap_size); + free(cdbr->mmap_base); free(cdbr); return NULL; } @@ -256,6 +255,10 @@ cdbr_find(struct cdbr *cdbr, const void *key, size_t key_len, void cdbr_close(struct cdbr *cdbr) { +#ifdef __minix + free(cdbr->mmap_base); +#else munmap(cdbr->mmap_base, cdbr->mmap_size); +#endif free(cdbr); } diff --git a/lib/nbsd_libc/citrus/citrus_mmap.c b/lib/nbsd_libc/citrus/citrus_mmap.c index 324a0cc15..cc166a6d2 100644 --- a/lib/nbsd_libc/citrus/citrus_mmap.c +++ b/lib/nbsd_libc/citrus/citrus_mmap.c @@ -75,8 +75,7 @@ _citrus_map_file(struct _citrus_region * __restrict r, } #ifdef __minix - head = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_ANON, -1, (off_t)0); - if (head == MAP_FAILED) { + if(!(head = malloc(st.st_size))) { ret = errno; goto error; } @@ -107,7 +106,11 @@ _citrus_unmap_file(struct _citrus_region *r) _DIAGASSERT(r != NULL); if (_region_head(r) != NULL) { +#ifdef __minix + free(_region_head(r)); +#else (void)munmap(_region_head(r), _region_size(r)); +#endif _region_init(r, NULL, 0); } } diff --git a/lib/nbsd_libc/db/recno/rec_close.c b/lib/nbsd_libc/db/recno/rec_close.c index aa3104416..7fb563286 100644 --- a/lib/nbsd_libc/db/recno/rec_close.c +++ b/lib/nbsd_libc/db/recno/rec_close.c @@ -78,8 +78,12 @@ __rec_close(DB *dbp) /* Committed to closing. */ status = RET_SUCCESS; +#ifndef __minix if (F_ISSET(t, R_MEMMAPPED) && munmap(t->bt_smap, t->bt_msize)) status = RET_ERROR; +#else + assert(!F_ISSET(t, R_MEMMAPPED)); +#endif if (!F_ISSET(t, R_INMEM)) { if (F_ISSET(t, R_CLOSEFP)) { diff --git a/lib/nbsd_libc/include/namespace.h b/lib/nbsd_libc/include/namespace.h index 4a688aa52..a2e6ca3c6 100644 --- a/lib/nbsd_libc/include/namespace.h +++ b/lib/nbsd_libc/include/namespace.h @@ -443,7 +443,6 @@ #define mi_vector_hash _mi_vector_hash #define mkstemp _mkstemp #define mktime_z _mktime_z -#define mmap _mmap #define mpool_close _mpool_close #define mpool_filter _mpool_filter #define mpool_get _mpool_get @@ -889,8 +888,6 @@ #define mkdir _mkdir #define mkfifo _mkfifo #define mknod _mknod -#define munmap _munmap -#define munmap_text _munmap_text #define open _open #define pathconf _pathconf #define ptrace _ptrace diff --git a/lib/nbsd_libc/nls/catclose.c b/lib/nbsd_libc/nls/catclose.c index 3c9944084..54f6e77c2 100644 --- a/lib/nbsd_libc/nls/catclose.c +++ b/lib/nbsd_libc/nls/catclose.c @@ -57,7 +57,11 @@ _catclose(catd) } if (catd) { +#ifdef __minix + free(catd->__data); +#else munmap(catd->__data, (size_t)catd->__size); +#endif free (catd); } diff --git a/lib/nbsd_libc/nls/catopen.c b/lib/nbsd_libc/nls/catopen.c index 085f8eef9..48519debd 100644 --- a/lib/nbsd_libc/nls/catopen.c +++ b/lib/nbsd_libc/nls/catopen.c @@ -170,14 +170,13 @@ load_msgcat(path) } #ifdef __minix - data = mmap(0, (size_t)st.st_size, PROT_READ, MAP_ANON, -1, (off_t)0); - if (data == MAP_FAILED) { + if(!(data = malloc((size_t)st.st_size))) { return (nl_catd)-1; } if (read(fd, data, st.st_size) != st.st_size) { - munmap(data, (size_t)st.st_size); + free(data); return (nl_catd)-1; } close (fd); @@ -193,12 +192,20 @@ load_msgcat(path) if (ntohl((u_int32_t)((struct _nls_cat_hdr *)data)->__magic) != _NLS_MAGIC) { +#ifdef __minix + free(data); +#else munmap(data, (size_t)st.st_size); +#endif return (nl_catd)-1; } if ((catd = malloc(sizeof (*catd))) == NULL) { +#ifdef __minix + free(data); +#else munmap(data, (size_t)st.st_size); +#endif return (nl_catd)-1; } diff --git a/lib/nbsd_libc/stdlib/malloc.c b/lib/nbsd_libc/stdlib/malloc.c index b28bd3ba3..6e100a0e3 100644 --- a/lib/nbsd_libc/stdlib/malloc.c +++ b/lib/nbsd_libc/stdlib/malloc.c @@ -12,6 +12,11 @@ * */ +#ifdef __minix +#define mmap minix_mmap +#define munmap minix_munmap +#endif + /* * Defining MALLOC_EXTRA_SANITY will enable extra checks which are related * to internal conditions and consistency in malloc.c. This has a diff --git a/lib/nbsd_libc/sys-minix/mmap.c b/lib/nbsd_libc/sys-minix/mmap.c index 60b2a5b8f..8869adada 100644 --- a/lib/nbsd_libc/sys-minix/mmap.c +++ b/lib/nbsd_libc/sys-minix/mmap.c @@ -6,9 +6,6 @@ /* INCLUDES HERE */ #ifdef __weak_alias -__weak_alias(mmap, _mmap) -__weak_alias(munmap, _munmap) -__weak_alias(munmap_text, _munmap_text) __weak_alias(vm_remap, _vm_remap) __weak_alias(vm_unmap, _vm_unmap) __weak_alias(vm_getphys, _vm_getphys) @@ -21,7 +18,7 @@ __weak_alias(vm_getrefcount, _vm_getrefcount) #include #include -PUBLIC void *mmap(void *addr, size_t len, int prot, int flags, +PUBLIC void *minix_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { message m; @@ -43,7 +40,7 @@ PUBLIC void *mmap(void *addr, size_t len, int prot, int flags, return (void *) m.VMM_RETADDR; } -PUBLIC int munmap(void *addr, size_t len) +PUBLIC int minix_munmap(void *addr, size_t len) { message m; @@ -54,7 +51,7 @@ PUBLIC int munmap(void *addr, size_t len) } -PUBLIC int munmap_text(void *addr, size_t len) +PUBLIC int minix_munmap_text(void *addr, size_t len) { message m; diff --git a/nbsd_include/sys/mman.h b/nbsd_include/sys/mman.h index 8a03de7d0..f91481b2b 100644 --- a/nbsd_include/sys/mman.h +++ b/nbsd_include/sys/mman.h @@ -64,11 +64,13 @@ typedef __off_t off_t; /* file offset */ #include __BEGIN_DECLS +#ifndef __minix void * mmap(void *, size_t, int, int, int, off_t); int munmap(void *, size_t); - -#ifdef __minix -int munmap_text(void *, size_t); +#else +void * minix_mmap(void *, size_t, int, int, int, off_t); +int minix_munmap(void *, size_t); +int minix_munmap_text(void *, size_t); void * vm_remap(int d, int s, void *da, void *sa, size_t si); int vm_unmap(int endpt, void *addr); unsigned long vm_getphys(int endpt, void *addr); diff --git a/servers/ipc/shm.c b/servers/ipc/shm.c index b90bf73cb..eabb1766f 100644 --- a/servers/ipc/shm.c +++ b/servers/ipc/shm.c @@ -72,7 +72,7 @@ PUBLIC int do_shmget(message *m) return ENOSPC; shm = &shm_list[shm_list_nr]; memset(shm, 0, sizeof(struct shm_struct)); - shm->page = (vir_bytes) mmap(0, size, + shm->page = (vir_bytes) minix_mmap(0, size, PROT_READ|PROT_WRITE, MAP_CONTIG|MAP_PREALLOC|MAP_ANON|MAP_IPC_SHARED, -1, 0); @@ -173,7 +173,7 @@ PUBLIC void update_refcount_and_destroy(void) int size = shm_list[i].shmid_ds.shm_segsz; if (size % I386_PAGE_SIZE) size += I386_PAGE_SIZE - size % I386_PAGE_SIZE; - munmap((void *)shm_list[i].page, size); + minix_munmap((void *)shm_list[i].page, size); } } shm_list_nr = j; diff --git a/servers/pm/utility.c b/servers/pm/utility.c index 003885363..cd1b8ed0c 100644 --- a/servers/pm/utility.c +++ b/servers/pm/utility.c @@ -30,11 +30,11 @@ #include "kernel/type.h" #include "kernel/proc.h" -#define munmap _munmap -#define munmap_text _munmap_text +#define minix_munmap _minix_munmap +#define minix_munmap_text _minix_munmap_text #include -#undef munmap -#undef munmap_text +#undef minix_munmap +#undef minix_munmap_text /*===========================================================================* * get_free_pid * @@ -156,19 +156,19 @@ message *m_ptr; int unmap_ok = 0; -PUBLIC int munmap(void *addrstart, vir_bytes len) +PUBLIC int minix_munmap(void *addrstart, vir_bytes len) { if(!unmap_ok) return ENOSYS; - return _munmap(addrstart, len); + return _minix_munmap(addrstart, len); } -PUBLIC int munmap_text(void *addrstart, vir_bytes len) +PUBLIC int minix_munmap_text(void *addrstart, vir_bytes len) { if(!unmap_ok) return ENOSYS; - return _munmap_text(addrstart, len); + return _minix_munmap_text(addrstart, len); } diff --git a/servers/rs/memory.c b/servers/rs/memory.c index 8745ece09..7d13bbe07 100644 --- a/servers/rs/memory.c +++ b/servers/rs/memory.c @@ -6,32 +6,32 @@ #include "inc.h" -#define munmap _munmap -#define munmap_text _munmap_text +#define minix_munmap _minix_munmap +#define minix_munmap_text _minix_munmap_text #include -#undef munmap -#undef munmap_text +#undef minix_munmap +#undef minix_munmap_text PUBLIC int unmap_ok = 0; /*===========================================================================* - * munmap * + * minix_munmap * *===========================================================================*/ -PUBLIC int munmap(void *addrstart, vir_bytes len) +PUBLIC int minix_munmap(void *addrstart, vir_bytes len) { if(!unmap_ok) return ENOSYS; - return _munmap(addrstart, len); + return _minix_munmap(addrstart, len); } /*===========================================================================* - * munmap_text * + * minix_munmap_text * *===========================================================================*/ -PUBLIC int munmap_text(void *addrstart, vir_bytes len) +PUBLIC int minix_munmap_text(void *addrstart, vir_bytes len) { if(!unmap_ok) return ENOSYS; - return _munmap_text(addrstart, len); + return _minix_munmap_text(addrstart, len); } -- 2.44.0