PERFORCE change 85648 for review

Todd Miller millert at FreeBSD.org
Fri Oct 21 08:32:40 PDT 2005


http://perforce.freebsd.org/chv.cgi?CH=85648

Change 85648 by millert at millert_ibook on 2005/10/21 15:32:23

	Collapse sebsd_ss_malloc() and sebsd_ss_free() into sebsd_malloc()
	and sebsd_free().  Having two different malloc/free implementations
	is confusing and error-prone.

Affected files ...

.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/linux-compat.h#6 edit
.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd.c#11 edit
.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd_syscall.c#6 edit
.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/ss/global.h#4 edit
.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/ss/mach_av.c#4 edit
.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/ss/queue.c#4 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/linux-compat.h#6 (text+ko) ====

@@ -84,7 +84,7 @@
 
 #define kmalloc(size,flags) malloc(size)
 #define kfree(v) free(v)
-#define __get_free_page(flags) malloc (PAGE_SIZE)
+#define __get_free_page(flags) malloc(PAGE_SIZE)
 #define GFP_ATOMIC  1
 #define GFP_KERNEL  2
 
@@ -119,11 +119,11 @@
 
 #ifdef __APPLE__
 
-extern void *sebsd_ss_malloc (size_t size, int flags);
-extern void sebsd_ss_free (void *);
+extern void *sebsd_malloc(size_t size, int flags);
+extern void sebsd_free(void *);
 
-#define malloc(size,type,flags)		sebsd_ss_malloc (size,flags)
-#define free(addr,type)			sebsd_ss_free (addr)
+#define malloc(size, type, flags)	sebsd_malloc(size, flags)
+#define free(addr, type)		sebsd_free(addr)
 
 #define M_SEBSD M_MACTEMP
 #else 
@@ -133,9 +133,9 @@
 #endif
 #endif /* __APPLE__ */
 
-#define kmalloc(size,flags) sebsd_ss_malloc(size, flags)
-#define kfree(v) sebsd_ss_free(v)
-#define __get_free_page(flags) sebsd_ss_malloc(PAGE_SIZE, flags) 
+#define kmalloc(size, flags)		sebsd_malloc(size, flags)
+#define kfree(v)			sebsd_free(v)
+#define __get_free_page(flags)		sebsd_malloc(PAGE_SIZE, flags) 
 /* XXX - GFP_ATOMIC should be M_NOWAIT but zone alloc chokes in avc init */
 #define GFP_ATOMIC  M_WAITOK
 #define GFP_KERNEL  M_WAITOK

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd.c#11 (text+ko) ====

@@ -79,21 +79,27 @@
 void *
 sebsd_malloc(size_t size, int flags)
 {
-	void *v;
+	size_t *vs;
 
-	v = (flags & M_NOWAIT) ?
-	    (void *)kalloc_noblock(size) : (void *)kalloc(size);
-	if (v != NULL && (flags & M_ZERO))
-		bzero(v, size);
-	return (v);
+	size += sizeof(size_t);
+	vs = (flags & M_NOWAIT) ?
+	    (size_t *)kalloc_noblock(size) : (size_t *)kalloc(size);
+	if (vs != NULL) {
+		bzero(vs, size);
+		*vs++ = size;
+	}
+	return (vs);
 }
 
 static void
-sebsd_free(void *v, size_t size)
+sebsd_free(void *v)
 {
+	size_t *vs = v;
 
-	if (v)
-		kfree((vm_offset_t)v, size);
+	if (vs != NULL) {
+		vs--;
+		kfree((vm_offset_t)vs, *vs);
+	}
 }
 
 #include <miscfs/devfs/devfsdefs.h>
@@ -110,32 +116,7 @@
 static int slot = 1; /* TBD, dynamic */
 #define	SLOT(l)	((void *)LABEL_TO_SLOT((l), slot).l_ptr)
 
