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