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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 22*97eda132Sraf 237c478bd9Sstevel@tonic-gate /* 24edc40228Sachartre * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/param.h> 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 337c478bd9Sstevel@tonic-gate #include <sys/systm.h> 347c478bd9Sstevel@tonic-gate #include <sys/errno.h> 357c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 367c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 377c478bd9Sstevel@tonic-gate #include <sys/swap.h> 387c478bd9Sstevel@tonic-gate #include <sys/file.h> 397c478bd9Sstevel@tonic-gate #include <sys/proc.h> 407c478bd9Sstevel@tonic-gate #include <sys/var.h> 417c478bd9Sstevel@tonic-gate #include <sys/uadmin.h> 427c478bd9Sstevel@tonic-gate #include <sys/signal.h> 437c478bd9Sstevel@tonic-gate #include <sys/time.h> 447c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 457c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 467c478bd9Sstevel@tonic-gate #include <sys/callb.h> 477c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 487c478bd9Sstevel@tonic-gate #include <sys/debug.h> 497c478bd9Sstevel@tonic-gate #include <sys/ftrace.h> 507c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 517c478bd9Sstevel@tonic-gate #include <sys/panic.h> 527c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 537c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 547c478bd9Sstevel@tonic-gate #include <sys/policy.h> 557c478bd9Sstevel@tonic-gate #include <sys/zone.h> 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* 587c478bd9Sstevel@tonic-gate * Administrivia system call. We provide this in two flavors: one for calling 597c478bd9Sstevel@tonic-gate * from the system call path (uadmin), and the other for calling from elsewhere 607c478bd9Sstevel@tonic-gate * within the kernel (kadmin). Callers must beware that certain uadmin cmd 617c478bd9Sstevel@tonic-gate * values (specifically A_SWAPCTL) are only supported by uadmin and not kadmin. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate extern ksema_t fsflush_sema; 657c478bd9Sstevel@tonic-gate kmutex_t ualock; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Kill all user processes in said zone. A special argument of ALL_ZONES is 707c478bd9Sstevel@tonic-gate * passed in when the system as a whole is shutting down. The lack of per-zone 717c478bd9Sstevel@tonic-gate * process lists is likely to make the following a performance bottleneck on a 727c478bd9Sstevel@tonic-gate * system with many zones. 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate void 757c478bd9Sstevel@tonic-gate killall(zoneid_t zoneid) 767c478bd9Sstevel@tonic-gate { 777c478bd9Sstevel@tonic-gate proc_t *p; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate ASSERT(zoneid != GLOBAL_ZONEID); 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Kill all processes except kernel daemons and ourself. 827c478bd9Sstevel@tonic-gate * Make a first pass to stop all processes so they won't 837c478bd9Sstevel@tonic-gate * be trying to restart children as we kill them. 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 867c478bd9Sstevel@tonic-gate for (p = practive; p != NULL; p = p->p_next) { 877c478bd9Sstevel@tonic-gate if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) && 887c478bd9Sstevel@tonic-gate p->p_exec != NULLVP && /* kernel daemons */ 897c478bd9Sstevel@tonic-gate p->p_as != &kas && 907c478bd9Sstevel@tonic-gate p->p_stat != SZOMB) { 917c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 927c478bd9Sstevel@tonic-gate p->p_flag |= SNOWAIT; 937c478bd9Sstevel@tonic-gate sigtoproc(p, NULL, SIGSTOP); 947c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate p = practive; 987c478bd9Sstevel@tonic-gate while (p != NULL) { 997c478bd9Sstevel@tonic-gate if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) && 1007c478bd9Sstevel@tonic-gate p->p_exec != NULLVP && /* kernel daemons */ 1017c478bd9Sstevel@tonic-gate p->p_as != &kas && 1027c478bd9Sstevel@tonic-gate p->p_stat != SIDL && 1037c478bd9Sstevel@tonic-gate p->p_stat != SZOMB) { 1047c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 1057c478bd9Sstevel@tonic-gate if (sigismember(&p->p_sig, SIGKILL)) { 1067c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1077c478bd9Sstevel@tonic-gate p = p->p_next; 1087c478bd9Sstevel@tonic-gate } else { 1097c478bd9Sstevel@tonic-gate sigtoproc(p, NULL, SIGKILL); 1107c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1117c478bd9Sstevel@tonic-gate (void) cv_timedwait(&p->p_srwchan_cv, 1127c478bd9Sstevel@tonic-gate &pidlock, lbolt + hz); 1137c478bd9Sstevel@tonic-gate p = practive; 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate } else { 1167c478bd9Sstevel@tonic-gate p = p->p_next; 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate int 1237c478bd9Sstevel@tonic-gate kadmin(int cmd, int fcn, void *mdep, cred_t *credp) 1247c478bd9Sstevel@tonic-gate { 1257c478bd9Sstevel@tonic-gate int error = 0; 1267c478bd9Sstevel@tonic-gate int locked = 0; 1277c478bd9Sstevel@tonic-gate char *buf; 1287c478bd9Sstevel@tonic-gate size_t buflen = 0; 129edc40228Sachartre boolean_t invoke_cb = B_FALSE; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * We might be called directly by the kernel's fault-handling code, so 1337c478bd9Sstevel@tonic-gate * we can't assert that the caller is in the global zone. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * Make sure that cmd is one of the valid <sys/uadmin.h> command codes 1387c478bd9Sstevel@tonic-gate * and that we have appropriate privileges for this action. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate switch (cmd) { 1417c478bd9Sstevel@tonic-gate case A_FTRACE: 1427c478bd9Sstevel@tonic-gate case A_SHUTDOWN: 1437c478bd9Sstevel@tonic-gate case A_REBOOT: 1447c478bd9Sstevel@tonic-gate case A_REMOUNT: 1457c478bd9Sstevel@tonic-gate case A_FREEZE: 1467c478bd9Sstevel@tonic-gate case A_DUMP: 1477c478bd9Sstevel@tonic-gate if (secpolicy_sys_config(credp, B_FALSE) != 0) 1487c478bd9Sstevel@tonic-gate return (EPERM); 1497c478bd9Sstevel@tonic-gate break; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate default: 1527c478bd9Sstevel@tonic-gate return (EINVAL); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 1567c478bd9Sstevel@tonic-gate * Serialize these operations on ualock. If it is held, just return 1577c478bd9Sstevel@tonic-gate * as if successful since the system will soon reset or remount. 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate if (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_REMOUNT) { 1607c478bd9Sstevel@tonic-gate if (!mutex_tryenter(&ualock)) 1617c478bd9Sstevel@tonic-gate return (0); 1627c478bd9Sstevel@tonic-gate locked = 1; 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate switch (cmd) { 1667c478bd9Sstevel@tonic-gate case A_SHUTDOWN: 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate proc_t *p = ttoproc(curthread); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * Release (almost) all of our own resources if we are called 1727c478bd9Sstevel@tonic-gate * from a user context, however if we are calling kadmin() from 1737c478bd9Sstevel@tonic-gate * a kernel context then we do not release these resources. 1747c478bd9Sstevel@tonic-gate */ 175*97eda132Sraf if (p != &p0) { 176*97eda132Sraf proc_is_exiting(p); 1777c478bd9Sstevel@tonic-gate if ((error = exitlwps(0)) != 0) 1787c478bd9Sstevel@tonic-gate return (error); 1797c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 1807c478bd9Sstevel@tonic-gate p->p_flag |= SNOWAIT; 1817c478bd9Sstevel@tonic-gate sigfillset(&p->p_ignore); 1827c478bd9Sstevel@tonic-gate curthread->t_lwp->lwp_cursig = 0; 1837c478bd9Sstevel@tonic-gate curthread->t_lwp->lwp_extsig = 0; 1847c478bd9Sstevel@tonic-gate if (p->p_exec) { 1857c478bd9Sstevel@tonic-gate vnode_t *exec_vp = p->p_exec; 1867c478bd9Sstevel@tonic-gate p->p_exec = NULLVP; 1877c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1887c478bd9Sstevel@tonic-gate VN_RELE(exec_vp); 1897c478bd9Sstevel@tonic-gate } else { 1907c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate pollcleanup(); 1947c478bd9Sstevel@tonic-gate closeall(P_FINFO(curproc)); 1957c478bd9Sstevel@tonic-gate relvm(); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate } else { 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * Reset t_cred if not set because much of the 2007c478bd9Sstevel@tonic-gate * filesystem code depends on CRED() being valid. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate if (curthread->t_cred == NULL) 2037c478bd9Sstevel@tonic-gate curthread->t_cred = kcred; 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * Communcate that init shouldn't be restarted. 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate zone_shutdown_global(); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate killall(ALL_ZONES); 2127c478bd9Sstevel@tonic-gate /* 2137c478bd9Sstevel@tonic-gate * If we are calling kadmin() from a kernel context then we 2147c478bd9Sstevel@tonic-gate * do not release these resources. 2157c478bd9Sstevel@tonic-gate */ 2167c478bd9Sstevel@tonic-gate if (ttoproc(curthread) != &p0) { 2177c478bd9Sstevel@tonic-gate VN_RELE(u.u_cdir); 2187c478bd9Sstevel@tonic-gate if (u.u_rdir) 2197c478bd9Sstevel@tonic-gate VN_RELE(u.u_rdir); 2207c478bd9Sstevel@tonic-gate if (u.u_cwd) 2217c478bd9Sstevel@tonic-gate refstr_rele(u.u_cwd); 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate u.u_cdir = rootdir; 2247c478bd9Sstevel@tonic-gate u.u_rdir = NULL; 2257c478bd9Sstevel@tonic-gate u.u_cwd = NULL; 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate /* 2297c478bd9Sstevel@tonic-gate * Allow the reboot/halt/poweroff code a chance to do 2307c478bd9Sstevel@tonic-gate * anything it needs to whilst we still have filesystems 2317c478bd9Sstevel@tonic-gate * mounted, like loading any modules necessary for later 2327c478bd9Sstevel@tonic-gate * performing the actual poweroff. 2337c478bd9Sstevel@tonic-gate */ 2347c478bd9Sstevel@tonic-gate if ((mdep != NULL) && (*(char *)mdep == '/')) { 2357c478bd9Sstevel@tonic-gate buf = i_convert_boot_device_name(mdep, NULL, &buflen); 2367c478bd9Sstevel@tonic-gate mdpreboot(cmd, fcn, buf); 2377c478bd9Sstevel@tonic-gate } else 2387c478bd9Sstevel@tonic-gate mdpreboot(cmd, fcn, mdep); 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /* 2417c478bd9Sstevel@tonic-gate * Allow fsflush to finish running and then prevent it 2427c478bd9Sstevel@tonic-gate * from ever running again so that vfs_unmountall() and 2437c478bd9Sstevel@tonic-gate * vfs_syncall() can acquire the vfs locks they need. 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate sema_p(&fsflush_sema); 2467c478bd9Sstevel@tonic-gate (void) callb_execute_class(CB_CL_UADMIN_PRE_VFS, NULL); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate vfs_unmountall(); 2497c478bd9Sstevel@tonic-gate (void) VFS_MOUNTROOT(rootvfs, ROOT_UNMOUNT); 2507c478bd9Sstevel@tonic-gate vfs_syncall(); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate dump_ereports(); 2537c478bd9Sstevel@tonic-gate dump_messages(); 2547c478bd9Sstevel@tonic-gate 255edc40228Sachartre invoke_cb = B_TRUE; 256edc40228Sachartre 2577c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate case A_REBOOT: 2617c478bd9Sstevel@tonic-gate if ((mdep != NULL) && (*(char *)mdep == '/')) { 2627c478bd9Sstevel@tonic-gate buf = i_convert_boot_device_name(mdep, NULL, &buflen); 263edc40228Sachartre mdboot(cmd, fcn, buf, invoke_cb); 2647c478bd9Sstevel@tonic-gate } else 265edc40228Sachartre mdboot(cmd, fcn, mdep, invoke_cb); 2667c478bd9Sstevel@tonic-gate /* no return expected */ 2677c478bd9Sstevel@tonic-gate break; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate case A_REMOUNT: 2707c478bd9Sstevel@tonic-gate (void) VFS_MOUNTROOT(rootvfs, ROOT_REMOUNT); 2717c478bd9Sstevel@tonic-gate break; 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate case A_FREEZE: 2747c478bd9Sstevel@tonic-gate { 2757c478bd9Sstevel@tonic-gate /* XXX: declare in some header file */ 2767c478bd9Sstevel@tonic-gate extern int cpr(int); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate if (modload("misc", "cpr") == -1) 2797c478bd9Sstevel@tonic-gate return (ENOTSUP); 2807c478bd9Sstevel@tonic-gate error = cpr(fcn); 2817c478bd9Sstevel@tonic-gate break; 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate case A_FTRACE: 2857c478bd9Sstevel@tonic-gate { 2867c478bd9Sstevel@tonic-gate switch (fcn) { 2877c478bd9Sstevel@tonic-gate case AD_FTRACE_START: 2887c478bd9Sstevel@tonic-gate (void) FTRACE_START(); 2897c478bd9Sstevel@tonic-gate break; 2907c478bd9Sstevel@tonic-gate case AD_FTRACE_STOP: 2917c478bd9Sstevel@tonic-gate (void) FTRACE_STOP(); 2927c478bd9Sstevel@tonic-gate break; 2937c478bd9Sstevel@tonic-gate default: 2947c478bd9Sstevel@tonic-gate error = EINVAL; 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate break; 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate case A_DUMP: 3007c478bd9Sstevel@tonic-gate { 3017c478bd9Sstevel@tonic-gate if (fcn == AD_NOSYNC) { 3027c478bd9Sstevel@tonic-gate in_sync = 1; 3037c478bd9Sstevel@tonic-gate break; 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate panic_bootfcn = fcn; 3077c478bd9Sstevel@tonic-gate panic_forced = 1; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate if ((mdep != NULL) && (*(char *)mdep == '/')) { 3107c478bd9Sstevel@tonic-gate panic_bootstr = i_convert_boot_device_name(mdep, 3117c478bd9Sstevel@tonic-gate NULL, &buflen); 3127c478bd9Sstevel@tonic-gate } else 3137c478bd9Sstevel@tonic-gate panic_bootstr = mdep; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate panic("forced crash dump initiated at user request"); 3167c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate default: 3207c478bd9Sstevel@tonic-gate error = EINVAL; 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate if (locked) 3247c478bd9Sstevel@tonic-gate mutex_exit(&ualock); 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate return (error); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate int 3307c478bd9Sstevel@tonic-gate uadmin(int cmd, int fcn, uintptr_t mdep) 3317c478bd9Sstevel@tonic-gate { 3327c478bd9Sstevel@tonic-gate int error = 0, rv = 0; 3337c478bd9Sstevel@tonic-gate size_t nbytes = 0; 3347c478bd9Sstevel@tonic-gate char buf[257]; 3357c478bd9Sstevel@tonic-gate cred_t *credp = CRED(); 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* 3387c478bd9Sstevel@tonic-gate * The swapctl system call doesn't have its own entry point: it uses 3397c478bd9Sstevel@tonic-gate * uadmin as a wrapper so we just call it directly from here. 3407c478bd9Sstevel@tonic-gate */ 3417c478bd9Sstevel@tonic-gate if (cmd == A_SWAPCTL) { 3427c478bd9Sstevel@tonic-gate if (get_udatamodel() == DATAMODEL_NATIVE) 3437c478bd9Sstevel@tonic-gate error = swapctl(fcn, (void *)mdep, &rv); 3447c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL) 3457c478bd9Sstevel@tonic-gate else 3467c478bd9Sstevel@tonic-gate error = swapctl32(fcn, (void *)mdep, &rv); 3477c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */ 3487c478bd9Sstevel@tonic-gate return (error ? set_errno(error) : rv); 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate /* 3527c478bd9Sstevel@tonic-gate * Handle zones. 3537c478bd9Sstevel@tonic-gate */ 3547c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 3557c478bd9Sstevel@tonic-gate error = zone_uadmin(cmd, fcn, credp); 3567c478bd9Sstevel@tonic-gate return (error ? set_errno(error) : 0); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate /* 3607c478bd9Sstevel@tonic-gate * Certain subcommands intepret a non-NULL mdep value as a pointer to 3617c478bd9Sstevel@tonic-gate * a boot string. Attempt to copy it in now, or reset mdep to NULL. 3627c478bd9Sstevel@tonic-gate */ 3637c478bd9Sstevel@tonic-gate if (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_DUMP) { 3647c478bd9Sstevel@tonic-gate if (mdep != NULL && copyinstr((const char *)mdep, buf, 3657c478bd9Sstevel@tonic-gate sizeof (buf) - 1, &nbytes) == 0) { 3667c478bd9Sstevel@tonic-gate buf[nbytes] = '\0'; 3677c478bd9Sstevel@tonic-gate mdep = (uintptr_t)buf; 3687c478bd9Sstevel@tonic-gate } else 3697c478bd9Sstevel@tonic-gate mdep = NULL; 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate if ((error = kadmin(cmd, fcn, (void *)mdep, credp)) != 0) 3737c478bd9Sstevel@tonic-gate return (set_errno(error)); 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate return (0); 3767c478bd9Sstevel@tonic-gate } 377