Print this page
5383 5234 breaks build on sparc

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libproc/common/Pcore.c
          +++ new/usr/src/lib/libproc/common/Pcore.c
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  /*
  26   26   * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  27   27   * Copyright (c) 2014, Joyent, Inc. All rights reserved.
  28   28   * Copyright (c) 2013 by Delphix. All rights reserved.
       29 + * Copyright 2015 Gary Mills
  29   30   */
  30   31  
  31   32  #include <sys/types.h>
  32   33  #include <sys/utsname.h>
  33   34  #include <sys/sysmacros.h>
  34   35  #include <sys/proc.h>
  35   36  
  36   37  #include <alloca.h>
  37   38  #include <rtld_db.h>
  38   39  #include <libgen.h>
↓ open down ↓ 3 lines elided ↑ open up ↑
  42   43  #include <unistd.h>
  43   44  #include <errno.h>
  44   45  #include <gelf.h>
  45   46  #include <stddef.h>
  46   47  #include <signal.h>
  47   48  
  48   49  #include "libproc.h"
  49   50  #include "Pcontrol.h"
  50   51  #include "P32ton.h"
  51   52  #include "Putil.h"
       53 +#ifdef __x86
  52   54  #include "Pcore_linux.h"
       55 +#endif
  53   56  
  54   57  /*
  55   58   * Pcore.c - Code to initialize a ps_prochandle from a core dump.  We
  56   59   * allocate an additional structure to hold information from the core
  57   60   * file, and attach this to the standard ps_prochandle in place of the
  58   61   * ability to examine /proc/<pid>/ files.
  59   62   */
  60   63  
  61   64  /*
  62   65   * Basic i/o function for reading and writing from the process address space
↓ open down ↓ 149 lines elided ↑ open up ↑
 212  215                  if (core->core_cred != NULL)
 213  216                          free(core->core_cred);
 214  217                  if (core->core_priv != NULL)
 215  218                          free(core->core_priv);
 216  219                  if (core->core_privinfo != NULL)
 217  220                          __priv_free_info(core->core_privinfo);
 218  221                  if (core->core_ppii != NULL)
 219  222                          free(core->core_ppii);
 220  223                  if (core->core_zonename != NULL)
 221  224                          free(core->core_zonename);
 222      -#if defined(__i386) || defined(__amd64)
      225 +#ifdef __x86
 223  226                  if (core->core_ldt != NULL)
 224  227                          free(core->core_ldt);
 225  228  #endif
 226  229  
 227  230                  free(core);
 228  231          }
 229  232  }
 230  233  
 231  234  /*ARGSUSED*/
 232  235  static char *
