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 */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 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 #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 367c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 377c478bd9Sstevel@tonic-gate #include <sys/param.h> 387c478bd9Sstevel@tonic-gate #include <sys/systm.h> 397c478bd9Sstevel@tonic-gate #include <sys/user.h> 407c478bd9Sstevel@tonic-gate #include <sys/unistd.h> 417c478bd9Sstevel@tonic-gate #include <sys/errno.h> 427c478bd9Sstevel@tonic-gate #include <sys/proc.h> 437c478bd9Sstevel@tonic-gate #include <sys/mman.h> 447c478bd9Sstevel@tonic-gate #include <sys/tuneable.h> 457c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 467c478bd9Sstevel@tonic-gate #include <sys/cred.h> 477c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h> 487c478bd9Sstevel@tonic-gate #include <sys/debug.h> 497c478bd9Sstevel@tonic-gate #include <sys/policy.h> 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <vm/as.h> 527c478bd9Sstevel@tonic-gate #include <vm/seg.h> 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate static uint_t mem_getpgszc(size_t); 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * Memory control operations 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate int 607c478bd9Sstevel@tonic-gate memcntl(caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask) 617c478bd9Sstevel@tonic-gate { 627c478bd9Sstevel@tonic-gate struct as *as = ttoproc(curthread)->p_as; 637c478bd9Sstevel@tonic-gate struct proc *p = ttoproc(curthread); 647c478bd9Sstevel@tonic-gate size_t pgsz; 657c478bd9Sstevel@tonic-gate uint_t szc, oszc, pgcmd; 667c478bd9Sstevel@tonic-gate int error = 0; 677c478bd9Sstevel@tonic-gate faultcode_t fc; 687c478bd9Sstevel@tonic-gate uintptr_t iarg; 697c478bd9Sstevel@tonic-gate STRUCT_DECL(memcntl_mha, mha); 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate if (mask) 727c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 737c478bd9Sstevel@tonic-gate if ((cmd == MC_LOCKAS) || (cmd == MC_UNLOCKAS)) { 747c478bd9Sstevel@tonic-gate if ((addr != 0) || (len != 0)) { 757c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate } else if (cmd != MC_HAT_ADVISE) { 787c478bd9Sstevel@tonic-gate if (((uintptr_t)addr & PAGEOFFSET) != 0 || len == 0) { 797c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 807c478bd9Sstevel@tonic-gate } 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * We're only concerned with the address range 837c478bd9Sstevel@tonic-gate * here, not the protections. The protections 847c478bd9Sstevel@tonic-gate * are only used as a "filter" in this code, 857c478bd9Sstevel@tonic-gate * they aren't set or modified here. 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate if (valid_usr_range(addr, len, 0, as, 887c478bd9Sstevel@tonic-gate as->a_userlimit) != RANGE_OKAY) { 897c478bd9Sstevel@tonic-gate return (set_errno(ENOMEM)); 907c478bd9Sstevel@tonic-gate } 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate if (cmd == MC_HAT_ADVISE) { 947c478bd9Sstevel@tonic-gate if (attr != 0 || mask != 0) { 957c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate } else { 997c478bd9Sstevel@tonic-gate if ((VALID_ATTR & attr) != attr) { 1007c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate if ((attr & SHARED) && (attr & PRIVATE)) { 1037c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate if (((cmd == MC_LOCKAS) || (cmd == MC_LOCK) || 1067c478bd9Sstevel@tonic-gate (cmd == MC_UNLOCKAS) || (cmd == MC_UNLOCK)) && 1077c478bd9Sstevel@tonic-gate (error = secpolicy_lock_memory(CRED())) != 0) 1087c478bd9Sstevel@tonic-gate return (set_errno(error)); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate if (attr) { 1117c478bd9Sstevel@tonic-gate attr |= PROT_USER; 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate switch (cmd) { 1157c478bd9Sstevel@tonic-gate case MC_SYNC: 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * MS_SYNC used to be defined to be zero but is now non-zero. 1187c478bd9Sstevel@tonic-gate * For binary compatibility we still accept zero 1197c478bd9Sstevel@tonic-gate * (the absence of MS_ASYNC) to mean the same thing. 1207c478bd9Sstevel@tonic-gate */ 1217c478bd9Sstevel@tonic-gate iarg = (uintptr_t)arg; 1227c478bd9Sstevel@tonic-gate if ((iarg & ~MS_INVALIDATE) == 0) 1237c478bd9Sstevel@tonic-gate iarg |= MS_SYNC; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate if (((iarg & ~(MS_SYNC|MS_ASYNC|MS_INVALIDATE)) != 0) || 1267c478bd9Sstevel@tonic-gate ((iarg & (MS_SYNC|MS_ASYNC)) == (MS_SYNC|MS_ASYNC))) { 1277c478bd9Sstevel@tonic-gate error = set_errno(EINVAL); 1287c478bd9Sstevel@tonic-gate } else { 1297c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, cmd, attr, iarg, NULL, 0); 1307c478bd9Sstevel@tonic-gate if (error) { 1317c478bd9Sstevel@tonic-gate (void) set_errno(error); 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate return (error); 1357c478bd9Sstevel@tonic-gate case MC_LOCKAS: 1367c478bd9Sstevel@tonic-gate if ((uintptr_t)arg & ~(MCL_FUTURE|MCL_CURRENT) || 1377c478bd9Sstevel@tonic-gate (uintptr_t)arg == 0) { 1387c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate break; 1417c478bd9Sstevel@tonic-gate case MC_LOCK: 1427c478bd9Sstevel@tonic-gate case MC_UNLOCKAS: 1437c478bd9Sstevel@tonic-gate case MC_UNLOCK: 1447c478bd9Sstevel@tonic-gate break; 1457c478bd9Sstevel@tonic-gate case MC_HAT_ADVISE: 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * Set prefered page size. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate STRUCT_INIT(mha, get_udatamodel()); 1507c478bd9Sstevel@tonic-gate if (copyin(arg, STRUCT_BUF(mha), STRUCT_SIZE(mha))) { 1517c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate pgcmd = STRUCT_FGET(mha, mha_cmd); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * Currently only MHA_MAPSIZE_VA, MHA_MAPSIZE_STACK 1587c478bd9Sstevel@tonic-gate * and MHA_MAPSIZE_BSSBRK are supported. Only one 1597c478bd9Sstevel@tonic-gate * command may be specified at a time. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate if ((~(MHA_MAPSIZE_VA|MHA_MAPSIZE_STACK|MHA_MAPSIZE_BSSBRK) & 1627c478bd9Sstevel@tonic-gate pgcmd) || pgcmd == 0 || !ISP2(pgcmd) || 1637c478bd9Sstevel@tonic-gate STRUCT_FGET(mha, mha_flags)) 1647c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate pgsz = STRUCT_FGET(mha, mha_pagesize); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * call platform specific map_pgsz() routine to get the 1707c478bd9Sstevel@tonic-gate * optimal pgsz if pgsz is 0. 1717c478bd9Sstevel@tonic-gate * 1727c478bd9Sstevel@tonic-gate * For stack and heap operations addr and len must be zero. 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate if ((pgcmd & (MHA_MAPSIZE_BSSBRK|MHA_MAPSIZE_STACK)) != 0) { 1757c478bd9Sstevel@tonic-gate if (addr != NULL || len != 0) { 1767c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * Disable autompss for this process unless pgsz == 0, 1817c478bd9Sstevel@tonic-gate * which means the system should pick. In the 1827c478bd9Sstevel@tonic-gate * pgsz == 0 case, leave the SAUTOLPG setting alone, as 1837c478bd9Sstevel@tonic-gate * we don't want to enable it when someone has 1847c478bd9Sstevel@tonic-gate * disabled automatic large page selection for the 1857c478bd9Sstevel@tonic-gate * whole system. 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 1887c478bd9Sstevel@tonic-gate if (pgsz != 0) { 1897c478bd9Sstevel@tonic-gate p->p_flag &= ~SAUTOLPG; 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate as_rangelock(as); 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate if (pgsz == 0) { 1967c478bd9Sstevel@tonic-gate int type; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate if (pgcmd == MHA_MAPSIZE_BSSBRK) 1997c478bd9Sstevel@tonic-gate type = MAPPGSZ_HEAP; 2007c478bd9Sstevel@tonic-gate else 2017c478bd9Sstevel@tonic-gate type = MAPPGSZ_STK; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate pgsz = map_pgsz(type, p, 0, 0, NULL); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate } else { 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * Note that we don't disable automatic large page 2087c478bd9Sstevel@tonic-gate * selection for anon segments based on use of 2097c478bd9Sstevel@tonic-gate * memcntl(). 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate if (pgsz == 0) { 2127c478bd9Sstevel@tonic-gate pgsz = map_pgsz(MAPPGSZ_VA, p, addr, len, 2137c478bd9Sstevel@tonic-gate NULL); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* 2177c478bd9Sstevel@tonic-gate * addr and len must be prefered page size aligned 2187c478bd9Sstevel@tonic-gate * and valid for range specified. 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate if (!IS_P2ALIGNED(addr, pgsz) || 2217c478bd9Sstevel@tonic-gate !IS_P2ALIGNED(len, pgsz)) { 2227c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate if (valid_usr_range(addr, len, 0, as, 2257c478bd9Sstevel@tonic-gate as->a_userlimit) != RANGE_OKAY) { 2267c478bd9Sstevel@tonic-gate return (set_errno(ENOMEM)); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate szc = mem_getpgszc(pgsz); 2317c478bd9Sstevel@tonic-gate if (szc == (uint_t)-1) { 2327c478bd9Sstevel@tonic-gate if ((pgcmd & (MHA_MAPSIZE_BSSBRK|MHA_MAPSIZE_STACK)) 2337c478bd9Sstevel@tonic-gate != 0) { 2347c478bd9Sstevel@tonic-gate as_rangeunlock(as); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /* 2407c478bd9Sstevel@tonic-gate * For stack and heap operations we first need to pad 2417c478bd9Sstevel@tonic-gate * out existing range (create new mappings) to the new 2427c478bd9Sstevel@tonic-gate * prefered page size boundary. Also the start of the 2437c478bd9Sstevel@tonic-gate * .bss for the heap or user's stack base may not be on 2447c478bd9Sstevel@tonic-gate * the new prefered page size boundary. For these cases 2457c478bd9Sstevel@tonic-gate * we align the base of the request on the new prefered 2467c478bd9Sstevel@tonic-gate * page size. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate if (pgcmd & MHA_MAPSIZE_BSSBRK) { 2497c478bd9Sstevel@tonic-gate if (szc == p->p_brkpageszc) { 2507c478bd9Sstevel@tonic-gate as_rangeunlock(as); 2517c478bd9Sstevel@tonic-gate return (0); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate if (szc > p->p_brkpageszc) { 2547c478bd9Sstevel@tonic-gate error = brk_internal(p->p_brkbase 2557c478bd9Sstevel@tonic-gate + p->p_brksize, szc); 2567c478bd9Sstevel@tonic-gate if (error) { 2577c478bd9Sstevel@tonic-gate as_rangeunlock(as); 2587c478bd9Sstevel@tonic-gate return (set_errno(error)); 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate oszc = p->p_brkpageszc; 2627c478bd9Sstevel@tonic-gate p->p_brkpageszc = szc; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(p->p_brkbase + p->p_brksize, pgsz)); 2657c478bd9Sstevel@tonic-gate addr = (caddr_t)P2ROUNDUP((uintptr_t)p->p_bssbase, 2667c478bd9Sstevel@tonic-gate pgsz); 2677c478bd9Sstevel@tonic-gate len = (p->p_brkbase + p->p_brksize) - addr; 2687c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(len, pgsz)); 2697c478bd9Sstevel@tonic-gate /* 2707c478bd9Sstevel@tonic-gate * Perhaps no existing pages to promote. 2717c478bd9Sstevel@tonic-gate */ 2727c478bd9Sstevel@tonic-gate if (len == 0) { 2737c478bd9Sstevel@tonic-gate as_rangeunlock(as); 2747c478bd9Sstevel@tonic-gate return (0); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate /* 2787c478bd9Sstevel@tonic-gate * The code below, as does grow.c, assumes stacks always grow 2797c478bd9Sstevel@tonic-gate * downward. 2807c478bd9Sstevel@tonic-gate */ 2817c478bd9Sstevel@tonic-gate if (pgcmd & MHA_MAPSIZE_STACK) { 2827c478bd9Sstevel@tonic-gate /* 2837c478bd9Sstevel@tonic-gate * Some boxes (x86) have a top of stack that 2847c478bd9Sstevel@tonic-gate * is not large page aligned. Since stacks are 2857c478bd9Sstevel@tonic-gate * usually small we'll just return and do nothing 2867c478bd9Sstevel@tonic-gate * for theses cases. Prefeered page size is advisory 2877c478bd9Sstevel@tonic-gate * so no need to return an error. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate if (szc == p->p_stkpageszc || 2907c478bd9Sstevel@tonic-gate !IS_P2ALIGNED(p->p_usrstack, pgsz)) { 2917c478bd9Sstevel@tonic-gate as_rangeunlock(as); 2927c478bd9Sstevel@tonic-gate return (0); 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (szc > p->p_stkpageszc) { 2967c478bd9Sstevel@tonic-gate error = grow_internal(p->p_usrstack 2977c478bd9Sstevel@tonic-gate - p->p_stksize, szc); 2987c478bd9Sstevel@tonic-gate if (error) { 2997c478bd9Sstevel@tonic-gate as_rangeunlock(as); 3007c478bd9Sstevel@tonic-gate return (set_errno(error)); 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate oszc = p->p_stkpageszc; 3047c478bd9Sstevel@tonic-gate p->p_stkpageszc = szc; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(p->p_usrstack, pgsz)); 3077c478bd9Sstevel@tonic-gate addr = p->p_usrstack - p->p_stksize; 3087c478bd9Sstevel@tonic-gate len = p->p_stksize; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * Perhaps nothing to promote, we wrapped around 3127c478bd9Sstevel@tonic-gate * or grow did not not grow the stack to a large 3137c478bd9Sstevel@tonic-gate * page boundary. 3147c478bd9Sstevel@tonic-gate */ 3157c478bd9Sstevel@tonic-gate if (!IS_P2ALIGNED(len, pgsz) || len == 0 || 3167c478bd9Sstevel@tonic-gate addr >= p->p_usrstack || (addr + len) < addr) { 3177c478bd9Sstevel@tonic-gate as_rangeunlock(as); 3187c478bd9Sstevel@tonic-gate return (0); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(addr, pgsz)); 3227c478bd9Sstevel@tonic-gate ASSERT(IS_P2ALIGNED(len, pgsz)); 3237c478bd9Sstevel@tonic-gate error = as_setpagesize(as, addr, len, szc, B_TRUE); 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * On stack or heap failures restore original 3277c478bd9Sstevel@tonic-gate * pg size code. 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate if (error) { 3307c478bd9Sstevel@tonic-gate if ((pgcmd & MHA_MAPSIZE_BSSBRK) != 0) { 3317c478bd9Sstevel@tonic-gate p->p_brkpageszc = oszc; 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate if ((pgcmd & MHA_MAPSIZE_STACK) != 0) { 3347c478bd9Sstevel@tonic-gate p->p_stkpageszc = oszc; 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate (void) set_errno(error); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate if ((pgcmd & (MHA_MAPSIZE_BSSBRK|MHA_MAPSIZE_STACK)) != 0) { 3397c478bd9Sstevel@tonic-gate as_rangeunlock(as); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate return (error); 3427c478bd9Sstevel@tonic-gate case MC_ADVISE: 3437c478bd9Sstevel@tonic-gate switch ((uintptr_t)arg) { 3447c478bd9Sstevel@tonic-gate case MADV_WILLNEED: 3457c478bd9Sstevel@tonic-gate fc = as_faulta(as, addr, len); 3467c478bd9Sstevel@tonic-gate if (fc) { 3477c478bd9Sstevel@tonic-gate if (FC_CODE(fc) == FC_OBJERR) 3487c478bd9Sstevel@tonic-gate error = set_errno(FC_ERRNO(fc)); 3497c478bd9Sstevel@tonic-gate else if (FC_CODE(fc) == FC_NOMAP) 3507c478bd9Sstevel@tonic-gate error = set_errno(ENOMEM); 3517c478bd9Sstevel@tonic-gate else 3527c478bd9Sstevel@tonic-gate error = set_errno(EINVAL); 3537c478bd9Sstevel@tonic-gate return (error); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate break; 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate case MADV_DONTNEED: 3587c478bd9Sstevel@tonic-gate /* 3597c478bd9Sstevel@tonic-gate * For now, don't need is turned into an as_ctl(MC_SYNC) 3607c478bd9Sstevel@tonic-gate * operation flagged for async invalidate. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, MC_SYNC, attr, 3637c478bd9Sstevel@tonic-gate MS_ASYNC | MS_INVALIDATE, NULL, 0); 3647c478bd9Sstevel@tonic-gate if (error) 3657c478bd9Sstevel@tonic-gate (void) set_errno(error); 3667c478bd9Sstevel@tonic-gate return (error); 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate default: 3697c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, cmd, attr, 3707c478bd9Sstevel@tonic-gate (uintptr_t)arg, NULL, 0); 3717c478bd9Sstevel@tonic-gate if (error) 3727c478bd9Sstevel@tonic-gate (void) set_errno(error); 3737c478bd9Sstevel@tonic-gate return (error); 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate break; 3767c478bd9Sstevel@tonic-gate default: 3777c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate error = as_ctl(as, addr, len, cmd, attr, (uintptr_t)arg, NULL, 0); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if (error) 3837c478bd9Sstevel@tonic-gate (void) set_errno(error); 3847c478bd9Sstevel@tonic-gate return (error); 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * Return page size code for page size passed in. If 389*4abce959Smec * matching page size not found or supported, return -1. 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate static uint_t 3927c478bd9Sstevel@tonic-gate mem_getpgszc(size_t pgsz) { 393*4abce959Smec return ((uint_t)page_szc_user_filtered(pgsz)); 3947c478bd9Sstevel@tonic-gate } 395