Loading...
libkern/c++/OSKext.cpp xnu-12377.121.6 xnu-11417.121.6
--- xnu/xnu-12377.121.6/libkern/c++/OSKext.cpp
+++ xnu/xnu-11417.121.6/libkern/c++/OSKext.cpp
@@ -50,9 +50,7 @@
 #include <mach/mach_time.h>
 #include <uuid/uuid.h>
 #include <sys/random.h>
-#include <sys/reboot.h>
 #include <pexpert/pexpert.h>
-#include <pexpert/device_tree.h>
 
 #include <sys/pgo.h>
 
@@ -552,7 +550,7 @@
 /*********************************************************************
  * sKextLoggingLock protects the logging variables declared immediately below.
  **********/
-__static_testable IOLock      * sKextLoggingLock           = NULL;
+static IOLock                 * sKextLoggingLock           = NULL;
 
 static  const OSKextLogSpec     kDefaultKernelLogFilter    = kOSKextLogBasicLevel |
     kOSKextLogVerboseFlagsMask;
@@ -1038,10 +1036,10 @@
 		sKeepSymbols = true;
 	}
 #endif /* CONFIG_DTRACE */
-#if KASAN_DYNAMIC_DENYLIST
+#if KASAN_DYNAMIC_BLACKLIST
 	/* needed for function lookup */
 	sKeepSymbols = true;
-#endif /* KASAN_DYNAMIC_DENYLIST */
+#endif
 
 	/*
 	 * Should we panic when the SystemKC is not linked against the
@@ -1222,7 +1220,7 @@
 #if __arm__ || __arm64__
 	/* Free the memory that was set up by iBoot.
 	 */
-#if !defined(KERNEL_INTEGRITY_KTRR) && !defined(KERNEL_INTEGRITY_CTRR) && !defined(KERNEL_INTEGRITY_PV_CTRR)
+#if !defined(KERNEL_INTEGRITY_KTRR) && !defined(KERNEL_INTEGRITY_CTRR)
 	/* We cannot free the KLD segment with CTRR enabled as it contains text and
 	 * is covered by the contiguous rorgn.
 	 */
@@ -1593,28 +1591,14 @@
 /*********************************************************************
 *********************************************************************/
 /* static */
-
 bool
 OSKext::driverkitEnabled(void)
 {
-	#if XNU_TARGET_OS_WATCH
-	/*
-	 * Driverkit support is available on watchOS only if the device
-	 * tree has the "supports-driverkit" property in its "/product" node
-	 */
-	DTEntry entry;
-	void const *prop = NULL;
-	unsigned int prop_size;
-
-	if (kSuccess != SecureDTLookupEntry(NULL, "/product", &entry)) {
-		return false;
-	}
-	if (kSuccess != SecureDTGetProperty(entry, "supports-driverkit", &prop, &prop_size)) {
-		return false;
-	}
-	#endif /* XNU_TARGET_OS_WATCH */
-
+#if XNU_TARGET_OS_WATCH
+	return false;
+#else //!XNU_TARGET_OS_WATCH
 	return true;
+#endif //XNU_TARGET_OS_WATCH
 }
 
 /*********************************************************************
@@ -1623,13 +1607,12 @@
 bool
 OSKext::iokitDaemonAvailable(void)
 {
-#if XNU_TARGET_OS_XR || XNU_TARGET_OS_BRIDGE
+#if !XNU_TARGET_OS_IOS && !XNU_TARGET_OS_OSX
 	int notused;
 	if (PE_parse_boot_argn("-restore", &notused, sizeof(notused))) {
 		return false;
 	}
-#endif /* XNU_TARGET_OS_XR || XNU_TARGET_OS_BRIDGE */
-
+#endif //!XNU_TARGET_OS_IOS && !XNU_TARGET_OS_OSX
 	return driverkitEnabled();
 }
 
@@ -1696,10 +1679,10 @@
 }
 
 void
-OSKext::setWillUserspaceReboot(void)
+OSKext::willUserspaceReboot(void)
 {
 	OSKext::willShutdown();
-	IOService::setWillUserspaceReboot();
+	IOService::userSpaceWillReboot();
 	gIOCatalogue->terminateDriversForUserspaceReboot();
 }
 
@@ -1719,12 +1702,6 @@
 	OSKext::setKernelRequestsEnabled(true);
 	sOSKextWasResetAfterUserspaceReboot = true;
 	IORecursiveLockUnlock(sKextLock);
