svn commit: r201476 - user/kmacy/releng_8_rump/lib/libunet
Kip Macy
kmacy at FreeBSD.org
Mon Jan 4 09:02:39 UTC 2010
Author: kmacy
Date: Mon Jan 4 09:02:39 2010
New Revision: 201476
URL: http://svn.freebsd.org/changeset/base/201476
Log:
add kmem definitions, remove kern_malloc.c due to use kmem_suballoc
Modified:
user/kmacy/releng_8_rump/lib/libunet/Makefile
user/kmacy/releng_8_rump/lib/libunet/unet_compat.c
user/kmacy/releng_8_rump/lib/libunet/unet_glue.c
Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile
==============================================================================
--- user/kmacy/releng_8_rump/lib/libunet/Makefile Mon Jan 4 08:33:33 2010 (r201475)
+++ user/kmacy/releng_8_rump/lib/libunet/Makefile Mon Jan 4 09:02:39 2010 (r201476)
@@ -12,7 +12,6 @@ LIB= unet
UNET_KERN_COMMON_OBJS += \
kern_environment.o \
kern_event.o \
- kern_malloc.o \
kern_mbuf.o \
kern_module.o \
kern_mtxpool.o \
Modified: user/kmacy/releng_8_rump/lib/libunet/unet_compat.c
==============================================================================
--- user/kmacy/releng_8_rump/lib/libunet/unet_compat.c Mon Jan 4 08:33:33 2010 (r201475)
+++ user/kmacy/releng_8_rump/lib/libunet/unet_compat.c Mon Jan 4 09:02:39 2010 (r201476)
@@ -2,11 +2,30 @@
#define _WANT_UCRED
#include <stdlib.h>
#include <sys/types.h>
+#include <sys/mman.h>
#include <sys/refcount.h>
#include <sys/ucred.h>
struct malloc_type;
-#if 0
+
+vm_offset_t kmem_malloc(void * map, int bytes, int wait);
+void kmem_free(void *map, vm_offset_t addr, vm_size_t size);
+
+vm_offset_t
+kmem_malloc(void * map, int bytes, int wait)
+{
+
+ return ((vm_offset_t)mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0));
+}
+
+
+void
+kmem_free(void *map, vm_offset_t addr, vm_size_t size)
+{
+
+ munmap((void *)addr, size);
+}
+
void *
unet_malloc(unsigned long size, struct malloc_type *type, int flags)
{
@@ -20,7 +39,7 @@ unet_free(void *addr, struct malloc_type
free(addr);
}
-#endif
+
/*
* Claim another reference to a ucred structure.
*/
Modified: user/kmacy/releng_8_rump/lib/libunet/unet_glue.c
==============================================================================
--- user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Mon Jan 4 08:33:33 2010 (r201475)
+++ user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Mon Jan 4 09:02:39 2010 (r201476)
@@ -21,6 +21,7 @@
#include <vm/pmap.h>
#include <vm/vm_object.h>
#include <vm/vm_map.h>
+#include <vm/vm_extern.h>
SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
"Sysctl internal magic");
@@ -34,6 +35,9 @@ SYSCTL_NODE(, CTL_NET, net, CTLFLAG
SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0,
"Virtual memory");
+MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory");
+MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers");
+
int ticks;
@@ -162,11 +166,10 @@ vslock(void *addr, size_t len)
return (0);
}
-int
+void
vsunlock(void *addr, size_t len)
{
- return (0);
}
@@ -629,3 +632,90 @@ kproc_exit(int ecode)
panic("");
}
+vm_offset_t
+kmem_alloc_contig(vm_map_t map, vm_size_t size, int flags, vm_paddr_t low,
+ vm_paddr_t high, unsigned long alignment, unsigned long boundary,
+ vm_memattr_t memattr)
+{
+ return (kmem_malloc(map, size, flags));
+}
+
+void
+malloc_init(void *data)
+{
+#ifdef notyet
+ struct malloc_type_internal *mtip;
+ struct malloc_type *mtp;
+
+ KASSERT(cnt.v_page_count != 0, ("malloc_register before vm_init"));
+
+ mtp = data;
+ if (mtp->ks_magic != M_MAGIC)
+ panic("malloc_init: bad malloc type magic");
+
+ mtip = uma_zalloc(mt_zone, M_WAITOK | M_ZERO);
+ mtp->ks_handle = mtip;
+
+ mtx_lock(&malloc_mtx);
+ mtp->ks_next = kmemstatistics;
+ kmemstatistics = mtp;
+ kmemcount++;
+ mtx_unlock(&malloc_mtx);
+#endif
+}
+
+void
+malloc_uninit(void *data)
+{
+#ifdef notyet
+ struct malloc_type_internal *mtip;
+ struct malloc_type_stats *mtsp;
+ struct malloc_type *mtp, *temp;
+ uma_slab_t slab;
+ long temp_allocs, temp_bytes;
+ int i;
+
+ mtp = data;
+ KASSERT(mtp->ks_magic == M_MAGIC,
+ ("malloc_uninit: bad malloc type magic"));
+ KASSERT(mtp->ks_handle != NULL, ("malloc_deregister: cookie NULL"));
+
+ mtx_lock(&malloc_mtx);
+ mtip = mtp->ks_handle;
+ mtp->ks_handle = NULL;
+ if (mtp != kmemstatistics) {
+ for (temp = kmemstatistics; temp != NULL;
+ temp = temp->ks_next) {
+ if (temp->ks_next == mtp) {
+ temp->ks_next = mtp->ks_next;
+ break;
+ }
+ }
+ KASSERT(temp,
+ ("malloc_uninit: type '%s' not found", mtp->ks_shortdesc));
+ } else
+ kmemstatistics = mtp->ks_next;
+ kmemcount--;
+ mtx_unlock(&malloc_mtx);
+
+ /*
+ * Look for memory leaks.
+ */
+ temp_allocs = temp_bytes = 0;
+ for (i = 0; i < MAXCPU; i++) {
+ mtsp = &mtip->mti_stats[i];
+ temp_allocs += mtsp->mts_numallocs;
+ temp_allocs -= mtsp->mts_numfrees;
+ temp_bytes += mtsp->mts_memalloced;
+ temp_bytes -= mtsp->mts_memfreed;
+ }
+ if (temp_allocs > 0 || temp_bytes > 0) {
+ printf("Warning: memory type %s leaked memory on destroy "
+ "(%ld allocations, %ld bytes leaked).\n", mtp->ks_shortdesc,
+ temp_allocs, temp_bytes);
+ }
+
+ slab = vtoslab((vm_offset_t) mtip & (~UMA_SLAB_MASK));
+ uma_zfree_arg(mt_zone, mtip, slab);
+#endif
+}
More information about the svn-src-user
mailing list