]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/commpage/commpage.c
xnu-2782.10.72.tar.gz
[apple/xnu.git] / osfmk / i386 / commpage / commpage.c
index 6bea2bef756a00a4d2321fd4b291a3b2fd62e856..eea96ab64532140928cde2de32f09d0d8c0478ad 100644 (file)
@@ -68,6 +68,8 @@
 #include <kern/page_decrypt.h>
 #include <kern/processor.h>
 
+#include <sys/kdebug.h>
+
 /* the lists of commpage routines are in commpage_asm.s  */
 extern commpage_descriptor*    commpage_32_routines[];
 extern commpage_descriptor*    commpage_64_routines[];
@@ -281,6 +283,10 @@ commpage_init_cpu_capabilities( void )
                                        CPUID_LEAF7_FEATURE_HLE);
        setif(bits, kHasAVX2_0,  cpuid_leaf7_features() &
                                        CPUID_LEAF7_FEATURE_AVX2);
+       setif(bits, kHasRDSEED,  cpuid_features() &
+                                       CPUID_LEAF7_FEATURE_RDSEED);
+       setif(bits, kHasADX,     cpuid_features() &
+                                       CPUID_LEAF7_FEATURE_ADX);
        
        uint64_t misc_enable = rdmsr64(MSR_IA32_MISC_ENABLE);
        setif(bits, kHasENFSTRG, (misc_enable & 1ULL) &&
@@ -457,8 +463,9 @@ commpage_populate( void )
        simple_lock_init(&commpage_active_cpus_lock, 0);
 
        commpage_update_active_cpus();
-        commpage_mach_approximate_time_init();
+       commpage_mach_approximate_time_init();
        rtc_nanotime_init_commpage();
+       commpage_update_kdebug_enable();
 }
 
 /* Fill in the common routines during kernel initialization. 
@@ -690,6 +697,34 @@ commpage_update_active_cpus(void)
        simple_unlock(&commpage_active_cpus_lock);
 }
 
+/*
+ * Update the commpage data with the value of the "kdebug_enable"
+ * global so that userspace can avoid trapping into the kernel
+ * for kdebug_trace() calls. Serialization is handled
+ * by the caller in bsd/kern/kdebug.c.
+ */
+void
+commpage_update_kdebug_enable(void)
+{
+       volatile uint32_t *saved_data_ptr;
+       char *cp;
+
+       cp = commPagePtr32;
+       if (cp) {
+               cp += (_COMM_PAGE_KDEBUG_ENABLE - _COMM_PAGE32_BASE_ADDRESS);
+               saved_data_ptr = (volatile uint32_t *)cp;
+               *saved_data_ptr = kdebug_enable;
+       }
+
+       cp = commPagePtr64;
+       if ( cp ) {
+               cp += (_COMM_PAGE_KDEBUG_ENABLE - _COMM_PAGE32_START_ADDRESS);
+               saved_data_ptr = (volatile uint32_t *)cp;
+               *saved_data_ptr = kdebug_enable;
+       }
+}
+
+
 /*
  * update the commpage data for last known value of mach_absolute_time()
  */
@@ -699,11 +734,11 @@ commpage_update_mach_approximate_time(uint64_t abstime)
 {
 #ifdef CONFIG_MACH_APPROXIMATE_TIME
        uint64_t saved_data;
-        char *cp;
-
-        cp = commPagePtr32;
+       char *cp;
+       
+       cp = commPagePtr32;
        if ( cp ) {
-               cp += (_COMM_PAGE_APPROX_TIME - _COMM_PAGE32_BASE_ADDRESS);
+               cp += (_COMM_PAGE_APPROX_TIME - _COMM_PAGE32_BASE_ADDRESS);
                saved_data = *(uint64_t *)cp;
                if (saved_data < abstime) {
                        /* ignoring the success/fail return value assuming that
@@ -713,9 +748,9 @@ commpage_update_mach_approximate_time(uint64_t abstime)
                        OSCompareAndSwap64(saved_data, abstime, (uint64_t *)cp);
                }
        }
-        cp = commPagePtr64;
+       cp = commPagePtr64;
        if ( cp ) {
-               cp += (_COMM_PAGE_APPROX_TIME - _COMM_PAGE32_START_ADDRESS);
+               cp += (_COMM_PAGE_APPROX_TIME - _COMM_PAGE32_START_ADDRESS);
                saved_data = *(uint64_t *)cp;
                if (saved_data < abstime) {
                        /* ignoring the success/fail return value assuming that