backout 5876 sys/regset.h pollutes name space
[unleashed.git] / usr / src / uts / intel / ia32 / os / copy_subr.c
blob0df1086260210b90f9a9aa892f830d3d81553163
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Miscellaneous C routines for copying data around without
31 * descending into assembler. Compilers are pretty good at
32 * scheduling instructions, and humans are pretty hopeless at
33 * writing correct assembler.
36 #include <sys/types.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/param.h>
42 * copyinstr_noerr and copyoutstr_noerr can be implemented completely
43 * in C on machines with shared user and kernel context.
45 static int
46 copystr_nofault(const char *src, char *dst, size_t maxlength,
47 size_t *lencopied)
49 int error = 0;
50 size_t leftover;
52 if ((leftover = maxlength) == 0)
53 error = ENAMETOOLONG;
54 else
55 do {
56 leftover--;
57 if ((*dst++ = *src++) == '\0')
58 break;
59 if (leftover == 0) {
60 error = ENAMETOOLONG;
61 break;
63 /*CONSTCOND*/
64 } while (1);
66 if (lencopied)
67 *lencopied = maxlength - leftover;
68 return (error);
72 int
73 copyinstr_noerr(const char *uaddr, char *kaddr, size_t maxlength,
74 size_t *lencopied)
76 char *ua = (char *)uaddr;
78 ASSERT((uintptr_t)kaddr > kernelbase);
80 if ((uintptr_t)ua > kernelbase) {
82 * force fault at kernelbase
84 ua = (char *)kernelbase;
86 return (copystr_nofault(ua, kaddr, maxlength, lencopied));
89 int
90 copyoutstr_noerr(const char *kaddr, char *uaddr, size_t maxlength,
91 size_t *lencopied)
93 char *ua = (char *)uaddr;
95 ASSERT((uintptr_t)kaddr > kernelbase);
97 if ((uintptr_t)ua > kernelbase) {
99 * force fault at kernelbase
101 ua = (char *)kernelbase;
103 return (copystr_nofault(kaddr, ua, maxlength, lencopied));