Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section


   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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2017, Joyent, Inc.
  25  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  26  */
  27 
  28 /*
  29  * DTrace - Dynamic Tracing for Solaris
  30  *
  31  * This is the implementation of the Solaris Dynamic Tracing framework
  32  * (DTrace).  The user-visible interface to DTrace is described at length in
  33  * the "Solaris Dynamic Tracing Guide".  The interfaces between the libdtrace
  34  * library, the in-kernel DTrace framework, and the DTrace providers are
  35  * described in the block comments in the <sys/dtrace.h> header file.  The
  36  * internal architecture of DTrace is described in the block comments in the
  37  * <sys/dtrace_impl.h> header file.  The comments contained within the DTrace
  38  * implementation very much assume mastery of all of these sources; if one has
  39  * an unanswered question about the implementation, one should consult them
  40  * first.
  41  *
  42  * The functions here are ordered roughly as follows:
  43  *
  44  *   - Probe context functions


3522                 if (!dtrace_priv_proc(state, mstate))
3523                         return (0);
3524 
3525                 /*
3526                  * See comment in DIF_VAR_PID.
3527                  */
3528                 if (DTRACE_ANCHORED(mstate->dtms_probe) && CPU_ON_INTR(CPU))
3529                         return (0);
3530 
3531                 /*
3532                  * It is always safe to dereference one's own t_lwp pointer in
3533                  * the event that this pointer is non-NULL.  (This is true
3534                  * because threads and lwps don't clean up their own state --
3535                  * they leave that task to whomever reaps them.)
3536                  */
3537                 if ((lwp = curthread->t_lwp) == NULL)
3538                         return (0);
3539 
3540                 return ((uint64_t)lwp->lwp_errno);
3541         }



















3542         default:
3543                 DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
3544                 return (0);
3545         }
3546 }
3547 
3548 static void
3549 dtrace_dif_variable_write(dtrace_mstate_t *mstate, dtrace_state_t *state,
3550     uint64_t v, uint64_t ndx, uint64_t data)
3551 {
3552         switch (v) {
3553         case DIF_VAR_UREGS: {
3554                 klwp_t *lwp;
3555 
3556                 if (dtrace_destructive_disallow ||
3557                     !dtrace_priv_proc_control(state, mstate)) {
3558                         return;
3559                 }
3560 
3561                 if ((lwp = curthread->t_lwp) == NULL) {




   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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2018, Joyent, Inc.
  25  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  26  */
  27 
  28 /*
  29  * DTrace - Dynamic Tracing for Solaris
  30  *
  31  * This is the implementation of the Solaris Dynamic Tracing framework
  32  * (DTrace).  The user-visible interface to DTrace is described at length in
  33  * the "Solaris Dynamic Tracing Guide".  The interfaces between the libdtrace
  34  * library, the in-kernel DTrace framework, and the DTrace providers are
  35  * described in the block comments in the <sys/dtrace.h> header file.  The
  36  * internal architecture of DTrace is described in the block comments in the
  37  * <sys/dtrace_impl.h> header file.  The comments contained within the DTrace
  38  * implementation very much assume mastery of all of these sources; if one has
  39  * an unanswered question about the implementation, one should consult them
  40  * first.
  41  *
  42  * The functions here are ordered roughly as follows:
  43  *
  44  *   - Probe context functions


3522                 if (!dtrace_priv_proc(state, mstate))
3523                         return (0);
3524 
3525                 /*
3526                  * See comment in DIF_VAR_PID.
3527                  */
3528                 if (DTRACE_ANCHORED(mstate->dtms_probe) && CPU_ON_INTR(CPU))
3529                         return (0);
3530 
3531                 /*
3532                  * It is always safe to dereference one's own t_lwp pointer in
3533                  * the event that this pointer is non-NULL.  (This is true
3534                  * because threads and lwps don't clean up their own state --
3535                  * they leave that task to whomever reaps them.)
3536                  */
3537                 if ((lwp = curthread->t_lwp) == NULL)
3538                         return (0);
3539 
3540                 return ((uint64_t)lwp->lwp_errno);
3541         }
3542 
3543         case DIF_VAR_THREADNAME:
3544                 /*
3545                  * See comment in DIF_VAR_PID.
3546                  */
3547                 if (DTRACE_ANCHORED(mstate->dtms_probe) && CPU_ON_INTR(CPU))
3548                         return (0);
3549 
3550                 if (curthread->t_name == NULL)
3551                         return (0);
3552 
3553                 /*
3554                  * Once set, ->t_name itself is never changed: any updates are
3555                  * made to the same buffer that we are pointing out.  So we are
3556                  * safe to dereference it here.
3557                  */
3558                 return (dtrace_dif_varstr((uintptr_t)curthread->t_name,
3559                     state, mstate));
3560 
3561         default:
3562                 DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
3563                 return (0);
3564         }
3565 }
3566 
3567 static void
3568 dtrace_dif_variable_write(dtrace_mstate_t *mstate, dtrace_state_t *state,
3569     uint64_t v, uint64_t ndx, uint64_t data)
3570 {
3571         switch (v) {
3572         case DIF_VAR_UREGS: {
3573                 klwp_t *lwp;
3574 
3575                 if (dtrace_destructive_disallow ||
3576                     !dtrace_priv_proc_control(state, mstate)) {
3577                         return;
3578                 }
3579 
3580                 if ((lwp = curthread->t_lwp) == NULL) {