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
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]
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.
46 copystr_nofault(const char *src
, char *dst
, size_t maxlength
,
52 if ((leftover
= maxlength
) == 0)
57 if ((*dst
++ = *src
++) == '\0')
67 *lencopied
= maxlength
- leftover
;
73 copyinstr_noerr(const char *uaddr
, char *kaddr
, size_t maxlength
,
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
));
90 copyoutstr_noerr(const char *kaddr
, char *uaddr
, size_t maxlength
,
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
));