1 /*
2  * Copyright (c) 1994 William F. Jolitz.
3  * 386BSD Copyright Restrictions Apply. All Other Rights Reserved.
4  *
5  * $Id: copyout_.h,v 1.1 95/01/21 16:03:46 bill Exp Locker: bill $
6  * Copy a constant length segment from the kernel to a user process.
7  */
8 
9 __INLINE int
copyout_(struct proc * p,const void * from,void * to,const u_int size)10 copyout_(struct proc *p, const void *from, void *to, const u_int size)
11 {
12 	int rv;
13 
14 	/* is this in the range of a valid user process address? */
15 	if ((unsigned)to > ENDUSERMEM || (unsigned)to + size > ENDUSERMEM)
16 		return(EFAULT);
17 
18 	/* set fault vector */
19 	asm volatile ("movl $4f, %0" : "=m" (p->p_md.md_onfault));
20 
21 	/* copy quantity */
22 	if (size == 1)
23 		*(char *) to = *(char *) from;
24 	else if (size == 2)
25 		*(short *) to = *(short *) from;
26 	else if (size == 4)
27 		*(long *) to = *(long *) from;
28 
29 	/* catch the possible fault */
30 	asm volatile ("\
31 		xorl %0, %0 ;		\
32 		jmp 5f ;		\
33 	4:	movl %1, %0 ;		\
34 	5:				"
35 		: "=r" (rv)
36 		: "i" (EFAULT));
37 
38 	/* clear the fault vector and return */
39 	p->p_md.md_onfault = 0;
40 	return (rv);
41 }
42