1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * Copyright (c) 1992 NeXT Computer, Inc. 30 * 31 * Selector value conversion/validation. 32 * 33 * HISTORY 34 * 35 * 19 June 1992 ? at NeXT 36 * Created. 37 */ 38 39 40static inline 41unsigned int 42sel_to_selector( 43 sel_t sel 44) 45{ 46 union { 47 sel_t sel; 48 unsigned short selector; 49 } tconv; 50 51 tconv.sel = sel; 52 53 return (tconv.selector); 54} 55 56static inline 57sel_t 58selector_to_sel( 59 unsigned int selector 60) 61{ 62 union { 63 unsigned short selector; 64 sel_t sel; 65 } tconv; 66 67 tconv.selector = selector; 68 69 return (tconv.sel); 70} 71 72#if 0 73static inline 74boolean_t 75valid_user_data_selector( 76 unsigned int selector 77) 78{ 79 sel_t sel = selector_to_sel(selector); 80 81 if (selector == 0) 82 return (TRUE); 83 84 if (sel.ti == SEL_LDT) 85 return (TRUE); 86 else if (sel.index < GDTSZ) { 87 data_desc_t *desc = (data_desc_t *)sel_to_gdt_entry(sel); 88 89 if (desc->dpl == USER_PRIV) 90 return (TRUE); 91 } 92 93 return (FALSE); 94} 95 96static inline 97boolean_t 98valid_user_code_selector( 99 unsigned int selector 100) 101{ 102 sel_t sel = selector_to_sel(selector); 103 104 if (selector == 0) 105 return (FALSE); 106 107 if (sel.ti == SEL_LDT) { 108 if (sel.rpl == USER_PRIV) 109 return (TRUE); 110 } 111 else if (sel.index < GDTSZ && sel.rpl == USER_PRIV) { 112 code_desc_t *desc = (code_desc_t *)sel_to_gdt_entry(sel); 113 114 if (desc->dpl == USER_PRIV) 115 return (TRUE); 116 } 117 118 return (FALSE); 119} 120 121static inline 122boolean_t 123valid_user_stack_selector( 124 unsigned int selector 125) 126{ 127 sel_t sel = selector_to_sel(selector); 128 129 if (selector == 0) 130 return (FALSE); 131 132 if (sel.ti == SEL_LDT) { 133 if (sel.rpl == USER_PRIV) 134 return (TRUE); 135 } 136 else if (sel.index < GDTSZ && sel.rpl == USER_PRIV) { 137 data_desc_t *desc = (data_desc_t *)sel_to_gdt_entry(sel); 138 139 if (desc->dpl == USER_PRIV) 140 return (TRUE); 141 } 142 143 return (FALSE); 144} 145#endif 146