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 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
28 * Copyright (c) 2013 by Delphix. All rights reserved.
29 */
30
31 #include <sys/types.h>
32 #include <sys/uio.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <limits.h>
36
37 #include "Pcontrol.h"
38 #include "P32ton.h"
39
40 /*
41 * This file implements the routines to read and write per-lwp register
42 * information from either a live process or core file opened with libproc.
43 * We build up a few common routines for reading and writing register
44 * information, and then the public functions are all trivial calls to these.
45 */
46
47 /*
335 lwp_info_t *lwp;
336
337 if (P->state == PS_IDLE) {
338 errno = ENODATA;
339 return (-1);
340 }
341
342 if (P->state != PS_DEAD) {
343 return (getlwpfile(P, lwpid, "lwpsinfo",
344 lps, sizeof (lwpsinfo_t)));
345 }
346
347 if ((lwp = getlwpcore(P, lwpid)) != NULL) {
348 (void) memcpy(lps, &lwp->lwp_psinfo, sizeof (lwpsinfo_t));
349 return (0);
350 }
351
352 return (-1);
353 }
354
355 int
356 Plwp_getspymaster(struct ps_prochandle *P, lwpid_t lwpid, psinfo_t *ps)
357 {
358 lwpstatus_t lps;
359
360 if (P->state == PS_IDLE) {
361 errno = ENODATA;
362 return (-1);
363 }
364
365 if (getlwpstatus(P, lwpid, &lps) != 0)
366 return (-1);
367
368 if (!(lps.pr_flags & PR_AGENT)) {
369 errno = EINVAL;
370 return (-1);
371 }
372
373 if (P->state != PS_DEAD) {
374 return (getlwpfile(P, lwpid, "spymaster",
|
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 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright 2018 Joyent, Inc.
28 * Copyright (c) 2013 by Delphix. All rights reserved.
29 */
30
31 #include <sys/types.h>
32 #include <sys/uio.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <limits.h>
36
37 #include "Pcontrol.h"
38 #include "P32ton.h"
39
40 /*
41 * This file implements the routines to read and write per-lwp register
42 * information from either a live process or core file opened with libproc.
43 * We build up a few common routines for reading and writing register
44 * information, and then the public functions are all trivial calls to these.
45 */
46
47 /*
335 lwp_info_t *lwp;
336
337 if (P->state == PS_IDLE) {
338 errno = ENODATA;
339 return (-1);
340 }
341
342 if (P->state != PS_DEAD) {
343 return (getlwpfile(P, lwpid, "lwpsinfo",
344 lps, sizeof (lwpsinfo_t)));
345 }
346
347 if ((lwp = getlwpcore(P, lwpid)) != NULL) {
348 (void) memcpy(lps, &lwp->lwp_psinfo, sizeof (lwpsinfo_t));
349 return (0);
350 }
351
352 return (-1);
353 }
354
355 int
356 Plwp_getname(struct ps_prochandle *P, lwpid_t lwpid,
357 char *buf, size_t bufsize)
358 {
359 char lwpname[THREAD_NAME_MAX];
360 char *from = NULL;
361 lwp_info_t *lwp;
362
363 if (P->state == PS_IDLE) {
364 errno = ENODATA;
365 return (-1);
366 }
367
368 if (P->state != PS_DEAD) {
369 if (getlwpfile(P, lwpid, "lwpname",
370 lwpname, sizeof (lwpname)) != 0)
371 return (-1);
372 from = lwpname;
373 } else {
374 if ((lwp = getlwpcore(P, lwpid)) == NULL)
375 return (-1);
376 from = lwp->lwp_name;
377 }
378
379 if (strlcpy(buf, from, bufsize) >= bufsize) {
380 errno = ENAMETOOLONG;
381 return (-1);
382 }
383
384 return (0);
385 }
386
387 int
388 Plwp_getspymaster(struct ps_prochandle *P, lwpid_t lwpid, psinfo_t *ps)
389 {
390 lwpstatus_t lps;
391
392 if (P->state == PS_IDLE) {
393 errno = ENODATA;
394 return (-1);
395 }
396
397 if (getlwpstatus(P, lwpid, &lps) != 0)
398 return (-1);
399
400 if (!(lps.pr_flags & PR_AGENT)) {
401 errno = EINVAL;
402 return (-1);
403 }
404
405 if (P->state != PS_DEAD) {
406 return (getlwpfile(P, lwpid, "spymaster",
|