-}
-
-extern "C" int
-OSKextIsInUserspaceReboot(void)
-{
-	return IOService::getWillUserspaceReboot();
 }
 
 extern "C" void
@@ -3846,7 +3823,7 @@
 
 	if (KERN_SUCCESS != kmem_alloc(kernel_map,
 	    (vm_offset_t*)&uncompressedDataBuffer, fullSize,
-	    KMA_DATA_SHARED, VM_KERN_MEMORY_OSKEXT)) {
+	    KMA_DATA, VM_KERN_MEMORY_OSKEXT)) {
 		/* How's this for cheesy? The kernel is only asked to extract
 		 * kext plists so we tailor the log messages.
 		 */
@@ -4243,7 +4220,7 @@
 			logInfoLength = serializer->getLength();
 
 			kmem_result = kmem_alloc(kernel_map, (vm_offset_t *)&buffer, round_page(logInfoLength),
-			    KMA_DATA_SHARED, VM_KERN_MEMORY_OSKEXT);
+			    KMA_DATA, VM_KERN_MEMORY_OSKEXT);
 			if (kmem_result != KERN_SUCCESS) {
 				OSKextLog(/* kext */ NULL,
 				    kOSKextLogErrorLevel |
@@ -4393,8 +4370,7 @@
 #endif /* defined (__arm64__) */
 		}
 	}
-
-	if (kernel_text_contains(address)) {
+	if ((address >= vm_kernel_stext) && (address < vm_kernel_etext)) {
 		foundKext.reset(sKernelKext, OSRetain);
 		goto finish;
 	}
@@ -10751,7 +10727,7 @@
 		/* This kmem_alloc sets the return value of the function.
 		 */
 		kmem_result = kmem_alloc(kernel_map, (vm_offset_t *)&buffer,
-		    round_page(responseLength), KMA_DATA_SHARED, VM_KERN_MEMORY_OSKEXT);
+		    round_page(responseLength), KMA_DATA, VM_KERN_MEMORY_OSKEXT);
 		if (kmem_result != KERN_SUCCESS) {
 			OSKextLog(/* kext */ NULL,
 			    kOSKextLogErrorLevel |
@@ -16364,23 +16340,15 @@
 		    last_unloaded_address, last_unloaded_size);
 	}
 
-	/*
-	 * In most cases the set of loaded kexts is statically determined by the
-	 * Boot KC, so it isn't very interesting to see in the paniclog.
-	 */
-	if (auxKCloaded) {
-		printf_func("loaded kexts:\n");
-		if (loaded_kext_paniclist &&
-		    pmap_find_phys(kernel_pmap, (addr64_t) (uintptr_t) loaded_kext_paniclist) &&
-		    loaded_kext_paniclist[0]) {
-			printf_func("%.*s",
-			    strnlen(loaded_kext_paniclist, loaded_kext_paniclist_size),
-			    loaded_kext_paniclist);
-		} else {
-			printf_func("(none)\n");
-		}
+	printf_func("loaded kexts:\n");
+	if (loaded_kext_paniclist &&
+	    pmap_find_phys(kernel_pmap, (addr64_t) (uintptr_t) loaded_kext_paniclist) &&
+	    loaded_kext_paniclist[0]) {
+		printf_func("%.*s",
+		    strnlen(loaded_kext_paniclist, loaded_kext_paniclist_size),
+		    loaded_kext_paniclist);
 	} else {
-		printf_func("loaded kexts: (skipped, see boot kernelcache)\n");
+		printf_func("(none)\n");
 	}
 	return;
 }
@@ -16445,7 +16413,7 @@
 			sLoadedKextSummariesAllocSize = 0;
 		}
 		result = kmem_alloc(kernel_map, (vm_offset_t *)&summaryHeaderAlloc, size,
-		    KMA_NONE, VM_KERN_MEMORY_OSKEXT);
+		    KMA_DATA, VM_KERN_MEMORY_OSKEXT);
 		if (result != KERN_SUCCESS) {
 			goto finish;
 		}
@@ -17010,13 +16978,13 @@
 sysctl_willuserspacereboot
 (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
 {
-	int new_value = 0, old_value = get_system_inuserspacereboot(), changed = 0;
+	int new_value = 0, old_value = 0, changed = 0;
 	int error = sysctl_io_number(req, old_value, sizeof(int), &new_value, &changed);
 	if (error) {
 		return error;
 	}
 	if (changed) {
-		OSKext::setWillUserspaceReboot();
+		OSKext::willUserspaceReboot();
 	}
 	return 0;
 }