1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 1997-2003 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#include <stdlib.h>
30#include <unistd.h>
31#include <errno.h>
32#include <sys/lwp.h>
33#include "libproc.h"
34
35/*
36 * exit() system call -- executed by subject process.
37 */
38int
39pr_exit(struct ps_prochandle *Pr, int status)
40{
41	sysret_t rval;			/* return value from exit() */
42	argdes_t argd[1];		/* arg descriptors for exit() */
43	argdes_t *adp;
44	int error;
45
46	if (Pr == NULL) {		/* no subject process */
47		exit(status);
48		return (0);		/* not reached */
49	}
50
51	adp = &argd[0];		/* status argument */
52	adp->arg_value = status;
53	adp->arg_object = NULL;
54	adp->arg_type = AT_BYVAL;
55	adp->arg_inout = AI_INPUT;
56	adp->arg_size = 0;
57
58	error = Psyscall(Pr, &rval, SYS_exit, 1, &argd[0]);
59	/* actually -- never returns.  Expect ENOENT */
60
61	if (error < 0) {
62		if (errno == ENOENT)	/* expected case */
63			error = ENOENT;
64		else
65			error = ENOSYS;
66	}
67
68	if (error == 0)		/* can't happen? */
69		return (rval.sys_rval1);
70
71	if (error == ENOENT)	/* expected case */
72		return (0);
73
74	errno = error;
75	return (-1);
76}
77
78/*
79 * lwp_exit() system call -- executed by subject lwp.
80 */
81int
82pr_lwp_exit(struct ps_prochandle *Pr)
83{
84	sysret_t rval;			/* return value from lwp_exit() */
85	int error;
86
87	if (Pr == NULL) {		/* no subject process */
88		(void) syscall(SYS_lwp_exit);
89		return (0);		/* not reached */
90	}
91
92	error = Psyscall(Pr, &rval, SYS_lwp_exit, 0, NULL);
93	/* actually -- never returns.  Expect ENOENT */
94
95	if (error < 0) {
96		if (errno == ENOENT)	/* expected case */
97			error = ENOENT;
98		else
99			error = ENOSYS;
100	}
101
102	if (error == 0)		/* can't happen? */
103		return (rval.sys_rval1);
104
105	if (error == ENOENT)	/* expected case */
106		return (0);
107
108	errno = error;
109	return (-1);
110}
111