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 +#if defined(__i386) || defined(__amd64)
  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 ↓ 361 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 +#if defined(__i386) || defined(__amd64)
      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 /* defined(__i386) || defined(__amd64) */
      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 ↓ 476 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 +#if defined(__i386) || defined(__amd64)
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 +#if defined(__i386) || defined(__amd64)
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
↓ open down ↓ 1053 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 +#if defined(__i386) || defined(__amd64)
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 +#if defined(__i386) || defined(__amd64)
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 +#if defined(__i386) || defined(__amd64)
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 /* defined(__i386) || defined(__amd64) */
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