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


   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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  27  * Copyright (c) 2014, Joyent, Inc. All rights reserved.
  28  * Copyright (c) 2013 by Delphix. All rights reserved.
  29  * Copyright 2015 Gary Mills
  30  */
  31 
  32 #include <sys/types.h>
  33 #include <sys/utsname.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/proc.h>
  36 
  37 #include <alloca.h>
  38 #include <rtld_db.h>
  39 #include <libgen.h>
  40 #include <limits.h>
  41 #include <string.h>
  42 #include <stdlib.h>
  43 #include <unistd.h>
  44 #include <errno.h>
  45 #include <gelf.h>
  46 #include <stddef.h>
  47 #include <signal.h>


 709         } else
 710 #endif
 711         if (nbytes < sizeof (lwpsinfo_t) ||
 712             read(P->asfd, &lps, sizeof (lps)) != sizeof (lps))
 713                 goto err;
 714 
 715         if ((lwp = lwpid2info(P, lps.pr_lwpid)) == NULL) {
 716                 dprintf("Pgrab_core: failed to add NT_LWPSINFO\n");
 717                 return (-1);
 718         }
 719 
 720         (void) memcpy(&lwp->lwp_psinfo, &lps, sizeof (lps));
 721         return (0);
 722 
 723 err:
 724         dprintf("Pgrab_core: failed to read NT_LWPSINFO\n");
 725         return (-1);
 726 }
 727 
 728 static int


























 729 note_fdinfo(struct ps_prochandle *P, size_t nbytes)
 730 {
 731         prfdinfo_t prfd;
 732         fd_info_t *fip;
 733 
 734         if ((nbytes < sizeof (prfd)) ||
 735             (read(P->asfd, &prfd, sizeof (prfd)) != sizeof (prfd))) {
 736                 dprintf("Pgrab_core: failed to read NT_FDINFO\n");
 737                 return (-1);
 738         }
 739 
 740         if ((fip = Pfd2info(P, prfd.pr_fd)) == NULL) {
 741                 dprintf("Pgrab_core: failed to add NT_FDINFO\n");
 742                 return (-1);
 743         }
 744         (void) memcpy(&fip->fd_info, &prfd, sizeof (prfd));
 745         return (0);
 746 }
 747 
 748 static int


1214 #ifdef __x86
1215         note_ldt,               /*  9   NT_LDT                  */
1216 #else
1217         note_notsup,            /*  9   NT_LDT                  */
1218 #endif
1219         note_pstatus,           /* 10   NT_PSTATUS              */
1220         note_notsup,            /* 11   unassigned              */
1221         note_notsup,            /* 12   unassigned              */
1222         note_psinfo,            /* 13   NT_PSINFO               */
1223         note_cred,              /* 14   NT_PRCRED               */
1224         note_utsname,           /* 15   NT_UTSNAME              */
1225         note_lwpstatus,         /* 16   NT_LWPSTATUS            */
1226         note_lwpsinfo,          /* 17   NT_LWPSINFO             */
1227         note_priv,              /* 18   NT_PRPRIV               */
1228         note_priv_info,         /* 19   NT_PRPRIVINFO           */
1229         note_content,           /* 20   NT_CONTENT              */
1230         note_zonename,          /* 21   NT_ZONENAME             */
1231         note_fdinfo,            /* 22   NT_FDINFO               */
1232         note_spymaster,         /* 23   NT_SPYMASTER            */
1233         note_secflags,          /* 24   NT_SECFLAGS             */

