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