-#ifdef __APPLE__
-
-void *
-sebsd_ss_malloc(size_t size, int flags)
-{
-	size_t *vs;
-
-	size += sizeof(size_t);
-	if ((vs = sebsd_malloc(size, flags)) != NULL)
-		*vs++ = size;
-	return (vs);
-}
-
-void
-sebsd_ss_free(void *v)
-{
-	size_t *vs = (size_t *)v;
-
-	if (vs == NULL)
-		return;
-
-	/* size of region is stored immediately before v */
-	sebsd_free(vs - 1, vs[-1]);
-}
-
-#else
+#ifndef __APPLE__
 MALLOC_DEFINE(M_SEBSD, "sebsd", "Security Enhanced BSD");
 #endif
 

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd_syscall.c#6 (text+ko) ====

@@ -137,7 +137,7 @@
 	}
 	error = copyout (&olen, outlen, sizeof(int));
 out2:
-	sebsd_ss_free(sids);
+	sebsd_free(sids);
 out:
 	return (error);
 }
@@ -244,24 +244,24 @@
 	    if (err)
 	      return err;
 	    size_t dummy;
-	    char *ctx = sebsd_ss_malloc (MAX_UC, M_WAITOK);
+	    char *ctx = sebsd_malloc (MAX_UC, M_WAITOK);
 	    err = copyinstr(uap.ctx, ctx, MAX_UC, &dummy);
 	    if (err) {
-	      sebsd_ss_free (ctx);
+	      sebsd_free (ctx);
 	      return err;
 	    }
-	    char *usr = sebsd_ss_malloc (MAX_UC, M_WAITOK);
+	    char *usr = sebsd_malloc (MAX_UC, M_WAITOK);
 	    err = copyinstr(uap.usr, usr, MAX_UC, &dummy);
 	    if (err) {
-	      sebsd_ss_free (ctx);
-	      sebsd_ss_free (usr);
+	      sebsd_free (ctx);
+	      sebsd_free (usr);
 	      return err;
 	    }
 	    ctx[MAX_UC-1] = 0;
 	    usr[MAX_UC-1] = 0;
 	    err = sys_get_sids (call, ctx, usr, uap.out, uap.outlen);
-	    sebsd_ss_free (ctx);
-	    sebsd_ss_free (usr);
+	    sebsd_free (ctx);
+	    sebsd_free (usr);
 	  }
 	  break;
 
@@ -272,31 +272,31 @@
 	    if (err)
 	      return err;
 	    size_t dummy;
-	    char *doms = sebsd_ss_malloc (MAX_UC, M_WAITOK);
+	    char *doms = sebsd_malloc (MAX_UC, M_WAITOK);
 	    err = copyinstr(uap.domain, doms, MAX_UC, &dummy);
 	    if (err) {
-	      sebsd_ss_free (doms);
+	      sebsd_free (doms);
 	      return err;
 	    }
-	    char *srcs = sebsd_ss_malloc (MAX_UC, M_WAITOK);
+	    char *srcs = sebsd_malloc (MAX_UC, M_WAITOK);
 	    err = copyinstr(uap.source, srcs, MAX_UC, &dummy);
 	    if (err) {
-	      sebsd_ss_free (doms);
-	      sebsd_ss_free (srcs);
+	      sebsd_free (doms);
+	      sebsd_free (srcs);
 	      return err;
 	    }
-	    char *scs = sebsd_ss_malloc (MAX_UC, M_WAITOK);
+	    char *scs = sebsd_malloc (MAX_UC, M_WAITOK);
 	    err = copyinstr(uap.sclass, scs, MAX_UC, &dummy);
 	    if (err) {
-	      sebsd_ss_free (doms);
-	      sebsd_ss_free (srcs);
-	      sebsd_ss_free (scs);
+	      sebsd_free (doms);
+	      sebsd_free (srcs);
+	      sebsd_free (scs);
 	      return err;
 	    }
 	    err = sys_change_sid (doms, srcs, scs, uap.out, uap.outlen);