1234 };
1235 
1236 static void
1237 core_report_mapping(struct ps_prochandle *P, GElf_Phdr *php)
1238 {
1239         prkillinfo_t killinfo;
1240         siginfo_t *si = &killinfo.prk_info;
1241         char signame[SIG2STR_MAX], sig[64], info[64];
1242         void *addr = (void *)(uintptr_t)php->p_vaddr;
1243 
1244         const char *errfmt = "core file data for mapping at %p not saved: %s\n";
1245         const char *incfmt = "core file incomplete due to %s%s\n";
1246         const char *msgfmt = "mappings at and above %p are missing\n";
1247 
1248         if (!(php->p_flags & PF_SUNW_KILLED)) {
1249                 int err = 0;
1250 
1251                 (void) pread64(P->asfd, &err,
1252                     sizeof (err), (off64_t)php->p_offset);
1253 




   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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  27  * Copyright (c) 2018, Joyent, Inc. All rights reserved.
  28  * Copyright (c) 2013 by Delphix. All rights reserved.
  29  * Copyright 2015 Gary Mills
  30  */
  31 
  32 #include <sys/types.h>
  33 #include <sys/utsname.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/proc.h>
  36 
  37 #include <alloca.h>
  38 #include <rtld_db.h>
  39 #include <libgen.h>
  40 #include <limits.h>
  41 #include <string.h>
  42 #include <stdlib.h>
  43 #include <unistd.h>
  44 #include <errno.h>
  45 #include <gelf.h>
  46 #include <stddef.h>
  47 #include <signal.h>


 709         } else
 710 #endif
 711         if (nbytes < sizeof (lwpsinfo_t) ||
 712             read(P->asfd, &lps, sizeof (lps)) != sizeof (lps))
 713                 goto err;
 714 
 715         if ((lwp = lwpid2info(P, lps.pr_lwpid)) == NULL) {
 716                 dprintf("Pgrab_core: failed to add NT_LWPSINFO\n");
 717                 return (-1);
 718         }
 719 
 720         (void) memcpy(&lwp->lwp_psinfo, &lps, sizeof (lps));
 721         return (0);
 722 
 723 err:
 724         dprintf("Pgrab_core: failed to read NT_LWPSINFO\n");
 725         return (-1);
 726 }
 727 
 728 static int
 729 note_lwpname(struct ps_prochandle *P, size_t nbytes)
 730 {
 731         prlwpname_t name;
 732         lwp_info_t *lwp;
 733 
 734         if (nbytes != sizeof (name) ||
 735             read(P->asfd, &name, sizeof (name)) != sizeof (name))
 736                 goto err;
 737 
 738         if ((lwp = lwpid2info(P, name.pr_lwpid)) == NULL)
 739                 goto err;
 740 
 741         if (strlcpy(lwp->lwp_name, name.pr_lwpname,
 742             sizeof (lwp->lwp_name)) >= sizeof (lwp->lwp_name)) {
 743                 errno = ENAMETOOLONG;
 744                 goto err;
 745         }
 746 
 747         return (0);
 748 
 749 err:
 750         dprintf("Pgrab_core: failed to read NT_LWPNAME\n");
 751         return (-1);
 752 }
 753 
 754 static int
 755 note_fdinfo(struct ps_prochandle *P, size_t nbytes)
 756 {
 757         prfdinfo_t prfd;
 758         fd_info_t *fip;
 759 
 760         if ((nbytes < sizeof (prfd)) ||
 761             (read(P->asfd, &prfd, sizeof (prfd)) != sizeof (prfd))) {
 762                 dprintf("Pgrab_core: failed to read NT_FDINFO\n");
 763                 return (-1);
 764         }
 765 
 766         if ((fip = Pfd2info(P, prfd.pr_fd)) == NULL) {
 767                 dprintf("Pgrab_core: failed to add NT_FDINFO\n");
 768                 return (-1);
 769         }
 770         (void) memcpy(&fip->fd_info, &prfd, sizeof (prfd));
 771         return (0);
 772 }
 773 
 774 static int


1240 #ifdef __x86
1241         note_ldt,               /*  9   NT_LDT                  */
1242 #else
1243         note_notsup,            /*  9   NT_LDT                  */
1244 #endif
1245         note_pstatus,           /* 10   NT_PSTATUS              */
1246         note_notsup,            /* 11   unassigned              */
1247         note_notsup,            /* 12   unassigned              */
1248         note_psinfo,            /* 13   NT_PSINFO               */
1249         note_cred,              /* 14   NT_PRCRED               */
1250         note_utsname,           /* 15   NT_UTSNAME              */
1251         note_lwpstatus,         /* 16   NT_LWPSTATUS            */
1252         note_lwpsinfo,          /* 17   NT_LWPSINFO             */
1253         note_priv,              /* 18   NT_PRPRIV               */
1254         note_priv_info,         /* 19   NT_PRPRIVINFO           */
1255         note_content,           /* 20   NT_CONTENT              */
1256         note_zonename,          /* 21   NT_ZONENAME             */
1257         note_fdinfo,            /* 22   NT_FDINFO               */
1258         note_spymaster,         /* 23   NT_SPYMASTER            */
1259         note_secflags,          /* 24   NT_SECFLAGS             */
1260         note_lwpname,           /* 25   NT_LWPNAME              */
1261 };
1262 
1263 static void
1264 core_report_mapping(struct ps_prochandle *P, GElf_Phdr *php)
1265 {
1266         prkillinfo_t killinfo;
1267         siginfo_t *si = &killinfo.prk_info;
1268         char signame[SIG2STR_MAX], sig[64], info[64];
1269         void *addr = (void *)(uintptr_t)php->p_vaddr;
1270 
1271         const char *errfmt = "core file data for mapping at %p not saved: %s\n";
1272         const char *incfmt = "core file incomplete due to %s%s\n";
1273         const char *msgfmt = "mappings at and above %p are missing\n";
1274 
1275         if (!(php->p_flags & PF_SUNW_KILLED)) {
1276                 int err = 0;
1277 
1278                 (void) pread64(P->asfd, &err,
1279                     sizeof (err), (off64_t)php->p_offset);
1280