From ffc607f8a4c1c6f1c63a7b61b54f185ada87a9a5 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Sun, 5 Nov 2006 18:54:52 +0000
Subject: 2006-11-05  Barry deFreese  <bddebian@comcast.net>

memcpy/memset cleanup.

	* include/string.h: New file.
	* include/mach/mig_support.h: Include `string.h'.
	[MACH_KERNEL] (bcopy): Remove extern declaration.
	[MACH_KERNEL] (memcpy): Remove macro.
	* device/cirbuf.c: Include `string.h'.
	(q_to_b, b_to_q): Replace bcopy() with memcpy() and bzero() with
	memset(), clean memcpy() and memset() invocation.
	* device/cons.c (cnputc): Likewise.
	* device/dev_pager.c (device_pager_data_request_done): Likewise.
	* device/ds_routines.c (device_write_get, ds_read_done): Likewise.
	* device/kmsg.c: Likewise.
	* device/net_io.c (net_filter, net_set_filter, net_getstat): Likewise.
	* i386/i386/fpu.c (fpu_set_state, fpu_get_state) fp_load)
	(fp_state_alloc): Likewise.
	* i386/i386/iopb.c (io_tss_init, i386_io_port_list): Likewise.
	* i386/i386/mp_desc.c (mp_desc_init): Likewise.
	* i386/i386/pcb.c (pcb_init, thread_setstatus)
	(thread_getstatus): Likewise.
	* i386/i386/phys.c (pmap_zero_page, pmap_copy_page, copy_to_phys)
	(copy_from_phys): Likewise.
	* i386/i386/trap.c (v86_assist): Likewise.
	* i386/i386/user_ldt.c (i386_set_ldt, i386_get_ldt): Likewise.
	* i386/i386at/immc.c (immc_cnputc): Likewise.
	* i386/i386at/kd_event.c (X_kdb_enter_init, X_kdb_exit_init): Likewise.
	* i386/intel/pmap.c (pmap_init, pmap_page_table_page_alloc)
	(pmap_create): Likewise.
	* ipc/ipc_entry.c (ipc_entry_grow_table): Likewise.
	* ipc/ipc_kmsg.c (ipc_kmsg_get_from_kernel)
	(ipc_kmsg_put_to_kernel): Likewise.
	* ipc/ipc_object.c (ipc_object_alloc, ipc_object_alloc_name): Likewise.
	* ipc/ipc_port.c (ipc_port_dngrow): Likewise.
	* ipc/ipc_space.c: Likewise.
	* ipc/mach_debug.c (mach_port_space_info)
	(mach_port_space_info): Likewise.
	* kern/act.c (act_create): Likewise.
	* kern/boot_script.c: Likewise.
	* kern/bootstrap.c: Likewise.
	* kern/eventcount.c (evc_init): Likewise.
	* kern/host.c (host_info, host_processor_sets): Likewise.
	* kern/lock.c (lock_init): Likewise.
	* kern/lock_mon.c (lock_info_clear): Likewise.
	* kern/mach_clock.c (mapable_time_init): Likewise.
	* kern/pc_sample.c (get_sampled_pcs): Likewise.
	* kern/processor.c (processor_set_things): Likewise.
	* kern/syscall_emulation.c (task_set_emulation_vector_internal)
	(task_get_emulation_vector, xxx_task_get_emulation_vector): Likewise.
	* kern/task.c (task_threads): Likewise.
	* kern/xpr.c (xprbootstrap): Likewise.
	* kern/zalloc.c (host_zone_info): Likewise.
	* vm/vm_debug.c (mach_vm_object_pages): Likewise.
	* vm/vm_kern.c (projected_buffer_allocate, copyinmap)
	(copyoutmap): Likewise.
	* vm/vm_object.c (vm_object_bootstrap): Likewise.
	* vm/vm_resident.c (vm_page_grab_contiguous_pages): Likewise.
