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