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
This commit is contained in:
Ben Gras 2011-07-16 03:11:10 +02:00
parent 76356eed97
commit 02081e4b62
23 changed files with 106 additions and 66 deletions

View file

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

View file

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

View file

@ -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);

View file

@ -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));

View file

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

View file

@ -10,6 +10,9 @@
#include <string.h>
#include <sys/mman.h>
#define mmap minix_mmap
#define munmap minix_munmap
#include "malloc-debug.h"
#if 0

View file

@ -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_ */

View file

@ -1,8 +1,8 @@
#define _SYSTEM 1
#include <lib.h>
#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 <string.h>
#include <errno.h>
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;

View file

@ -1,6 +1,6 @@
#include <machine/asm.h>
IMPORT(_mmap)
ENTRY(mmap)
jmp _C_LABEL(_mmap)
IMPORT(_minix_mmap)
ENTRY(minix_mmap)
jmp _C_LABEL(_minix_mmap)

View file

@ -1,10 +1,10 @@
#include <machine/asm.h>
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)

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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)) {

View file

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

View file

@ -57,7 +57,11 @@ _catclose(catd)
}
if (catd) {
#ifdef __minix
free(catd->__data);
#else
munmap(catd->__data, (size_t)catd->__size);
#endif
free (catd);
}

View file

@ -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;
}

View file

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

View file

@ -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 <string.h>
#include <errno.h>
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;

View file

@ -64,11 +64,13 @@ typedef __off_t off_t; /* file offset */
#include <sys/cdefs.h>
__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);

View file

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

View file

@ -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 <sys/mman.h>
#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);
}

View file

@ -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 <sys/mman.h>
#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);
}