---
 kern/act.c               |  4 +++-
 kern/boot_script.c       |  2 --
 kern/bootstrap.c         |  5 +++--
 kern/eventcount.c        |  4 +++-
 kern/host.c              | 16 +++++++++-------
 kern/lock.c              |  4 +++-
 kern/lock_mon.c          |  6 ++++--
 kern/mach_clock.c        |  4 +++-
 kern/pc_sample.c         | 20 +++++++++++---------
 kern/processor.c         |  4 +++-
 kern/syscall_emulation.c | 28 +++++++++++++++-------------
 kern/task.c              |  4 +++-
 kern/xpr.c               |  4 +++-
 kern/zalloc.c            |  6 ++++--
 14 files changed, 67 insertions(+), 44 deletions(-)

(limited to 'kern')

diff --git a/kern/act.c b/kern/act.c
index 0d0baea..a7a8ac9 100644
--- a/kern/act.c
+++ b/kern/act.c
@@ -26,6 +26,8 @@
 
 #ifdef MIGRATING_THREADS
 
+#include <string.h>
+
 #include <mach_ipc_compat.h> /* XXX */
 #include <mach/kern_return.h>
 #include <mach/alert.h>
@@ -113,7 +115,7 @@ kern_return_t act_create(task_t task, vm_offset_t user_stack,
 	/* XXX ipt_unlock(act_freelist); */
 	act->ipt_next = 0;
 #endif
-	bzero(act, sizeof(*act)); /*XXX shouldn't be needed */
+	memset(act, 0, sizeof(*act)); /*XXX shouldn't be needed */
 
 #ifdef DEBUG
 	act->lower = act->higher = 0;
diff --git a/kern/boot_script.c b/kern/boot_script.c
index d031752..9349126 100644
--- a/kern/boot_script.c
+++ b/kern/boot_script.c
@@ -3,9 +3,7 @@
 /* Written by Shantanu Goel (goel@cs.columbia.edu).  */
 
 #include <mach/mach_types.h>
-#if !KERNEL || OSKIT_MACH
 #include <string.h>
-#endif
 #include "boot_script.h"
 
 
diff --git a/kern/bootstrap.c b/kern/bootstrap.c
index 19e25ea..3613e38 100644
--- a/kern/bootstrap.c
+++ b/kern/bootstrap.c
@@ -30,6 +30,9 @@
  * Bootstrap the various built-in servers.
  */
 
+#include <alloca.h>
+#include <string.h>
+
 #include <mach/port.h>
 #include <mach/message.h>
 #include <machine/vm_param.h>
@@ -40,7 +43,6 @@
 #include <kern/lock.h>
 #include <vm/vm_kern.h>
 #include <device/device_port.h>
-#include <alloca.h>
 
 #if	MACH_KDB
 #include <machine/db_machdep.h>
@@ -49,7 +51,6 @@
 
 #if OSKIT_MACH
 #include <stddef.h>
-#include <string.h>
 #include <oskit/machine/base_multiboot.h>
 #include <oskit/exec/exec.h>
 #include <oskit/c/stdio.h>
diff --git a/kern/eventcount.c b/kern/eventcount.c
index 1418c82..b562f1a 100644
--- a/kern/eventcount.c
+++ b/kern/eventcount.c
@@ -35,6 +35,8 @@
  *
  */
 
+#include <string.h>
+
 #include <mach/machine.h>
 #include <kern/ast.h>
 #include "cpu_number.h"
@@ -67,7 +69,7 @@ evc_init(evc_t	ev)
 {
 	int i;
 
-	bzero((char*)ev, sizeof(*ev));
+	memset(ev, 0, sizeof(*ev));
 
 	/* keep track of who is who */
 	for (i = 0; i < MAX_EVCS; i++)
diff --git a/kern/host.c b/kern/host.c
index a757266..6e98c2c 100644
--- a/kern/host.c
+++ b/kern/host.c
@@ -29,6 +29,8 @@
  *	Non-ipc host functions.
  */
 
+#include <string.h>
+
 #include <kern/assert.h>
 #include <kern/kalloc.h>
 #include <kern/host.h>
@@ -182,12 +184,12 @@ kern_return_t	host_info(
 
 		load_info = (host_load_info_t) info;
 
-		bcopy((char *) avenrun,
-		      (char *) load_info->avenrun,
-		      sizeof avenrun);
-		bcopy((char *) mach_factor,
-		      (char *) load_info->mach_factor,
-		      sizeof mach_factor);
+		memcpy(load_info->avenrun,
+		       avenrun,
+		       sizeof avenrun);
+		memcpy(load_info->mach_factor,
+		       mach_factor,
+		       sizeof mach_factor);
 
 		*count = HOST_LOAD_INFO_COUNT;
 		return KERN_SUCCESS;
@@ -302,7 +304,7 @@ host_processor_sets(
 			return KERN_RESOURCE_SHORTAGE;
 		}
 
-		bcopy((char *) addr, (char *) newaddr, size_needed);
+		memcpy((char *) newaddr, (char *) addr, size_needed);
 		kfree(addr, size);
 		psets = (processor_set_t *) newaddr;
 	}
diff --git a/kern/lock.c b/kern/lock.c
index 15bc988..ba0f0c2 100644
--- a/kern/lock.c
+++ b/kern/lock.c
@@ -34,6 +34,8 @@
  *	Locking primitives implementation
  */
 
+#include <string.h>
+
 #include <kern/lock.h>
 #include <kern/thread.h>
 #include <kern/sched_prim.h>
@@ -219,7 +221,7 @@ void lock_init(
 	lock_t		l,
 	boolean_t	can_sleep)
 {
-	bzero((char *)l, sizeof(lock_data_t));
+	memset(l, 0, sizeof(lock_data_t));
 	simple_lock_init(&l->interlock);
 	l->want_write = FALSE;
 	l->want_upgrade = FALSE;
diff --git a/kern/lock_mon.c b/kern/lock_mon.c
index 1d92ebf..a9a3989 100644
--- a/kern/lock_mon.c
+++ b/kern/lock_mon.c
@@ -39,6 +39,8 @@
  */
 
 #include <sys/types.h>
+#include <string.h>
+
 #include <mach/machine/vm_types.h>
 #include <mach/boolean.h>
 #include <kern/thread.h>
@@ -263,10 +265,10 @@ lock_info_clear()
 	for (bucket = 0; bucket < LOCK_INFO_HASH_COUNT; bucket++) {
 		li = &lock_info[bucket].info[0];
 		for (i= 0; i< LOCK_INFO_PER_BUCKET; i++, li++) {
-			bzero(li, sizeof(struct lock_info));
+			memset(li, 0, sizeof(struct lock_info));
 		}
 	}
-	bzero(&default_lock_info, sizeof(struct lock_info));
+	memset(&default_lock_info, 0, sizeof(struct lock_info));
 }
 
 print_lock_info(li)
diff --git a/kern/mach_clock.c b/kern/mach_clock.c
index 71cd583..d67897b 100644
--- a/kern/mach_clock.c
+++ b/kern/mach_clock.c
@@ -34,6 +34,8 @@
  *	Clock primitives.
  */
 
+#include <string.h>
+
 #include <mach/boolean.h>
 #include <mach/machine.h>
 #include <mach/time_value.h>
@@ -491,7 +493,7 @@ void mapable_time_init()
 	if (kmem_alloc_wired(kernel_map, (vm_offset_t *) &mtime, PAGE_SIZE)
 						!= KERN_SUCCESS)
 		panic("mapable_time_init");
-	bzero((char *)mtime, PAGE_SIZE);
+	memset(mtime, 0, PAGE_SIZE);
 	update_mapped_time(&time);
 }
 
diff --git a/kern/pc_sample.c b/kern/pc_sample.c
index 87c7a6c..b414941 100644
--- a/kern/pc_sample.c
+++ b/kern/pc_sample.c
@@ -24,6 +24,8 @@
  * the rights to redistribute these changes.
  */
 
+#include <string.h>
+
 #include <mach/mach_types.h>	/* vm_address_t */
 #include <mach/std_types.h>	/* pointer_t */
 #include <mach/pc_sample.h>
@@ -174,19 +176,19 @@ get_sampled_pcs(
 	     * Simple case: no wraparound.
 	     * Copy from seqidx1 to seqidx2.
 	     */
-	    bcopy((sampled_pc_array_t)cp->buffer + seqidx1 + 1,
-		  sampled_pcs_out,
-		  nsamples * sizeof(sampled_pc_t));
+	    memcpy(sampled_pcs_out,
+		   (sampled_pc_array_t)cp->buffer + seqidx1 + 1,
+		   nsamples * sizeof(sampled_pc_t));
 	} else {
 	    /* seqidx1 > seqidx2 -- Handle wraparound. */
 
-	    bcopy((sampled_pc_array_t)cp->buffer + seqidx1 + 1,
-		  sampled_pcs_out,
-		  (MAX_PC_SAMPLES - seqidx1 - 1) * sizeof(sampled_pc_t));
+	    memcpy(sampled_pcs_out,
+		   (sampled_pc_array_t)cp->buffer + seqidx1 + 1,
+		   (MAX_PC_SAMPLES - seqidx1 - 1) * sizeof(sampled_pc_t));
 
-	    bcopy((sampled_pc_array_t)cp->buffer,
-		  sampled_pcs_out + (MAX_PC_SAMPLES - seqidx1 - 1),
-		  (seqidx2 + 1) * sizeof(sampled_pc_t));
+	    memcpy(sampled_pcs_out + (MAX_PC_SAMPLES - seqidx1 - 1),
+		   (sampled_pc_array_t)cp->buffer,
+		   (seqidx2 + 1) * sizeof(sampled_pc_t));
 	}
     } else {
 	/*  could either be zero because of overflow, or because
diff --git a/kern/processor.c b/kern/processor.c
index a6e65c8..df9cb2e 100644
--- a/kern/processor.c
+++ b/kern/processor.c
@@ -27,6 +27,8 @@
  *	processor.c: processor and processor_set manipulation routines.
  */
 
+#include <string.h>
+
 #include <mach/boolean.h>
 #include <mach/policy.h>
 #include <mach/processor_info.h>
@@ -971,7 +973,7 @@ processor_set_things(
 				return KERN_RESOURCE_SHORTAGE;
 			}
 
-			bcopy((char *) addr, (char *) newaddr, size_needed);
+			memcpy((void *) newaddr, (void *) addr, size_needed);
 			kfree(addr, size);
 			addr = newaddr;
 		}
