]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/mp_desc.h
xnu-792.tar.gz
[apple/xnu.git] / osfmk / i386 / mp_desc.h
index fd85e29adc2919430e7cbcd02017fe2f775bc5d9..3a89fad0707e034dd75d3bb420241444533ed991 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
 #ifndef        _I386_MP_DESC_H_
 #define        _I386_MP_DESC_H_
 
-#include <cpus.h>
 #include <mach_kdb.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
 
 /*
  * Multiprocessor i386/i486 systems use a separate copy of the
@@ -83,33 +85,85 @@ struct mp_desc_table {
        struct i386_tss         dbtss;
 };
 
-/*
- * They are pointed to by a per-processor array.
- */
-extern struct mp_desc_table    *mp_desc_table[NCPUS];
+#define        current_gdt()   (current_cpu_datap()->cpu_desc_index.cdi_gdt)
+#define        current_idt()   (current_cpu_datap()->cpu_desc_index.cdi_idt)
+#define        current_ldt()   (current_cpu_datap()->cpu_desc_index.cdi_ldt)
+#define        current_ktss()  (current_cpu_datap()->cpu_desc_index.cdi_ktss)
+#define        current_dbtss() (current_cpu_datap()->cpu_desc_index.cdi_dbtss)
 
-/*
- * The kernel TSS gets its own pointer.
- */
-extern struct i386_tss         *mp_ktss[NCPUS];
-#if    MACH_KDB
-extern struct i386_tss         *mp_dbtss[NCPUS];
-#endif /* MACH_KDB */
+#define        gdt_desc_p(sel) \
+       ((struct real_descriptor *)&current_gdt()[sel_idx(sel)])
+#define        ldt_desc_p(sel) \
+       ((struct real_descriptor *)&current_ldt()[sel_idx(sel)])
 
-/*
- * So does the GDT and IDT.
- */
-extern struct fake_descriptor  *mp_gdt[NCPUS];
-extern struct fake_descriptor  *mp_idt[NCPUS];
-extern struct fake_descriptor  *mp_ldt[NCPUS];
+extern void    mp_desc_init(cpu_data_t *cdp, boolean_t is_boot_cpu);
 
+static inline boolean_t
+valid_user_data_selector(uint16_t selector)
+{
+    sel_t      sel = selector_to_sel(selector);
+    
+    if (selector == 0)
+       return (TRUE);
 
-/*
- * Each CPU calls this routine to set up its descriptor tables.
- */
+    if (sel.ti == SEL_LDT)
+       return (TRUE);
+    else if (sel.index < GDTSZ) {
+       if ((gdt_desc_p(selector)->access & ACC_PL_U) == ACC_PL_U)
+           return (TRUE);
+    }
+               
+    return (FALSE);
+}
+
+static inline boolean_t
+valid_user_code_selector(uint16_t selector)
+{
+    sel_t      sel = selector_to_sel(selector);
+    
+    if (selector == 0)
+       return (FALSE);
+
+    if (sel.ti == SEL_LDT) {
+       if (sel.rpl == USER_PRIV)
+           return (TRUE);
+    }
+    else if (sel.index < GDTSZ && sel.rpl == USER_PRIV) {
+       if ((gdt_desc_p(selector)->access & ACC_PL_U) == ACC_PL_U)
+           return (TRUE);
+    }
+
+    return (FALSE);
+}
+
+static inline boolean_t
+valid_user_stack_selector(uint16_t selector)
+{
+    sel_t      sel = selector_to_sel(selector);
+    
+    if (selector == 0)
+       return (FALSE);
+
+    if (sel.ti == SEL_LDT) {
+       if (sel.rpl == USER_PRIV)
+           return (TRUE);
+    }
+    else if (sel.index < GDTSZ && sel.rpl == USER_PRIV) {
+       if ((gdt_desc_p(selector)->access & ACC_PL_U) == ACC_PL_U)
+           return (TRUE);
+    }
+               
+    return (FALSE);
+}
+
+extern boolean_t
+valid_user_segment_selectors(uint16_t cs,
+                             uint16_t ss,
+                             uint16_t ds,
+                             uint16_t es,
+                             uint16_t fs,
+                             uint16_t gs);
 
-extern struct mp_desc_table *  mp_desc_init(
-                                       int             cpu);
-extern void                    interrupt_stack_alloc(void);
+__END_DECLS
 
 #endif /* _I386_MP_DESC_H_ */