Print this page
XXX AVX procfs
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/ia32/os/sendsig.c
+++ new/usr/src/uts/intel/ia32/os/sendsig.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
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 /*
23 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
28 28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
29 29 /* All Rights Reserved */
30 30
31 31 #include <sys/types.h>
32 32 #include <sys/param.h>
33 33 #include <sys/sysmacros.h>
34 34 #include <sys/signal.h>
35 35 #include <sys/systm.h>
36 36 #include <sys/user.h>
37 37 #include <sys/mman.h>
38 38 #include <sys/class.h>
39 39 #include <sys/proc.h>
40 40 #include <sys/procfs.h>
41 41 #include <sys/buf.h>
42 42 #include <sys/kmem.h>
43 43 #include <sys/cred.h>
44 44 #include <sys/archsystm.h>
45 45 #include <sys/vmparam.h>
46 46 #include <sys/prsystm.h>
47 47 #include <sys/reboot.h>
48 48 #include <sys/uadmin.h>
49 49 #include <sys/vfs.h>
50 50 #include <sys/vnode.h>
51 51 #include <sys/file.h>
52 52 #include <sys/session.h>
53 53 #include <sys/ucontext.h>
54 54 #include <sys/dnlc.h>
55 55 #include <sys/var.h>
56 56 #include <sys/cmn_err.h>
57 57 #include <sys/debugreg.h>
58 58 #include <sys/thread.h>
59 59 #include <sys/vtrace.h>
60 60 #include <sys/consdev.h>
61 61 #include <sys/psw.h>
62 62 #include <sys/regset.h>
63 63
64 64 #include <sys/privregs.h>
65 65
66 66 #include <sys/stack.h>
67 67 #include <sys/swap.h>
68 68 #include <vm/hat.h>
69 69 #include <vm/anon.h>
70 70 #include <vm/as.h>
71 71 #include <vm/page.h>
72 72 #include <vm/seg.h>
73 73 #include <vm/seg_kmem.h>
74 74 #include <vm/seg_map.h>
75 75 #include <vm/seg_vn.h>
76 76 #include <sys/exec.h>
77 77 #include <sys/acct.h>
78 78 #include <sys/core.h>
79 79 #include <sys/corectl.h>
80 80 #include <sys/modctl.h>
81 81 #include <sys/tuneable.h>
82 82 #include <c2/audit.h>
83 83 #include <sys/bootconf.h>
84 84 #include <sys/dumphdr.h>
85 85 #include <sys/promif.h>
86 86 #include <sys/systeminfo.h>
87 87 #include <sys/kdi.h>
88 88 #include <sys/contract_impl.h>
89 89 #include <sys/x86_archext.h>
90 90
91 91 /*
92 92 * Construct the execution environment for the user's signal
93 93 * handler and arrange for control to be given to it on return
94 94 * to userland. The library code now calls setcontext() to
95 95 * clean up after the signal handler, so sigret() is no longer
96 96 * needed.
97 97 *
98 98 * (The various 'volatile' declarations are need to ensure that values
99 99 * are correct on the error return from on_fault().)
100 100 */
101 101
102 102 #if defined(__amd64)
103 103
104 104 /*
105 105 * An amd64 signal frame looks like this on the stack:
106 106 *
107 107 * old %rsp:
108 108 * <128 bytes of untouched stack space>
109 109 * <a siginfo_t [optional]>
110 110 * <a ucontext_t>
111 111 * <siginfo_t *>
112 112 * <signal number>
113 113 * new %rsp: <return address (deliberately invalid)>
114 114 *
115 115 * The signal number and siginfo_t pointer are only pushed onto the stack in
116 116 * order to allow stack backtraces. The actual signal handling code expects the
117 117 * arguments in registers.
118 118 */
119 119
120 120 struct sigframe {
121 121 caddr_t retaddr;
122 122 long signo;
123 123 siginfo_t *sip;
124 124 };
125 125
↓ open down ↓ |
125 lines elided |
↑ open up ↑ |
126 126 int
127 127 sendsig(int sig, k_siginfo_t *sip, void (*hdlr)())
128 128 {
129 129 volatile int minstacksz;
130 130 int newstack;
131 131 label_t ljb;
132 132 volatile caddr_t sp;
133 133 caddr_t fp;
134 134 volatile struct regs *rp;
135 135 volatile greg_t upc;
136 - volatile proc_t *p = ttoproc(curthread);
136 + proc_t *volatile p = ttoproc(curthread);
137 137 struct as *as = p->p_as;
138 138 klwp_t *lwp = ttolwp(curthread);
139 139 ucontext_t *volatile tuc = NULL;
140 140 ucontext_t *uc;
141 141 siginfo_t *sip_addr;
142 142 volatile int watched;
143 + char *volatile xregs = NULL;
144 + volatile size_t xregs_size = 0;
143 145
144 146 /*
145 147 * This routine is utterly dependent upon STACK_ALIGN being
146 148 * 16 and STACK_ENTRY_ALIGN being 8. Let's just acknowledge
147 149 * that and require it.
148 150 */
149 151
150 152 #if STACK_ALIGN != 16 || STACK_ENTRY_ALIGN != 8
151 153 #error "sendsig() amd64 did not find the expected stack alignments"
152 154 #endif
153 155
154 156 rp = lwptoregs(lwp);
155 157 upc = rp->r_pc;
156 158
157 159 /*
158 160 * Since we're setting up to run the signal handler we have to
159 161 * arrange that the stack at entry to the handler is (only)
160 162 * STACK_ENTRY_ALIGN (i.e. 8) byte aligned so that when the handler
161 163 * executes its push of %rbp, the stack realigns to STACK_ALIGN
162 164 * (i.e. 16) correctly.
163 165 *
164 166 * The new sp will point to the sigframe and the ucontext_t. The
165 167 * above means that sp (and thus sigframe) will be 8-byte aligned,
166 168 * but not 16-byte aligned. ucontext_t, however, contains %xmm regs
167 169 * which must be 16-byte aligned. Because of this, for correct
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
168 170 * alignment, sigframe must be a multiple of 8-bytes in length, but
169 171 * not 16-bytes. This will place ucontext_t at a nice 16-byte boundary.
170 172 */
171 173
172 174 /* LINTED: logical expression always true: op "||" */
173 175 ASSERT((sizeof (struct sigframe) % 16) == 8);
174 176
175 177 minstacksz = sizeof (struct sigframe) + SA(sizeof (*uc));
176 178 if (sip != NULL)
177 179 minstacksz += SA(sizeof (siginfo_t));
180 +
181 + /*
182 + * Extra registers, if supported by this platform, may be of arbitrary
183 + * length. Size them now so we know how big the signal frame has to be.
184 + */
185 + xregs_size = xregs_getsize(p);
186 + minstacksz += SA(xregs_size);
187 +
178 188 ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
179 189
180 190 /*
181 191 * Figure out whether we will be handling this signal on
182 192 * an alternate stack specified by the user. Then allocate
183 193 * and validate the stack requirements for the signal handler
184 194 * context. on_fault will catch any faults.
185 195 */
186 196 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
187 197 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
188 198
189 199 if (newstack) {
190 200 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
191 201 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
192 202 } else {
193 203 /*
194 204 * Drop below the 128-byte reserved region of the stack frame
195 205 * we're interrupting.
196 206 */
197 207 fp = (caddr_t)rp->r_sp - STACK_RESERVE;
198 208 }
199 209
200 210 /*
201 211 * Force proper stack pointer alignment, even in the face of a
202 212 * misaligned stack pointer from user-level before the signal.
203 213 */
204 214 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
205 215
206 216 /*
207 217 * Most of the time during normal execution, the stack pointer
208 218 * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
209 219 * (for example) just after a call instruction (which pushes
210 220 * the return address), the callers stack misaligns until the
211 221 * 'push %rbp' happens in the callee prolog. So while we should
212 222 * expect the stack pointer to be always at least STACK_ENTRY_ALIGN
213 223 * aligned, we should -not- expect it to always be STACK_ALIGN aligned.
214 224 * We now adjust to ensure that the new sp is aligned to
215 225 * STACK_ENTRY_ALIGN but not to STACK_ALIGN.
216 226 */
217 227 sp = fp - minstacksz;
218 228 if (((uintptr_t)sp & (STACK_ALIGN - 1ul)) == 0) {
219 229 sp -= STACK_ENTRY_ALIGN;
220 230 minstacksz = fp - sp;
221 231 }
222 232
223 233 /*
224 234 * Now, make sure the resulting signal frame address is sane
225 235 */
226 236 if (sp >= as->a_userlimit || fp >= as->a_userlimit) {
227 237 #ifdef DEBUG
228 238 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
229 239 PTOU(p)->u_comm, p->p_pid, sig);
230 240 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
231 241 (void *)sp, (void *)hdlr, (uintptr_t)upc);
232 242 printf("sp above USERLIMIT\n");
233 243 #endif
234 244 return (0);
235 245 }
236 246
237 247 watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
238 248
239 249 if (on_fault(&ljb))
240 250 goto badstack;
241 251
242 252 if (sip != NULL) {
243 253 zoneid_t zoneid;
244 254
245 255 fp -= SA(sizeof (siginfo_t));
246 256 uzero(fp, sizeof (siginfo_t));
247 257 if (SI_FROMUSER(sip) &&
248 258 (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
249 259 zoneid != sip->si_zoneid) {
250 260 k_siginfo_t sani_sip = *sip;
251 261
252 262 sani_sip.si_pid = p->p_zone->zone_zsched->p_pid;
253 263 sani_sip.si_uid = 0;
254 264 sani_sip.si_ctid = -1;
255 265 sani_sip.si_zoneid = zoneid;
256 266 copyout_noerr(&sani_sip, fp, sizeof (sani_sip));
257 267 } else
258 268 copyout_noerr(sip, fp, sizeof (*sip));
259 269 sip_addr = (siginfo_t *)fp;
260 270
261 271 if (sig == SIGPROF &&
262 272 curthread->t_rprof != NULL &&
263 273 curthread->t_rprof->rp_anystate) {
264 274 /*
265 275 * We stand on our head to deal with
266 276 * the real time profiling signal.
267 277 * Fill in the stuff that doesn't fit
268 278 * in a normal k_siginfo structure.
269 279 */
270 280 int i = sip->si_nsysarg;
271 281
272 282 while (--i >= 0)
273 283 sulword_noerr(
274 284 (ulong_t *)&(sip_addr->si_sysarg[i]),
275 285 (ulong_t)lwp->lwp_arg[i]);
276 286 copyout_noerr(curthread->t_rprof->rp_state,
277 287 sip_addr->si_mstate,
278 288 sizeof (curthread->t_rprof->rp_state));
279 289 }
280 290 } else
281 291 sip_addr = NULL;
↓ open down ↓ |
94 lines elided |
↑ open up ↑ |
282 292
283 293 /*
284 294 * save the current context on the user stack directly after the
285 295 * sigframe. Since sigframe is 8-byte-but-not-16-byte aligned,
286 296 * and since sizeof (struct sigframe) is 24, this guarantees
287 297 * 16-byte alignment for ucontext_t and its %xmm registers.
288 298 */
289 299 uc = (ucontext_t *)(sp + sizeof (struct sigframe));
290 300 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
291 301 savecontext(tuc, &lwp->lwp_sigoldmask);
302 +
303 + /*
304 + * Save extra register state if it exists.
305 + */
306 + if (xregs_size != 0) {
307 + xregs_setptr(lwp, tuc, sp);
308 + xregs = kmem_alloc(xregs_size, KM_SLEEP);
309 + xregs_get(lwp, xregs);
310 + copyout_noerr(xregs, sp, xregs_size);
311 + kmem_free(xregs, xregs_size);
312 + xregs = NULL;
313 + sp += SA(xregs_size);
314 + }
315 +
292 316 copyout_noerr(tuc, uc, sizeof (*tuc));
293 317 kmem_free(tuc, sizeof (*tuc));
294 318 tuc = NULL;
295 319
296 320 lwp->lwp_oldcontext = (uintptr_t)uc;
297 321
298 322 if (newstack) {
299 323 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
300 324 if (lwp->lwp_ustack)
301 325 copyout_noerr(&lwp->lwp_sigaltstack,
302 326 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
303 327 }
304 328
305 329 /*
306 330 * Set up signal handler return and stack linkage
307 331 */
308 332 {
309 333 struct sigframe frame;
310 334
311 335 /*
312 336 * ensure we never return "normally"
313 337 */
314 338 frame.retaddr = (caddr_t)(uintptr_t)-1L;
315 339 frame.signo = sig;
316 340 frame.sip = sip_addr;
317 341 copyout_noerr(&frame, sp, sizeof (frame));
318 342 }
319 343
320 344 no_fault();
321 345 if (watched)
322 346 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
323 347
324 348 /*
325 349 * Set up user registers for execution of signal handler.
326 350 */
327 351 rp->r_sp = (greg_t)sp;
328 352 rp->r_pc = (greg_t)hdlr;
329 353 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
330 354
331 355 rp->r_rdi = sig;
332 356 rp->r_rsi = (uintptr_t)sip_addr;
333 357 rp->r_rdx = (uintptr_t)uc;
334 358
335 359 if ((rp->r_cs & 0xffff) != UCS_SEL ||
336 360 (rp->r_ss & 0xffff) != UDS_SEL) {
337 361 /*
338 362 * Try our best to deliver the signal.
339 363 */
340 364 rp->r_cs = UCS_SEL;
341 365 rp->r_ss = UDS_SEL;
342 366 }
343 367
344 368 /*
345 369 * Don't set lwp_eosys here. sendsig() is called via psig() after
346 370 * lwp_eosys is handled, so setting it here would affect the next
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
347 371 * system call.
348 372 */
349 373 return (1);
350 374
351 375 badstack:
352 376 no_fault();
353 377 if (watched)
354 378 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
355 379 if (tuc)
356 380 kmem_free(tuc, sizeof (*tuc));
381 + if (xregs)
382 + kmem_free(xregs, xregs_size);
357 383 #ifdef DEBUG
358 384 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
359 385 PTOU(p)->u_comm, p->p_pid, sig);
360 386 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
361 387 (void *)sp, (void *)hdlr, (uintptr_t)upc);
362 388 #endif
363 389 return (0);
364 390 }
365 391
366 392 #ifdef _SYSCALL32_IMPL
367 393
368 394 /*
369 395 * An i386 SVR4/ABI signal frame looks like this on the stack:
370 396 *
371 397 * old %esp:
372 398 * <a siginfo32_t [optional]>
373 399 * <a ucontext32_t>
374 400 * <pointer to that ucontext32_t>
375 401 * <pointer to that siginfo32_t>
376 402 * <signo>
377 403 * new %esp: <return address (deliberately invalid)>
378 404 */
379 405 struct sigframe32 {
380 406 caddr32_t retaddr;
381 407 uint32_t signo;
382 408 caddr32_t sip;
383 409 caddr32_t ucp;
384 410 };
385 411
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
386 412 int
387 413 sendsig32(int sig, k_siginfo_t *sip, void (*hdlr)())
388 414 {
389 415 volatile int minstacksz;
390 416 int newstack;
391 417 label_t ljb;
392 418 volatile caddr_t sp;
393 419 caddr_t fp;
394 420 volatile struct regs *rp;
395 421 volatile greg_t upc;
396 - volatile proc_t *p = ttoproc(curthread);
422 + proc_t *volatile p = ttoproc(curthread);
397 423 klwp_t *lwp = ttolwp(curthread);
398 424 ucontext32_t *volatile tuc = NULL;
399 425 ucontext32_t *uc;
400 426 siginfo32_t *sip_addr;
401 427 volatile int watched;
428 + char *volatile xregs = NULL;
429 + volatile size_t xregs_size = 0;
402 430
403 431 rp = lwptoregs(lwp);
404 432 upc = rp->r_pc;
405 433
406 434 minstacksz = SA32(sizeof (struct sigframe32)) + SA32(sizeof (*uc));
407 435 if (sip != NULL)
408 436 minstacksz += SA32(sizeof (siginfo32_t));
437 +
438 + /*
439 + * Extra registers, if supported by this platform, may be of arbitrary
440 + * length. Size them now so we know how big the signal frame has to be.
441 + */
442 + xregs_size = xregs_getsize(p);
443 + minstacksz += SA32(xregs_size);
444 +
409 445 ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
410 446
411 447 /*
412 448 * Figure out whether we will be handling this signal on
413 449 * an alternate stack specified by the user. Then allocate
414 450 * and validate the stack requirements for the signal handler
415 451 * context. on_fault will catch any faults.
416 452 */
417 453 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
418 454 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
419 455
420 456 if (newstack) {
421 457 fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
422 458 SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
423 459 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
424 460 user_desc_t *ldt;
425 461 /*
426 462 * If the stack segment selector is -not- pointing at
427 463 * the UDS_SEL descriptor and we have an LDT entry for
428 464 * it instead, add the base address to find the effective va.
429 465 */
430 466 if ((ldt = p->p_ldt) != NULL)
431 467 fp = (caddr_t)rp->r_sp +
432 468 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
433 469 else
434 470 fp = (caddr_t)rp->r_sp;
435 471 } else
436 472 fp = (caddr_t)rp->r_sp;
437 473
438 474 /*
439 475 * Force proper stack pointer alignment, even in the face of a
440 476 * misaligned stack pointer from user-level before the signal.
441 477 * Don't use the SA32() macro because that rounds up, not down.
442 478 */
443 479 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
444 480 sp = fp - minstacksz;
445 481
446 482 /*
447 483 * Make sure lwp hasn't trashed its stack
448 484 */
449 485 if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
450 486 fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
451 487 #ifdef DEBUG
452 488 printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
453 489 PTOU(p)->u_comm, p->p_pid, sig);
454 490 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
455 491 (void *)sp, (void *)hdlr, (uintptr_t)upc);
456 492 printf("sp above USERLIMIT\n");
457 493 #endif
458 494 return (0);
459 495 }
460 496
461 497 watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
462 498
463 499 if (on_fault(&ljb))
464 500 goto badstack;
465 501
466 502 if (sip != NULL) {
467 503 siginfo32_t si32;
468 504 zoneid_t zoneid;
469 505
470 506 siginfo_kto32(sip, &si32);
471 507 if (SI_FROMUSER(sip) &&
472 508 (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
473 509 zoneid != sip->si_zoneid) {
474 510 si32.si_pid = p->p_zone->zone_zsched->p_pid;
475 511 si32.si_uid = 0;
476 512 si32.si_ctid = -1;
477 513 si32.si_zoneid = zoneid;
478 514 }
479 515 fp -= SA32(sizeof (si32));
480 516 uzero(fp, sizeof (si32));
481 517 copyout_noerr(&si32, fp, sizeof (si32));
482 518 sip_addr = (siginfo32_t *)fp;
483 519
484 520 if (sig == SIGPROF &&
485 521 curthread->t_rprof != NULL &&
486 522 curthread->t_rprof->rp_anystate) {
487 523 /*
488 524 * We stand on our head to deal with
489 525 * the real-time profiling signal.
490 526 * Fill in the stuff that doesn't fit
491 527 * in a normal k_siginfo structure.
492 528 */
493 529 int i = sip->si_nsysarg;
494 530
495 531 while (--i >= 0)
496 532 suword32_noerr(&(sip_addr->si_sysarg[i]),
497 533 (uint32_t)lwp->lwp_arg[i]);
498 534 copyout_noerr(curthread->t_rprof->rp_state,
499 535 sip_addr->si_mstate,
↓ open down ↓ |
81 lines elided |
↑ open up ↑ |
500 536 sizeof (curthread->t_rprof->rp_state));
501 537 }
502 538 } else
503 539 sip_addr = NULL;
504 540
505 541 /* save the current context on the user stack */
506 542 fp -= SA32(sizeof (*tuc));
507 543 uc = (ucontext32_t *)fp;
508 544 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
509 545 savecontext32(tuc, &lwp->lwp_sigoldmask);
546 +
547 + /*
548 + * Save extra register state if it exists.
549 + */
550 + if (xregs_size != 0) {
551 + xregs_setptr32(lwp, tuc, (caddr32_t)(uintptr_t)sp);
552 + xregs = kmem_alloc(xregs_size, KM_SLEEP);
553 + xregs_get(lwp, xregs);
554 + copyout_noerr(xregs, sp, xregs_size);
555 + kmem_free(xregs, xregs_size);
556 + xregs = NULL;
557 + sp += SA32(xregs_size);
558 + }
559 +
510 560 copyout_noerr(tuc, uc, sizeof (*tuc));
511 561 kmem_free(tuc, sizeof (*tuc));
512 562 tuc = NULL;
513 563
514 564 lwp->lwp_oldcontext = (uintptr_t)uc;
515 565
516 566 if (newstack) {
517 567 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
518 568 if (lwp->lwp_ustack) {
519 569 stack32_t stk32;
520 570
521 571 stk32.ss_sp = (caddr32_t)(uintptr_t)
522 572 lwp->lwp_sigaltstack.ss_sp;
523 573 stk32.ss_size = (size32_t)
524 574 lwp->lwp_sigaltstack.ss_size;
525 575 stk32.ss_flags = (int32_t)
526 576 lwp->lwp_sigaltstack.ss_flags;
527 577 copyout_noerr(&stk32,
528 578 (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
529 579 }
530 580 }
531 581
532 582 /*
533 583 * Set up signal handler arguments
534 584 */
535 585 {
536 586 struct sigframe32 frame32;
537 587
538 588 frame32.sip = (caddr32_t)(uintptr_t)sip_addr;
539 589 frame32.ucp = (caddr32_t)(uintptr_t)uc;
540 590 frame32.signo = sig;
541 591 frame32.retaddr = 0xffffffff; /* never return! */
542 592 copyout_noerr(&frame32, sp, sizeof (frame32));
543 593 }
544 594
545 595 no_fault();
546 596 if (watched)
547 597 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
548 598
549 599 rp->r_sp = (greg_t)(uintptr_t)sp;
550 600 rp->r_pc = (greg_t)(uintptr_t)hdlr;
551 601 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
552 602
553 603 if ((rp->r_cs & 0xffff) != U32CS_SEL ||
554 604 (rp->r_ss & 0xffff) != UDS_SEL) {
555 605 /*
556 606 * Try our best to deliver the signal.
557 607 */
558 608 rp->r_cs = U32CS_SEL;
559 609 rp->r_ss = UDS_SEL;
560 610 }
561 611
562 612 /*
563 613 * Don't set lwp_eosys here. sendsig() is called via psig() after
564 614 * lwp_eosys is handled, so setting it here would affect the next
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
565 615 * system call.
566 616 */
567 617 return (1);
568 618
569 619 badstack:
570 620 no_fault();
571 621 if (watched)
572 622 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
573 623 if (tuc)
574 624 kmem_free(tuc, sizeof (*tuc));
625 + if (xregs_size)
626 + kmem_free(xregs, xregs_size);
575 627 #ifdef DEBUG
576 628 printf("sendsig32: bad signal stack cmd=%s pid=%d, sig=%d\n",
577 629 PTOU(p)->u_comm, p->p_pid, sig);
578 630 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
579 631 (void *)sp, (void *)hdlr, (uintptr_t)upc);
580 632 #endif
581 633 return (0);
582 634 }
583 635
584 636 #endif /* _SYSCALL32_IMPL */
585 637
586 638 #elif defined(__i386)
587 639
588 640 /*
589 641 * An i386 SVR4/ABI signal frame looks like this on the stack:
590 642 *
591 643 * old %esp:
592 644 * <a siginfo32_t [optional]>
593 645 * <a ucontext32_t>
594 646 * <pointer to that ucontext32_t>
595 647 * <pointer to that siginfo32_t>
596 648 * <signo>
597 649 * new %esp: <return address (deliberately invalid)>
598 650 */
599 651 struct sigframe {
600 652 void (*retaddr)();
601 653 uint_t signo;
602 654 siginfo_t *sip;
603 655 ucontext_t *ucp;
604 656 };
605 657
606 658 int
607 659 sendsig(int sig, k_siginfo_t *sip, void (*hdlr)())
608 660 {
609 661 volatile int minstacksz;
610 662 int newstack;
611 663 label_t ljb;
612 664 volatile caddr_t sp;
613 665 caddr_t fp;
614 666 struct regs *rp;
615 667 volatile greg_t upc;
616 668 volatile proc_t *p = ttoproc(curthread);
617 669 klwp_t *lwp = ttolwp(curthread);
618 670 ucontext_t *volatile tuc = NULL;
619 671 ucontext_t *uc;
620 672 siginfo_t *sip_addr;
621 673 volatile int watched;
622 674
623 675 rp = lwptoregs(lwp);
624 676 upc = rp->r_pc;
625 677
626 678 minstacksz = SA(sizeof (struct sigframe)) + SA(sizeof (*uc));
627 679 if (sip != NULL)
628 680 minstacksz += SA(sizeof (siginfo_t));
629 681 ASSERT((minstacksz & (STACK_ALIGN - 1ul)) == 0);
630 682
631 683 /*
632 684 * Figure out whether we will be handling this signal on
633 685 * an alternate stack specified by the user. Then allocate
634 686 * and validate the stack requirements for the signal handler
635 687 * context. on_fault will catch any faults.
636 688 */
637 689 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
638 690 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
639 691
640 692 if (newstack) {
641 693 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
642 694 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
643 695 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
644 696 user_desc_t *ldt;
645 697 /*
646 698 * If the stack segment selector is -not- pointing at
647 699 * the UDS_SEL descriptor and we have an LDT entry for
648 700 * it instead, add the base address to find the effective va.
649 701 */
650 702 if ((ldt = p->p_ldt) != NULL)
651 703 fp = (caddr_t)rp->r_sp +
652 704 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
653 705 else
654 706 fp = (caddr_t)rp->r_sp;
655 707 } else
656 708 fp = (caddr_t)rp->r_sp;
657 709
658 710 /*
659 711 * Force proper stack pointer alignment, even in the face of a
660 712 * misaligned stack pointer from user-level before the signal.
661 713 * Don't use the SA() macro because that rounds up, not down.
662 714 */
663 715 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN - 1ul));
664 716 sp = fp - minstacksz;
665 717
666 718 /*
667 719 * Make sure lwp hasn't trashed its stack.
668 720 */
669 721 if (sp >= (caddr_t)USERLIMIT || fp >= (caddr_t)USERLIMIT) {
670 722 #ifdef DEBUG
671 723 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
672 724 PTOU(p)->u_comm, p->p_pid, sig);
673 725 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
674 726 (void *)sp, (void *)hdlr, (uintptr_t)upc);
675 727 printf("sp above USERLIMIT\n");
676 728 #endif
677 729 return (0);
678 730 }
679 731
680 732 watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
681 733
682 734 if (on_fault(&ljb))
683 735 goto badstack;
684 736
685 737 if (sip != NULL) {
686 738 zoneid_t zoneid;
687 739
688 740 fp -= SA(sizeof (siginfo_t));
689 741 uzero(fp, sizeof (siginfo_t));
690 742 if (SI_FROMUSER(sip) &&
691 743 (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
692 744 zoneid != sip->si_zoneid) {
693 745 k_siginfo_t sani_sip = *sip;
694 746
695 747 sani_sip.si_pid = p->p_zone->zone_zsched->p_pid;
696 748 sani_sip.si_uid = 0;
697 749 sani_sip.si_ctid = -1;
698 750 sani_sip.si_zoneid = zoneid;
699 751 copyout_noerr(&sani_sip, fp, sizeof (sani_sip));
700 752 } else
701 753 copyout_noerr(sip, fp, sizeof (*sip));
702 754 sip_addr = (siginfo_t *)fp;
703 755
704 756 if (sig == SIGPROF &&
705 757 curthread->t_rprof != NULL &&
706 758 curthread->t_rprof->rp_anystate) {
707 759 /*
708 760 * We stand on our head to deal with
709 761 * the real time profiling signal.
710 762 * Fill in the stuff that doesn't fit
711 763 * in a normal k_siginfo structure.
712 764 */
713 765 int i = sip->si_nsysarg;
714 766
715 767 while (--i >= 0)
716 768 suword32_noerr(&(sip_addr->si_sysarg[i]),
717 769 (uint32_t)lwp->lwp_arg[i]);
718 770 copyout_noerr(curthread->t_rprof->rp_state,
719 771 sip_addr->si_mstate,
720 772 sizeof (curthread->t_rprof->rp_state));
721 773 }
722 774 } else
723 775 sip_addr = NULL;
724 776
725 777 /* save the current context on the user stack */
726 778 fp -= SA(sizeof (*tuc));
727 779 uc = (ucontext_t *)fp;
728 780 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
729 781 savecontext(tuc, &lwp->lwp_sigoldmask);
730 782 copyout_noerr(tuc, uc, sizeof (*tuc));
731 783 kmem_free(tuc, sizeof (*tuc));
732 784 tuc = NULL;
733 785
734 786 lwp->lwp_oldcontext = (uintptr_t)uc;
735 787
736 788 if (newstack) {
737 789 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
738 790 if (lwp->lwp_ustack)
739 791 copyout_noerr(&lwp->lwp_sigaltstack,
740 792 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
741 793 }
742 794
743 795 /*
744 796 * Set up signal handler arguments
745 797 */
746 798 {
747 799 struct sigframe frame;
748 800
749 801 frame.sip = sip_addr;
750 802 frame.ucp = uc;
751 803 frame.signo = sig;
752 804 frame.retaddr = (void (*)())0xffffffff; /* never return! */
753 805 copyout_noerr(&frame, sp, sizeof (frame));
754 806 }
755 807
756 808 no_fault();
757 809 if (watched)
758 810 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
759 811
760 812 rp->r_sp = (greg_t)sp;
761 813 rp->r_pc = (greg_t)hdlr;
762 814 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
763 815
764 816 if ((rp->r_cs & 0xffff) != UCS_SEL ||
765 817 (rp->r_ss & 0xffff) != UDS_SEL) {
766 818 rp->r_cs = UCS_SEL;
767 819 rp->r_ss = UDS_SEL;
768 820 }
769 821
770 822 /*
771 823 * Don't set lwp_eosys here. sendsig() is called via psig() after
772 824 * lwp_eosys is handled, so setting it here would affect the next
773 825 * system call.
774 826 */
775 827 return (1);
776 828
777 829 badstack:
778 830 no_fault();
779 831 if (watched)
780 832 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
781 833 if (tuc)
782 834 kmem_free(tuc, sizeof (*tuc));
783 835 #ifdef DEBUG
784 836 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
785 837 PTOU(p)->u_comm, p->p_pid, sig);
786 838 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
787 839 (void *)sp, (void *)hdlr, (uintptr_t)upc);
788 840 #endif
789 841 return (0);
790 842 }
791 843
792 844 #endif /* __i386 */
↓ open down ↓ |
208 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX