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