17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*9acbbeafSnn35248 * Common Development and Distribution License (the "License"). 6*9acbbeafSnn35248 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*9acbbeafSnn35248 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/uio.h> 307c478bd9Sstevel@tonic-gate #include <string.h> 317c478bd9Sstevel@tonic-gate #include <errno.h> 32*9acbbeafSnn35248 #include <limits.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include "Pcontrol.h" 357c478bd9Sstevel@tonic-gate #include "P32ton.h" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * This file implements the routines to read and write per-lwp register 397c478bd9Sstevel@tonic-gate * information from either a live process or core file opened with libproc. 407c478bd9Sstevel@tonic-gate * We build up a few common routines for reading and writing register 417c478bd9Sstevel@tonic-gate * information, and then the public functions are all trivial calls to these. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * Utility function to return a pointer to the structure of cached information 467c478bd9Sstevel@tonic-gate * about an lwp in the core file, given its lwpid. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate static lwp_info_t * 497c478bd9Sstevel@tonic-gate getlwpcore(struct ps_prochandle *P, lwpid_t lwpid) 507c478bd9Sstevel@tonic-gate { 517c478bd9Sstevel@tonic-gate lwp_info_t *lwp = list_next(&P->core->core_lwp_head); 527c478bd9Sstevel@tonic-gate uint_t i; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate for (i = 0; i < P->core->core_nlwp; i++, lwp = list_next(lwp)) { 557c478bd9Sstevel@tonic-gate if (lwp->lwp_id == lwpid) 567c478bd9Sstevel@tonic-gate return (lwp); 577c478bd9Sstevel@tonic-gate } 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate errno = EINVAL; 607c478bd9Sstevel@tonic-gate return (NULL); 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Utility function to open and read the contents of a per-lwp /proc file. 657c478bd9Sstevel@tonic-gate * This function is used to slurp in lwpstatus, xregs, and asrs. 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate static int 687c478bd9Sstevel@tonic-gate getlwpfile(struct ps_prochandle *P, lwpid_t lwpid, 697c478bd9Sstevel@tonic-gate const char *fbase, void *rp, size_t n) 707c478bd9Sstevel@tonic-gate { 71*9acbbeafSnn35248 char fname[PATH_MAX]; 727c478bd9Sstevel@tonic-gate int fd; 737c478bd9Sstevel@tonic-gate 74*9acbbeafSnn35248 (void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/%s", 75*9acbbeafSnn35248 procfs_path, (int)P->status.pr_pid, (int)lwpid, fbase); 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate if ((fd = open(fname, O_RDONLY)) >= 0) { 787c478bd9Sstevel@tonic-gate if (read(fd, rp, n) > 0) { 797c478bd9Sstevel@tonic-gate (void) close(fd); 807c478bd9Sstevel@tonic-gate return (0); 817c478bd9Sstevel@tonic-gate } 827c478bd9Sstevel@tonic-gate (void) close(fd); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate return (-1); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * Get the lwpstatus_t for an lwp from either the live process or our 897c478bd9Sstevel@tonic-gate * cached information from the core file. This is used to get the 907c478bd9Sstevel@tonic-gate * general-purpose registers or floating point registers. 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate int 937c478bd9Sstevel@tonic-gate getlwpstatus(struct ps_prochandle *P, lwpid_t lwpid, lwpstatus_t *lps) 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * For both live processes and cores, our job is easy if the lwpid 997c478bd9Sstevel@tonic-gate * matches that of the representative lwp: 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate if (P->status.pr_lwp.pr_lwpid == lwpid) { 1027c478bd9Sstevel@tonic-gate (void) memcpy(lps, &P->status.pr_lwp, sizeof (lwpstatus_t)); 1037c478bd9Sstevel@tonic-gate return (0); 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * If this is a live process, then just read the information out 1087c478bd9Sstevel@tonic-gate * of the per-lwp status file: 1097c478bd9Sstevel@tonic-gate */ 1107c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 1117c478bd9Sstevel@tonic-gate return (getlwpfile(P, lwpid, "lwpstatus", 1127c478bd9Sstevel@tonic-gate lps, sizeof (lwpstatus_t))); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * If this is a core file, we need to iterate through our list of 1177c478bd9Sstevel@tonic-gate * cached lwp information and then copy out the status. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate if (P->core != NULL && (lwp = getlwpcore(P, lwpid)) != NULL) { 1207c478bd9Sstevel@tonic-gate (void) memcpy(lps, &lwp->lwp_status, sizeof (lwpstatus_t)); 1217c478bd9Sstevel@tonic-gate return (0); 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate return (-1); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * Utility function to modify lwp registers. This is done using either the 1297c478bd9Sstevel@tonic-gate * process control file or per-lwp control file as necessary. 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate static int 1327c478bd9Sstevel@tonic-gate setlwpregs(struct ps_prochandle *P, lwpid_t lwpid, long cmd, 1337c478bd9Sstevel@tonic-gate const void *rp, size_t n) 1347c478bd9Sstevel@tonic-gate { 1357c478bd9Sstevel@tonic-gate iovec_t iov[2]; 136*9acbbeafSnn35248 char fname[PATH_MAX]; 1377c478bd9Sstevel@tonic-gate int fd; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate if (P->state != PS_STOP) { 1407c478bd9Sstevel@tonic-gate errno = EBUSY; 1417c478bd9Sstevel@tonic-gate return (-1); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate iov[0].iov_base = (caddr_t)&cmd; 1457c478bd9Sstevel@tonic-gate iov[0].iov_len = sizeof (long); 1467c478bd9Sstevel@tonic-gate iov[1].iov_base = (caddr_t)rp; 1477c478bd9Sstevel@tonic-gate iov[1].iov_len = n; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * Writing the process control file writes the representative lwp. 1517c478bd9Sstevel@tonic-gate * Psync before we write to make sure we are consistent with the 1527c478bd9Sstevel@tonic-gate * primary interfaces. Similarly, make sure to update P->status 1537c478bd9Sstevel@tonic-gate * afterward if we are modifying one of its register sets. 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate if (P->status.pr_lwp.pr_lwpid == lwpid) { 1567c478bd9Sstevel@tonic-gate Psync(P); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate if (writev(P->ctlfd, iov, 2) == -1) 1597c478bd9Sstevel@tonic-gate return (-1); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate if (cmd == PCSREG) 1627c478bd9Sstevel@tonic-gate (void) memcpy(P->status.pr_lwp.pr_reg, rp, n); 1637c478bd9Sstevel@tonic-gate else if (cmd == PCSFPREG) 1647c478bd9Sstevel@tonic-gate (void) memcpy(&P->status.pr_lwp.pr_fpreg, rp, n); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate return (0); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * If the lwp we want is not the representative lwp, we need to 1717c478bd9Sstevel@tonic-gate * open the ctl file for that specific lwp. 1727c478bd9Sstevel@tonic-gate */ 173*9acbbeafSnn35248 (void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/lwpctl", 174*9acbbeafSnn35248 procfs_path, (int)P->status.pr_pid, (int)lwpid); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate if ((fd = open(fname, O_WRONLY)) >= 0) { 1777c478bd9Sstevel@tonic-gate if (writev(fd, iov, 2) > 0) { 1787c478bd9Sstevel@tonic-gate (void) close(fd); 1797c478bd9Sstevel@tonic-gate return (0); 1807c478bd9Sstevel@tonic-gate } 1817c478bd9Sstevel@tonic-gate (void) close(fd); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate return (-1); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate int 1877c478bd9Sstevel@tonic-gate Plwp_getregs(struct ps_prochandle *P, lwpid_t lwpid, prgregset_t gregs) 1887c478bd9Sstevel@tonic-gate { 1897c478bd9Sstevel@tonic-gate lwpstatus_t lps; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate if (getlwpstatus(P, lwpid, &lps) == -1) 1927c478bd9Sstevel@tonic-gate return (-1); 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate (void) memcpy(gregs, lps.pr_reg, sizeof (prgregset_t)); 1957c478bd9Sstevel@tonic-gate return (0); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate int 1997c478bd9Sstevel@tonic-gate Plwp_setregs(struct ps_prochandle *P, lwpid_t lwpid, const prgregset_t gregs) 2007c478bd9Sstevel@tonic-gate { 2017c478bd9Sstevel@tonic-gate return (setlwpregs(P, lwpid, PCSREG, gregs, sizeof (prgregset_t))); 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate int 2057c478bd9Sstevel@tonic-gate Plwp_getfpregs(struct ps_prochandle *P, lwpid_t lwpid, prfpregset_t *fpregs) 2067c478bd9Sstevel@tonic-gate { 2077c478bd9Sstevel@tonic-gate lwpstatus_t lps; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate if (getlwpstatus(P, lwpid, &lps) == -1) 2107c478bd9Sstevel@tonic-gate return (-1); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate (void) memcpy(fpregs, &lps.pr_fpreg, sizeof (prfpregset_t)); 2137c478bd9Sstevel@tonic-gate return (0); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate int Plwp_setfpregs(struct ps_prochandle *P, lwpid_t lwpid, 2177c478bd9Sstevel@tonic-gate const prfpregset_t *fpregs) 2187c478bd9Sstevel@tonic-gate { 2197c478bd9Sstevel@tonic-gate return (setlwpregs(P, lwpid, PCSFPREG, fpregs, sizeof (prfpregset_t))); 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate #if defined(sparc) || defined(__sparc) 2237c478bd9Sstevel@tonic-gate int 2247c478bd9Sstevel@tonic-gate Plwp_getxregs(struct ps_prochandle *P, lwpid_t lwpid, prxregset_t *xregs) 2257c478bd9Sstevel@tonic-gate { 2267c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 2297c478bd9Sstevel@tonic-gate errno = ENODATA; 2307c478bd9Sstevel@tonic-gate return (-1); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 2347c478bd9Sstevel@tonic-gate if (P->state != PS_STOP) { 2357c478bd9Sstevel@tonic-gate errno = EBUSY; 2367c478bd9Sstevel@tonic-gate return (-1); 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate return (getlwpfile(P, lwpid, "xregs", 2407c478bd9Sstevel@tonic-gate xregs, sizeof (prxregset_t))); 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) != NULL && lwp->lwp_xregs != NULL) { 2447c478bd9Sstevel@tonic-gate (void) memcpy(xregs, lwp->lwp_xregs, sizeof (prxregset_t)); 2457c478bd9Sstevel@tonic-gate return (0); 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate if (lwp != NULL) 2497c478bd9Sstevel@tonic-gate errno = ENODATA; 2507c478bd9Sstevel@tonic-gate return (-1); 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate int 2547c478bd9Sstevel@tonic-gate Plwp_setxregs(struct ps_prochandle *P, lwpid_t lwpid, const prxregset_t *xregs) 2557c478bd9Sstevel@tonic-gate { 2567c478bd9Sstevel@tonic-gate return (setlwpregs(P, lwpid, PCSXREG, xregs, sizeof (prxregset_t))); 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate int 2607c478bd9Sstevel@tonic-gate Plwp_getgwindows(struct ps_prochandle *P, lwpid_t lwpid, gwindows_t *gwins) 2617c478bd9Sstevel@tonic-gate { 2627c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 2657c478bd9Sstevel@tonic-gate errno = ENODATA; 2667c478bd9Sstevel@tonic-gate return (-1); 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 2707c478bd9Sstevel@tonic-gate if (P->state != PS_STOP) { 2717c478bd9Sstevel@tonic-gate errno = EBUSY; 2727c478bd9Sstevel@tonic-gate return (-1); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate return (getlwpfile(P, lwpid, "gwindows", 2767c478bd9Sstevel@tonic-gate gwins, sizeof (gwindows_t))); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) != NULL && lwp->lwp_gwins != NULL) { 2807c478bd9Sstevel@tonic-gate *gwins = *lwp->lwp_gwins; 2817c478bd9Sstevel@tonic-gate return (0); 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate if (lwp != NULL) 2857c478bd9Sstevel@tonic-gate errno = ENODATA; 2867c478bd9Sstevel@tonic-gate return (-1); 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate #if defined(__sparcv9) 2907c478bd9Sstevel@tonic-gate int 2917c478bd9Sstevel@tonic-gate Plwp_getasrs(struct ps_prochandle *P, lwpid_t lwpid, asrset_t asrs) 2927c478bd9Sstevel@tonic-gate { 2937c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 2967c478bd9Sstevel@tonic-gate errno = ENODATA; 2977c478bd9Sstevel@tonic-gate return (-1); 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 3017c478bd9Sstevel@tonic-gate if (P->state != PS_STOP) { 3027c478bd9Sstevel@tonic-gate errno = EBUSY; 3037c478bd9Sstevel@tonic-gate return (-1); 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate return (getlwpfile(P, lwpid, "asrs", asrs, sizeof (asrset_t))); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) != NULL && lwp->lwp_asrs != NULL) { 3107c478bd9Sstevel@tonic-gate (void) memcpy(asrs, lwp->lwp_asrs, sizeof (asrset_t)); 3117c478bd9Sstevel@tonic-gate return (0); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate if (lwp != NULL) 3157c478bd9Sstevel@tonic-gate errno = ENODATA; 3167c478bd9Sstevel@tonic-gate return (-1); 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate } 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate int 3217c478bd9Sstevel@tonic-gate Plwp_setasrs(struct ps_prochandle *P, lwpid_t lwpid, const asrset_t asrs) 3227c478bd9Sstevel@tonic-gate { 3237c478bd9Sstevel@tonic-gate return (setlwpregs(P, lwpid, PCSASRS, asrs, sizeof (asrset_t))); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */ 3267c478bd9Sstevel@tonic-gate #endif /* __sparc */ 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate int 3297c478bd9Sstevel@tonic-gate Plwp_getpsinfo(struct ps_prochandle *P, lwpid_t lwpid, lwpsinfo_t *lps) 3307c478bd9Sstevel@tonic-gate { 3317c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 3347c478bd9Sstevel@tonic-gate errno = ENODATA; 3357c478bd9Sstevel@tonic-gate return (-1); 3367c478bd9Sstevel@tonic-gate } 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 3397c478bd9Sstevel@tonic-gate return (getlwpfile(P, lwpid, "lwpsinfo", 3407c478bd9Sstevel@tonic-gate lps, sizeof (lwpsinfo_t))); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) != NULL) { 3447c478bd9Sstevel@tonic-gate (void) memcpy(lps, &lwp->lwp_psinfo, sizeof (lwpsinfo_t)); 3457c478bd9Sstevel@tonic-gate return (0); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate return (-1); 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate int 3527c478bd9Sstevel@tonic-gate Plwp_stack(struct ps_prochandle *P, lwpid_t lwpid, stack_t *stkp) 3537c478bd9Sstevel@tonic-gate { 3547c478bd9Sstevel@tonic-gate uintptr_t addr; 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 3577c478bd9Sstevel@tonic-gate errno = ENODATA; 3587c478bd9Sstevel@tonic-gate return (-1); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 3627c478bd9Sstevel@tonic-gate lwpstatus_t ls; 3637c478bd9Sstevel@tonic-gate if (getlwpfile(P, lwpid, "lwpstatus", &ls, sizeof (ls)) != 0) 3647c478bd9Sstevel@tonic-gate return (-1); 3657c478bd9Sstevel@tonic-gate addr = ls.pr_ustack; 3667c478bd9Sstevel@tonic-gate } else { 3677c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 3687c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) == NULL) 3697c478bd9Sstevel@tonic-gate return (-1); 3707c478bd9Sstevel@tonic-gate addr = lwp->lwp_status.pr_ustack; 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate if (P->status.pr_dmodel == PR_MODEL_NATIVE) { 3757c478bd9Sstevel@tonic-gate if (Pread(P, stkp, sizeof (*stkp), addr) != sizeof (*stkp)) 3767c478bd9Sstevel@tonic-gate return (-1); 3777c478bd9Sstevel@tonic-gate #ifdef _LP64 3787c478bd9Sstevel@tonic-gate } else { 3797c478bd9Sstevel@tonic-gate stack32_t stk32; 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate if (Pread(P, &stk32, sizeof (stk32), addr) != sizeof (stk32)) 3827c478bd9Sstevel@tonic-gate return (-1); 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate stack_32_to_n(&stk32, stkp); 3857c478bd9Sstevel@tonic-gate #endif 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate return (0); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate int 3927c478bd9Sstevel@tonic-gate Plwp_main_stack(struct ps_prochandle *P, lwpid_t lwpid, stack_t *stkp) 3937c478bd9Sstevel@tonic-gate { 3947c478bd9Sstevel@tonic-gate uintptr_t addr; 3957c478bd9Sstevel@tonic-gate lwpstatus_t ls; 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 3987c478bd9Sstevel@tonic-gate errno = ENODATA; 3997c478bd9Sstevel@tonic-gate return (-1); 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 4037c478bd9Sstevel@tonic-gate if (getlwpfile(P, lwpid, "lwpstatus", &ls, sizeof (ls)) != 0) 4047c478bd9Sstevel@tonic-gate return (-1); 4057c478bd9Sstevel@tonic-gate } else { 4067c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 4077c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) == NULL) 4087c478bd9Sstevel@tonic-gate return (-1); 4097c478bd9Sstevel@tonic-gate ls = lwp->lwp_status; 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate addr = ls.pr_ustack; 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate /* 4157c478bd9Sstevel@tonic-gate * Read out the current stack; if the SS_ONSTACK flag is set then 4167c478bd9Sstevel@tonic-gate * this LWP is operating on the alternate signal stack. We can 4177c478bd9Sstevel@tonic-gate * recover the original stack from pr_oldcontext. 4187c478bd9Sstevel@tonic-gate */ 4197c478bd9Sstevel@tonic-gate if (P->status.pr_dmodel == PR_MODEL_NATIVE) { 4207c478bd9Sstevel@tonic-gate if (Pread(P, stkp, sizeof (*stkp), addr) != sizeof (*stkp)) 4217c478bd9Sstevel@tonic-gate return (-1); 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate if (stkp->ss_flags & SS_ONSTACK) 4247c478bd9Sstevel@tonic-gate goto on_altstack; 4257c478bd9Sstevel@tonic-gate #ifdef _LP64 4267c478bd9Sstevel@tonic-gate } else { 4277c478bd9Sstevel@tonic-gate stack32_t stk32; 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate if (Pread(P, &stk32, sizeof (stk32), addr) != sizeof (stk32)) 4307c478bd9Sstevel@tonic-gate return (-1); 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate if (stk32.ss_flags & SS_ONSTACK) 4337c478bd9Sstevel@tonic-gate goto on_altstack; 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate stack_32_to_n(&stk32, stkp); 4367c478bd9Sstevel@tonic-gate #endif 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate return (0); 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate on_altstack: 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate if (P->status.pr_dmodel == PR_MODEL_NATIVE) { 4447c478bd9Sstevel@tonic-gate ucontext_t *ctxp = (void *)ls.pr_oldcontext; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate if (Pread(P, stkp, sizeof (*stkp), 4477c478bd9Sstevel@tonic-gate (uintptr_t)&ctxp->uc_stack) != sizeof (*stkp)) 4487c478bd9Sstevel@tonic-gate return (-1); 4497c478bd9Sstevel@tonic-gate #ifdef _LP64 4507c478bd9Sstevel@tonic-gate } else { 4517c478bd9Sstevel@tonic-gate ucontext32_t *ctxp = (void *)ls.pr_oldcontext; 4527c478bd9Sstevel@tonic-gate stack32_t stk32; 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate if (Pread(P, &stk32, sizeof (stk32), 4557c478bd9Sstevel@tonic-gate (uintptr_t)&ctxp->uc_stack) != sizeof (stk32)) 4567c478bd9Sstevel@tonic-gate return (-1); 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate stack_32_to_n(&stk32, stkp); 4597c478bd9Sstevel@tonic-gate #endif 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate return (0); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate int 4667c478bd9Sstevel@tonic-gate Plwp_alt_stack(struct ps_prochandle *P, lwpid_t lwpid, stack_t *stkp) 4677c478bd9Sstevel@tonic-gate { 4687c478bd9Sstevel@tonic-gate if (P->state == PS_IDLE) { 4697c478bd9Sstevel@tonic-gate errno = ENODATA; 4707c478bd9Sstevel@tonic-gate return (-1); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate if (P->state != PS_DEAD) { 4747c478bd9Sstevel@tonic-gate lwpstatus_t ls; 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate if (getlwpfile(P, lwpid, "lwpstatus", &ls, sizeof (ls)) != 0) 4777c478bd9Sstevel@tonic-gate return (-1); 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate if (ls.pr_altstack.ss_flags & SS_DISABLE) { 4807c478bd9Sstevel@tonic-gate errno = ENODATA; 4817c478bd9Sstevel@tonic-gate return (-1); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate *stkp = ls.pr_altstack; 4857c478bd9Sstevel@tonic-gate } else { 4867c478bd9Sstevel@tonic-gate lwp_info_t *lwp; 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate if ((lwp = getlwpcore(P, lwpid)) == NULL) 4897c478bd9Sstevel@tonic-gate return (-1); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate if (lwp->lwp_status.pr_altstack.ss_flags & SS_DISABLE) { 4927c478bd9Sstevel@tonic-gate errno = ENODATA; 4937c478bd9Sstevel@tonic-gate return (-1); 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate *stkp = lwp->lwp_status.pr_altstack; 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate return (0); 5007c478bd9Sstevel@tonic-gate } 501