↓ open down ↓ 31 lines elided ↑ open up ↑
 264  267          core_info_t *core = data;
 265  268  
 266  269          if (core->core_zonename == NULL) {
 267  270                  errno = ENODATA;
 268  271                  return (NULL);
 269  272          }
 270  273          (void) strlcpy(s, core->core_zonename, n);
 271  274          return (s);
 272  275  }
 273  276  
 274      -#if defined(__i386) || defined(__amd64)
      277 +#ifdef __x86
 275  278  /*ARGSUSED*/
 276  279  static int
 277  280  Pldt_core(struct ps_prochandle *P, struct ssd *pldt, int nldt, void *data)
 278  281  {
 279  282          core_info_t *core = data;
 280  283  
 281  284          if (pldt == NULL || nldt == 0)
 282  285                  return (core->core_nldt);
 283  286  
 284  287          if (core->core_ldt != NULL) {
↓ open down ↓ 13 lines elided ↑ open up ↑
 298  301  static const ps_ops_t P_core_ops = {
 299  302          .pop_pread      = Pread_core,
 300  303          .pop_pwrite     = Pwrite_core,
 301  304          .pop_cred       = Pcred_core,
 302  305          .pop_priv       = Ppriv_core,
 303  306          .pop_psinfo     = Ppsinfo_core,
 304  307          .pop_fini       = Pfini_core,
 305  308          .pop_platform   = Pplatform_core,
 306  309          .pop_uname      = Puname_core,
 307  310          .pop_zonename   = Pzonename_core,
 308      -#if defined(__i386) || defined(__amd64)
      311 +#ifdef __x86
 309  312          .pop_ldt        = Pldt_core
 310  313  #endif
 311  314  };
 312  315  
 313  316  /*
 314  317   * Return the lwp_info_t for the given lwpid.  If no such lwpid has been
 315  318   * encountered yet, allocate a new structure and return a pointer to it.
 316  319   * Create a list of lwp_info_t structures sorted in decreasing lwp_id order.
 317  320   */
 318  321  static lwp_info_t *
↓ open down ↓ 105 lines elided ↑ open up ↑
 424  427                  lps.pr_cursig = 0;
 425  428  
 426  429          (void) memcpy(&lwp->lwp_status, &lps, sizeof (lps));
 427  430          return (0);
 428  431  
 429  432  err:
 430  433          dprintf("Pgrab_core: failed to read NT_LWPSTATUS\n");
 431  434          return (-1);
 432  435  }
 433  436  
      437 +#ifdef __x86
      438 +
 434  439  static void
 435  440  lx_prpsinfo32_to_psinfo(lx_prpsinfo32_t *p32, psinfo_t *psinfo)
 436  441  {
 437  442          psinfo->pr_flag = p32->pr_flag;
 438  443          psinfo->pr_pid = p32->pr_pid;
 439  444          psinfo->pr_ppid = p32->pr_ppid;
 440  445          psinfo->pr_uid = p32->pr_uid;
 441  446          psinfo->pr_gid = p32->pr_gid;
 442  447          psinfo->pr_sid = p32->pr_sid;
 443  448          psinfo->pr_pgid = p32->pr_pgrp;
↓ open down ↓ 178 lines elided ↑ open up ↑
 622  627                  lx_prstatus32_to_lwp(&prs32, lwp);
 623  628          else
 624  629                  lx_prstatus64_to_lwp(&prs64, lwp);
 625  630  
 626  631          return (0);
 627  632  err:
 628  633          dprintf("Pgrab_core: failed to read NT_PRSTATUS\n");
 629  634          return (-1);
 630  635  }
 631  636  
      637 +#endif /* __x86 */
      638 +
 632  639  static int
 633  640  note_psinfo(struct ps_prochandle *P, size_t nbytes)
 634  641  {
 635  642  #ifdef _LP64
 636  643          core_info_t *core = P->data;
 637  644  
 638  645          if (core->core_dmodel == PR_MODEL_ILP32) {
 639  646                  psinfo32_t ps32;
 640  647  
 641  648                  if (nbytes < sizeof (psinfo32_t) ||
↓ open down ↓ 178 lines elided ↑ open up ↑
 820  827          if (pcrp->pr_ngroups > ngroups) {
 821  828                  dprintf("pr_ngroups = %d; resetting to %d based on note size\n",
 822  829                      pcrp->pr_ngroups, ngroups);
 823  830                  pcrp->pr_ngroups = ngroups;
 824  831          }
 825  832  
 826  833          core->core_cred = pcrp;
 827  834          return (0);
 828  835  }
 829  836  
 830      -#if defined(__i386) || defined(__amd64)
      837 +#ifdef __x86
 831  838  static int
 832  839  note_ldt(struct ps_prochandle *P, size_t nbytes)
 833  840  {
 834  841          core_info_t *core = P->data;
 835  842          struct ssd *pldt;
 836  843          uint_t nldt;
 837  844  
 838  845          if (core->core_ldt != NULL || nbytes < sizeof (struct ssd))
 839  846                  return (0);     /* Already seen or bad size */
 840  847  
↓ open down ↓ 277 lines elided ↑ open up ↑
1118 1125              (ulong_t)nbytes);
1119 1126          return (0);
1120 1127  }
1121 1128  
1122 1129  /*
1123 1130   * Populate a table of function pointers indexed by Note type with our
1124 1131   * functions to process each type of core file note:
1125 1132   */
1126 1133  static int (*nhdlrs[])(struct ps_prochandle *, size_t) = {
1127 1134          note_notsup,            /*  0   unassigned              */
     1135 +#ifdef __x86
1128 1136          note_linux_prstatus,            /*  1   NT_PRSTATUS (old)       */
     1137 +#else
     1138 +        note_notsup,            /*  1   NT_PRSTATUS (old)       */
     1139 +#endif
1129 1140          note_notsup,            /*  2   NT_PRFPREG (old)        */
     1141 +#ifdef __x86
1130 1142          note_linux_psinfo,              /*  3   NT_PRPSINFO (old)       */
     1143 +#else
     1144 +        note_notsup,            /*  3   NT_PRPSINFO (old)       */
     1145 +#endif
1131 1146  #ifdef __sparc
1132 1147          note_xreg,              /*  4   NT_PRXREG               */
1133 1148  #else
1134 1149          note_notsup,            /*  4   NT_PRXREG               */
1135 1150  #endif
1136 1151          note_platform,          /*  5   NT_PLATFORM             */
1137 1152          note_auxv,              /*  6   NT_AUXV                 */
1138 1153  #ifdef __sparc
1139 1154          note_gwindows,          /*  7   NT_GWINDOWS             */
1140 1155  #ifdef __sparcv9
1141 1156          note_asrs,              /*  8   NT_ASRS                 */
1142 1157  #else
1143 1158          note_notsup,            /*  8   NT_ASRS                 */
1144 1159  #endif
1145 1160  #else
1146 1161          note_notsup,            /*  7   NT_GWINDOWS             */
1147 1162          note_notsup,            /*  8   NT_ASRS                 */
1148 1163  #endif
1149      -#if defined(__i386) || defined(__amd64)
     1164 +#ifdef __x86
1150 1165          note_ldt,               /*  9   NT_LDT                  */
1151 1166  #else
1152 1167          note_notsup,            /*  9   NT_LDT                  */
1153 1168  #endif
1154 1169          note_pstatus,           /* 10   NT_PSTATUS              */
1155 1170          note_notsup,            /* 11   unassigned              */
1156 1171          note_notsup,            /* 12   unassigned              */
1157 1172          note_psinfo,            /* 13   NT_PSINFO               */
1158 1173          note_cred,              /* 14   NT_PRCRED               */
1159 1174          note_utsname,           /* 15   NT_UTSNAME              */
↓ open down ↓ 1034 lines elided ↑ open up ↑
2194 2209          struct ps_prochandle *P;
2195 2210          core_info_t *core_info;
2196 2211          map_info_t *stk_mp, *brk_mp;
2197 2212          const char *execname;
2198 2213          char *interp;
2199 2214          int i, notes, pagesize;
2200 2215          uintptr_t addr, base_addr;
2201 2216          struct stat64 stbuf;
2202 2217          void *phbuf, *php;
2203 2218          size_t nbytes;
     2219 +#ifdef __x86
2204 2220          boolean_t from_linux = B_FALSE;
     2221 +#endif
2205 2222  
2206 2223          elf_file_t aout;
2207 2224          elf_file_t core;
2208 2225  
2209 2226          Elf_Scn *scn, *intp_scn = NULL;
2210 2227          Elf_Data *dp;
2211 2228  
2212 2229          GElf_Phdr phdr, note_phdr;
2213 2230          GElf_Shdr shdr;
2214 2231          GElf_Xword nleft;
↓ open down ↓ 227 lines elided ↑ open up ↑
2442 2459                          if (nhdlrs[nhdr.n_type](P, nhdr.n_descsz) < 0) {
2443 2460                                  dprintf("handler for type %d returned < 0",
2444 2461                                      nhdr.n_type);
2445 2462                                  *perr = G_NOTE;
2446 2463                                  goto err;
2447 2464                          }
2448 2465                          /*
2449 2466                           * The presence of either of these notes indicates that
2450 2467                           * the dump was generated on Linux.
2451 2468                           */
     2469 +#ifdef __x86
2452 2470                          if (nhdr.n_type == NT_PRSTATUS ||
2453 2471                              nhdr.n_type == NT_PRPSINFO)
2454 2472                                  from_linux = B_TRUE;
     2473 +#endif
2455 2474                  } else {
2456 2475                          (void) note_notsup(P, nhdr.n_descsz);
2457 2476                  }
2458 2477  
2459 2478                  /*
2460 2479                   * Seek past the current note data to the next Elf_Nhdr
2461 2480                   */
2462 2481                  descsz = P2ROUNDUP((off64_t)nhdr.n_descsz, (off64_t)4);
2463 2482                  if (lseek64(P->asfd, off + descsz, SEEK_SET) == (off64_t)-1) {
2464 2483                          dprintf("Pgrab_core: failed to seek to next nhdr\n");
↓ open down ↓ 1 lines elided ↑ open up ↑
2466 2485                          goto err;
2467 2486                  }
2468 2487  
2469 2488                  /*
2470 2489                   * Subtract the size of the header and its data from what
2471 2490                   * we have left to process.
2472 2491                   */
2473 2492                  nleft -= sizeof (nhdr) + namesz + descsz;
2474 2493          }
2475 2494  
     2495 +#ifdef __x86
2476 2496          if (from_linux) {
2477 2497                  size_t tcount, pid;
2478 2498                  lwp_info_t *lwp;
2479 2499  
2480 2500                  P->status.pr_dmodel = core_info->core_dmodel;
2481 2501  
2482 2502                  lwp = list_next(&core_info->core_lwp_head);
2483 2503  
2484 2504                  pid = P->status.pr_pid;
2485 2505  
↓ open down ↓ 33 lines elided ↑ open up ↑
2519 2539  
2520 2540                  dprintf("setting representative thread: %d\n", lwp->lwp_id);
2521 2541  
2522 2542                  lwp->lwp_id = 1;
2523 2543                  lwp->lwp_status.pr_lwpid = 1;
2524 2544  
2525 2545                  /* set representative thread */
2526 2546                  (void) memcpy(&P->status.pr_lwp, &lwp->lwp_status,
2527 2547                      sizeof (P->status.pr_lwp));
2528 2548          }
     2549 +#endif /* __x86 */
2529 2550  
2530 2551          if (nleft != 0) {
2531 2552                  dprintf("Pgrab_core: note section malformed\n");
2532 2553                  *perr = G_STRANGE;
2533 2554                  goto err;
2534 2555          }
2535 2556  
2536 2557          if ((pagesize = Pgetauxval(P, AT_PAGESZ)) == -1) {
2537 2558                  pagesize = getpagesize();
2538 2559                  dprintf("AT_PAGESZ missing; defaulting to %d\n", pagesize);
↓ open down ↓ 232 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX