Wrap malloc() so that we catch the kernel arguments (namely M_ZERO)

properly.  It's fairly amusing that this wasn't noticed until now.
This commit is contained in:
pooka 2007-08-15 22:13:15 +00:00
parent 399122feeb
commit cfd4dc8f38
4 changed files with 30 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.rump,v 1.3 2007/08/07 21:33:13 pooka Exp $
# $NetBSD: Makefile.rump,v 1.4 2007/08/15 22:13:15 pooka Exp $
#
.include <bsd.own.mk>
@ -20,4 +20,6 @@ CPPFLAGS+= -D_KERNEL -DDIAGNOSTIC -I${NETBSDSRCDIR}/common/include
CPPFLAGS+= -nostdinc -I${NETBSDSRCDIR}/sys
.endif
LDFLAGS+= -Wl,--wrap=malloc
LIBRUMPDIR != cd ${NETBSDSRCDIR}/sys/rump/librump/rumpkern && ${PRINTOBJDIR}

View File

@ -1,4 +1,4 @@
/* $NetBSD: emul.c,v 1.8 2007/08/14 13:54:15 pooka Exp $ */
/* $NetBSD: emul.c,v 1.9 2007/08/15 22:13:15 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -27,6 +27,8 @@
* SUCH DAMAGE.
*/
#define malloc(a,b,c) __wrap_malloc(a,b,c)
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/null.h>
@ -243,6 +245,18 @@ malloc_type_detach(struct malloc_type *type)
return;
}
void *
__wrap_malloc(unsigned long size, struct malloc_type *type, int flags)
{
void *rv;
rv = rumpuser_malloc(size, flags * (M_CANFAIL | M_NOWAIT));
if (rv && flags & M_ZERO)
memset(rv, 0, size);
return rv;
}
void
nanotime(struct timespec *ts)
{

View File

@ -1,14 +1,13 @@
# $NetBSD: Makefile,v 1.2 2007/08/07 20:39:54 pooka Exp $
# $NetBSD: Makefile,v 1.3 2007/08/15 22:13:16 pooka Exp $
#
.include <bsd.own.mk>
LIB= rumpuser
SRCS= rumpuser.c
NOPIC= # defined
MKLINT= no
MKPROFILE= no
WARNS= 4
DBG= -O0 -g
RUMPKERNEL= no
.include "${NETBSDSRCDIR}/sys/rump/Makefile.rump"
.include <bsd.lib.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser.c,v 1.4 2007/08/07 20:40:53 pooka Exp $ */
/* $NetBSD: rumpuser.c,v 1.5 2007/08/15 22:13:16 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -27,6 +27,8 @@
* SUCH DAMAGE.
*/
#define malloc(a) __real_malloc(a)
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -36,6 +38,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "rumpuser.h"
@ -76,6 +79,9 @@ _rumpuser_malloc(size_t howmuch, int canfail, const char *func, int line)
abort();
}
if (rv)
memset(rv, 0, howmuch);
return rv;
}