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 * Copyright 2026 Oxide Computer Company 28 */ 29 30 #include <stdlib.h> 31 #include <unistd.h> 32 #include <errno.h> 33 #include <sys/lwp.h> 34 #include "libproc.h" 35 36 /* 37 * exit() system call -- executed by subject process. 38 */ 39 int 40 pr_exit(struct ps_prochandle *Pr, int status) 41 { 42 sysret_t rval; /* return value from exit() */ 43 argdes_t argd[1]; /* arg descriptors for exit() */ 44 argdes_t *adp; 45 int error; 46 47 if (Pr == NULL) { /* no subject process */ 48 exit(status); 49 return (0); /* not reached */ 50 } 51 52 adp = &argd[0]; /* status argument */ 53 adp->arg_value = status; 54 adp->arg_object = NULL; 55 adp->arg_type = AT_BYVAL; 56 adp->arg_inout = AI_INPUT; 57 adp->arg_size = 0; 58 59 /* 60 * The injected exit() call does not return. The expected result is 61 * a local failure with ENOENT in errno, indicating that the process 62 * has gone. 63 */ 64 error = Psyscall(Pr, &rval, SYS_exit, 1, &argd[0]); 65 66 if (error == 0 || (error < 0 && errno == ENOENT)) 67 return (0); 68 69 /* 70 * If the injected call failed in the subject process then errno is 71 * set from that. Otherwise it is left as that of the operation 72 * which failed locally while injecting the call. 73 */ 74 if (error > 0) 75 errno = error; 76 return (-1); 77 } 78 79 /* 80 * lwp_exit() system call -- executed by subject lwp. 81 */ 82 int 83 pr_lwp_exit(struct ps_prochandle *Pr) 84 { 85 sysret_t rval; /* return value from lwp_exit() */ 86 int error; 87 88 if (Pr == NULL) { /* no subject process */ 89 (void) syscall(SYS_lwp_exit); 90 return (0); /* not reached */ 91 } 92 93 /* 94 * The injected _lwp_exit() call does not return, and Psyscall() 95 * reports success once it has observed the lwp disappear. A local 96 * failure, indicated by a negative return with ENOENT in errno, is 97 * another way of finding that the lwp has gone. 98 */ 99 error = Psyscall(Pr, &rval, SYS_lwp_exit, 0, NULL); 100 101 if (error == 0 || (error < 0 && errno == ENOENT)) 102 return (0); 103 104 /* 105 * If the injected call failed in the subject process then errno is 106 * set from that. Otherwise it is left as that of the operation 107 * which failed locally while injecting the call. 108 */ 109 if (error > 0) 110 errno = error; 111 return (-1); 112 } 113