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
↓ 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
↓ 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().)
↓ 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  
↓ 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          /*
↓ 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)
↓ 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          /*
↓ 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)
↓ 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:
↓ open down ↓ 14 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX