Print this page
5042 stop using deprecated atomic functions
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/sparc/v9/syscall/install_utrap.c
+++ new/usr/src/uts/sparc/v9/syscall/install_utrap.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 26 #include <sys/types.h>
29 27 #include <sys/errno.h>
30 28 #include <sys/systm.h>
31 29 #include <sys/atomic.h>
32 30 #include <sys/kmem.h>
33 31 #include <sys/machpcb.h>
34 32 #include <sys/utrap.h>
35 33 #include <sys/model.h>
36 34
37 35 int
38 36 install_utrap(utrap_entry_t type, utrap_handler_t new_handler,
39 37 utrap_handler_t *old_handlerp)
40 38 {
41 39 struct proc *p = curthread->t_procp;
42 40 utrap_handler_t *ov, *nv, *pv, *sv, *tmp;
43 41 caddr32_t nv32;
44 42 int idx;
45 43
46 44 /*
47 45 * Check trap number.
48 46 */
49 47 switch (type) {
50 48 case UTRAP_V8P_FP_DISABLED:
51 49 #ifdef SF_ERRATA_30 /* call causes fp-disabled */
52 50 {
53 51 extern int spitfire_call_bug;
54 52
55 53 if (spitfire_call_bug)
56 54 return ((int)set_errno(ENOSYS));
57 55 }
58 56 #endif /* SF_ERRATA_30 */
59 57 idx = UTRAP_V8P_FP_DISABLED;
60 58 break;
61 59 case UTRAP_V8P_MEM_ADDRESS_NOT_ALIGNED:
62 60 idx = UTRAP_V8P_MEM_ADDRESS_NOT_ALIGNED;
63 61 break;
64 62 default:
65 63 return ((int)set_errno(EINVAL));
66 64 }
67 65 if (get_udatamodel() == DATAMODEL_LP64)
68 66 return ((int)set_errno(EINVAL));
69 67
70 68 /*
71 69 * Be sure handler address is word aligned. The uintptr_t casts are
72 70 * there to prevent warnings when using a certain compiler, and the
73 71 * temporary 32 bit variable is intended to ensure proper code
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
74 72 * generation and avoid a messy quadruple cast.
75 73 */
76 74 nv32 = (caddr32_t)(uintptr_t)new_handler;
77 75 nv = (utrap_handler_t *)(uintptr_t)nv32;
78 76 if (nv != UTRAP_UTH_NOCHANGE) {
79 77 if (((uintptr_t)nv) & 0x3)
80 78 return ((int)set_errno(EINVAL));
81 79 }
82 80 /*
83 81 * Allocate proc space for saving the addresses to these user
84 - * trap handlers, which must later be freed. Use casptr to
82 + * trap handlers, which must later be freed. Use atomic_cas_ptr to
85 83 * do this atomically.
86 84 */
87 85 if (p->p_utraps == NULL) {
88 86 pv = sv = kmem_zalloc((UT_PRECISE_MAXTRAPS+1) *
89 87 sizeof (utrap_handler_t *), KM_SLEEP);
90 - tmp = casptr(&p->p_utraps, NULL, sv);
88 + tmp = atomic_cas_ptr(&p->p_utraps, NULL, sv);
91 89 if (tmp != NULL) {
92 90 kmem_free(pv, (UT_PRECISE_MAXTRAPS+1) *
93 91 sizeof (utrap_handler_t *));
94 92 }
95 93 }
96 94 ASSERT(p->p_utraps != NULL);
97 95
98 96 /*
99 - * Use casptr to atomically install the handler.
97 + * Use atomic_cas_ptr to atomically install the handler.
100 98 */
101 99 ov = p->p_utraps[idx];
102 100 if (new_handler != (utrap_handler_t)UTRAP_UTH_NOCHANGE) {
103 101 for (;;) {
104 - tmp = casptr(&p->p_utraps[idx], ov, nv);
102 + tmp = atomic_cas_ptr(&p->p_utraps[idx], ov, nv);
105 103 if (ov == tmp)
106 104 break;
107 105 ov = tmp;
108 106 }
109 107 }
110 108 if (old_handlerp != NULL) {
111 109 if (suword32(old_handlerp, (uint32_t)(uintptr_t)ov) == -1)
112 110 return ((int)set_errno(EINVAL));
113 111 }
114 112 return (0);
115 113 }
116 114
117 115 void
118 116 utrap_dup(struct proc *pp, struct proc *cp)
119 117 {
120 118 if (pp->p_utraps != NULL) {
121 119 cp->p_utraps = kmem_alloc((UT_PRECISE_MAXTRAPS+1) *
122 120 sizeof (utrap_handler_t *), KM_SLEEP);
123 121 bcopy(pp->p_utraps, cp->p_utraps,
124 122 (UT_PRECISE_MAXTRAPS+1) * sizeof (utrap_handler_t *));
125 123 } else {
126 124 cp->p_utraps = NULL;
127 125 }
128 126 }
129 127
130 128 void
131 129 utrap_free(struct proc *p)
132 130 {
133 131 /* Free any kmem_alloc'ed space for user trap handlers. */
134 132 if (p->p_utraps != NULL) {
135 133 kmem_free(p->p_utraps, (UT_PRECISE_MAXTRAPS+1) *
136 134 sizeof (utrap_handler_t *));
137 135 p->p_utraps = NULL;
138 136 }
139 137 }
140 138
141 139 /*
142 140 * The code below supports the set of user traps which are required and
143 141 * "must be provided by all ABI-conforming implementations", according to
144 142 * 3.3.3 User Traps of the SPARC V9 ABI SUPPLEMENT, Delta Document 1.38.
145 143 * There is only 1 deferred trap in Ultra I&II, the asynchronous error
146 144 * traps, which are not required, so the deferred args are not used.
147 145 */
148 146 /*ARGSUSED*/
149 147 int
150 148 sparc_utrap_install(utrap_entry_t type,
151 149 utrap_handler_t new_precise, utrap_handler_t new_deferred,
152 150 utrap_handler_t *old_precise, utrap_handler_t *old_deferred)
153 151 {
154 152 struct proc *p = curthread->t_procp;
155 153 utrap_handler_t *ov, *nvp, *pv, *sv, *tmp;
156 154 int idx;
157 155
158 156 /*
159 157 * Check trap number.
160 158 */
161 159 switch (type) {
162 160 case UT_ILLTRAP_INSTRUCTION:
163 161 idx = UT_ILLTRAP_INSTRUCTION;
164 162 break;
165 163 case UT_FP_DISABLED:
166 164 #ifdef SF_ERRATA_30 /* call causes fp-disabled */
167 165 {
168 166 extern int spitfire_call_bug;
169 167
170 168 if (spitfire_call_bug)
171 169 return ((int)set_errno(ENOSYS));
172 170 }
173 171 #endif /* SF_ERRATA_30 */
174 172 idx = UT_FP_DISABLED;
175 173 break;
176 174 case UT_FP_EXCEPTION_IEEE_754:
177 175 idx = UT_FP_EXCEPTION_IEEE_754;
178 176 break;
179 177 case UT_TAG_OVERFLOW:
180 178 idx = UT_TAG_OVERFLOW;
181 179 break;
182 180 case UT_DIVISION_BY_ZERO:
183 181 idx = UT_DIVISION_BY_ZERO;
184 182 break;
185 183 case UT_MEM_ADDRESS_NOT_ALIGNED:
186 184 idx = UT_MEM_ADDRESS_NOT_ALIGNED;
187 185 break;
188 186 case UT_PRIVILEGED_ACTION:
189 187 idx = UT_PRIVILEGED_ACTION;
190 188 break;
191 189 case UT_TRAP_INSTRUCTION_16:
192 190 case UT_TRAP_INSTRUCTION_17:
193 191 case UT_TRAP_INSTRUCTION_18:
194 192 case UT_TRAP_INSTRUCTION_19:
195 193 case UT_TRAP_INSTRUCTION_20:
196 194 case UT_TRAP_INSTRUCTION_21:
197 195 case UT_TRAP_INSTRUCTION_22:
198 196 case UT_TRAP_INSTRUCTION_23:
199 197 case UT_TRAP_INSTRUCTION_24:
200 198 case UT_TRAP_INSTRUCTION_25:
201 199 case UT_TRAP_INSTRUCTION_26:
202 200 case UT_TRAP_INSTRUCTION_27:
203 201 case UT_TRAP_INSTRUCTION_28:
204 202 case UT_TRAP_INSTRUCTION_29:
205 203 case UT_TRAP_INSTRUCTION_30:
206 204 case UT_TRAP_INSTRUCTION_31:
207 205 idx = type;
208 206 break;
209 207 default:
210 208 return ((int)set_errno(EINVAL));
211 209 }
212 210
213 211 if (get_udatamodel() == DATAMODEL_ILP32)
214 212 return ((int)set_errno(EINVAL));
215 213
216 214 /*
217 215 * Be sure handler address is word aligned.
↓ open down ↓ |
103 lines elided |
↑ open up ↑ |
218 216 * There are no deferred traps, so ignore them.
219 217 */
220 218 nvp = (utrap_handler_t *)new_precise;
221 219 if (nvp != UTRAP_UTH_NOCHANGE) {
222 220 if (((uintptr_t)nvp) & 0x3)
223 221 return ((int)set_errno(EINVAL));
224 222 }
225 223
226 224 /*
227 225 * Allocate proc space for saving the addresses to these user
228 - * trap handlers, which must later be freed. Use casptr to
226 + * trap handlers, which must later be freed. Use atomic_cas_ptr to
229 227 * do this atomically.
230 228 */
231 229 if (p->p_utraps == NULL) {
232 230 pv = sv = kmem_zalloc((UT_PRECISE_MAXTRAPS+1) *
233 231 sizeof (utrap_handler_t *), KM_SLEEP);
234 - tmp = casptr(&p->p_utraps, NULL, sv);
232 + tmp = atomic_cas_ptr(&p->p_utraps, NULL, sv);
235 233 if (tmp != NULL) {
236 234 kmem_free(pv, (UT_PRECISE_MAXTRAPS+1) *
237 235 sizeof (utrap_handler_t *));
238 236 }
239 237 }
240 238 ASSERT(p->p_utraps != NULL);
241 239
242 240 /*
243 - * Use casptr to atomically install the handlers.
241 + * Use atomic_cas_ptr to atomically install the handlers.
244 242 */
245 243 ov = p->p_utraps[idx];
246 244 if (new_precise != (utrap_handler_t)UTH_NOCHANGE) {
247 245 for (;;) {
248 - tmp = casptr(&p->p_utraps[idx], ov, nvp);
246 + tmp = atomic_cas_ptr(&p->p_utraps[idx], ov, nvp);
249 247 if (ov == tmp)
250 248 break;
251 249 ov = tmp;
252 250 }
253 251 }
254 252 if (old_precise != NULL) {
255 253 if (suword64(old_precise, (uint64_t)ov) == -1)
256 254 return ((int)set_errno(EINVAL));
257 255 }
258 256 return (0);
259 257 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX