Skip to content

Commit

Permalink
drop the minix_ prefixes for mmap and munmap
Browse files Browse the repository at this point in the history
also cleanup of various minix-specific changes, cleanup of
mmap-related testing.

Change-Id: I289a4fc50cf8a13df4a6082038d860853a4bd024
  • Loading branch information
bengras authored and sambuc committed Mar 3, 2014
1 parent b0cab62 commit dda632a
Show file tree
Hide file tree
Showing 34 changed files with 198 additions and 181 deletions.
3 changes: 0 additions & 3 deletions commands/grep/mmfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@

#define MAX_MAP_LEN 1048576

#define munmap minix_munmap
#define mmap minix_mmap

mmf_t *
mmopen(char *fn, char *mode)
{
Expand Down
4 changes: 2 additions & 2 deletions drivers/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static int m_block_ioctl(devminor_t minor, unsigned long request,
size -= l;
}
size = rounddown(size, PAGE_SIZE);
r = minix_munmap((void *) a, size);
r = munmap((void *) a, size);
if(r != OK) {
printf("memory: WARNING: munmap failed: %d\n", r);
}
Expand All @@ -586,7 +586,7 @@ static int m_block_ioctl(devminor_t minor, unsigned long request,

/* Try to allocate a piece of memory for the RAM disk. */
if(ramdev_size > 0 &&
(mem = minix_mmap(NULL, ramdev_size, PROT_READ|PROT_WRITE,
(mem = 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);
Expand Down
4 changes: 2 additions & 2 deletions drivers/uds/uds.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uds_open(devminor_t UNUSED(orig_minor), int access,
* in use. We use mmap instead of malloc to allow the memory to be
* actually freed later.
*/
if ((buf = minix_mmap(NULL, UDS_BUF, PROT_READ | PROT_WRITE,
if ((buf = mmap(NULL, UDS_BUF, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0)) == MAP_FAILED)
return ENOMEM;

Expand Down Expand Up @@ -166,7 +166,7 @@ uds_close(devminor_t minor)
uds_clear_fds(minor, &uds_fd_table[minor].ancillary_data);

/* Release the memory for the ring buffer. */
minix_munmap(uds_fd_table[minor].buf, UDS_BUF);
munmap(uds_fd_table[minor].buf, UDS_BUF);

/* Set the socket back to its original UDS_FREE state. */
memset(&uds_fd_table[minor], '\0', sizeof(uds_fd_t));
Expand Down
6 changes: 3 additions & 3 deletions drivers/vnd/vnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ vnd_ioctl(devminor_t UNUSED(minor), unsigned long request, endpoint_t endpt,
* of malloc to allow the memory to be actually freed later.
*/
if (r == OK) {
state.buf = minix_mmap(NULL, VND_BUF_SIZE, PROT_READ |
state.buf = mmap(NULL, VND_BUF_SIZE, PROT_READ |
PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (state.buf == MAP_FAILED)
r = ENOMEM;
Expand Down Expand Up @@ -432,7 +432,7 @@ vnd_ioctl(devminor_t UNUSED(minor), unsigned long request, endpoint_t endpt,
}

if (r != OK) {
minix_munmap(state.buf, VND_BUF_SIZE);
munmap(state.buf, VND_BUF_SIZE);
close(state.fd);
state.fd = -1;
}
Expand All @@ -457,7 +457,7 @@ vnd_ioctl(devminor_t UNUSED(minor), unsigned long request, endpoint_t endpt,
* allow reuse until the device has been closed by the other
* users.
*/
minix_munmap(state.buf, VND_BUF_SIZE);
munmap(state.buf, VND_BUF_SIZE);
close(state.fd);
state.fd = -1;

Expand Down
4 changes: 2 additions & 2 deletions lib/libc/include/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,8 @@
#define truncate _truncate
#define write _write
#define writev _writev
#define minix_mmap _minix_mmap
#define minix_munmap _minix_munmap
#define mmap _mmap
#define munmap _munmap
#define vfork __vfork14
#endif /* __minix */

Expand Down
3 changes: 0 additions & 3 deletions lib/libc/minix/minix-malloc-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include <sys/mman.h>
#include <unistd.h>

#define mmap minix_mmap
#define munmap minix_munmap

#include "malloc-debug.h"

#if 0
Expand Down
8 changes: 3 additions & 5 deletions lib/libc/stdlib/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
*/

#ifdef __minix
#include <machine/vmparam.h>
#define mmap minix_mmap
#define munmap minix_munmap
#ifdef _LIBSYS
#include <minix/sysutil.h>
#include <machine/vmparam.h>
#define MALLOC_NO_SYSCALLS
#define wrtwarning(w) printf("libminc malloc warning: %s\n", w)
#define wrterror(w) panic("libminc malloc error: %s\n", w)
Expand Down Expand Up @@ -98,8 +96,8 @@ void utrace(struct ut *, int);
* This is necessary for VM to be able to define its own versions, and
* use this malloc.
*/
#undef minix_mmap
#undef minix_munmap
#undef mmap
#undef munmap

#include <sys/types.h>
#if defined(__NetBSD__)
Expand Down
8 changes: 4 additions & 4 deletions lib/libc/sys-minix/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ __weak_alias(vm_remap, _vm_remap)
__weak_alias(vm_unmap, _vm_unmap)
__weak_alias(vm_getphys, _vm_getphys)
__weak_alias(vm_getrefcount, _vm_getrefcount)
__weak_alias(minix_mmap, _minix_mmap)
__weak_alias(minix_munmap, _minix_munmap)
__weak_alias(mmap, _mmap)
__weak_alias(munmap, _munmap)
#endif


Expand Down Expand Up @@ -71,13 +71,13 @@ int minix_vfs_mmap(endpoint_t who, off_t offset, size_t len,
return _syscall(VM_PROC_NR, VM_VFS_MMAP, &m);
}

void *minix_mmap(void *addr, size_t len, int prot, int flags,
void *mmap(void *addr, size_t len, int prot, int flags,
int fd, off_t offset)
{
return minix_mmap_for(SELF, addr, len, prot, flags, fd, offset);
}

int minix_munmap(void *addr, size_t len)
int munmap(void *addr, size_t len)
{
message m;

Expand Down
14 changes: 7 additions & 7 deletions lib/libminixfs/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ lmfs_alloc_block(struct buf *bp)

len = roundup(fs_block_size, PAGE_SIZE);

if((bp->data = minix_mmap(0, fs_block_size,
if((bp->data = mmap(0, fs_block_size,
PROT_READ|PROT_WRITE, MAP_PREALLOC|MAP_ANON, -1, 0)) == MAP_FAILED) {
free_unused_blocks();
if((bp->data = minix_mmap(0, fs_block_size, PROT_READ|PROT_WRITE,
if((bp->data = mmap(0, fs_block_size, PROT_READ|PROT_WRITE,
MAP_PREALLOC|MAP_ANON, -1, 0)) == MAP_FAILED) {
panic("libminixfs: could not allocate block");
}
Expand All @@ -190,7 +190,7 @@ struct buf *lmfs_get_block(register dev_t dev, register block_t block,
return lmfs_get_block_ino(dev, block, only_search, VMC_NO_INODE, 0);
}

void minix_munmap_t(void *a, int len)
void munmap_t(void *a, int len)
{
vir_bytes av = (vir_bytes) a;
assert(a);
Expand All @@ -202,7 +202,7 @@ void minix_munmap_t(void *a, int len)

assert(!(len % PAGE_SIZE));

if(minix_munmap(a, len) < 0)
if(munmap(a, len) < 0)
panic("libminixfs cache: munmap failed");
}

Expand Down Expand Up @@ -240,7 +240,7 @@ static void freeblock(struct buf *bp)
MARKCLEAN(bp); /* NO_DEV blocks may be marked dirty */
if(bp->lmfs_bytes > 0) {
assert(bp->data);
minix_munmap_t(bp->data, bp->lmfs_bytes);
munmap_t(bp->data, bp->lmfs_bytes);
bp->lmfs_bytes = 0;
bp->data = NULL;
} else assert(!bp->data);
Expand Down Expand Up @@ -571,7 +571,7 @@ void lmfs_invalidate(
if (bp->lmfs_dev == device) {
assert(bp->data);
assert(bp->lmfs_bytes > 0);
minix_munmap_t(bp->data, bp->lmfs_bytes);
munmap_t(bp->data, bp->lmfs_bytes);
bp->lmfs_dev = NO_DEV;
bp->lmfs_bytes = 0;
bp->data = NULL;
Expand Down Expand Up @@ -862,7 +862,7 @@ void lmfs_buf_pool(int new_nr_bufs)
for (bp = &buf[0]; bp < &buf[nr_bufs]; bp++) {
if(bp->data) {
assert(bp->lmfs_bytes > 0);
minix_munmap_t(bp->data, bp->lmfs_bytes);
munmap_t(bp->data, bp->lmfs_bytes);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/libmthread/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void *arg;
char *guard_start, *guard_end;

stacksize = round_page(stacksize + MTHREAD_GUARDSIZE);
stackaddr = minix_mmap(NULL, stacksize,
stackaddr = mmap(NULL, stacksize,
PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
-1, 0);
if (stackaddr == MAP_FAILED)
Expand Down Expand Up @@ -431,7 +431,7 @@ void *arg;
# error "Unsupported platform"
#endif
stacksize = guarded_stacksize;
if (minix_munmap(guard_start, MTHREAD_GUARDSIZE) != 0)
if (munmap(guard_start, MTHREAD_GUARDSIZE) != 0)
mthread_panic("unable to unmap stack space for guard");
tcb->m_context.uc_stack.ss_sp = guard_end;
} else
Expand Down Expand Up @@ -465,7 +465,7 @@ mthread_thread_t thread;
rt->m_cond = NULL;
if (rt->m_attr.ma_stackaddr == NULL) { /* We allocated stack space */
if (rt->m_context.uc_stack.ss_sp) {
if (minix_munmap(rt->m_context.uc_stack.ss_sp,
if (munmap(rt->m_context.uc_stack.ss_sp,
rt->m_context.uc_stack.ss_size) != 0) {
mthread_panic("unable to unmap memory");
}
Expand Down
8 changes: 4 additions & 4 deletions lib/libpuffs/callcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ slowccalloc(struct puffs_usermount *pu)
if (puffs_fakecc)
return &fakecc;

sp = minix_mmap(NULL, stacksize, PROT_READ|PROT_WRITE,
sp = mmap(NULL, stacksize, PROT_READ|PROT_WRITE,
MAP_ANON|MAP_PRIVATE, -1, 0);
if (sp == MAP_FAILED)
return NULL;
Expand All @@ -194,11 +194,11 @@ slowccalloc(struct puffs_usermount *pu)

/* initialize both ucontext's */
if (getcontext(&pcc->pcc_uc) == -1) {
minix_munmap(pcc, stacksize);
munmap(pcc, stacksize);
return NULL;
}
if (getcontext(&pcc->pcc_uc_ret) == -1) {
minix_munmap(pcc, stacksize);
munmap(pcc, stacksize);
return NULL;
}

Expand Down Expand Up @@ -280,7 +280,7 @@ cc_free(struct puffs_cc *pcc)

DPRINTF(("invalidating pcc %p\n", pcc));
assert(!puffs_fakecc);
minix_munmap(pcc, stacksize);
munmap(pcc, stacksize);
}

void
Expand Down
31 changes: 5 additions & 26 deletions lib/libsys/alloc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,17 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys)
if(flags & AC_LOWER1M)
mmapflags |= MAP_LOWER1M;
if(flags & AC_ALIGN64K)
mmapflags |= MAP_ALIGN64K;
mmapflags |= MAP_ALIGNMENT_64KB;

/* First try to get memory with minix_mmap. This is guaranteed
/* First try to get memory with 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) minix_mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0);
buf = (vir_bytes) 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.
* Memory returned with malloc() will be preallocated and
* contiguous, so fallback on that, and ask for a little extra
* so we can page align it ourselves.
*/
if(buf == (vir_bytes) MAP_FAILED) {
u32_t align = 0;
if(errno != (_SIGN ENXIO)) {
return NULL;
}
if(flags & AC_ALIGN4K)
align = 4*1024;
if(flags & AC_ALIGN64K)
align = 64*1024;
if(len + align < len)
return NULL;
len += align;
if(!(buf = (vir_bytes) malloc(len))) {
return NULL;
}
if(align)
buf += align - (buf % align);
return NULL;
}

/* Get physical address, if requested. */
Expand All @@ -59,6 +38,6 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys)

int free_contig(void *addr, size_t len)
{
return minix_munmap(addr, len);
return munmap(addr, len);
}

4 changes: 0 additions & 4 deletions libexec/ld.elf_so/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ __RCSID("$NetBSD: load.c,v 1.42 2010/12/24 12:41:43 skrll Exp $");
#include <sys/sysctl.h>
#include <dirent.h>

#ifdef __minix
#define munmap minix_munmap
#endif

#include "debug.h"
#include "rtld.h"

Expand Down
2 changes: 0 additions & 2 deletions libexec/ld.elf_so/map_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ __RCSID("$NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $");
#include "rtld.h"

#ifdef __minix
#define munmap minix_munmap
#define mmap minix_mmap
#ifndef MAP_SHARED
#define MAP_SHARED MAP_PRIVATE /* minix: MAP_SHARED should be MAP_PRIVATE */
#endif
Expand Down
8 changes: 2 additions & 6 deletions libexec/ld.elf_so/map_object_fallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ __RCSID("$NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $");
#include "debug.h"
#include "rtld.h"

#ifdef __minix
#define munmap minix_munmap
#endif

#define MINIXVERBOSE 0

#if MINIXVERBOSE
Expand Down Expand Up @@ -137,7 +133,7 @@ _rtld_map_object_fallback(const char *path, int fd, const struct stat *sb)
}

#ifdef __minix
ehdr = minix_mmap(NULL, _rtld_pagesz, PROT_READ|PROT_WRITE,
ehdr = mmap(NULL, _rtld_pagesz, PROT_READ|PROT_WRITE,
MAP_PREALLOC|MAP_ANON, -1, (off_t)0);
Pread(ehdr, _rtld_pagesz, fd, 0);
#if MINIXVERBOSE
Expand Down Expand Up @@ -368,7 +364,7 @@ _rtld_map_object_fallback(const char *path, int fd, const struct stat *sb)
mapbase = mmap(base_addr, mapsize, text_flags,
mapflags | MAP_FILE | MAP_PRIVATE, fd, base_offset);
#else
mapbase = minix_mmap(base_addr, mapsize, PROT_READ|PROT_WRITE,
mapbase = mmap(base_addr, mapsize, PROT_READ|PROT_WRITE,
MAP_ANON | MAP_PREALLOC, -1, 0);
#if MINIXVERBOSE
fprintf(stderr, "minix mmap for whole block: 0x%lx-0x%lx\n", mapbase, mapbase+mapsize);
Expand Down
4 changes: 0 additions & 4 deletions libexec/ld.elf_so/rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
* John Polstra <[email protected]>.
*/

#ifdef __minix
#define munmap minix_munmap
#endif

#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $");
Expand Down
6 changes: 0 additions & 6 deletions libexec/ld.elf_so/xmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
* SUCH DAMAGE.
*/

#ifdef __minix
/* Minix mmap can do this. */
#define mmap minix_mmap
#define munmap minix_munmap
#endif

#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/
#endif /* LIBC_SCCS and not lint */
Expand Down
6 changes: 0 additions & 6 deletions sbin/newfs_ext2fs/mke2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* mmap/munmap are used in this file just to allocate/free memory
* so these functions are ok.
*/
#define mmap minix_mmap
#define munmap minix_munmap

/*
* mke2fs.c: "re-invent (dumb but non-GPLed) wheel as a fun project"
*
Expand Down
Loading

0 comments on commit dda632a

Please sign in to comment.