| @@ -1,122 +1,124 @@ | | | @@ -1,122 +1,124 @@ |
1 | /* $NetBSD: rumpcopy.c,v 1.6 2010/10/27 20:44:49 pooka Exp $ */ | | 1 | /* $NetBSD: rumpcopy.c,v 1.7 2010/10/29 15:27:50 pooka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2009 Antti Kantee. All Rights Reserved. | | 4 | * Copyright (c) 2009 Antti Kantee. All Rights Reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS | | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 | * SUCH DAMAGE. | | 25 | * SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: rumpcopy.c,v 1.6 2010/10/27 20:44:49 pooka Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: rumpcopy.c,v 1.7 2010/10/29 15:27:50 pooka Exp $"); |
30 | | | 30 | |
31 | #include <sys/param.h> | | 31 | #include <sys/param.h> |
32 | #include <sys/lwp.h> | | 32 | #include <sys/lwp.h> |
33 | #include <sys/systm.h> | | 33 | #include <sys/systm.h> |
34 | | | 34 | |
35 | #include <rump/rump.h> | | 35 | #include <rump/rump.h> |
36 | | | 36 | |
37 | #include "rump_private.h" | | 37 | #include "rump_private.h" |
38 | | | 38 | |
39 | int | | 39 | int |
40 | copyin(const void *uaddr, void *kaddr, size_t len) | | 40 | copyin(const void *uaddr, void *kaddr, size_t len) |
41 | { | | 41 | { |
| | | 42 | |
42 | if (__predict_false(uaddr == NULL && len)) { | | 43 | if (__predict_false(uaddr == NULL && len)) { |
43 | return EFAULT; | | 44 | return EFAULT; |
44 | } | | 45 | } |
45 | | | 46 | |
46 | if (curproc->p_vmspace == &vmspace0) { | | 47 | if (curproc->p_vmspace == &vmspace0) { |
47 | memcpy(kaddr, uaddr, len); | | 48 | memcpy(kaddr, uaddr, len); |
48 | } else { | | 49 | } else { |
49 | rumpuser_sp_copyin(uaddr, kaddr, len); | | 50 | rumpuser_sp_copyin(uaddr, kaddr, len); |
50 | } | | 51 | } |
51 | return 0; | | 52 | return 0; |
52 | } | | 53 | } |
53 | | | 54 | |
54 | int | | 55 | int |
55 | copyout(const void *kaddr, void *uaddr, size_t len) | | 56 | copyout(const void *kaddr, void *uaddr, size_t len) |
56 | { | | 57 | { |
| | | 58 | |
57 | if (__predict_false(uaddr == NULL && len)) { | | 59 | if (__predict_false(uaddr == NULL && len)) { |
58 | return EFAULT; | | 60 | return EFAULT; |
59 | } | | 61 | } |
60 | | | 62 | |
61 | if (curproc->p_vmspace == &vmspace0) { | | 63 | if (curproc->p_vmspace == &vmspace0) { |
62 | memcpy(uaddr, kaddr, len); | | 64 | memcpy(uaddr, kaddr, len); |
63 | } else { | | 65 | } else { |
64 | rumpuser_sp_copyout(kaddr, uaddr, len); | | 66 | rumpuser_sp_copyout(kaddr, uaddr, len); |
65 | } | | 67 | } |
66 | return 0; | | 68 | return 0; |
67 | } | | 69 | } |
68 | | | 70 | |
69 | int | | 71 | int |
70 | subyte(void *uaddr, int byte) | | 72 | subyte(void *uaddr, int byte) |
71 | { | | 73 | { |
72 | | | 74 | |
73 | if (curproc->p_vmspace == &vmspace0) | | 75 | if (curproc->p_vmspace == &vmspace0) |
74 | *(char *)uaddr = byte; | | 76 | *(char *)uaddr = byte; |
75 | else | | 77 | else |
76 | rumpuser_sp_copyout(&byte, uaddr, 1); | | 78 | rumpuser_sp_copyout(&byte, uaddr, 1); |
77 | return 0; | | 79 | return 0; |
78 | } | | 80 | } |
79 | | | 81 | |
80 | int | | 82 | int |
81 | copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done) | | 83 | copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done) |
82 | { | | 84 | { |
83 | | | 85 | |
84 | strlcpy(kdaddr, kfaddr, len); | | 86 | strlcpy(kdaddr, kfaddr, len); |
85 | if (done) | | 87 | if (done) |
86 | *done = strlen(kdaddr)+1; /* includes termination */ | | 88 | *done = strlen(kdaddr)+1; /* includes termination */ |
87 | return 0; | | 89 | return 0; |
88 | } | | 90 | } |
89 | | | 91 | |
90 | int | | 92 | int |
91 | copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done) | | 93 | copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done) |
92 | { | | 94 | { |
93 | | | 95 | |
94 | if (curproc->p_vmspace == &vmspace0) | | 96 | if (curproc->p_vmspace == &vmspace0) |
95 | strlcpy(kaddr, uaddr, len); | | 97 | strlcpy(kaddr, uaddr, len); |
96 | else | | 98 | else |
97 | rumpuser_sp_copyin(uaddr, kaddr, len); | | 99 | rumpuser_sp_copyin(uaddr, kaddr, len); |
98 | if (done) | | 100 | if (done) |
99 | *done = strlen(kaddr)+1; /* includes termination */ | | 101 | *done = strlen(kaddr)+1; /* includes termination */ |
100 | return 0; | | 102 | return 0; |
101 | } | | 103 | } |
102 | | | 104 | |
103 | int | | 105 | int |
104 | copyoutstr(const void *kaddr, void *uaddr, size_t len, size_t *done) | | 106 | copyoutstr(const void *kaddr, void *uaddr, size_t len, size_t *done) |
105 | { | | 107 | { |
106 | | | 108 | |
107 | if (curproc->p_vmspace == &vmspace0) | | 109 | if (curproc->p_vmspace == &vmspace0) |
108 | strlcpy(uaddr, kaddr, len); | | 110 | strlcpy(uaddr, kaddr, len); |
109 | else | | 111 | else |
110 | rumpuser_sp_copyout(kaddr, uaddr, len); | | 112 | rumpuser_sp_copyout(kaddr, uaddr, len); |
111 | if (done) | | 113 | if (done) |
112 | *done = strlen(uaddr)+1; /* includes termination */ | | 114 | *done = strlen(uaddr)+1; /* includes termination */ |
113 | return 0; | | 115 | return 0; |
114 | } | | 116 | } |
115 | | | 117 | |
116 | int | | 118 | int |
117 | kcopy(const void *src, void *dst, size_t len) | | 119 | kcopy(const void *src, void *dst, size_t len) |
118 | { | | 120 | { |
119 | | | 121 | |
120 | memcpy(dst, src, len); | | 122 | memcpy(dst, src, len); |
121 | return 0; | | 123 | return 0; |
122 | } | | 124 | } |