-	    sebsd_ss_free (doms);
-	    sebsd_ss_free (srcs);
-	    sebsd_ss_free (scs);
+	    sebsd_free (doms);
+	    sebsd_free (srcs);
+	    sebsd_free (scs);
 	    return err;
 	  }
 	  break;

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/ss/global.h#4 (text+ko) ====

@@ -23,17 +23,12 @@
  */
 #include <sys/malloc.h>
 
-#if defined(_KERNEL) || defined(KERNEL)
-/*#define sebsd_malloc(a,b,c) sebsd_malloc(a,c)
-  #define sebsd_free(a,b) free(a,b)*/
-#else /* _KERNEL */
+#if !defined(_KERNEL) && !defined(KERNEL)
 #include <stdlib.h>
 #include <errno.h>
 #define sebsd_malloc(a,b,c) (c&M_ZERO)?calloc(1,a):malloc(a)
 #define sebsd_free(a,b) free(a)
-#define sebsd_ss_malloc(a,b) (b&M_ZERO)?calloc(1,a):malloc(a)
-#define sebsd_ss_free(a) free(a)
-#define kmalloc(l,f) sebsd_ss_malloc(l,f)
+#define kmalloc(l,f) sebsd_malloc(l,f)
 #define	mtx_lock(a)
 #define	mtx_unlock(a)
 #endif /* _KERNEL */

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/ss/mach_av.c#4 (text+ko) ====

@@ -51,14 +51,14 @@
 		int size = *p++;
 		int i;
 
-		struct msgid_classinfo *c = sebsd_ss_malloc
+		struct msgid_classinfo *c = sebsd_malloc
 			(sizeof(int) * nclasses + sizeof(struct msgid_classinfo), M_WAITOK);
 		c->baseid = msgid;
 		c->nclasses = nclasses;
 		for (i = 0; i < nclasses; i++)
 			c->classes[i] = *p++;
 		for (i = msgid; i < msgid + size; i++) {
-			int *ip = sebsd_ss_malloc(sizeof(int), M_WAITOK);
+			int *ip = sebsd_malloc(sizeof(int), M_WAITOK);
 			*ip = i;
 			hashtab_insert(msgid2class, ip, c);
 		}

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/ss/queue.c#4 (text+ko) ====

@@ -22,7 +22,7 @@
 {
 	queue_t q;
 
-	q = (queue_t) sebsd_ss_malloc(sizeof(struct queue_info),
+	q = (queue_t) sebsd_malloc(sizeof(struct queue_info),
 				      M_WAITOK);
 	if (q == NULL)
 		return NULL;
@@ -40,7 +40,7 @@
 	if (!q)
 		return -1;
 
-	newnode = (queue_node_ptr_t) sebsd_ss_malloc(sizeof(struct queue_node),
+	newnode = (queue_node_ptr_t) sebsd_malloc(sizeof(struct queue_node),
 						     M_WAITOK);
 	if (newnode == NULL)
 		return -1;
@@ -66,7 +66,7 @@
 	if (!q)
 		return -1;
 
-	newnode = (queue_node_ptr_t) sebsd_ss_malloc(sizeof(struct queue_node),
+	newnode = (queue_node_ptr_t) sebsd_malloc(sizeof(struct queue_node),
 						     M_WAITOK);
 	if (newnode == NULL)
 		return -1;
@@ -103,7 +103,7 @@
 		q->tail = NULL;
 
 	e = node->element;
-	sebsd_ss_free(node);
+	sebsd_free(node);
 
 	return e;
 }
@@ -132,10 +132,10 @@
 	while (p != NULL) {
 		temp = p;
 		p = p->next;
-		sebsd_ss_free(temp);
+		sebsd_free(temp);
 	}
 
-	sebsd_ss_free(q);
+	sebsd_free(q);
 }
 
 int queue_map(queue_t q, int (*f) (queue_element_t, void *), void *vp)
@@ -188,7 +188,7 @@
 			temp = p;
 			p = p->next;
 			g(temp->element, vp);
-			sebsd_ss_free(temp);
+			sebsd_free(temp);
 		} else {
 			last = p;
 			p = p->next;


More information about the p4-projects mailing list