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