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