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 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * 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*def11082Srh87107 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.25 */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 347c478bd9Sstevel@tonic-gate #include <sys/param.h> 357c478bd9Sstevel@tonic-gate #include <sys/systm.h> 367c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 377c478bd9Sstevel@tonic-gate #include <sys/cred.h> 387c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 397c478bd9Sstevel@tonic-gate #include <sys/file.h> 407c478bd9Sstevel@tonic-gate #include <sys/errno.h> 417c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 427c478bd9Sstevel@tonic-gate #include <sys/user.h> 437c478bd9Sstevel@tonic-gate #include <sys/buf.h> 447c478bd9Sstevel@tonic-gate #include <sys/var.h> 457c478bd9Sstevel@tonic-gate #include <sys/conf.h> 467c478bd9Sstevel@tonic-gate #include <sys/debug.h> 477c478bd9Sstevel@tonic-gate #include <sys/proc.h> 487c478bd9Sstevel@tonic-gate #include <sys/signal.h> 497c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 507c478bd9Sstevel@tonic-gate #include <sys/acct.h> 517c478bd9Sstevel@tonic-gate #include <sys/procset.h> 527c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 537c478bd9Sstevel@tonic-gate #include <sys/fault.h> 547c478bd9Sstevel@tonic-gate #include <sys/syscall.h> 557c478bd9Sstevel@tonic-gate #include <sys/ucontext.h> 567c478bd9Sstevel@tonic-gate #include <sys/procfs.h> 577c478bd9Sstevel@tonic-gate #include <sys/session.h> 587c478bd9Sstevel@tonic-gate #include <sys/task.h> 597c478bd9Sstevel@tonic-gate #include <sys/project.h> 607c478bd9Sstevel@tonic-gate #include <sys/pool.h> 617c478bd9Sstevel@tonic-gate #include <sys/zone.h> 627c478bd9Sstevel@tonic-gate #include <sys/contract/process_impl.h> 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate id_t getmyid(idtype_t); 657c478bd9Sstevel@tonic-gate int checkprocset(procset_t *); 667c478bd9Sstevel@tonic-gate static kthread_t *getlwpptr(id_t); 677c478bd9Sstevel@tonic-gate int procinset(proc_t *, procset_t *); 687c478bd9Sstevel@tonic-gate static int lwpinset(proc_t *, procset_t *, kthread_t *, int *); 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * The dotoprocs function locates the process(es) specified 72ddc470ccSjimp * by the procset structure pointed to by psp. funcp points to a 73ddc470ccSjimp * function which dotoprocs will call for each process in the 74ddc470ccSjimp * specified set. The arguments to this function will be a pointer 75ddc470ccSjimp * to the current process from the set and arg. 767c478bd9Sstevel@tonic-gate * If the called function returns -1, it means that processing of the 777c478bd9Sstevel@tonic-gate * procset should stop and a normal (non-error) return should be made 787c478bd9Sstevel@tonic-gate * to the caller of dotoprocs. 797c478bd9Sstevel@tonic-gate * If the called function returns any other non-zero value the search 807c478bd9Sstevel@tonic-gate * is terminated and the function's return value is returned to 817c478bd9Sstevel@tonic-gate * the caller of dotoprocs. This will normally be an error code. 827c478bd9Sstevel@tonic-gate * Otherwise, dotoprocs will return zero after processing the entire 837c478bd9Sstevel@tonic-gate * process set unless no processes were found in which case ESRCH will 847c478bd9Sstevel@tonic-gate * be returned. 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate int 877c478bd9Sstevel@tonic-gate dotoprocs(procset_t *psp, int (*funcp)(), char *arg) 887c478bd9Sstevel@tonic-gate { 897c478bd9Sstevel@tonic-gate proc_t *prp; /* A process from the set */ 907c478bd9Sstevel@tonic-gate int error; 917c478bd9Sstevel@tonic-gate int nfound; /* Nbr of processes found. */ 927c478bd9Sstevel@tonic-gate proc_t *lastprp; /* Last proc found. */ 937c478bd9Sstevel@tonic-gate 94ddc470ccSjimp ASSERT(funcp != NULL); 95ddc470ccSjimp 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * Check that the procset_t is valid. 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate error = checkprocset(psp); 1007c478bd9Sstevel@tonic-gate if (error) { 1017c478bd9Sstevel@tonic-gate return (error); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Check for the special value P_MYID in either operand 1057c478bd9Sstevel@tonic-gate * and replace it with the correct value. We don't check 1067c478bd9Sstevel@tonic-gate * for an error return from getmyid() because the idtypes 1077c478bd9Sstevel@tonic-gate * have been validated by the checkprocset() call above. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 1107c478bd9Sstevel@tonic-gate if (psp->p_lid == P_MYID) { 1117c478bd9Sstevel@tonic-gate psp->p_lid = getmyid(psp->p_lidtype); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate if (psp->p_rid == P_MYID) { 1147c478bd9Sstevel@tonic-gate psp->p_rid = getmyid(psp->p_ridtype); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * If psp only acts on a single proc, we can reduce pidlock hold time 1197c478bd9Sstevel@tonic-gate * by avoiding a needless scan of the entire proc list. Although 1207c478bd9Sstevel@tonic-gate * there are many procset_t combinations which might boil down to a 1217c478bd9Sstevel@tonic-gate * single proc, the most common case is an AND operation where one 1227c478bd9Sstevel@tonic-gate * side is a specific pid, and the other side is P_ALL, so that is 1237c478bd9Sstevel@tonic-gate * the case for which we will provide a fast path. Other cases could 1247c478bd9Sstevel@tonic-gate * be added in a similar fashion if they were to become significant 1257c478bd9Sstevel@tonic-gate * pidlock bottlenecks. 1267c478bd9Sstevel@tonic-gate * 1277c478bd9Sstevel@tonic-gate * Perform the check symmetrically: either the left or right side may 1287c478bd9Sstevel@tonic-gate * specify a pid, with the opposite side being 'all'. 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate if (psp->p_op == POP_AND) { 1317c478bd9Sstevel@tonic-gate if (((psp->p_lidtype == P_PID) && (psp->p_ridtype == P_ALL)) || 1327c478bd9Sstevel@tonic-gate ((psp->p_ridtype == P_PID) && (psp->p_lidtype == P_ALL))) { 1337c478bd9Sstevel@tonic-gate id_t pid; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate pid = (psp->p_lidtype == P_PID) ? 1367c478bd9Sstevel@tonic-gate psp->p_lid : psp->p_rid; 137ddc470ccSjimp if (((prp = prfind((pid_t)pid)) == NULL) || 138ddc470ccSjimp (prp->p_stat == SIDL || prp->p_stat == SZOMB || 139ddc470ccSjimp prp->p_tlist == NULL || prp->p_flag & SSYS)) { 140ddc470ccSjimp /* 141ddc470ccSjimp * Specified proc doesn't exist or should 142ddc470ccSjimp * not be operated on. 143ddc470ccSjimp * Don't need to make HASZONEACCESS check 144ddc470ccSjimp * here since prfind() takes care of that. 145ddc470ccSjimp */ 1467c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1477c478bd9Sstevel@tonic-gate return (ESRCH); 1487c478bd9Sstevel@tonic-gate } 149ddc470ccSjimp /* 150ddc470ccSjimp * Operate only on the specified proc. It's okay 151ddc470ccSjimp * if it's init. 152ddc470ccSjimp */ 1537c478bd9Sstevel@tonic-gate error = (*funcp)(prp, arg); 1547c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1557c478bd9Sstevel@tonic-gate if (error == -1) 1567c478bd9Sstevel@tonic-gate error = 0; 1577c478bd9Sstevel@tonic-gate return (error); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate nfound = 0; 1627c478bd9Sstevel@tonic-gate error = 0; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate for (prp = practive; prp != NULL; prp = prp->p_next) { 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * If caller is in a non-global zone, skip processes 1677c478bd9Sstevel@tonic-gate * in other zones. 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate if (!HASZONEACCESS(curproc, prp->p_zone->zone_id)) 1707c478bd9Sstevel@tonic-gate continue; 171*def11082Srh87107 172*def11082Srh87107 /* 173*def11082Srh87107 * Ignore this process if it's coming or going, 174*def11082Srh87107 * if it's a system process or if it's not in 175*def11082Srh87107 * the given procset_t. 176*def11082Srh87107 */ 177*def11082Srh87107 if (prp->p_stat == SIDL || prp->p_stat == SZOMB) 1787c478bd9Sstevel@tonic-gate continue; 179*def11082Srh87107 180*def11082Srh87107 mutex_enter(&prp->p_lock); 181*def11082Srh87107 if (prp->p_flag & SSYS || procinset(prp, psp) == 0) { 182*def11082Srh87107 mutex_exit(&prp->p_lock); 183*def11082Srh87107 } else { 184*def11082Srh87107 mutex_exit(&prp->p_lock); 1857c478bd9Sstevel@tonic-gate nfound++; 1867c478bd9Sstevel@tonic-gate lastprp = prp; 187ddc470ccSjimp if (prp != proc_init) { 1887c478bd9Sstevel@tonic-gate error = (*funcp)(prp, arg); 1897c478bd9Sstevel@tonic-gate if (error == -1) { 1907c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1917c478bd9Sstevel@tonic-gate return (0); 1927c478bd9Sstevel@tonic-gate } else if (error) { 1937c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1947c478bd9Sstevel@tonic-gate return (error); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate if (nfound == 0) { 2007c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 2017c478bd9Sstevel@tonic-gate return (ESRCH); 2027c478bd9Sstevel@tonic-gate } 203ddc470ccSjimp if (nfound == 1 && lastprp == proc_init) 2047c478bd9Sstevel@tonic-gate error = (*funcp)(lastprp, arg); 2057c478bd9Sstevel@tonic-gate if (error == -1) 2067c478bd9Sstevel@tonic-gate error = 0; 2077c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 2087c478bd9Sstevel@tonic-gate return (error); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * Check if a procset_t is valid. Return zero or an errno. 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate int 2157c478bd9Sstevel@tonic-gate checkprocset(procset_t *psp) 2167c478bd9Sstevel@tonic-gate { 2177c478bd9Sstevel@tonic-gate switch (psp->p_lidtype) { 2187c478bd9Sstevel@tonic-gate case P_LWPID: 2197c478bd9Sstevel@tonic-gate case P_PID: 2207c478bd9Sstevel@tonic-gate case P_PPID: 2217c478bd9Sstevel@tonic-gate case P_PGID: 2227c478bd9Sstevel@tonic-gate case P_SID: 2237c478bd9Sstevel@tonic-gate case P_TASKID: 2247c478bd9Sstevel@tonic-gate case P_CID: 2257c478bd9Sstevel@tonic-gate case P_UID: 2267c478bd9Sstevel@tonic-gate case P_GID: 2277c478bd9Sstevel@tonic-gate case P_PROJID: 2287c478bd9Sstevel@tonic-gate case P_POOLID: 2297c478bd9Sstevel@tonic-gate case P_ZONEID: 2307c478bd9Sstevel@tonic-gate case P_CTID: 2317c478bd9Sstevel@tonic-gate case P_ALL: 2327c478bd9Sstevel@tonic-gate break; 2337c478bd9Sstevel@tonic-gate default: 2347c478bd9Sstevel@tonic-gate return (EINVAL); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate switch (psp->p_ridtype) { 2387c478bd9Sstevel@tonic-gate case P_LWPID: 2397c478bd9Sstevel@tonic-gate case P_PID: 2407c478bd9Sstevel@tonic-gate case P_PPID: 2417c478bd9Sstevel@tonic-gate case P_PGID: 2427c478bd9Sstevel@tonic-gate case P_SID: 2437c478bd9Sstevel@tonic-gate case P_TASKID: 2447c478bd9Sstevel@tonic-gate case P_CID: 2457c478bd9Sstevel@tonic-gate case P_UID: 2467c478bd9Sstevel@tonic-gate case P_GID: 2477c478bd9Sstevel@tonic-gate case P_PROJID: 2487c478bd9Sstevel@tonic-gate case P_POOLID: 2497c478bd9Sstevel@tonic-gate case P_ZONEID: 2507c478bd9Sstevel@tonic-gate case P_CTID: 2517c478bd9Sstevel@tonic-gate case P_ALL: 2527c478bd9Sstevel@tonic-gate break; 2537c478bd9Sstevel@tonic-gate default: 2547c478bd9Sstevel@tonic-gate return (EINVAL); 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate switch (psp->p_op) { 2587c478bd9Sstevel@tonic-gate case POP_DIFF: 2597c478bd9Sstevel@tonic-gate case POP_AND: 2607c478bd9Sstevel@tonic-gate case POP_OR: 2617c478bd9Sstevel@tonic-gate case POP_XOR: 2627c478bd9Sstevel@tonic-gate break; 2637c478bd9Sstevel@tonic-gate default: 2647c478bd9Sstevel@tonic-gate return (EINVAL); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate return (0); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate /* 271*def11082Srh87107 * procinset returns 1 if the process pointed to by pp is in the process 272*def11082Srh87107 * set specified by psp, otherwise 0 is returned. A process that is 273*def11082Srh87107 * exiting, by which we mean that its p_tlist is NULL, cannot belong 274*def11082Srh87107 * to any set; pp's p_lock must be held across the call to this function. 275*def11082Srh87107 * The caller should ensure that the process does not belong to the SYS 276*def11082Srh87107 * scheduling class. 2777c478bd9Sstevel@tonic-gate * 2787c478bd9Sstevel@tonic-gate * This function expects to be called with a valid procset_t. 2797c478bd9Sstevel@tonic-gate * The set should be checked using checkprocset() before calling 2807c478bd9Sstevel@tonic-gate * this function. 2817c478bd9Sstevel@tonic-gate */ 2827c478bd9Sstevel@tonic-gate int 2837c478bd9Sstevel@tonic-gate procinset(proc_t *pp, procset_t *psp) 2847c478bd9Sstevel@tonic-gate { 2857c478bd9Sstevel@tonic-gate int loperand = 0; 2867c478bd9Sstevel@tonic-gate int roperand = 0; 2877c478bd9Sstevel@tonic-gate int lwplinproc = 0; 2887c478bd9Sstevel@tonic-gate int lwprinproc = 0; 2897c478bd9Sstevel@tonic-gate kthread_t *tp = proctot(pp); 2907c478bd9Sstevel@tonic-gate 291*def11082Srh87107 ASSERT(MUTEX_HELD(&pp->p_lock)); 292*def11082Srh87107 293*def11082Srh87107 if (tp == NULL) 294*def11082Srh87107 return (0); 295*def11082Srh87107 2967c478bd9Sstevel@tonic-gate switch (psp->p_lidtype) { 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate case P_LWPID: 2997c478bd9Sstevel@tonic-gate if (pp == ttoproc(curthread)) 3007c478bd9Sstevel@tonic-gate if (getlwpptr(psp->p_lid) != NULL) 3017c478bd9Sstevel@tonic-gate lwplinproc++; 3027c478bd9Sstevel@tonic-gate break; 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate case P_PID: 3057c478bd9Sstevel@tonic-gate if (pp->p_pid == psp->p_lid) 3067c478bd9Sstevel@tonic-gate loperand++; 3077c478bd9Sstevel@tonic-gate break; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate case P_PPID: 3107c478bd9Sstevel@tonic-gate if (pp->p_ppid == psp->p_lid) 3117c478bd9Sstevel@tonic-gate loperand++; 3127c478bd9Sstevel@tonic-gate break; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate case P_PGID: 3157c478bd9Sstevel@tonic-gate if (pp->p_pgrp == psp->p_lid) 3167c478bd9Sstevel@tonic-gate loperand++; 3177c478bd9Sstevel@tonic-gate break; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate case P_SID: 3209acbbeafSnn35248 mutex_enter(&pp->p_splock); 3217c478bd9Sstevel@tonic-gate if (pp->p_sessp->s_sid == psp->p_lid) 3227c478bd9Sstevel@tonic-gate loperand++; 3239acbbeafSnn35248 mutex_exit(&pp->p_splock); 3247c478bd9Sstevel@tonic-gate break; 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate case P_CID: 3277c478bd9Sstevel@tonic-gate ASSERT(tp != NULL); 3287c478bd9Sstevel@tonic-gate /* This case is broken for now. Need to be fixed XXX */ 3297c478bd9Sstevel@tonic-gate if (tp->t_cid == psp->p_lid) 3307c478bd9Sstevel@tonic-gate /* 3317c478bd9Sstevel@tonic-gate * if (checkcid(psp->p_lid)) 3327c478bd9Sstevel@tonic-gate */ 3337c478bd9Sstevel@tonic-gate loperand++; 3347c478bd9Sstevel@tonic-gate break; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate case P_TASKID: 3377c478bd9Sstevel@tonic-gate if (pp->p_task->tk_tkid == psp->p_lid) 3387c478bd9Sstevel@tonic-gate loperand++; 3397c478bd9Sstevel@tonic-gate break; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate case P_UID: 3427c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 3437c478bd9Sstevel@tonic-gate if (crgetuid(pp->p_cred) == psp->p_lid) 3447c478bd9Sstevel@tonic-gate loperand++; 3457c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 3467c478bd9Sstevel@tonic-gate break; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate case P_GID: 3497c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 3507c478bd9Sstevel@tonic-gate if (crgetgid(pp->p_cred) == psp->p_lid) 3517c478bd9Sstevel@tonic-gate loperand++; 3527c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 3537c478bd9Sstevel@tonic-gate break; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate case P_PROJID: 3567c478bd9Sstevel@tonic-gate if (pp->p_task->tk_proj->kpj_id == psp->p_lid) 3577c478bd9Sstevel@tonic-gate loperand++; 3587c478bd9Sstevel@tonic-gate break; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate case P_POOLID: 3617c478bd9Sstevel@tonic-gate if (pp->p_pool->pool_id == psp->p_lid) 3627c478bd9Sstevel@tonic-gate loperand++; 3637c478bd9Sstevel@tonic-gate break; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate case P_ZONEID: 3667c478bd9Sstevel@tonic-gate if (pp->p_zone->zone_id == psp->p_lid) 3677c478bd9Sstevel@tonic-gate loperand++; 3687c478bd9Sstevel@tonic-gate break; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate case P_CTID: 3717c478bd9Sstevel@tonic-gate if (PRCTID(pp) == psp->p_lid) 3727c478bd9Sstevel@tonic-gate loperand++; 3737c478bd9Sstevel@tonic-gate break; 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate case P_ALL: 3767c478bd9Sstevel@tonic-gate loperand++; 3777c478bd9Sstevel@tonic-gate break; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate default: 3807c478bd9Sstevel@tonic-gate #ifdef DEBUG 3817c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "procinset called with bad set"); 3827c478bd9Sstevel@tonic-gate return (0); 3837c478bd9Sstevel@tonic-gate #else 3847c478bd9Sstevel@tonic-gate return (0); 3857c478bd9Sstevel@tonic-gate #endif 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate switch (psp->p_ridtype) { 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate case P_LWPID: 3917c478bd9Sstevel@tonic-gate if (pp == ttoproc(curthread)) 3927c478bd9Sstevel@tonic-gate if (getlwpptr(psp->p_rid) != NULL) 3937c478bd9Sstevel@tonic-gate lwprinproc++; 3947c478bd9Sstevel@tonic-gate break; 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate case P_PID: 3977c478bd9Sstevel@tonic-gate if (pp->p_pid == psp->p_rid) 3987c478bd9Sstevel@tonic-gate roperand++; 3997c478bd9Sstevel@tonic-gate break; 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate case P_PPID: 4027c478bd9Sstevel@tonic-gate if (pp->p_ppid == psp->p_rid) 4037c478bd9Sstevel@tonic-gate roperand++; 4047c478bd9Sstevel@tonic-gate break; 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate case P_PGID: 4077c478bd9Sstevel@tonic-gate if (pp->p_pgrp == psp->p_rid) 4087c478bd9Sstevel@tonic-gate roperand++; 4097c478bd9Sstevel@tonic-gate break; 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate case P_SID: 4129acbbeafSnn35248 mutex_enter(&pp->p_splock); 4137c478bd9Sstevel@tonic-gate if (pp->p_sessp->s_sid == psp->p_rid) 4147c478bd9Sstevel@tonic-gate roperand++; 4159acbbeafSnn35248 mutex_exit(&pp->p_splock); 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate case P_TASKID: 4197c478bd9Sstevel@tonic-gate if (pp->p_task->tk_tkid == psp->p_rid) 4207c478bd9Sstevel@tonic-gate roperand++; 4217c478bd9Sstevel@tonic-gate break; 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate case P_CID: 4247c478bd9Sstevel@tonic-gate ASSERT(tp != NULL); 4257c478bd9Sstevel@tonic-gate /* This case is broken for now. Need to be fixed XXX */ 4267c478bd9Sstevel@tonic-gate if (tp->t_cid == psp->p_rid) 4277c478bd9Sstevel@tonic-gate /* 4287c478bd9Sstevel@tonic-gate * if (checkcid(psp->p_rid)) 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate roperand++; 4317c478bd9Sstevel@tonic-gate break; 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate case P_UID: 4347c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 4357c478bd9Sstevel@tonic-gate if (crgetuid(pp->p_cred) == psp->p_rid) 4367c478bd9Sstevel@tonic-gate roperand++; 4377c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 4387c478bd9Sstevel@tonic-gate break; 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate case P_GID: 4417c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 4427c478bd9Sstevel@tonic-gate if (crgetgid(pp->p_cred) == psp->p_rid) 4437c478bd9Sstevel@tonic-gate roperand++; 4447c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 4457c478bd9Sstevel@tonic-gate break; 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate case P_PROJID: 4487c478bd9Sstevel@tonic-gate if (pp->p_task->tk_proj->kpj_id == psp->p_rid) 4497c478bd9Sstevel@tonic-gate roperand++; 4507c478bd9Sstevel@tonic-gate break; 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate case P_POOLID: 4537c478bd9Sstevel@tonic-gate if (pp->p_pool->pool_id == psp->p_rid) 4547c478bd9Sstevel@tonic-gate roperand++; 4557c478bd9Sstevel@tonic-gate break; 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate case P_ZONEID: 4587c478bd9Sstevel@tonic-gate if (pp->p_zone->zone_id == psp->p_rid) 4597c478bd9Sstevel@tonic-gate roperand++; 4607c478bd9Sstevel@tonic-gate break; 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate case P_CTID: 4637c478bd9Sstevel@tonic-gate if (PRCTID(pp) == psp->p_rid) 4647c478bd9Sstevel@tonic-gate roperand++; 4657c478bd9Sstevel@tonic-gate break; 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate case P_ALL: 4687c478bd9Sstevel@tonic-gate roperand++; 4697c478bd9Sstevel@tonic-gate break; 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate default: 4727c478bd9Sstevel@tonic-gate #ifdef DEBUG 4737c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "procinset called with bad set"); 4747c478bd9Sstevel@tonic-gate return (0); 4757c478bd9Sstevel@tonic-gate #else 4767c478bd9Sstevel@tonic-gate return (0); 4777c478bd9Sstevel@tonic-gate #endif 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate switch (psp->p_op) { 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate case POP_DIFF: 4837c478bd9Sstevel@tonic-gate if (loperand && !lwprinproc && !roperand) 4847c478bd9Sstevel@tonic-gate return (1); 4857c478bd9Sstevel@tonic-gate else 4867c478bd9Sstevel@tonic-gate return (0); 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate case POP_AND: 4897c478bd9Sstevel@tonic-gate if (loperand && roperand) 4907c478bd9Sstevel@tonic-gate return (1); 4917c478bd9Sstevel@tonic-gate else 4927c478bd9Sstevel@tonic-gate return (0); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate case POP_OR: 4957c478bd9Sstevel@tonic-gate if (loperand || roperand) 4967c478bd9Sstevel@tonic-gate return (1); 4977c478bd9Sstevel@tonic-gate else 4987c478bd9Sstevel@tonic-gate return (0); 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate case POP_XOR: 5017c478bd9Sstevel@tonic-gate if ((loperand && !lwprinproc && !roperand) || 5027c478bd9Sstevel@tonic-gate (roperand && !lwplinproc && !loperand)) 5037c478bd9Sstevel@tonic-gate return (1); 5047c478bd9Sstevel@tonic-gate else 5057c478bd9Sstevel@tonic-gate return (0); 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate default: 5087c478bd9Sstevel@tonic-gate #ifdef DEBUG 5097c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "procinset called with bad set"); 5107c478bd9Sstevel@tonic-gate return (0); 5117c478bd9Sstevel@tonic-gate #else 5127c478bd9Sstevel@tonic-gate return (0); 5137c478bd9Sstevel@tonic-gate #endif 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate /* NOTREACHED */ 5167c478bd9Sstevel@tonic-gate } 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* 5197c478bd9Sstevel@tonic-gate * lwpinset returns 1 if the thread pointed to 5207c478bd9Sstevel@tonic-gate * by tp is in the process set specified by psp and is not in 5217c478bd9Sstevel@tonic-gate * the sys scheduling class - otherwise 0 is returned. 5227c478bd9Sstevel@tonic-gate * 5237c478bd9Sstevel@tonic-gate * This function expects to be called with a valid procset_t. 5247c478bd9Sstevel@tonic-gate * The set should be checked using checkprocset() before calling 5257c478bd9Sstevel@tonic-gate * this function. 5267c478bd9Sstevel@tonic-gate */ 5277c478bd9Sstevel@tonic-gate int 5287c478bd9Sstevel@tonic-gate lwpinset(proc_t *pp, procset_t *psp, kthread_t *tp, int *done) 5297c478bd9Sstevel@tonic-gate { 5307c478bd9Sstevel@tonic-gate int loperand = 0; 5317c478bd9Sstevel@tonic-gate int roperand = 0; 5327c478bd9Sstevel@tonic-gate int lwplinset = 0; 5337c478bd9Sstevel@tonic-gate int lwprinset = 0; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate ASSERT(ttoproc(tp) == pp); 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate /* 5387c478bd9Sstevel@tonic-gate * If process is in the sys class return (0). 5397c478bd9Sstevel@tonic-gate */ 5407c478bd9Sstevel@tonic-gate if (proctot(pp)->t_cid == 0) { 5417c478bd9Sstevel@tonic-gate return (0); 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate switch (psp->p_lidtype) { 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate case P_LWPID: 5477c478bd9Sstevel@tonic-gate if (tp->t_tid == psp->p_lid) 5487c478bd9Sstevel@tonic-gate lwplinset ++; 5497c478bd9Sstevel@tonic-gate break; 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate case P_PID: 5527c478bd9Sstevel@tonic-gate if (pp->p_pid == psp->p_lid) 5537c478bd9Sstevel@tonic-gate loperand++; 5547c478bd9Sstevel@tonic-gate break; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate case P_PPID: 5577c478bd9Sstevel@tonic-gate if (pp->p_ppid == psp->p_lid) 5587c478bd9Sstevel@tonic-gate loperand++; 5597c478bd9Sstevel@tonic-gate break; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate case P_PGID: 5627c478bd9Sstevel@tonic-gate if (pp->p_pgrp == psp->p_lid) 5637c478bd9Sstevel@tonic-gate loperand++; 5647c478bd9Sstevel@tonic-gate break; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate case P_SID: 5679acbbeafSnn35248 mutex_enter(&pp->p_splock); 5687c478bd9Sstevel@tonic-gate if (pp->p_sessp->s_sid == psp->p_lid) 5697c478bd9Sstevel@tonic-gate loperand++; 5709acbbeafSnn35248 mutex_exit(&pp->p_splock); 5717c478bd9Sstevel@tonic-gate break; 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate case P_TASKID: 5747c478bd9Sstevel@tonic-gate if (pp->p_task->tk_tkid == psp->p_lid) 5757c478bd9Sstevel@tonic-gate loperand++; 5767c478bd9Sstevel@tonic-gate break; 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate case P_CID: 5797c478bd9Sstevel@tonic-gate if (tp->t_cid == psp->p_lid) 5807c478bd9Sstevel@tonic-gate loperand++; 5817c478bd9Sstevel@tonic-gate break; 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate case P_UID: 5847c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 5857c478bd9Sstevel@tonic-gate if (crgetuid(pp->p_cred) == psp->p_lid) 5867c478bd9Sstevel@tonic-gate loperand++; 5877c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 5887c478bd9Sstevel@tonic-gate break; 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate case P_GID: 5917c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 5927c478bd9Sstevel@tonic-gate if (crgetgid(pp->p_cred) == psp->p_lid) 5937c478bd9Sstevel@tonic-gate loperand++; 5947c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 5957c478bd9Sstevel@tonic-gate break; 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate case P_PROJID: 5987c478bd9Sstevel@tonic-gate if (pp->p_task->tk_proj->kpj_id == psp->p_lid) 5997c478bd9Sstevel@tonic-gate loperand++; 6007c478bd9Sstevel@tonic-gate break; 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate case P_POOLID: 6037c478bd9Sstevel@tonic-gate if (pp->p_pool->pool_id == psp->p_lid) 6047c478bd9Sstevel@tonic-gate loperand++; 6057c478bd9Sstevel@tonic-gate break; 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate case P_ZONEID: 6087c478bd9Sstevel@tonic-gate if (pp->p_zone->zone_id == psp->p_lid) 6097c478bd9Sstevel@tonic-gate loperand++; 6107c478bd9Sstevel@tonic-gate break; 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate case P_CTID: 6137c478bd9Sstevel@tonic-gate if (PRCTID(pp) == psp->p_lid) 6147c478bd9Sstevel@tonic-gate loperand++; 6157c478bd9Sstevel@tonic-gate break; 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate case P_ALL: 6187c478bd9Sstevel@tonic-gate loperand++; 6197c478bd9Sstevel@tonic-gate break; 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate default: 6227c478bd9Sstevel@tonic-gate #ifdef DEBUG 6237c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "lwpinset called with bad set"); 6247c478bd9Sstevel@tonic-gate return (0); 6257c478bd9Sstevel@tonic-gate #else 6267c478bd9Sstevel@tonic-gate return (0); 6277c478bd9Sstevel@tonic-gate #endif 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate switch (psp->p_ridtype) { 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate case P_LWPID: 6337c478bd9Sstevel@tonic-gate if (tp->t_tid == psp->p_rid) 6347c478bd9Sstevel@tonic-gate lwprinset ++; 6357c478bd9Sstevel@tonic-gate break; 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate case P_PID: 6387c478bd9Sstevel@tonic-gate if (pp->p_pid == psp->p_rid) 6397c478bd9Sstevel@tonic-gate roperand++; 6407c478bd9Sstevel@tonic-gate break; 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate case P_PPID: 6437c478bd9Sstevel@tonic-gate if (pp->p_ppid == psp->p_rid) 6447c478bd9Sstevel@tonic-gate roperand++; 6457c478bd9Sstevel@tonic-gate break; 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate case P_PGID: 6487c478bd9Sstevel@tonic-gate if (pp->p_pgrp == psp->p_rid) 6497c478bd9Sstevel@tonic-gate roperand++; 6507c478bd9Sstevel@tonic-gate break; 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate case P_SID: 6539acbbeafSnn35248 mutex_enter(&pp->p_splock); 6547c478bd9Sstevel@tonic-gate if (pp->p_sessp->s_sid == psp->p_rid) 6557c478bd9Sstevel@tonic-gate roperand++; 6569acbbeafSnn35248 mutex_exit(&pp->p_splock); 6577c478bd9Sstevel@tonic-gate break; 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate case P_TASKID: 6607c478bd9Sstevel@tonic-gate if (pp->p_task->tk_tkid == psp->p_rid) 6617c478bd9Sstevel@tonic-gate roperand++; 6627c478bd9Sstevel@tonic-gate break; 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate case P_CID: 6657c478bd9Sstevel@tonic-gate if (tp->t_cid == psp->p_rid) 6667c478bd9Sstevel@tonic-gate roperand++; 6677c478bd9Sstevel@tonic-gate break; 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate case P_UID: 6707c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 6717c478bd9Sstevel@tonic-gate if (crgetuid(pp->p_cred) == psp->p_rid) 6727c478bd9Sstevel@tonic-gate roperand++; 6737c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 6747c478bd9Sstevel@tonic-gate break; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate case P_GID: 6777c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 6787c478bd9Sstevel@tonic-gate if (crgetgid(pp->p_cred) == psp->p_rid) 6797c478bd9Sstevel@tonic-gate roperand++; 6807c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 6817c478bd9Sstevel@tonic-gate break; 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate case P_PROJID: 6847c478bd9Sstevel@tonic-gate if (pp->p_task->tk_proj->kpj_id == psp->p_rid) 6857c478bd9Sstevel@tonic-gate roperand++; 6867c478bd9Sstevel@tonic-gate break; 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate case P_POOLID: 6897c478bd9Sstevel@tonic-gate if (pp->p_pool->pool_id == psp->p_rid) 6907c478bd9Sstevel@tonic-gate roperand++; 6917c478bd9Sstevel@tonic-gate break; 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate case P_ZONEID: 6947c478bd9Sstevel@tonic-gate if (pp->p_zone->zone_id == psp->p_rid) 6957c478bd9Sstevel@tonic-gate roperand++; 6967c478bd9Sstevel@tonic-gate break; 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate case P_CTID: 6997c478bd9Sstevel@tonic-gate if (PRCTID(pp) == psp->p_rid) 7007c478bd9Sstevel@tonic-gate roperand++; 7017c478bd9Sstevel@tonic-gate break; 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate case P_ALL: 7047c478bd9Sstevel@tonic-gate roperand++; 7057c478bd9Sstevel@tonic-gate break; 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate default: 7087c478bd9Sstevel@tonic-gate #ifdef DEBUG 7097c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "lwpinset called with bad set"); 7107c478bd9Sstevel@tonic-gate return (0); 7117c478bd9Sstevel@tonic-gate #else 7127c478bd9Sstevel@tonic-gate return (0); 7137c478bd9Sstevel@tonic-gate #endif 7147c478bd9Sstevel@tonic-gate } 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate if (lwplinset && lwprinset) 7177c478bd9Sstevel@tonic-gate *done = 1; 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate switch (psp->p_op) { 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate case POP_DIFF: 7227c478bd9Sstevel@tonic-gate if ((loperand || lwplinset) && !(lwprinset || roperand)) 7237c478bd9Sstevel@tonic-gate return (1); 7247c478bd9Sstevel@tonic-gate else 7257c478bd9Sstevel@tonic-gate return (0); 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate case POP_AND: 7287c478bd9Sstevel@tonic-gate if ((loperand || lwplinset) && (roperand || lwprinset)) 7297c478bd9Sstevel@tonic-gate return (1); 7307c478bd9Sstevel@tonic-gate else 7317c478bd9Sstevel@tonic-gate return (0); 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate case POP_OR: 7347c478bd9Sstevel@tonic-gate if (loperand || roperand || lwplinset || lwprinset) 7357c478bd9Sstevel@tonic-gate return (1); 7367c478bd9Sstevel@tonic-gate else 7377c478bd9Sstevel@tonic-gate return (0); 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate case POP_XOR: 7407c478bd9Sstevel@tonic-gate if (((loperand || lwplinset) && 7417c478bd9Sstevel@tonic-gate !(lwprinset || roperand)) || 7427c478bd9Sstevel@tonic-gate ((roperand || lwprinset) && 7437c478bd9Sstevel@tonic-gate !(lwplinset || loperand))) 7447c478bd9Sstevel@tonic-gate return (1); 7457c478bd9Sstevel@tonic-gate else 7467c478bd9Sstevel@tonic-gate return (0); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate default: 7497c478bd9Sstevel@tonic-gate #ifdef DEBUG 7507c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "lwpinset called with bad set"); 7517c478bd9Sstevel@tonic-gate return (0); 7527c478bd9Sstevel@tonic-gate #else 7537c478bd9Sstevel@tonic-gate return (0); 7547c478bd9Sstevel@tonic-gate #endif 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate /* NOTREACHED */ 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate /* 7597c478bd9Sstevel@tonic-gate * Check for common cases of procsets which specify only the 7607c478bd9Sstevel@tonic-gate * current process. cur_inset_only() returns B_TRUE when 7617c478bd9Sstevel@tonic-gate * the current process is the only one in the set. B_FALSE 7627c478bd9Sstevel@tonic-gate * is returned to indicate that this may not be the case. 7637c478bd9Sstevel@tonic-gate */ 7647c478bd9Sstevel@tonic-gate boolean_t 7657c478bd9Sstevel@tonic-gate cur_inset_only(procset_t *psp) 7667c478bd9Sstevel@tonic-gate { 7677c478bd9Sstevel@tonic-gate if (((psp->p_lidtype == P_PID && 7687c478bd9Sstevel@tonic-gate (psp->p_lid == P_MYID || 7697c478bd9Sstevel@tonic-gate psp->p_lid == ttoproc(curthread)->p_pid)) || 7707c478bd9Sstevel@tonic-gate ((psp->p_lidtype == P_LWPID) && 7717c478bd9Sstevel@tonic-gate (psp->p_lid == P_MYID || 7727c478bd9Sstevel@tonic-gate psp->p_lid == curthread->t_tid))) && 7737c478bd9Sstevel@tonic-gate psp->p_op == POP_AND && psp->p_ridtype == P_ALL) 7747c478bd9Sstevel@tonic-gate return (B_TRUE); 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate if (((psp->p_ridtype == P_PID && 7777c478bd9Sstevel@tonic-gate (psp->p_rid == P_MYID || 7787c478bd9Sstevel@tonic-gate psp->p_rid == ttoproc(curthread)->p_pid)) || 7797c478bd9Sstevel@tonic-gate ((psp->p_ridtype == P_LWPID) && 7807c478bd9Sstevel@tonic-gate (psp->p_rid == P_MYID || 7817c478bd9Sstevel@tonic-gate psp->p_rid == curthread->t_tid))) && 7827c478bd9Sstevel@tonic-gate psp->p_op == POP_AND && psp->p_lidtype == P_ALL) 7837c478bd9Sstevel@tonic-gate return (B_TRUE); 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate return (B_FALSE); 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate 7887c478bd9Sstevel@tonic-gate id_t 7897c478bd9Sstevel@tonic-gate getmyid(idtype_t idtype) 7907c478bd9Sstevel@tonic-gate { 7917c478bd9Sstevel@tonic-gate proc_t *pp; 7927c478bd9Sstevel@tonic-gate uid_t uid; 7937c478bd9Sstevel@tonic-gate gid_t gid; 7949acbbeafSnn35248 pid_t sid; 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate pp = ttoproc(curthread); 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate switch (idtype) { 7997c478bd9Sstevel@tonic-gate case P_LWPID: 8007c478bd9Sstevel@tonic-gate return (curthread->t_tid); 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate case P_PID: 8037c478bd9Sstevel@tonic-gate return (pp->p_pid); 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate case P_PPID: 8067c478bd9Sstevel@tonic-gate return (pp->p_ppid); 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate case P_PGID: 8097c478bd9Sstevel@tonic-gate return (pp->p_pgrp); 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate case P_SID: 8129acbbeafSnn35248 mutex_enter(&pp->p_splock); 8139acbbeafSnn35248 sid = pp->p_sessp->s_sid; 8149acbbeafSnn35248 mutex_exit(&pp->p_splock); 8159acbbeafSnn35248 return (sid); 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate case P_TASKID: 8187c478bd9Sstevel@tonic-gate return (pp->p_task->tk_tkid); 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate case P_CID: 8217c478bd9Sstevel@tonic-gate return (curthread->t_cid); 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate case P_UID: 8247c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 8257c478bd9Sstevel@tonic-gate uid = crgetuid(pp->p_cred); 8267c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 8277c478bd9Sstevel@tonic-gate return (uid); 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate case P_GID: 8307c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_crlock); 8317c478bd9Sstevel@tonic-gate gid = crgetgid(pp->p_cred); 8327c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_crlock); 8337c478bd9Sstevel@tonic-gate return (gid); 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate case P_PROJID: 8367c478bd9Sstevel@tonic-gate return (pp->p_task->tk_proj->kpj_id); 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate case P_POOLID: 8397c478bd9Sstevel@tonic-gate return (pp->p_pool->pool_id); 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate case P_ZONEID: 8427c478bd9Sstevel@tonic-gate return (pp->p_zone->zone_id); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate case P_CTID: 8457c478bd9Sstevel@tonic-gate return (PRCTID(pp)); 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate case P_ALL: 8487c478bd9Sstevel@tonic-gate /* 8497c478bd9Sstevel@tonic-gate * The value doesn't matter for P_ALL. 8507c478bd9Sstevel@tonic-gate */ 8517c478bd9Sstevel@tonic-gate return (0); 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate default: 8547c478bd9Sstevel@tonic-gate return (-1); 8557c478bd9Sstevel@tonic-gate } 8567c478bd9Sstevel@tonic-gate } 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate static kthread_t * 8597c478bd9Sstevel@tonic-gate getlwpptr(id_t id) 8607c478bd9Sstevel@tonic-gate { 8617c478bd9Sstevel@tonic-gate proc_t *p; 8627c478bd9Sstevel@tonic-gate kthread_t *t; 8637c478bd9Sstevel@tonic-gate 864*def11082Srh87107 ASSERT(MUTEX_HELD(&(ttoproc(curthread)->p_lock))); 865*def11082Srh87107 8667c478bd9Sstevel@tonic-gate if (id == P_MYID) 8677c478bd9Sstevel@tonic-gate t = curthread; 8687c478bd9Sstevel@tonic-gate else { 8697c478bd9Sstevel@tonic-gate p = ttoproc(curthread); 8707c478bd9Sstevel@tonic-gate t = idtot(p, id); 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate return (t); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* 8777c478bd9Sstevel@tonic-gate * The dotolwp function locates the LWP(s) specified by the procset structure 8787c478bd9Sstevel@tonic-gate * pointed to by psp. If funcp is non-NULL then it points to a function 8797c478bd9Sstevel@tonic-gate * which dotolwp will call for each LWP in the specified set. 8807c478bd9Sstevel@tonic-gate * LWPIDs specified in the procset structure always refer to lwps in curproc. 8817c478bd9Sstevel@tonic-gate * The arguments for this function must be "char *arg", and "kthread_t *tp", 8827c478bd9Sstevel@tonic-gate * where tp is a pointer to the current thread from the set. 8837c478bd9Sstevel@tonic-gate * Note that these arguments are passed to the function in reversed order 8847c478bd9Sstevel@tonic-gate * than the order of arguments passed by dotoprocs() to its callback function. 8857c478bd9Sstevel@tonic-gate * Also note that there are two separate cases where this routine returns zero. 8867c478bd9Sstevel@tonic-gate * In the first case no mutex is grabbed, in the second the p_lock mutex 8877c478bd9Sstevel@tonic-gate * is NOT RELEASED. The priocntl code is expecting this behaviour. 8887c478bd9Sstevel@tonic-gate */ 8897c478bd9Sstevel@tonic-gate int 8907c478bd9Sstevel@tonic-gate dotolwp(procset_t *psp, int (*funcp)(), char *arg) 8917c478bd9Sstevel@tonic-gate { 8927c478bd9Sstevel@tonic-gate int error = 0; 8937c478bd9Sstevel@tonic-gate int nfound = 0; 8947c478bd9Sstevel@tonic-gate kthread_t *tp; 8957c478bd9Sstevel@tonic-gate proc_t *pp; 8967c478bd9Sstevel@tonic-gate int done = 0; 8977c478bd9Sstevel@tonic-gate 8987c478bd9Sstevel@tonic-gate /* 8997c478bd9Sstevel@tonic-gate * Check that the procset_t is valid. 9007c478bd9Sstevel@tonic-gate */ 9017c478bd9Sstevel@tonic-gate error = checkprocset(psp); 9027c478bd9Sstevel@tonic-gate if (error) { 9037c478bd9Sstevel@tonic-gate return (error); 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate /* 9097c478bd9Sstevel@tonic-gate * Check for the special value P_MYID in either operand 9107c478bd9Sstevel@tonic-gate * and replace it with the correct value. We don't check 9117c478bd9Sstevel@tonic-gate * for an error return from getmyid() because the idtypes 9127c478bd9Sstevel@tonic-gate * have been validated by the checkprocset() call above. 9137c478bd9Sstevel@tonic-gate */ 9147c478bd9Sstevel@tonic-gate if (psp->p_lid == P_MYID) { 9157c478bd9Sstevel@tonic-gate psp->p_lid = getmyid(psp->p_lidtype); 9167c478bd9Sstevel@tonic-gate } 9177c478bd9Sstevel@tonic-gate if (psp->p_rid == P_MYID) { 9187c478bd9Sstevel@tonic-gate psp->p_rid = getmyid(psp->p_ridtype); 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate pp = ttoproc(curthread); 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 924*def11082Srh87107 if (procinset(pp, psp) || 925*def11082Srh87107 (tp = pp->p_tlist) == NULL) { 9267c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 9277c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 9287c478bd9Sstevel@tonic-gate return (0); 9297c478bd9Sstevel@tonic-gate } 9307c478bd9Sstevel@tonic-gate do { 9317c478bd9Sstevel@tonic-gate if (lwpinset(pp, psp, tp, &done)) { 9327c478bd9Sstevel@tonic-gate nfound ++; 9337c478bd9Sstevel@tonic-gate error = (*funcp)(arg, tp); 9347c478bd9Sstevel@tonic-gate if (error) { 9357c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 9367c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 9377c478bd9Sstevel@tonic-gate return (error); 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate } 9407c478bd9Sstevel@tonic-gate } while (((tp = tp->t_forw) != pp->p_tlist) && !done); 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate if (nfound == 0) { 9437c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 9447c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 9457c478bd9Sstevel@tonic-gate return (ESRCH); 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 9497c478bd9Sstevel@tonic-gate return (error); 9507c478bd9Sstevel@tonic-gate } 951