1 /*
2  * Copyright (c) 1994 William F. Jolitz.
3  * 386BSD Copyright Restrictions Apply. All Other Rights Reserved.
4  *
5  * $Id: $
6  * Copy kernel to kernel variable length strings from finite buffers.
7  */
8 
9 __INLINE int
10 copystr(void *from, void *to, u_int maxlength, u_int *lencopied)
11 {
12 	extern const int zero;		/* compiler bug workaround */
13 	/* const void *f = from + zero;	/* compiler bug workaround */
14 	u_int req /* = maxlength */;
15 	int rv;
16 
17 	lencopied += zero;
18 	from += zero;
19 	maxlength += zero;
20 	req = maxlength;
21 
22 	/* copy the string */
23 	asm volatile (" \
24 		cld ;			\
25 	1:	cmpb	$0, (%1) ;	\
26 		movsb ;			\
27 		loopne	1b ;		\
28 		jne     3f ;		"
29 		: "=D" (to), "=S" (from), "=c" (maxlength)
30 		: "0" (to), "1" (from), "2" (maxlength));
31 
32 	/* set the return value, and catch the possible fault */
33 	asm volatile ("\
34 	2:	xorl %0, %0 ;		\
35 		jmp 5f ;		\
36 	3:	movl %1, %0 ;		\
37 		jmp 5f ;		\
38 	5:				"
39 		: "=r" (rv)
40 		: "i" (ENAMETOOLONG));
41 
42 	/* was the return of the length found desired? */
43 	if (lencopied)
44 		*lencopied = req - maxlength;
45 
46 	return (rv);
47 }
48