summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2013-06-11 13:00:32 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2013-06-11 13:00:32 +0000
commit06d0e35d57b12324d6f7c5ef5abe894ab2d462b7 (patch)
treefbecef27713e00892abe9cb490d9ecfaf5ab8a79
parent812fafd61031a5a53fa06b12a4c88ac019128251 (diff)
convert some easy bcopy to memcpy and clean up fdexpand a bit.
ok kettenis
-rw-r--r--sys/kern/kern_descrip.c44
-rw-r--r--sys/kern/kern_fork.c20
2 files changed, 33 insertions, 31 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 26ab25644bb..50eda54ad14 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.100 2013/06/05 01:26:00 guenther Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.101 2013/06/11 13:00:31 tedu Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -752,7 +752,8 @@ void
fdexpand(struct proc *p)
{
struct filedesc *fdp = p->p_fd;
- int nfiles, i;
+ int nfiles;
+ size_t copylen;
struct file **newofile;
char *newofileflags;
u_int *newhimap, *newlomap;
@@ -774,12 +775,13 @@ fdexpand(struct proc *p)
* Copy the existing ofile and ofileflags arrays
* and zero the new portion of each array.
*/
- bcopy(fdp->fd_ofiles, newofile,
- (i = sizeof(struct file *) * fdp->fd_nfiles));
- bzero((char *)newofile + i, nfiles * sizeof(struct file *) - i);
- bcopy(fdp->fd_ofileflags, newofileflags,
- (i = sizeof(char) * fdp->fd_nfiles));
- bzero(newofileflags + i, nfiles * sizeof(char) - i);
+ copylen = sizeof(struct file *) * fdp->fd_nfiles;
+ memcpy(newofile, fdp->fd_ofiles, copylen);
+ memset((char *)newofile + copylen, 0,
+ nfiles * sizeof(struct file *) - copylen);
+ copylen = sizeof(char) * fdp->fd_nfiles;
+ memcpy(newofileflags, fdp->fd_ofileflags, copylen);
+ memset(newofileflags + copylen, 0, nfiles * sizeof(char) - copylen);
if (fdp->fd_nfiles > NDFILE)
free(fdp->fd_ofiles, M_FILEDESC);
@@ -790,15 +792,15 @@ fdexpand(struct proc *p)
newlomap = malloc(NDLOSLOTS(nfiles) * sizeof(u_int),
M_FILEDESC, M_WAITOK);
- bcopy(fdp->fd_himap, newhimap,
- (i = NDHISLOTS(fdp->fd_nfiles) * sizeof(u_int)));
- bzero((char *)newhimap + i,
- NDHISLOTS(nfiles) * sizeof(u_int) - i);
+ copylen = NDHISLOTS(fdp->fd_nfiles) * sizeof(u_int);
+ memcpy(newhimap, fdp->fd_himap, copylen);
+ memset((char *)newhimap + copylen, 0,
+ NDHISLOTS(nfiles) * sizeof(u_int) - copylen);
- bcopy(fdp->fd_lomap, newlomap,
- (i = NDLOSLOTS(fdp->fd_nfiles) * sizeof(u_int)));
- bzero((char *)newlomap + i,
- NDLOSLOTS(nfiles) * sizeof(u_int) - i);
+ copylen = NDLOSLOTS(fdp->fd_nfiles) * sizeof(u_int);
+ memcpy(newlomap, fdp->fd_lomap, copylen);
+ memset((char *)newlomap + copylen, 0,
+ NDLOSLOTS(nfiles) * sizeof(u_int) - copylen);
if (NDHISLOTS(fdp->fd_nfiles) > NDHISLOTS(NDFILE)) {
free(fdp->fd_himap, M_FILEDESC);
@@ -921,7 +923,7 @@ fdcopy(struct proc *p)
fdplock(fdp);
newfdp = pool_get(&fdesc_pool, PR_WAITOK);
- bcopy(fdp, newfdp, sizeof(struct filedesc));
+ memcpy(newfdp, fdp, sizeof(struct filedesc));
if (newfdp->fd_cdir)
vref(newfdp->fd_cdir);
if (newfdp->fd_rdir)
@@ -964,10 +966,10 @@ fdcopy(struct proc *p)
M_FILEDESC, M_WAITOK);
}
newfdp->fd_nfiles = i;
- bcopy(fdp->fd_ofiles, newfdp->fd_ofiles, i * sizeof(struct file **));
- bcopy(fdp->fd_ofileflags, newfdp->fd_ofileflags, i * sizeof(char));
- bcopy(fdp->fd_himap, newfdp->fd_himap, NDHISLOTS(i) * sizeof(u_int));
- bcopy(fdp->fd_lomap, newfdp->fd_lomap, NDLOSLOTS(i) * sizeof(u_int));
+ memcpy(newfdp->fd_ofiles, fdp->fd_ofiles, i * sizeof(struct file **));
+ memcpy(newfdp->fd_ofileflags, fdp->fd_ofileflags, i * sizeof(char));
+ memcpy(newfdp->fd_himap, fdp->fd_himap, NDHISLOTS(i) * sizeof(u_int));
+ memcpy(newfdp->fd_lomap, fdp->fd_lomap, NDLOSLOTS(i) * sizeof(u_int));
fdpunlock(fdp);
fdplock(newfdp);
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 4eeb65c83ed..48fea3532fc 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.151 2013/06/06 13:09:37 haesbaert Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.152 2013/06/11 13:00:31 tedu Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -196,14 +196,14 @@ process_new(struct proc *p, struct process *parent)
* Start by zeroing the section of proc that is zero-initialized,
* then copy the section that is copied directly from the parent.
*/
- bzero(&pr->ps_startzero,
- (unsigned) ((caddr_t)&pr->ps_endzero - (caddr_t)&pr->ps_startzero));
- bcopy(&parent->ps_startcopy, &pr->ps_startcopy,
- (unsigned) ((caddr_t)&pr->ps_endcopy - (caddr_t)&pr->ps_startcopy));
+ memset(&pr->ps_startzero, 0,
+ (caddr_t)&pr->ps_endzero - (caddr_t)&pr->ps_startzero);
+ memcpy(&pr->ps_startcopy, &parent->ps_startcopy,
+ (caddr_t)&pr->ps_endcopy - (caddr_t)&pr->ps_startcopy);
/* post-copy fixups */
pr->ps_cred = pool_get(&pcred_pool, PR_WAITOK);
- bcopy(parent->ps_cred, pr->ps_cred, sizeof(*pr->ps_cred));
+ memcpy(pr->ps_cred, parent->ps_cred, sizeof(*pr->ps_cred));
crhold(parent->ps_cred->pc_ucred);
pr->ps_limit->p_refcnt++;
@@ -333,10 +333,10 @@ fork1(struct proc *curp, int exitsig, int flags, void *stack, pid_t *tidptr,
* Start by zeroing the section of proc that is zero-initialized,
* then copy the section that is copied directly from the parent.
*/
- bzero(&p->p_startzero,
- (unsigned) ((caddr_t)&p->p_endzero - (caddr_t)&p->p_startzero));
- bcopy(&curp->p_startcopy, &p->p_startcopy,
- (unsigned) ((caddr_t)&p->p_endcopy - (caddr_t)&p->p_startcopy));
+ memset(&p->p_startzero, 0,
+ (caddr_t)&p->p_endzero - (caddr_t)&p->p_startzero);
+ memcpy(&p->p_startcopy, &curp->p_startcopy,
+ (caddr_t)&p->p_endcopy - (caddr_t)&p->p_startcopy);
/*
* Initialize the timeouts.