3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 #include <sys/param.h>
  31 #include <sys/types.h>
  32 #include <sys/vmparam.h>
  33 #include <sys/systm.h>
  34 #include <sys/signal.h>
  35 #include <sys/stack.h>
  36 #include <sys/frame.h>
  37 #include <sys/proc.h>
  38 #include <sys/brand.h>
  39 #include <sys/ucontext.h>
  40 #include <sys/asm_linkage.h>
  41 #include <sys/kmem.h>
  42 #include <sys/errno.h>
 
 
  93             ucp->uc_stack.ss_size == 0) {
  94 
  95                 if (lwp->lwp_sigaltstack.ss_flags == SS_ONSTACK) {
  96                         ucp->uc_stack = lwp->lwp_sigaltstack;
  97                 } else {
  98                         ucp->uc_stack.ss_sp = p->p_usrstack - p->p_stksize;
  99                         ucp->uc_stack.ss_size = p->p_stksize;
 100                         ucp->uc_stack.ss_flags = 0;
 101                 }
 102         }
 103 
 104         getgregs(lwp, ucp->uc_mcontext.gregs);
 105         getasrs(lwp, ucp->uc_mcontext.asrs);
 106 
 107         getfpregs(lwp, &ucp->uc_mcontext.fpregs);
 108         getfpasrs(lwp, ucp->uc_mcontext.asrs);
 109         if (ucp->uc_mcontext.fpregs.fpu_en == 0)
 110                 ucp->uc_flags &= ~UC_FPU;
 111         ucp->uc_mcontext.gwins = (gwindows_t *)NULL;
 112 
 113         /*
 114          * Save signal mask.
 115          */
 116         sigktou(mask, &ucp->uc_sigmask);
 117 }
 118 
 119 
 120 void
 121 restorecontext(ucontext_t *ucp)
 122 {
 123         kthread_t *t = curthread;
 124         klwp_t *lwp = ttolwp(t);
 125         mcontext_t *mcp = &ucp->uc_mcontext;
 126         model_t model = lwp_getdatamodel(lwp);
 127 
 128         (void) flush_user_windows_to_stack(NULL);
 129         if (lwp->lwp_pcb.pcb_xregstat != XREGNONE)
 130                 xregrestore(lwp, 0);
 131 
 132         lwp->lwp_oldcontext = (uintptr_t)ucp->uc_link;
 133 
 134         if (ucp->uc_flags & UC_STACK) {
 135                 if (ucp->uc_stack.ss_flags == SS_ONSTACK)
 136                         lwp->lwp_sigaltstack = ucp->uc_stack;
 
 395                         ucp->uc_stack.ss_size =
 396                             (size32_t)lwp->lwp_sigaltstack.ss_size;
 397                         ucp->uc_stack.ss_flags = SS_ONSTACK;
 398                 } else {
 399                         ucp->uc_stack.ss_sp =
 400                             (caddr32_t)(uintptr_t)p->p_usrstack - p->p_stksize;
 401                         ucp->uc_stack.ss_size =
 402                             (size32_t)p->p_stksize;
 403                         ucp->uc_stack.ss_flags = 0;
 404                 }
 405         }
 406 
 407         getgregs32(lwp, ucp->uc_mcontext.gregs);
 408         getfpregs(lwp, &fpregs);
 409         fpuregset_nto32(&fpregs, &ucp->uc_mcontext.fpregs, dfq);
 410 
 411         if (ucp->uc_mcontext.fpregs.fpu_en == 0)
 412                 ucp->uc_flags &= ~UC_FPU;
 413         ucp->uc_mcontext.gwins = (caddr32_t)NULL;
 414 
 415         /*
 416          * Save signal mask (the 32- and 64-bit sigset_t structures are
 417          * identical).
 418          */
 419         sigktou(mask, (sigset_t *)&ucp->uc_sigmask);
 420 }
 421 
 422 int
 423 getsetcontext32(int flag, void *arg)
 424 {
 425         ucontext32_t uc;
 426         ucontext_t   ucnat;
 427         struct _fq fpu_qnat[MAXFPQ]; /* to hold "native" floating queue */
 428         struct fq32 fpu_q[MAXFPQ]; /* to hold 32 bit floating queue */
 429         fpregset32_t *fpp;
 430         gwindows32_t *gwin = NULL;      /* to hold windows */
 431         caddr_t xregs;
 432         int xregs_size = 0;
 433         extern int nwindows;
 434         klwp_t *lwp = ttolwp(curthread);
 435         ucontext32_t *ucp;
 436         uint32_t ustack32;
 437         stack32_t dummy_stk32;
 438 
 439         /*
 
 | 
 
 
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2015 Joyent, Inc.
  24  */
  25 /*
  26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  31 /*        All Rights Reserved   */
  32 
  33 #include <sys/param.h>
  34 #include <sys/types.h>
  35 #include <sys/vmparam.h>
  36 #include <sys/systm.h>
  37 #include <sys/signal.h>
  38 #include <sys/stack.h>
  39 #include <sys/frame.h>
  40 #include <sys/proc.h>
  41 #include <sys/brand.h>
  42 #include <sys/ucontext.h>
  43 #include <sys/asm_linkage.h>
  44 #include <sys/kmem.h>
  45 #include <sys/errno.h>
 
 
  96             ucp->uc_stack.ss_size == 0) {
  97 
  98                 if (lwp->lwp_sigaltstack.ss_flags == SS_ONSTACK) {
  99                         ucp->uc_stack = lwp->lwp_sigaltstack;
 100                 } else {
 101                         ucp->uc_stack.ss_sp = p->p_usrstack - p->p_stksize;
 102                         ucp->uc_stack.ss_size = p->p_stksize;
 103                         ucp->uc_stack.ss_flags = 0;
 104                 }
 105         }
 106 
 107         getgregs(lwp, ucp->uc_mcontext.gregs);
 108         getasrs(lwp, ucp->uc_mcontext.asrs);
 109 
 110         getfpregs(lwp, &ucp->uc_mcontext.fpregs);
 111         getfpasrs(lwp, ucp->uc_mcontext.asrs);
 112         if (ucp->uc_mcontext.fpregs.fpu_en == 0)
 113                 ucp->uc_flags &= ~UC_FPU;
 114         ucp->uc_mcontext.gwins = (gwindows_t *)NULL;
 115 
 116         if (mask != NULL) {
 117                 /*
 118                  * Save signal mask.
 119                  */
 120                 sigktou(mask, &ucp->uc_sigmask);
 121         } else {
 122                 ucp->uc_flags &= ~UC_SIGMASK;
 123                 bzero(&ucp->uc_sigmask, sizeof (ucp->uc_sigmask));
 124         }
 125 }
 126 
 127 
 128 void
 129 restorecontext(ucontext_t *ucp)
 130 {
 131         kthread_t *t = curthread;
 132         klwp_t *lwp = ttolwp(t);
 133         mcontext_t *mcp = &ucp->uc_mcontext;
 134         model_t model = lwp_getdatamodel(lwp);
 135 
 136         (void) flush_user_windows_to_stack(NULL);
 137         if (lwp->lwp_pcb.pcb_xregstat != XREGNONE)
 138                 xregrestore(lwp, 0);
 139 
 140         lwp->lwp_oldcontext = (uintptr_t)ucp->uc_link;
 141 
 142         if (ucp->uc_flags & UC_STACK) {
 143                 if (ucp->uc_stack.ss_flags == SS_ONSTACK)
 144                         lwp->lwp_sigaltstack = ucp->uc_stack;
 
 403                         ucp->uc_stack.ss_size =
 404                             (size32_t)lwp->lwp_sigaltstack.ss_size;
 405                         ucp->uc_stack.ss_flags = SS_ONSTACK;
 406                 } else {
 407                         ucp->uc_stack.ss_sp =
 408                             (caddr32_t)(uintptr_t)p->p_usrstack - p->p_stksize;
 409                         ucp->uc_stack.ss_size =
 410                             (size32_t)p->p_stksize;
 411                         ucp->uc_stack.ss_flags = 0;
 412                 }
 413         }
 414 
 415         getgregs32(lwp, ucp->uc_mcontext.gregs);
 416         getfpregs(lwp, &fpregs);
 417         fpuregset_nto32(&fpregs, &ucp->uc_mcontext.fpregs, dfq);
 418 
 419         if (ucp->uc_mcontext.fpregs.fpu_en == 0)
 420                 ucp->uc_flags &= ~UC_FPU;
 421         ucp->uc_mcontext.gwins = (caddr32_t)NULL;
 422 
 423         if (mask != NULL) {
 424                 /*
 425                  * Save signal mask (the 32- and 64-bit sigset_t structures are
 426                  * identical).
 427                  */
 428                 sigktou(mask, (sigset_t *)&ucp->uc_sigmask);
 429         } else {
 430                 ucp->uc_flags &= ~UC_SIGMASK;
 431                 bzero(&ucp->uc_sigmask, sizeof (ucp->uc_sigmask));
 432         }
 433 }
 434 
 435 int
 436 getsetcontext32(int flag, void *arg)
 437 {
 438         ucontext32_t uc;
 439         ucontext_t   ucnat;
 440         struct _fq fpu_qnat[MAXFPQ]; /* to hold "native" floating queue */
 441         struct fq32 fpu_q[MAXFPQ]; /* to hold 32 bit floating queue */
 442         fpregset32_t *fpp;
 443         gwindows32_t *gwin = NULL;      /* to hold windows */
 444         caddr_t xregs;
 445         int xregs_size = 0;
 446         extern int nwindows;
 447         klwp_t *lwp = ttolwp(curthread);
 448         ucontext32_t *ucp;
 449         uint32_t ustack32;
 450         stack32_t dummy_stk32;
 451 
 452         /*
 
 |