diff --git a/kern/syscall_emulation.c b/kern/syscall_emulation.c
index 5443a33..06781d5 100644
--- a/kern/syscall_emulation.c
+++ b/kern/syscall_emulation.c
@@ -24,6 +24,8 @@
  * the rights to redistribute these changes.
  */
 
+#include <string.h>
+
 #include <mach/error.h>
 #include <mach/vm_param.h>
 #include <kern/syscall_emulation.h>
@@ -198,9 +200,9 @@ task_set_emulation_vector_internal(task, vector_start, emulation_vector,
 		     * Copy the entries to the new emulation vector,
 		     * deallocate the current one, and use the new one.
 		     */
-		    bcopy((char *)&cur_eml->disp_vector[0],
-			  (char *)&new_eml->disp_vector[cur_start-new_start],
-			  cur_eml->disp_count * sizeof(vm_offset_t));
+		    memcpy(&new_eml->disp_vector[cur_start-new_start],
+			   &cur_eml->disp_vector[0],
+			   cur_eml->disp_count * sizeof(vm_offset_t));
 
 		    if (--cur_eml->ref_count == 0)
 			old_eml = cur_eml;	/* discard old vector */
@@ -258,7 +260,7 @@ task_set_emulation_vector_internal(task, vector_start, emulation_vector,
 	    new_size = count_to_size(new_end - new_start);
 	    new_eml = (eml_dispatch_t) kalloc(new_size);
 
-	    bzero((char *)new_eml, new_size);
+	    memset(new_eml, 0, new_size);
 	    simple_lock_init(&new_eml->lock);
 	    new_eml->ref_count = 1;
 	    new_eml->disp_min   = new_start;
@@ -271,9 +273,9 @@ task_set_emulation_vector_internal(task, vector_start, emulation_vector,
 	 * We have the emulation vector.
 	 * Install the new emulation entries.
 	 */
-	bcopy((char *)&emulation_vector[0],
-	      (char *)&cur_eml->disp_vector[vector_start - cur_eml->disp_min],
-	      emulation_vector_count * sizeof(vm_offset_t));
+	memcpy(&cur_eml->disp_vector[vector_start - cur_eml->disp_min],
+	       &emulation_vector[0],
+	       emulation_vector_count * sizeof(vm_offset_t));
 
 	task_unlock(task);
 
@@ -417,9 +419,9 @@ task_get_emulation_vector(task, vector_start, emulation_vector,
 	 */
 	*vector_start = eml->disp_min;
 	*emulation_vector_count = eml->disp_count;
-	bcopy((char *)eml->disp_vector,
-	      (char *)addr,
-	      vector_size);
+	memcpy((void *)addr,
+	       eml->disp_vector,
+	       vector_size);
 
 	/*
 	 * Unlock the task and free any memory we did not need
@@ -444,7 +446,7 @@ task_get_emulation_vector(task, vector_start, emulation_vector,
 	 */
 	size_left = size_used - vector_size;
 	if (size_left > 0)
-	    bzero((char *)addr + vector_size, size_left);
+	    memset((char *)addr + vector_size, 0, size_left);
 
 	/*
 	 * Make memory into copyin form - this unwires it.
@@ -495,8 +497,8 @@ xxx_task_get_emulation_vector(task, vector_start, emulation_vector,
 
 	*vector_start = eml->disp_min;
 	*emulation_vector_count = eml->disp_count;
-	bcopy((char *)eml->disp_vector, (char *)emulation_vector,
-	      *emulation_vector_count * sizeof(vm_offset_t));
+	memcpy(emulation_vector, eml->disp_vector,
+	       *emulation_vector_count * sizeof(vm_offset_t));
 	simple_unlock(&eml->lock);
 
 	task_unlock(task);
diff --git a/kern/task.c b/kern/task.c
index c7633c1..f620bdf 100644
--- a/kern/task.c
+++ b/kern/task.c
@@ -31,6 +31,8 @@
  *	Task management primitives implementation.
  */
 
+#include <string.h>
+
 #include <mach/machine/vm_types.h>
 #include <mach/vm_param.h>
 #include <mach/task_info.h>
@@ -625,7 +627,7 @@ kern_return_t task_threads(
 				return KERN_RESOURCE_SHORTAGE;
 			}
 
-			bcopy((char *) addr, (char *) newaddr, size_needed);
+			memcpy((void *) newaddr, (void *) addr, size_needed);
 			kfree(addr, size);
 			threads = (thread_t *) newaddr;
 		}
diff --git a/kern/xpr.c b/kern/xpr.c
index e3e5377..b5f6e71 100644
--- a/kern/xpr.c
+++ b/kern/xpr.c
@@ -27,6 +27,8 @@
 /*
  * xpr silent tracing circular buffer.
  */
+#include <string.h>
+
 #include <kern/xpr.h>
 #include <kern/lock.h>
 #include "cpu_number.h"
@@ -112,7 +114,7 @@ void xprbootstrap()
 		 *	the previous buffer contents.
 		 */
 
-		bzero((char *) addr, size);
+		memset((char *) addr, 0, size);
 	}
 
 	xprbase = (struct xprbuf *) addr;
diff --git a/kern/zalloc.c b/kern/zalloc.c
index 18239be..48fbb32 100644
--- a/kern/zalloc.c
+++ b/kern/zalloc.c
@@ -34,6 +34,8 @@
  *	data blocks for which quick allocation/deallocation is possible.
  */
 
+#include <string.h>
+
 #include <kern/macro_help.h>
 #include <kern/sched.h>
 #include <kern/time_out.h>
@@ -942,7 +944,7 @@ kern_return_t host_zone_info(host, namesp, namesCntp, infop, infoCntp)
 		used = max_zones * sizeof *names;
 
 		if (used != names_size)
-			bzero((char *) (names_addr + used), names_size - used);
+			memset((char *) (names_addr + used), 0, names_size - used);
 
 		kr = vm_map_copyin(ipc_kernel_map, names_addr, names_size,
 				   TRUE, &copy);
@@ -959,7 +961,7 @@ kern_return_t host_zone_info(host, namesp, namesCntp, infop, infoCntp)
 		used = max_zones * sizeof *info;
 
 		if (used != info_size)
-			bzero((char *) (info_addr + used), info_size - used);
+			memset((char *) (info_addr + used), 0, info_size - used);
 
 		kr = vm_map_copyin(ipc_kernel_map, info_addr, info_size,
 				   TRUE, &copy);
-- 
cgit v1.2.3