/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident	"$Header: shadow.c 1.2 90/07/16 $"

/*
 * shadow.c--support routines for managing shadow data structures across
 * major process events.
 *
 * It is very desirable to maintain both the size and offset of various
 * kernel data structures such as the user and proc structures.  One way to
 * do this is to attach new chunks of memory via pointers from the structure,
 * instead of just adding the whole thing onto the structure.  This works
 * well, but requires special support when a process forks (to duplicate or
 * share the resource) or exits (to free it or decrement its use count).
 * This source file provides a single place to add all such code.
 */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/timer.h>
#include <sys/signal.h>
#include <sys/procstats.h>
#include <sys/proc.h>
#include <sys/user.h>

extern caddr_t kmem_alloc();

/*
 * A process is fork()ing--duplicate resources appropriately.  Both processes
 * may be assumed to be swapped in and locked.
 */
shadow_fork(old, new)
	struct proc *old, *new;
{
	/* Duplicate FPA emulation save area if present */
	if (old->p_uarea->u_fpaesave) {
		new->p_uarea->u_fpaesave =
			(struct fpaesave *)kmem_alloc(sizeof(struct fpaesave));
		bcopy((caddr_t)old->p_uarea->u_fpaesave,
			(caddr_t)new->p_uarea->u_fpaesave,
			sizeof(struct fpaesave));
	}
}

/*
 * A process is exit()ing--free resources
 */
shadow_exit(p)
	struct proc *p;
{
	/* Free FPA emulation save area if present */
	if (p->p_uarea->u_fpaesave) {
		kmem_free((caddr_t)p->p_uarea->u_fpaesave,
			sizeof(struct fpaesave));
		p->p_uarea->u_fpaesave = NULL;
	}
}
