Merge glibc-ports into ports/ directory.
[platform/upstream/glibc.git] / hurd / hurdmalloc.c
index 5f719df..12da1f2 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#define bcopy(s,d,n)   memcpy ((d), (s), (n)) /* No overlap handling.  */
-
 #include "hurdmalloc.h"                /* XXX see that file */
 
 #include <mach.h>
 #define vm_allocate __vm_allocate
 #define vm_page_size __vm_page_size
 
-/* 
+/*
  * Mach Operating System
  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  * All Rights Reserved.
- * 
+ *
  * Permission to use, copy, modify and distribute this software and its
  * documentation is hereby granted, provided that both the copyright
  * notice and this permission notice appear in all copies of the
  * software, derivative works or modified versions, and any portions
  * thereof, and that both notices appear in supporting documentation.
- * 
+ *
  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
+ *
  * Carnegie Mellon requests users of this software to return to
- * 
+ *
  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  *  School of Computer Science
  *  Carnegie Mellon University
  *  Pittsburgh PA 15213-3890
- * 
+ *
  * any improvements or extensions that they make and grant Carnegie Mellon
  * the rights to redistribute these changes.
  */
 /*
- * HISTORY
- * $Log$
- * Revision 1.11  1996/06/06 15:13:47  miles
- * Changes to bring in line with the hurd libthreads/malloc.c:
- *   (more_memory): Use assert_perror instead of MACH_CALL.
- *   "cthread_internals.h": Include removed.
- *   (realloc): Use LOG2_MIN_SIZE.
- *   (LOG2_MIN_SIZE): New macro.
- *   (realloc): Don't bother allocating a new block if the
- *     new size request fits in the old one and doesn't waste any space.
- *     Only free the old block if we successfully got a new one.
- *   [MCHECK] (struct header): New type.
- *   (union header): Only define if !MCHECK.
- *   (HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros.
- *   [MCHECK] (MIN_SIZE): Add correct definition for this case.
- *   (more_memory, malloc, free, realloc): Use above macros, and add appropiate
- *     checks & frobs in MCHECK case.
- *
- * Revision 1.6  1996/03/07 21:13:08  miles
- * (realloc):
- *   Use LOG2_MIN_SIZE.
- *   Don't bother allocating a new block if the new size request fits in the old
- *     one and doesn't waste any space.
- *   Only free the old block if we successfully got a new one.
- * (LOG2_MIN_SIZE): New macro.
- *
- * Revision 1.5  1996/03/06 23:51:04  miles
- * [MCHECK] (struct header): New type.
- * (union header): Only define if !MCHECK.
- * (HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros.
- * [MCHECK] (MIN_SIZE): Add correct definition for this case.
- * (more_memory, malloc, free, realloc):
- *   Use above macros, and add appropiate checks & frobs in MCHECK case.
- *
- * Revision 1.4  1994/05/05 11:21:42  roland
- * entered into RCS
+ * (pre-GNU) HISTORY
  *
  * Revision 2.7  91/05/14  17:57:34  mrt
  *     Correcting copyright
- * 
+ *
  * Revision 2.6  91/02/14  14:20:26  mrt
  *     Added new Mach copyright
  *     [91/02/13  12:41:21  mrt]
- * 
+ *
  * Revision 2.5  90/11/05  14:37:33  rpd
  *     Added malloc_fork* code.
  *     [90/11/02            rwd]
- * 
+ *
  *     Add spin_lock_t.
  *     [90/10/31            rwd]
- * 
+ *
  * Revision 2.4  90/08/07  14:31:28  rpd
  *     Removed RCS keyword nonsense.
- * 
+ *
  * Revision 2.3  90/06/02  15:14:00  rpd
  *     Converted to new IPC.
  *     [90/03/20  20:56:57  rpd]
- * 
+ *
  * Revision 2.2  89/12/08  19:53:59  rwd
  *     Removed conditionals.
  *     [89/10/23            rwd]
- * 
+ *
  * Revision 2.1  89/08/03  17:09:46  rwd
  * Created.
- * 
+ *
  *
  * 13-Sep-88  Eric Cooper (ecc) at Carnegie Mellon University
  *     Changed realloc() to copy min(old size, new size) bytes.
@@ -167,7 +130,7 @@ typedef struct free_list {
        header_t head;          /* head of free list for this size */
 #ifdef DEBUG
        int in_use;             /* # mallocs - # frees */
-#endif DEBUG
+#endif /* DEBUG */
 } *free_list_t;
 
 /*
@@ -206,9 +169,7 @@ malloc_init (void)
 }
 
 static void
-more_memory(size, fl)
-       int size;
-       register free_list_t fl;
+more_memory(int size, free_list_t fl)
 {
        register int amount;
        register int n;
@@ -292,7 +253,7 @@ malloc(size)
 
 #ifdef DEBUG
        fl->in_use += 1;
-#endif DEBUG
+#endif /* DEBUG */
        spin_unlock(&fl->lock);
        /*
         * Store free list pointer in block header
@@ -324,7 +285,7 @@ free(base)
 
 #ifdef MCHECK
        assert (HEADER_CHECK (h) == CHECK_BUSY);
-#endif 
+#endif
 
        fl = HEADER_FREE (h);
        i = fl - malloc_free_list;
@@ -346,11 +307,11 @@ free(base)
        HEADER_NEXT (h) = fl->head;
 #ifdef MCHECK
        HEADER_CHECK (h) = CHECK_FREE;
-#endif 
+#endif
        fl->head = h;
 #ifdef DEBUG
        fl->in_use -= 1;
-#endif DEBUG
+#endif /* DEBUG */
        spin_unlock(&fl->lock);
        return;
 }
@@ -407,8 +368,8 @@ realloc(old_base, new_size)
         */
        new_base = malloc(new_size);
        if (new_base)
-         bcopy(old_base, new_base,
-               (int) (old_size < new_size ? old_size : new_size));
+         memcpy (new_base, old_base,
+                 (int) (old_size < new_size ? old_size : new_size));
 
        if (new_base || new_size == 0)
          /* Free OLD_BASE, but only if the malloc didn't fail.  */
@@ -446,22 +407,24 @@ print_malloc_free_list()
        fprintf(stderr, " all sizes %10d %10d %10d\n",
                total_used, total_free, total_used + total_free);
 }
-#endif DEBUG
+#endif /* DEBUG */
 
-static void malloc_fork_prepare()
+static void
+malloc_fork_prepare(void)
 /*
  * Prepare the malloc module for a fork by insuring that no thread is in a
  * malloc critical section.
  */
 {
     register int i;
-    
+
     for (i = 0; i < NBUCKETS; i++) {
        spin_lock(&malloc_free_list[i].lock);
     }
 }
 
-static void malloc_fork_parent()
+static void
+malloc_fork_parent(void)
 /*
  * Called in the parent process after a fork() to resume normal operation.
  */
@@ -473,7 +436,8 @@ static void malloc_fork_parent()
     }
 }
 
-static void malloc_fork_child()
+static void
+malloc_fork_child(void)
 /*
  * Called in the child process after a fork() to resume normal operation.
  */