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
507b65a64Saguzovsk * Common Development and Distribution License (the "License").
607b65a64Saguzovsk * 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 /*
2207b65a64Saguzovsk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
249d12795fSRobert Mustacchi * Copyright (c) 2015 Joyent, Inc.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/bitmap.h>
337c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
347c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate #include <sys/systm.h>
377c478bd9Sstevel@tonic-gate #include <sys/user.h>
387c478bd9Sstevel@tonic-gate #include <sys/unistd.h>
397c478bd9Sstevel@tonic-gate #include <sys/errno.h>
407c478bd9Sstevel@tonic-gate #include <sys/proc.h>
417c478bd9Sstevel@tonic-gate #include <sys/mman.h>
427c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
437c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
447c478bd9Sstevel@tonic-gate #include <sys/cred.h>
457c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
467c478bd9Sstevel@tonic-gate #include <sys/debug.h>
477c478bd9Sstevel@tonic-gate #include <sys/policy.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #include <vm/as.h>
507c478bd9Sstevel@tonic-gate #include <vm/seg.h>
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate static uint_t mem_getpgszc(size_t);
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate * Memory control operations
567c478bd9Sstevel@tonic-gate */
577c478bd9Sstevel@tonic-gate int
memcntl(caddr_t addr,size_t len,int cmd,caddr_t arg,int attr,int mask)587c478bd9Sstevel@tonic-gate memcntl(caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask)
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate struct as *as = ttoproc(curthread)->p_as;
617c478bd9Sstevel@tonic-gate struct proc *p = ttoproc(curthread);
627c478bd9Sstevel@tonic-gate size_t pgsz;
637c478bd9Sstevel@tonic-gate uint_t szc, oszc, pgcmd;
647c478bd9Sstevel@tonic-gate int error = 0;
657c478bd9Sstevel@tonic-gate faultcode_t fc;
667c478bd9Sstevel@tonic-gate uintptr_t iarg;
677c478bd9Sstevel@tonic-gate STRUCT_DECL(memcntl_mha, mha);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate if (mask)
707c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
717c478bd9Sstevel@tonic-gate if ((cmd == MC_LOCKAS) || (cmd == MC_UNLOCKAS)) {
727c478bd9Sstevel@tonic-gate if ((addr != 0) || (len != 0)) {
737c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate } else if (cmd != MC_HAT_ADVISE) {
767c478bd9Sstevel@tonic-gate if (((uintptr_t)addr & PAGEOFFSET) != 0 || len == 0) {
777c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate * We're only concerned with the address range
817c478bd9Sstevel@tonic-gate * here, not the protections. The protections
827c478bd9Sstevel@tonic-gate * are only used as a "filter" in this code,
837c478bd9Sstevel@tonic-gate * they aren't set or modified here.
847c478bd9Sstevel@tonic-gate */
857c478bd9Sstevel@tonic-gate if (valid_usr_range(addr, len, 0, as,
867c478bd9Sstevel@tonic-gate as->a_userlimit) != RANGE_OKAY) {
877c478bd9Sstevel@tonic-gate return (set_errno(ENOMEM));
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate if (cmd == MC_HAT_ADVISE) {
927c478bd9Sstevel@tonic-gate if (attr != 0 || mask != 0) {
937c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate } else {
977c478bd9Sstevel@tonic-gate if ((VALID_ATTR & attr) != attr) {
987c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate if ((attr & SHARED) && (attr & PRIVATE)) {
1017c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate if (((cmd == MC_LOCKAS) || (cmd == MC_LOCK) ||
1047c478bd9Sstevel@tonic-gate (cmd == MC_UNLOCKAS) || (cmd == MC_UNLOCK)) &&
1057c478bd9Sstevel@tonic-gate (error = secpolicy_lock_memory(CRED())) != 0)
1067c478bd9Sstevel@tonic-gate return (set_errno(error));
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate if (attr) {
1097c478bd9Sstevel@tonic-gate attr |= PROT_USER;
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate switch (cmd) {
1137c478bd9Sstevel@tonic-gate case MC_SYNC:
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * MS_SYNC used to be defined to be zero but is now non-zero.
1167c478bd9Sstevel@tonic-gate * For binary compatibility we still accept zero
1177c478bd9Sstevel@tonic-gate * (the absence of MS_ASYNC) to mean the same thing.
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate iarg = (uintptr_t)arg;
1207c478bd9Sstevel@tonic-gate if ((iarg & ~MS_INVALIDATE) == 0)
1217c478bd9Sstevel@tonic-gate iarg |= MS_SYNC;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate if (((iarg & ~(MS_SYNC|MS_ASYNC|MS_INVALIDATE)) != 0) ||
1247c478bd9Sstevel@tonic-gate ((iarg & (MS_SYNC|MS_ASYNC)) == (MS_SYNC|MS_ASYNC))) {
1257c478bd9Sstevel@tonic-gate error = set_errno(EINVAL);
1267c478bd9Sstevel@tonic-gate } else {
1277c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, cmd, attr, iarg, NULL, 0);
1287c478bd9Sstevel@tonic-gate if (error) {
1297c478bd9Sstevel@tonic-gate (void) set_errno(error);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate return (error);
1337c478bd9Sstevel@tonic-gate case MC_LOCKAS:
1347c478bd9Sstevel@tonic-gate if ((uintptr_t)arg & ~(MCL_FUTURE|MCL_CURRENT) ||
1357c478bd9Sstevel@tonic-gate (uintptr_t)arg == 0) {
1367c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate break;
1397c478bd9Sstevel@tonic-gate case MC_LOCK:
1407c478bd9Sstevel@tonic-gate case MC_UNLOCKAS:
1417c478bd9Sstevel@tonic-gate case MC_UNLOCK:
1427c478bd9Sstevel@tonic-gate break;
1437c478bd9Sstevel@tonic-gate case MC_HAT_ADVISE:
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * Set prefered page size.
1467c478bd9Sstevel@tonic-gate */
1477c478bd9Sstevel@tonic-gate STRUCT_INIT(mha, get_udatamodel());
1487c478bd9Sstevel@tonic-gate if (copyin(arg, STRUCT_BUF(mha), STRUCT_SIZE(mha))) {
1497c478bd9Sstevel@tonic-gate return (set_errno(EFAULT));
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate pgcmd = STRUCT_FGET(mha, mha_cmd);
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate * Currently only MHA_MAPSIZE_VA, MHA_MAPSIZE_STACK
1567c478bd9Sstevel@tonic-gate * and MHA_MAPSIZE_BSSBRK are supported. Only one
1577c478bd9Sstevel@tonic-gate * command may be specified at a time.
1587c478bd9Sstevel@tonic-gate */
1597c478bd9Sstevel@tonic-gate if ((~(MHA_MAPSIZE_VA|MHA_MAPSIZE_STACK|MHA_MAPSIZE_BSSBRK) &
1607c478bd9Sstevel@tonic-gate pgcmd) || pgcmd == 0 || !ISP2(pgcmd) ||
1617c478bd9Sstevel@tonic-gate STRUCT_FGET(mha, mha_flags))
1627c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate pgsz = STRUCT_FGET(mha, mha_pagesize);
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * call platform specific map_pgsz() routine to get the
1687c478bd9Sstevel@tonic-gate * optimal pgsz if pgsz is 0.
1697c478bd9Sstevel@tonic-gate *
1707c478bd9Sstevel@tonic-gate * For stack and heap operations addr and len must be zero.
1717c478bd9Sstevel@tonic-gate */
1727c478bd9Sstevel@tonic-gate if ((pgcmd & (MHA_MAPSIZE_BSSBRK|MHA_MAPSIZE_STACK)) != 0) {
1737c478bd9Sstevel@tonic-gate if (addr != NULL || len != 0) {
1747c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * Disable autompss for this process unless pgsz == 0,
1797c478bd9Sstevel@tonic-gate * which means the system should pick. In the
1807c478bd9Sstevel@tonic-gate * pgsz == 0 case, leave the SAUTOLPG setting alone, as
1817c478bd9Sstevel@tonic-gate * we don't want to enable it when someone has
1827c478bd9Sstevel@tonic-gate * disabled automatic large page selection for the
1837c478bd9Sstevel@tonic-gate * whole system.
1847c478bd9Sstevel@tonic-gate */
1857c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
1867c478bd9Sstevel@tonic-gate if (pgsz != 0) {
1877c478bd9Sstevel@tonic-gate p->p_flag &= ~SAUTOLPG;
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate as_rangelock(as);
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate if (pgsz == 0) {
1947c478bd9Sstevel@tonic-gate int type;
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate if (pgcmd == MHA_MAPSIZE_BSSBRK)
1977c478bd9Sstevel@tonic-gate type = MAPPGSZ_HEAP;
1987c478bd9Sstevel@tonic-gate else
1997c478bd9Sstevel@tonic-gate type = MAPPGSZ_STK;
2007c478bd9Sstevel@tonic-gate
201ec25b48fSsusans pgsz = map_pgsz(type, p, 0, 0, 1);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate } else {
2047c478bd9Sstevel@tonic-gate /*
205ec25b48fSsusans * addr and len must be valid for range specified.
206ec25b48fSsusans */
207ec25b48fSsusans if (valid_usr_range(addr, len, 0, as,
208ec25b48fSsusans as->a_userlimit) != RANGE_OKAY) {
209ec25b48fSsusans return (set_errno(ENOMEM));
210ec25b48fSsusans }
211ec25b48fSsusans /*
2127c478bd9Sstevel@tonic-gate * Note that we don't disable automatic large page
2137c478bd9Sstevel@tonic-gate * selection for anon segments based on use of
2147c478bd9Sstevel@tonic-gate * memcntl().
2157c478bd9Sstevel@tonic-gate */
2167c478bd9Sstevel@tonic-gate if (pgsz == 0) {
217ec25b48fSsusans error = as_set_default_lpsize(as, addr, len);
218ec25b48fSsusans if (error) {
219ec25b48fSsusans (void) set_errno(error);
220ec25b48fSsusans }
221ec25b48fSsusans return (error);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate * addr and len must be prefered page size aligned
2267c478bd9Sstevel@tonic-gate */
2277c478bd9Sstevel@tonic-gate if (!IS_P2ALIGNED(addr, pgsz) ||
2287c478bd9Sstevel@tonic-gate !IS_P2ALIGNED(len, pgsz)) {
2297c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate szc = mem_getpgszc(pgsz);
2347c478bd9Sstevel@tonic-gate if (szc == (uint_t)-1) {
2357c478bd9Sstevel@tonic-gate if ((pgcmd & (MHA_MAPSIZE_BSSBRK|MHA_MAPSIZE_STACK))
2367c478bd9Sstevel@tonic-gate != 0) {
2377c478bd9Sstevel@tonic-gate as_rangeunlock(as);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate * For stack and heap operations we first need to pad
2447c478bd9Sstevel@tonic-gate * out existing range (create new mappings) to the new
2457c478bd9Sstevel@tonic-gate * prefered page size boundary. Also the start of the
2467c478bd9Sstevel@tonic-gate * .bss for the heap or user's stack base may not be on
2477c478bd9Sstevel@tonic-gate * the new prefered page size boundary. For these cases
2487c478bd9Sstevel@tonic-gate * we align the base of the request on the new prefered
2497c478bd9Sstevel@tonic-gate * page size.
2507c478bd9Sstevel@tonic-gate */
2517c478bd9Sstevel@tonic-gate if (pgcmd & MHA_MAPSIZE_BSSBRK) {
2527c478bd9Sstevel@tonic-gate if (szc == p->p_brkpageszc) {
2537c478bd9Sstevel@tonic-gate as_rangeunlock(as);
2547c478bd9Sstevel@tonic-gate return (0);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate if (szc > p->p_brkpageszc) {
2577c478bd9Sstevel@tonic-gate error = brk_internal(p->p_brkbase
2587c478bd9Sstevel@tonic-gate + p->p_brksize, szc);
2597c478bd9Sstevel@tonic-gate if (error) {
2607c478bd9Sstevel@tonic-gate as_rangeunlock(as);
2617c478bd9Sstevel@tonic-gate return (set_errno(error));
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate }
264ec25b48fSsusans /*
265ec25b48fSsusans * It is possible for brk_internal to silently fail to
266ec25b48fSsusans * promote the heap size, so don't panic or ASSERT.
267ec25b48fSsusans */
268ec25b48fSsusans if (!IS_P2ALIGNED(p->p_brkbase + p->p_brksize, pgsz)) {
269ec25b48fSsusans as_rangeunlock(as);
270ec25b48fSsusans return (set_errno(ENOMEM));
271ec25b48fSsusans }
2727c478bd9Sstevel@tonic-gate oszc = p->p_brkpageszc;
2737c478bd9Sstevel@tonic-gate p->p_brkpageszc = szc;
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate addr = (caddr_t)P2ROUNDUP((uintptr_t)p->p_bssbase,
2767c478bd9Sstevel@tonic-gate pgsz);
2777c478bd9Sstevel@tonic-gate len = (p->p_brkbase + p->p_brksize) - addr;
2787c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(len, pgsz));
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate * Perhaps no existing pages to promote.
2817c478bd9Sstevel@tonic-gate */
2827c478bd9Sstevel@tonic-gate if (len == 0) {
2837c478bd9Sstevel@tonic-gate as_rangeunlock(as);
2847c478bd9Sstevel@tonic-gate return (0);
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate * The code below, as does grow.c, assumes stacks always grow
2897c478bd9Sstevel@tonic-gate * downward.
2907c478bd9Sstevel@tonic-gate */
2917c478bd9Sstevel@tonic-gate if (pgcmd & MHA_MAPSIZE_STACK) {
292e7f81dc7Ssusans if (szc == p->p_stkpageszc) {
2937c478bd9Sstevel@tonic-gate as_rangeunlock(as);
2947c478bd9Sstevel@tonic-gate return (0);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate if (szc > p->p_stkpageszc) {
298ec25b48fSsusans error = grow_internal(p->p_usrstack -
299ec25b48fSsusans p->p_stksize, szc);
3007c478bd9Sstevel@tonic-gate if (error) {
3017c478bd9Sstevel@tonic-gate as_rangeunlock(as);
3027c478bd9Sstevel@tonic-gate return (set_errno(error));
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate }
305ec25b48fSsusans /*
306ec25b48fSsusans * It is possible for grow_internal to silently fail to
307ec25b48fSsusans * promote the stack size, so don't panic or ASSERT.
308ec25b48fSsusans */
309ec25b48fSsusans if (!IS_P2ALIGNED(p->p_usrstack - p->p_stksize, pgsz)) {
310ec25b48fSsusans as_rangeunlock(as);
311ec25b48fSsusans return (set_errno(ENOMEM));
312ec25b48fSsusans }
3137c478bd9Sstevel@tonic-gate oszc = p->p_stkpageszc;
3147c478bd9Sstevel@tonic-gate p->p_stkpageszc = szc;
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate addr = p->p_usrstack - p->p_stksize;
317e7f81dc7Ssusans len = P2ALIGN(p->p_stksize, pgsz);
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate /*
320e7f81dc7Ssusans * Perhaps nothing to promote.
3217c478bd9Sstevel@tonic-gate */
322e7f81dc7Ssusans if (len == 0 || addr >= p->p_usrstack ||
323e7f81dc7Ssusans (addr + len) < addr) {
3247c478bd9Sstevel@tonic-gate as_rangeunlock(as);
3257c478bd9Sstevel@tonic-gate return (0);
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(addr, pgsz));
3297c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(len, pgsz));
3307c478bd9Sstevel@tonic-gate error = as_setpagesize(as, addr, len, szc, B_TRUE);
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate * On stack or heap failures restore original
3347c478bd9Sstevel@tonic-gate * pg size code.
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate if (error) {
3377c478bd9Sstevel@tonic-gate if ((pgcmd & MHA_MAPSIZE_BSSBRK) != 0) {
3387c478bd9Sstevel@tonic-gate p->p_brkpageszc = oszc;
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate if ((pgcmd & MHA_MAPSIZE_STACK) != 0) {
3417c478bd9Sstevel@tonic-gate p->p_stkpageszc = oszc;
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate (void) set_errno(error);
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate if ((pgcmd & (MHA_MAPSIZE_BSSBRK|MHA_MAPSIZE_STACK)) != 0) {
3467c478bd9Sstevel@tonic-gate as_rangeunlock(as);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate return (error);
3497c478bd9Sstevel@tonic-gate case MC_ADVISE:
350*eaef830eSBryan Cantrill if ((uintptr_t)arg == MADV_FREE ||
351*eaef830eSBryan Cantrill (uintptr_t)arg == MADV_PURGE) {
35207b65a64Saguzovsk len &= PAGEMASK;
35307b65a64Saguzovsk }
3547c478bd9Sstevel@tonic-gate switch ((uintptr_t)arg) {
3557c478bd9Sstevel@tonic-gate case MADV_WILLNEED:
3567c478bd9Sstevel@tonic-gate fc = as_faulta(as, addr, len);
3577c478bd9Sstevel@tonic-gate if (fc) {
3587c478bd9Sstevel@tonic-gate if (FC_CODE(fc) == FC_OBJERR)
3597c478bd9Sstevel@tonic-gate error = set_errno(FC_ERRNO(fc));
3607c478bd9Sstevel@tonic-gate else if (FC_CODE(fc) == FC_NOMAP)
3617c478bd9Sstevel@tonic-gate error = set_errno(ENOMEM);
3627c478bd9Sstevel@tonic-gate else
3637c478bd9Sstevel@tonic-gate error = set_errno(EINVAL);
3647c478bd9Sstevel@tonic-gate return (error);
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate break;
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate case MADV_DONTNEED:
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate * For now, don't need is turned into an as_ctl(MC_SYNC)
3717c478bd9Sstevel@tonic-gate * operation flagged for async invalidate.
3727c478bd9Sstevel@tonic-gate */
3737c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, MC_SYNC, attr,
3747c478bd9Sstevel@tonic-gate MS_ASYNC | MS_INVALIDATE, NULL, 0);
3757c478bd9Sstevel@tonic-gate if (error)
3767c478bd9Sstevel@tonic-gate (void) set_errno(error);
3777c478bd9Sstevel@tonic-gate return (error);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate default:
3807c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, cmd, attr,
3817c478bd9Sstevel@tonic-gate (uintptr_t)arg, NULL, 0);
3827c478bd9Sstevel@tonic-gate if (error)
3837c478bd9Sstevel@tonic-gate (void) set_errno(error);
3847c478bd9Sstevel@tonic-gate return (error);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate break;
3879d12795fSRobert Mustacchi case MC_INHERIT_ZERO:
388ede2438eSRichard PALO if (arg != 0 || attr != 0 || mask != 0)
3899d12795fSRobert Mustacchi return (set_errno(EINVAL));
3909d12795fSRobert Mustacchi break;
3917c478bd9Sstevel@tonic-gate default:
3927c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, cmd, attr, (uintptr_t)arg, NULL, 0);
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate if (error)
3987c478bd9Sstevel@tonic-gate (void) set_errno(error);
3997c478bd9Sstevel@tonic-gate return (error);
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate /*
4037c478bd9Sstevel@tonic-gate * Return page size code for page size passed in. If
4044abce959Smec * matching page size not found or supported, return -1.
4057c478bd9Sstevel@tonic-gate */
4067c478bd9Sstevel@tonic-gate static uint_t
mem_getpgszc(size_t pgsz)4077c478bd9Sstevel@tonic-gate mem_getpgszc(size_t pgsz) {
4084abce959Smec return ((uint_t)page_szc_user_filtered(pgsz));
4097c478bd9Sstevel@tonic-gate }
410