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