]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | /* |
2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. | |
3 | */ | |
4 | /* | |
5 | * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved | |
6 | * Copyright (c) 1993 NeXT Computer, Inc. | |
7 | * | |
8 | */ | |
9 | ||
cb323159 | 10 | #include <sys/cdefs.h> |
5ba3f43e A |
11 | #include <sys/param.h> |
12 | #include <sys/systm.h> | |
13 | #include <sys/ioctl.h> | |
14 | #include <sys/tty.h> | |
15 | #include <sys/conf.h> | |
16 | #include <sys/kauth.h> | |
17 | #include <sys/ucred.h> | |
18 | #include <sys/proc_internal.h> | |
c3c9b80d | 19 | #include <sys/sysproto.h> |
5ba3f43e A |
20 | #include <sys/user.h> |
21 | #include <kern/task.h> | |
22 | #include <kern/thread.h> | |
23 | #include <vm/vm_map.h> | |
24 | ||
c3c9b80d | 25 | |
5ba3f43e A |
26 | /* |
27 | * copy a null terminated string from the kernel address space into the user | |
28 | * address space. - if the user is denied write access, return EFAULT. - if | |
29 | * the end of string isn't found before maxlen bytes are copied, return | |
30 | * ENAMETOOLONG, indicating an incomplete copy. - otherwise, return 0, | |
31 | * indicating success. the number of bytes copied is always returned in | |
32 | * lencopied. | |
33 | */ | |
34 | int | |
35 | copyoutstr(const void *from, user_addr_t to, size_t maxlen, size_t * lencopied) | |
36 | { | |
37 | size_t slen; | |
38 | size_t len; | |
cb323159 A |
39 | int error = copyoutstr_prevalidate(from, to, maxlen); |
40 | ||
41 | if (__improbable(error)) { | |
42 | return error; | |
43 | } | |
5ba3f43e A |
44 | |
45 | slen = strlen(from) + 1; | |
0a7de745 | 46 | if (slen > maxlen) { |
5ba3f43e | 47 | error = ENAMETOOLONG; |
0a7de745 | 48 | } |
5ba3f43e | 49 | |
f427ee49 | 50 | len = MIN(maxlen, slen); |
0a7de745 | 51 | if (copyout(from, to, len)) { |
5ba3f43e | 52 | error = EFAULT; |
0a7de745 | 53 | } |
5ba3f43e A |
54 | *lencopied = len; |
55 | ||
56 | return error; | |
57 | } | |
58 | ||
59 | ||
60 | /* | |
61 | * copy a null terminated string from one point to another in the kernel | |
62 | * address space. - no access checks are performed. - if the end of string | |
63 | * isn't found before maxlen bytes are copied, return ENAMETOOLONG, | |
64 | * indicating an incomplete copy. - otherwise, return 0, indicating success. | |
65 | * the number of bytes copied is always returned in lencopied. | |
66 | */ | |
67 | /* from ppc/fault_copy.c -Titan1T4 VERSION */ | |
68 | int | |
69 | copystr(const void *vfrom, void *vto, size_t maxlen, size_t * lencopied) | |
70 | { | |
71 | size_t l; | |
72 | char const *from = (char const *) vfrom; | |
73 | char *to = (char *) vto; | |
74 | ||
75 | for (l = 0; l < maxlen; l++) { | |
76 | if ((*to++ = *from++) == '\0') { | |
0a7de745 | 77 | if (lencopied) { |
5ba3f43e | 78 | *lencopied = l + 1; |
0a7de745 | 79 | } |
5ba3f43e A |
80 | return 0; |
81 | } | |
82 | } | |
0a7de745 | 83 | if (lencopied) { |
5ba3f43e | 84 | *lencopied = maxlen; |
0a7de745 | 85 | } |
5ba3f43e A |
86 | return ENAMETOOLONG; |
87 | } | |
88 | ||
89 | int | |
90 | copywithin(void *src, void *dst, size_t count) | |
91 | { | |
92 | bcopy(src, dst, count); | |
93 | return 0; | |
94 | } | |
c3c9b80d | 95 |