1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/errno.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/swap.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/file.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/proc.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/var.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/uadmin.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/signal.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 44*7c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/callb.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/debug.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/ftrace.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 51*7c478bd9Sstevel@tonic-gate #include <sys/panic.h> 52*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 53*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 54*7c478bd9Sstevel@tonic-gate #include <sys/policy.h> 55*7c478bd9Sstevel@tonic-gate #include <sys/zone.h> 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * Administrivia system call. We provide this in two flavors: one for calling 59*7c478bd9Sstevel@tonic-gate * from the system call path (uadmin), and the other for calling from elsewhere 60*7c478bd9Sstevel@tonic-gate * within the kernel (kadmin). Callers must beware that certain uadmin cmd 61*7c478bd9Sstevel@tonic-gate * values (specifically A_SWAPCTL) are only supported by uadmin and not kadmin. 62*7c478bd9Sstevel@tonic-gate */ 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate extern ksema_t fsflush_sema; 65*7c478bd9Sstevel@tonic-gate kmutex_t ualock; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * Kill all user processes in said zone. A special argument of ALL_ZONES is 70*7c478bd9Sstevel@tonic-gate * passed in when the system as a whole is shutting down. The lack of per-zone 71*7c478bd9Sstevel@tonic-gate * process lists is likely to make the following a performance bottleneck on a 72*7c478bd9Sstevel@tonic-gate * system with many zones. 73*7c478bd9Sstevel@tonic-gate */ 74*7c478bd9Sstevel@tonic-gate void 75*7c478bd9Sstevel@tonic-gate killall(zoneid_t zoneid) 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate proc_t *p; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate ASSERT(zoneid != GLOBAL_ZONEID); 80*7c478bd9Sstevel@tonic-gate /* 81*7c478bd9Sstevel@tonic-gate * Kill all processes except kernel daemons and ourself. 82*7c478bd9Sstevel@tonic-gate * Make a first pass to stop all processes so they won't 83*7c478bd9Sstevel@tonic-gate * be trying to restart children as we kill them. 84*7c478bd9Sstevel@tonic-gate */ 85*7c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 86*7c478bd9Sstevel@tonic-gate for (p = practive; p != NULL; p = p->p_next) { 87*7c478bd9Sstevel@tonic-gate if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) && 88*7c478bd9Sstevel@tonic-gate p->p_exec != NULLVP && /* kernel daemons */ 89*7c478bd9Sstevel@tonic-gate p->p_as != &kas && 90*7c478bd9Sstevel@tonic-gate p->p_stat != SZOMB) { 91*7c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 92*7c478bd9Sstevel@tonic-gate p->p_flag |= SNOWAIT; 93*7c478bd9Sstevel@tonic-gate sigtoproc(p, NULL, SIGSTOP); 94*7c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate p = practive; 98*7c478bd9Sstevel@tonic-gate while (p != NULL) { 99*7c478bd9Sstevel@tonic-gate if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) && 100*7c478bd9Sstevel@tonic-gate p->p_exec != NULLVP && /* kernel daemons */ 101*7c478bd9Sstevel@tonic-gate p->p_as != &kas && 102*7c478bd9Sstevel@tonic-gate p->p_stat != SIDL && 103*7c478bd9Sstevel@tonic-gate p->p_stat != SZOMB) { 104*7c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 105*7c478bd9Sstevel@tonic-gate if (sigismember(&p->p_sig, SIGKILL)) { 106*7c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 107*7c478bd9Sstevel@tonic-gate p = p->p_next; 108*7c478bd9Sstevel@tonic-gate } else { 109*7c478bd9Sstevel@tonic-gate sigtoproc(p, NULL, SIGKILL); 110*7c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 111*7c478bd9Sstevel@tonic-gate (void) cv_timedwait(&p->p_srwchan_cv, 112*7c478bd9Sstevel@tonic-gate &pidlock, lbolt + hz); 113*7c478bd9Sstevel@tonic-gate p = practive; 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate } else { 116*7c478bd9Sstevel@tonic-gate p = p->p_next; 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate } 119*7c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate int 123*7c478bd9Sstevel@tonic-gate kadmin(int cmd, int fcn, void *mdep, cred_t *credp) 124*7c478bd9Sstevel@tonic-gate { 125*7c478bd9Sstevel@tonic-gate int error = 0; 126*7c478bd9Sstevel@tonic-gate int locked = 0; 127*7c478bd9Sstevel@tonic-gate char *buf; 128*7c478bd9Sstevel@tonic-gate size_t buflen = 0; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate /* 131*7c478bd9Sstevel@tonic-gate * We might be called directly by the kernel's fault-handling code, so 132*7c478bd9Sstevel@tonic-gate * we can't assert that the caller is in the global zone. 133*7c478bd9Sstevel@tonic-gate */ 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* 136*7c478bd9Sstevel@tonic-gate * Make sure that cmd is one of the valid <sys/uadmin.h> command codes 137*7c478bd9Sstevel@tonic-gate * and that we have appropriate privileges for this action. 138*7c478bd9Sstevel@tonic-gate */ 139*7c478bd9Sstevel@tonic-gate switch (cmd) { 140*7c478bd9Sstevel@tonic-gate case A_FTRACE: 141*7c478bd9Sstevel@tonic-gate case A_SHUTDOWN: 142*7c478bd9Sstevel@tonic-gate case A_REBOOT: 143*7c478bd9Sstevel@tonic-gate case A_REMOUNT: 144*7c478bd9Sstevel@tonic-gate case A_FREEZE: 145*7c478bd9Sstevel@tonic-gate case A_DUMP: 146*7c478bd9Sstevel@tonic-gate if (secpolicy_sys_config(credp, B_FALSE) != 0) 147*7c478bd9Sstevel@tonic-gate return (EPERM); 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate default: 151*7c478bd9Sstevel@tonic-gate return (EINVAL); 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* 155*7c478bd9Sstevel@tonic-gate * Serialize these operations on ualock. If it is held, just return 156*7c478bd9Sstevel@tonic-gate * as if successful since the system will soon reset or remount. 157*7c478bd9Sstevel@tonic-gate */ 158*7c478bd9Sstevel@tonic-gate if (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_REMOUNT) { 159*7c478bd9Sstevel@tonic-gate if (!mutex_tryenter(&ualock)) 160*7c478bd9Sstevel@tonic-gate return (0); 161*7c478bd9Sstevel@tonic-gate locked = 1; 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate switch (cmd) { 165*7c478bd9Sstevel@tonic-gate case A_SHUTDOWN: 166*7c478bd9Sstevel@tonic-gate { 167*7c478bd9Sstevel@tonic-gate proc_t *p = ttoproc(curthread); 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate /* 170*7c478bd9Sstevel@tonic-gate * Release (almost) all of our own resources if we are called 171*7c478bd9Sstevel@tonic-gate * from a user context, however if we are calling kadmin() from 172*7c478bd9Sstevel@tonic-gate * a kernel context then we do not release these resources. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate if (ttoproc(curthread) != &p0) { 175*7c478bd9Sstevel@tonic-gate if ((error = exitlwps(0)) != 0) 176*7c478bd9Sstevel@tonic-gate return (error); 177*7c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 178*7c478bd9Sstevel@tonic-gate p->p_flag |= SNOWAIT; 179*7c478bd9Sstevel@tonic-gate sigfillset(&p->p_ignore); 180*7c478bd9Sstevel@tonic-gate curthread->t_lwp->lwp_cursig = 0; 181*7c478bd9Sstevel@tonic-gate curthread->t_lwp->lwp_extsig = 0; 182*7c478bd9Sstevel@tonic-gate if (p->p_exec) { 183*7c478bd9Sstevel@tonic-gate vnode_t *exec_vp = p->p_exec; 184*7c478bd9Sstevel@tonic-gate p->p_exec = NULLVP; 185*7c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 186*7c478bd9Sstevel@tonic-gate VN_RELE(exec_vp); 187*7c478bd9Sstevel@tonic-gate } else { 188*7c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate pollcleanup(); 192*7c478bd9Sstevel@tonic-gate closeall(P_FINFO(curproc)); 193*7c478bd9Sstevel@tonic-gate relvm(); 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate } else { 196*7c478bd9Sstevel@tonic-gate /* 197*7c478bd9Sstevel@tonic-gate * Reset t_cred if not set because much of the 198*7c478bd9Sstevel@tonic-gate * filesystem code depends on CRED() being valid. 199*7c478bd9Sstevel@tonic-gate */ 200*7c478bd9Sstevel@tonic-gate if (curthread->t_cred == NULL) 201*7c478bd9Sstevel@tonic-gate curthread->t_cred = kcred; 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /* 205*7c478bd9Sstevel@tonic-gate * Communcate that init shouldn't be restarted. 206*7c478bd9Sstevel@tonic-gate */ 207*7c478bd9Sstevel@tonic-gate zone_shutdown_global(); 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate killall(ALL_ZONES); 210*7c478bd9Sstevel@tonic-gate /* 211*7c478bd9Sstevel@tonic-gate * If we are calling kadmin() from a kernel context then we 212*7c478bd9Sstevel@tonic-gate * do not release these resources. 213*7c478bd9Sstevel@tonic-gate */ 214*7c478bd9Sstevel@tonic-gate if (ttoproc(curthread) != &p0) { 215*7c478bd9Sstevel@tonic-gate VN_RELE(u.u_cdir); 216*7c478bd9Sstevel@tonic-gate if (u.u_rdir) 217*7c478bd9Sstevel@tonic-gate VN_RELE(u.u_rdir); 218*7c478bd9Sstevel@tonic-gate if (u.u_cwd) 219*7c478bd9Sstevel@tonic-gate refstr_rele(u.u_cwd); 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate u.u_cdir = rootdir; 222*7c478bd9Sstevel@tonic-gate u.u_rdir = NULL; 223*7c478bd9Sstevel@tonic-gate u.u_cwd = NULL; 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate /* 227*7c478bd9Sstevel@tonic-gate * Allow the reboot/halt/poweroff code a chance to do 228*7c478bd9Sstevel@tonic-gate * anything it needs to whilst we still have filesystems 229*7c478bd9Sstevel@tonic-gate * mounted, like loading any modules necessary for later 230*7c478bd9Sstevel@tonic-gate * performing the actual poweroff. 231*7c478bd9Sstevel@tonic-gate */ 232*7c478bd9Sstevel@tonic-gate if ((mdep != NULL) && (*(char *)mdep == '/')) { 233*7c478bd9Sstevel@tonic-gate buf = i_convert_boot_device_name(mdep, NULL, &buflen); 234*7c478bd9Sstevel@tonic-gate mdpreboot(cmd, fcn, buf); 235*7c478bd9Sstevel@tonic-gate } else 236*7c478bd9Sstevel@tonic-gate mdpreboot(cmd, fcn, mdep); 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate /* 239*7c478bd9Sstevel@tonic-gate * Allow fsflush to finish running and then prevent it 240*7c478bd9Sstevel@tonic-gate * from ever running again so that vfs_unmountall() and 241*7c478bd9Sstevel@tonic-gate * vfs_syncall() can acquire the vfs locks they need. 242*7c478bd9Sstevel@tonic-gate */ 243*7c478bd9Sstevel@tonic-gate sema_p(&fsflush_sema); 244*7c478bd9Sstevel@tonic-gate (void) callb_execute_class(CB_CL_UADMIN_PRE_VFS, NULL); 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate vfs_unmountall(); 247*7c478bd9Sstevel@tonic-gate (void) VFS_MOUNTROOT(rootvfs, ROOT_UNMOUNT); 248*7c478bd9Sstevel@tonic-gate vfs_syncall(); 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate (void) callb_execute_class(CB_CL_UADMIN_POST_VFS, NULL); 251*7c478bd9Sstevel@tonic-gate dump_ereports(); 252*7c478bd9Sstevel@tonic-gate dump_messages(); 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate case A_REBOOT: 258*7c478bd9Sstevel@tonic-gate if ((mdep != NULL) && (*(char *)mdep == '/')) { 259*7c478bd9Sstevel@tonic-gate buf = i_convert_boot_device_name(mdep, NULL, &buflen); 260*7c478bd9Sstevel@tonic-gate mdboot(cmd, fcn, buf); 261*7c478bd9Sstevel@tonic-gate } else 262*7c478bd9Sstevel@tonic-gate mdboot(cmd, fcn, mdep); 263*7c478bd9Sstevel@tonic-gate /* no return expected */ 264*7c478bd9Sstevel@tonic-gate break; 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate case A_REMOUNT: 267*7c478bd9Sstevel@tonic-gate (void) VFS_MOUNTROOT(rootvfs, ROOT_REMOUNT); 268*7c478bd9Sstevel@tonic-gate break; 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate case A_FREEZE: 271*7c478bd9Sstevel@tonic-gate { 272*7c478bd9Sstevel@tonic-gate /* XXX: declare in some header file */ 273*7c478bd9Sstevel@tonic-gate extern int cpr(int); 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate if (modload("misc", "cpr") == -1) 276*7c478bd9Sstevel@tonic-gate return (ENOTSUP); 277*7c478bd9Sstevel@tonic-gate error = cpr(fcn); 278*7c478bd9Sstevel@tonic-gate break; 279*7c478bd9Sstevel@tonic-gate } 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate case A_FTRACE: 282*7c478bd9Sstevel@tonic-gate { 283*7c478bd9Sstevel@tonic-gate switch (fcn) { 284*7c478bd9Sstevel@tonic-gate case AD_FTRACE_START: 285*7c478bd9Sstevel@tonic-gate (void) FTRACE_START(); 286*7c478bd9Sstevel@tonic-gate break; 287*7c478bd9Sstevel@tonic-gate case AD_FTRACE_STOP: 288*7c478bd9Sstevel@tonic-gate (void) FTRACE_STOP(); 289*7c478bd9Sstevel@tonic-gate break; 290*7c478bd9Sstevel@tonic-gate default: 291*7c478bd9Sstevel@tonic-gate error = EINVAL; 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate break; 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate case A_DUMP: 297*7c478bd9Sstevel@tonic-gate { 298*7c478bd9Sstevel@tonic-gate if (fcn == AD_NOSYNC) { 299*7c478bd9Sstevel@tonic-gate in_sync = 1; 300*7c478bd9Sstevel@tonic-gate break; 301*7c478bd9Sstevel@tonic-gate } 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate panic_bootfcn = fcn; 304*7c478bd9Sstevel@tonic-gate panic_forced = 1; 305*7c478bd9Sstevel@tonic-gate 306*7c478bd9Sstevel@tonic-gate if ((mdep != NULL) && (*(char *)mdep == '/')) { 307*7c478bd9Sstevel@tonic-gate panic_bootstr = i_convert_boot_device_name(mdep, 308*7c478bd9Sstevel@tonic-gate NULL, &buflen); 309*7c478bd9Sstevel@tonic-gate } else 310*7c478bd9Sstevel@tonic-gate panic_bootstr = mdep; 311*7c478bd9Sstevel@tonic-gate 312*7c478bd9Sstevel@tonic-gate panic("forced crash dump initiated at user request"); 313*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 314*7c478bd9Sstevel@tonic-gate } 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate default: 317*7c478bd9Sstevel@tonic-gate error = EINVAL; 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate if (locked) 321*7c478bd9Sstevel@tonic-gate mutex_exit(&ualock); 322*7c478bd9Sstevel@tonic-gate 323*7c478bd9Sstevel@tonic-gate return (error); 324*7c478bd9Sstevel@tonic-gate } 325*7c478bd9Sstevel@tonic-gate 326*7c478bd9Sstevel@tonic-gate int 327*7c478bd9Sstevel@tonic-gate uadmin(int cmd, int fcn, uintptr_t mdep) 328*7c478bd9Sstevel@tonic-gate { 329*7c478bd9Sstevel@tonic-gate int error = 0, rv = 0; 330*7c478bd9Sstevel@tonic-gate size_t nbytes = 0; 331*7c478bd9Sstevel@tonic-gate char buf[257]; 332*7c478bd9Sstevel@tonic-gate cred_t *credp = CRED(); 333*7c478bd9Sstevel@tonic-gate 334*7c478bd9Sstevel@tonic-gate /* 335*7c478bd9Sstevel@tonic-gate * The swapctl system call doesn't have its own entry point: it uses 336*7c478bd9Sstevel@tonic-gate * uadmin as a wrapper so we just call it directly from here. 337*7c478bd9Sstevel@tonic-gate */ 338*7c478bd9Sstevel@tonic-gate if (cmd == A_SWAPCTL) { 339*7c478bd9Sstevel@tonic-gate if (get_udatamodel() == DATAMODEL_NATIVE) 340*7c478bd9Sstevel@tonic-gate error = swapctl(fcn, (void *)mdep, &rv); 341*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL) 342*7c478bd9Sstevel@tonic-gate else 343*7c478bd9Sstevel@tonic-gate error = swapctl32(fcn, (void *)mdep, &rv); 344*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */ 345*7c478bd9Sstevel@tonic-gate return (error ? set_errno(error) : rv); 346*7c478bd9Sstevel@tonic-gate } 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate /* 349*7c478bd9Sstevel@tonic-gate * Handle zones. 350*7c478bd9Sstevel@tonic-gate */ 351*7c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 352*7c478bd9Sstevel@tonic-gate error = zone_uadmin(cmd, fcn, credp); 353*7c478bd9Sstevel@tonic-gate return (error ? set_errno(error) : 0); 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate /* 357*7c478bd9Sstevel@tonic-gate * Certain subcommands intepret a non-NULL mdep value as a pointer to 358*7c478bd9Sstevel@tonic-gate * a boot string. Attempt to copy it in now, or reset mdep to NULL. 359*7c478bd9Sstevel@tonic-gate */ 360*7c478bd9Sstevel@tonic-gate if (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_DUMP) { 361*7c478bd9Sstevel@tonic-gate if (mdep != NULL && copyinstr((const char *)mdep, buf, 362*7c478bd9Sstevel@tonic-gate sizeof (buf) - 1, &nbytes) == 0) { 363*7c478bd9Sstevel@tonic-gate buf[nbytes] = '\0'; 364*7c478bd9Sstevel@tonic-gate mdep = (uintptr_t)buf; 365*7c478bd9Sstevel@tonic-gate } else 366*7c478bd9Sstevel@tonic-gate mdep = NULL; 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate if ((error = kadmin(cmd, fcn, (void *)mdep, credp)) != 0) 370*7c478bd9Sstevel@tonic-gate return (set_errno(error)); 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate return (0); 373*7c478bd9Sstevel@tonic-gate } 374