10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52546Scarlsonj * Common Development and Distribution License (the "License"). 62546Scarlsonj * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*7009Scth * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/sysmacros.h> 340Sstevel@tonic-gate #include <sys/param.h> 350Sstevel@tonic-gate #include <sys/vmparam.h> 360Sstevel@tonic-gate #include <sys/systm.h> 370Sstevel@tonic-gate #include <sys/cred.h> 380Sstevel@tonic-gate #include <sys/user.h> 390Sstevel@tonic-gate #include <sys/proc.h> 400Sstevel@tonic-gate #include <sys/conf.h> 410Sstevel@tonic-gate #include <sys/tuneable.h> 420Sstevel@tonic-gate #include <sys/cpuvar.h> 430Sstevel@tonic-gate #include <sys/archsystm.h> 440Sstevel@tonic-gate #include <sys/vmem.h> 450Sstevel@tonic-gate #include <vm/seg_kmem.h> 460Sstevel@tonic-gate #include <sys/errno.h> 470Sstevel@tonic-gate #include <sys/cmn_err.h> 480Sstevel@tonic-gate #include <sys/debug.h> 490Sstevel@tonic-gate #include <sys/atomic.h> 500Sstevel@tonic-gate #include <sys/model.h> 510Sstevel@tonic-gate #include <sys/kmem.h> 520Sstevel@tonic-gate #include <sys/memlist.h> 530Sstevel@tonic-gate #include <sys/autoconf.h> 540Sstevel@tonic-gate #include <sys/ontrap.h> 550Sstevel@tonic-gate #include <sys/utsname.h> 560Sstevel@tonic-gate #include <sys/zone.h> 570Sstevel@tonic-gate 580Sstevel@tonic-gate #ifdef __sparc 590Sstevel@tonic-gate #include <sys/membar.h> 600Sstevel@tonic-gate #endif 610Sstevel@tonic-gate 620Sstevel@tonic-gate /* 630Sstevel@tonic-gate * Routine which sets a user error; placed in 640Sstevel@tonic-gate * illegal entries in the bdevsw and cdevsw tables. 650Sstevel@tonic-gate */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate int 680Sstevel@tonic-gate nodev() 690Sstevel@tonic-gate { 700Sstevel@tonic-gate return (curthread->t_lwp ? 710Sstevel@tonic-gate ttolwp(curthread)->lwp_error = ENXIO : ENXIO); 720Sstevel@tonic-gate } 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * Null routine; placed in insignificant entries 760Sstevel@tonic-gate * in the bdevsw and cdevsw tables. 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate 790Sstevel@tonic-gate int 800Sstevel@tonic-gate nulldev() 810Sstevel@tonic-gate { 820Sstevel@tonic-gate return (0); 830Sstevel@tonic-gate } 840Sstevel@tonic-gate 850Sstevel@tonic-gate static kmutex_t udevlock; 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * Generate an unused major device number. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate major_t 910Sstevel@tonic-gate getudev() 920Sstevel@tonic-gate { 930Sstevel@tonic-gate static major_t next = 0; 940Sstevel@tonic-gate major_t ret; 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Ensure that we start allocating major numbers above the 'devcnt' 980Sstevel@tonic-gate * count. The only limit we place on the number is that it should be a 990Sstevel@tonic-gate * legal 32-bit SVR4 major number and be greater than or equal to devcnt 1000Sstevel@tonic-gate * in the current system). 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate mutex_enter(&udevlock); 1030Sstevel@tonic-gate if (next == 0) 1040Sstevel@tonic-gate next = devcnt; 1050Sstevel@tonic-gate if (next <= L_MAXMAJ32 && next >= devcnt) 1060Sstevel@tonic-gate ret = next++; 1070Sstevel@tonic-gate else { 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * If we fail to allocate a major number because devcnt has 1100Sstevel@tonic-gate * reached L_MAXMAJ32, we may be the victim of a sparsely 1110Sstevel@tonic-gate * populated devnames array. We scan the array backwards 1120Sstevel@tonic-gate * looking for an empty slot; if we find one, mark it as 1130Sstevel@tonic-gate * DN_GETUDEV so it doesn't get taken by subsequent consumers 1140Sstevel@tonic-gate * users of the devnames array, and issue a warning. 1150Sstevel@tonic-gate * It is vital for this routine to take drastic measures to 1160Sstevel@tonic-gate * succeed, since the kernel really needs it to boot. 1170Sstevel@tonic-gate */ 1180Sstevel@tonic-gate int i; 1190Sstevel@tonic-gate for (i = devcnt - 1; i >= 0; i--) { 1200Sstevel@tonic-gate LOCK_DEV_OPS(&devnamesp[i].dn_lock); 1210Sstevel@tonic-gate if (devnamesp[i].dn_name == NULL && 1220Sstevel@tonic-gate ((devnamesp[i].dn_flags & DN_TAKEN_GETUDEV) == 0)) 1230Sstevel@tonic-gate break; 1240Sstevel@tonic-gate UNLOCK_DEV_OPS(&devnamesp[i].dn_lock); 1250Sstevel@tonic-gate } 1260Sstevel@tonic-gate if (i != -1) { 1270Sstevel@tonic-gate cmn_err(CE_WARN, "Reusing device major number %d.", i); 1280Sstevel@tonic-gate ASSERT(i >= 0 && i < devcnt); 1290Sstevel@tonic-gate devnamesp[i].dn_flags |= DN_TAKEN_GETUDEV; 1300Sstevel@tonic-gate UNLOCK_DEV_OPS(&devnamesp[i].dn_lock); 1310Sstevel@tonic-gate ret = (major_t)i; 1320Sstevel@tonic-gate } else { 133*7009Scth ret = DDI_MAJOR_T_NONE; 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate mutex_exit(&udevlock); 1370Sstevel@tonic-gate return (ret); 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Compress 'long' device number encoding to 32-bit device number 1430Sstevel@tonic-gate * encoding. If it won't fit, we return failure, but set the 1440Sstevel@tonic-gate * device number to 32-bit NODEV for the sake of our callers. 1450Sstevel@tonic-gate */ 1460Sstevel@tonic-gate int 1470Sstevel@tonic-gate cmpldev(dev32_t *dst, dev_t dev) 1480Sstevel@tonic-gate { 1490Sstevel@tonic-gate #if defined(_LP64) 1500Sstevel@tonic-gate if (dev == NODEV) { 1510Sstevel@tonic-gate *dst = NODEV32; 1520Sstevel@tonic-gate } else { 1530Sstevel@tonic-gate major_t major = dev >> L_BITSMINOR; 1540Sstevel@tonic-gate minor_t minor = dev & L_MAXMIN; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate if (major > L_MAXMAJ32 || minor > L_MAXMIN32) { 1570Sstevel@tonic-gate *dst = NODEV32; 1580Sstevel@tonic-gate return (0); 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate *dst = (dev32_t)((major << L_BITSMINOR32) | minor); 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate #else 1640Sstevel@tonic-gate *dst = (dev32_t)dev; 1650Sstevel@tonic-gate #endif 1660Sstevel@tonic-gate return (1); 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * Expand 32-bit dev_t's to long dev_t's. Expansion always "fits" 1710Sstevel@tonic-gate * into the return type, but we're careful to expand NODEV explicitly. 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate dev_t 1740Sstevel@tonic-gate expldev(dev32_t dev32) 1750Sstevel@tonic-gate { 1760Sstevel@tonic-gate #ifdef _LP64 1770Sstevel@tonic-gate if (dev32 == NODEV32) 1780Sstevel@tonic-gate return (NODEV); 1790Sstevel@tonic-gate return (makedevice((dev32 >> L_BITSMINOR32) & L_MAXMAJ32, 1800Sstevel@tonic-gate dev32 & L_MAXMIN32)); 1810Sstevel@tonic-gate #else 1820Sstevel@tonic-gate return ((dev_t)dev32); 1830Sstevel@tonic-gate #endif 1840Sstevel@tonic-gate } 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate #ifndef _LP64 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * Keep these entry points for 32-bit systems but enforce the use 1890Sstevel@tonic-gate * of MIN/MAX macros on 64-bit systems. The DDI header files already 1900Sstevel@tonic-gate * define min/max as macros so drivers shouldn't need these functions. 1910Sstevel@tonic-gate */ 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate int 1940Sstevel@tonic-gate min(int a, int b) 1950Sstevel@tonic-gate { 1960Sstevel@tonic-gate return (a < b ? a : b); 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate int 2000Sstevel@tonic-gate max(int a, int b) 2010Sstevel@tonic-gate { 2020Sstevel@tonic-gate return (a > b ? a : b); 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate uint_t 2060Sstevel@tonic-gate umin(uint_t a, uint_t b) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate return (a < b ? a : b); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate uint_t 2120Sstevel@tonic-gate umax(uint_t a, uint_t b) 2130Sstevel@tonic-gate { 2140Sstevel@tonic-gate return (a > b ? a : b); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate #endif /* !_LP64 */ 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* 2200Sstevel@tonic-gate * Parse suboptions from a string. 2210Sstevel@tonic-gate * Same as getsubopt(3C). 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate int 2240Sstevel@tonic-gate getsubopt(char **optionsp, char * const *tokens, char **valuep) 2250Sstevel@tonic-gate { 2260Sstevel@tonic-gate char *s = *optionsp, *p; 2270Sstevel@tonic-gate int i; 2280Sstevel@tonic-gate size_t optlen; 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate *valuep = NULL; 2310Sstevel@tonic-gate if (*s == '\0') 2320Sstevel@tonic-gate return (-1); 2330Sstevel@tonic-gate p = strchr(s, ','); /* find next option */ 2340Sstevel@tonic-gate if (p == NULL) { 2350Sstevel@tonic-gate p = s + strlen(s); 2360Sstevel@tonic-gate } else { 2370Sstevel@tonic-gate *p++ = '\0'; /* mark end and point to next */ 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate *optionsp = p; /* point to next option */ 2400Sstevel@tonic-gate p = strchr(s, '='); /* find value */ 2410Sstevel@tonic-gate if (p == NULL) { 2420Sstevel@tonic-gate optlen = strlen(s); 2430Sstevel@tonic-gate *valuep = NULL; 2440Sstevel@tonic-gate } else { 2450Sstevel@tonic-gate optlen = p - s; 2460Sstevel@tonic-gate *valuep = ++p; 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate for (i = 0; tokens[i] != NULL; i++) { 2490Sstevel@tonic-gate if ((optlen == strlen(tokens[i])) && 2500Sstevel@tonic-gate (strncmp(s, tokens[i], optlen) == 0)) 2510Sstevel@tonic-gate return (i); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate /* no match, point value at option and return error */ 2540Sstevel@tonic-gate *valuep = s; 2550Sstevel@tonic-gate return (-1); 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * Append the suboption string 'opt' starting at the position 'str' 2600Sstevel@tonic-gate * within the buffer defined by 'buf' and 'len'. If 'buf' is not null, 2610Sstevel@tonic-gate * a comma is appended first. 2620Sstevel@tonic-gate * Return a pointer to the end of the resulting string (the null byte). 2630Sstevel@tonic-gate * Return NULL if there isn't enough space left to append 'opt'. 2640Sstevel@tonic-gate */ 2650Sstevel@tonic-gate char * 2660Sstevel@tonic-gate append_subopt(const char *buf, size_t len, char *str, const char *opt) 2670Sstevel@tonic-gate { 2680Sstevel@tonic-gate size_t l = strlen(opt); 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate /* 2710Sstevel@tonic-gate * Include a ',' if this is not the first option. 2720Sstevel@tonic-gate * Include space for the null byte. 2730Sstevel@tonic-gate */ 2740Sstevel@tonic-gate if (strlen(buf) + (buf[0] != '\0') + l + 1 > len) 2750Sstevel@tonic-gate return (NULL); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate if (buf[0] != '\0') 2780Sstevel@tonic-gate *str++ = ','; 2790Sstevel@tonic-gate (void) strcpy(str, opt); 2800Sstevel@tonic-gate return (str + l); 2810Sstevel@tonic-gate } 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate /* 2840Sstevel@tonic-gate * Tables to convert a single byte to/from binary-coded decimal (BCD). 2850Sstevel@tonic-gate */ 2860Sstevel@tonic-gate uchar_t byte_to_bcd[256] = { 2870Sstevel@tonic-gate 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 2880Sstevel@tonic-gate 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 2890Sstevel@tonic-gate 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 2900Sstevel@tonic-gate 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 2910Sstevel@tonic-gate 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 2920Sstevel@tonic-gate 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 2930Sstevel@tonic-gate 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 2940Sstevel@tonic-gate 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 2950Sstevel@tonic-gate 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 2960Sstevel@tonic-gate 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 2970Sstevel@tonic-gate }; 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate uchar_t bcd_to_byte[256] = { /* CSTYLED */ 3000Sstevel@tonic-gate 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 3010Sstevel@tonic-gate 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0, 0, 3020Sstevel@tonic-gate 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 0, 0, 0, 0, 0, 3030Sstevel@tonic-gate 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 0, 0, 0, 0, 0, 3040Sstevel@tonic-gate 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0, 0, 0, 0, 0, 0, 3050Sstevel@tonic-gate 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0, 0, 0, 0, 0, 0, 3060Sstevel@tonic-gate 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0, 0, 0, 0, 0, 0, 3070Sstevel@tonic-gate 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0, 0, 0, 0, 0, 0, 3080Sstevel@tonic-gate 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0, 0, 0, 0, 0, 0, 3090Sstevel@tonic-gate 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 3100Sstevel@tonic-gate }; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * Hot-patch a single instruction in the kernel's text. 3140Sstevel@tonic-gate * If you want to patch multiple instructions you must 3150Sstevel@tonic-gate * arrange to do it so that all intermediate stages are 3160Sstevel@tonic-gate * sane -- we don't stop other cpus while doing this. 3170Sstevel@tonic-gate * Size must be 1, 2, or 4 bytes with iaddr aligned accordingly. 3180Sstevel@tonic-gate */ 3190Sstevel@tonic-gate void 3200Sstevel@tonic-gate hot_patch_kernel_text(caddr_t iaddr, uint32_t new_instr, uint_t size) 3210Sstevel@tonic-gate { 3220Sstevel@tonic-gate caddr_t vaddr; 3230Sstevel@tonic-gate page_t **ppp; 3240Sstevel@tonic-gate uintptr_t off = (uintptr_t)iaddr & PAGEOFFSET; 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate vaddr = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP); 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate (void) as_pagelock(&kas, &ppp, iaddr - off, PAGESIZE, S_WRITE); 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate hat_devload(kas.a_hat, vaddr, PAGESIZE, 3310Sstevel@tonic-gate hat_getpfnum(kas.a_hat, iaddr - off), 3320Sstevel@tonic-gate PROT_READ | PROT_WRITE, HAT_LOAD_LOCK | HAT_LOAD_NOCONSIST); 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate switch (size) { 3350Sstevel@tonic-gate case 1: 3360Sstevel@tonic-gate *(uint8_t *)(vaddr + off) = new_instr; 3370Sstevel@tonic-gate break; 3380Sstevel@tonic-gate case 2: 3390Sstevel@tonic-gate *(uint16_t *)(vaddr + off) = new_instr; 3400Sstevel@tonic-gate break; 3410Sstevel@tonic-gate case 4: 3420Sstevel@tonic-gate *(uint32_t *)(vaddr + off) = new_instr; 3430Sstevel@tonic-gate break; 3440Sstevel@tonic-gate default: 3450Sstevel@tonic-gate panic("illegal hot-patch"); 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate membar_enter(); 3490Sstevel@tonic-gate sync_icache(vaddr + off, size); 3500Sstevel@tonic-gate sync_icache(iaddr, size); 3510Sstevel@tonic-gate as_pageunlock(&kas, ppp, iaddr - off, PAGESIZE, S_WRITE); 3520Sstevel@tonic-gate hat_unload(kas.a_hat, vaddr, PAGESIZE, HAT_UNLOAD_UNLOCK); 3530Sstevel@tonic-gate vmem_free(heap_arena, vaddr, PAGESIZE); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate /* 3570Sstevel@tonic-gate * Routine to report an attempt to execute non-executable data. If the 3580Sstevel@tonic-gate * address executed lies in the stack, explicitly say so. 3590Sstevel@tonic-gate */ 3600Sstevel@tonic-gate void 3610Sstevel@tonic-gate report_stack_exec(proc_t *p, caddr_t addr) 3620Sstevel@tonic-gate { 3630Sstevel@tonic-gate if (!noexec_user_stack_log) 3640Sstevel@tonic-gate return; 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate if (addr < p->p_usrstack && addr >= (p->p_usrstack - p->p_stksize)) { 3670Sstevel@tonic-gate cmn_err(CE_NOTE, "%s[%d] attempt to execute code " 3680Sstevel@tonic-gate "on stack by uid %d", p->p_user.u_comm, 3690Sstevel@tonic-gate p->p_pid, crgetruid(p->p_cred)); 3700Sstevel@tonic-gate } else { 3710Sstevel@tonic-gate cmn_err(CE_NOTE, "%s[%d] attempt to execute non-executable " 3720Sstevel@tonic-gate "data at 0x%p by uid %d", p->p_user.u_comm, 3730Sstevel@tonic-gate p->p_pid, (void *) addr, crgetruid(p->p_cred)); 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate delay(hz / 50); 3770Sstevel@tonic-gate } 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate /* 3800Sstevel@tonic-gate * Determine whether the address range [addr, addr + len) is in memlist mp. 3810Sstevel@tonic-gate */ 3820Sstevel@tonic-gate int 3830Sstevel@tonic-gate address_in_memlist(struct memlist *mp, uint64_t addr, size_t len) 3840Sstevel@tonic-gate { 3850Sstevel@tonic-gate while (mp != 0) { 3860Sstevel@tonic-gate if ((addr >= mp->address) && 3870Sstevel@tonic-gate (addr + len <= mp->address + mp->size)) 3880Sstevel@tonic-gate return (1); /* TRUE */ 3890Sstevel@tonic-gate mp = mp->next; 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate return (0); /* FALSE */ 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /* 3950Sstevel@tonic-gate * Pop the topmost element from the t_ontrap stack, removing the current set of 3960Sstevel@tonic-gate * on_trap() protections. Refer to <sys/ontrap.h> for more info. If the 3970Sstevel@tonic-gate * stack is already empty, no_trap() just returns. 3980Sstevel@tonic-gate */ 3990Sstevel@tonic-gate void 4000Sstevel@tonic-gate no_trap(void) 4010Sstevel@tonic-gate { 4020Sstevel@tonic-gate if (curthread->t_ontrap != NULL) { 4030Sstevel@tonic-gate #ifdef __sparc 4040Sstevel@tonic-gate membar_sync(); /* deferred error barrier (see sparcv9_subr.s) */ 4050Sstevel@tonic-gate #endif 4060Sstevel@tonic-gate curthread->t_ontrap = curthread->t_ontrap->ot_prev; 4070Sstevel@tonic-gate } 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate /* 4110Sstevel@tonic-gate * Return utsname.nodename outside a zone, or the zone name within. 4120Sstevel@tonic-gate */ 4130Sstevel@tonic-gate char * 4140Sstevel@tonic-gate uts_nodename(void) 4150Sstevel@tonic-gate { 4160Sstevel@tonic-gate if (curproc == NULL) 4170Sstevel@tonic-gate return (utsname.nodename); 4180Sstevel@tonic-gate return (curproc->p_zone->zone_nodename); 4190Sstevel@tonic-gate } 420