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