]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/sel_inline.h
xnu-344.23.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sel_inline.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
de355530
A
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.
1c79356b 11 *
de355530
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
de355530
A
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.
1c79356b
A
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
34static inline
35unsigned int
36sel_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
50static inline
51sel_t
52selector_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
67static inline
68boolean_t
69valid_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
90static inline
91boolean_t
92valid_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
115static inline
116boolean_t
117valid_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