Loading...
--- xnu/xnu-12377.121.6/libkern/OSKextLib.cpp
+++ xnu/xnu-4903.270.47/libkern/OSKextLib.cpp
@@ -31,13 +31,10 @@
#include <libkern/mkext.h>
};
-#include <kern/telemetry.h>
#include <libkern/c++/OSContainers.h>
#include <libkern/c++/OSKext.h>
#include <libkern/OSKextLib.h>
#include <libkern/OSKextLibPrivate.h>
-#include <vm/vm_kern_xnu.h>
-#include <vm/vm_map_xnu.h>
extern "C" {
#if PRAGMA_MARK
@@ -77,12 +74,6 @@
/*********************************************************************
*********************************************************************/
-
-// FIXME: Implementation of this function is hidden from the static analyzer.
-// The analyzer is worried about the lack of release and suggests
-// refactoring the code into the typical non-owning container pattern.
-// Feel free to remove the #ifndef and address the warning!
-#ifndef __clang_analyzer__
OSReturn
OSKextRetainKextWithLoadTag(uint32_t loadTag)
{
@@ -117,16 +108,9 @@
finish:
return result;
}
-#endif // __clang_analyzer__
-
-/*********************************************************************
-*********************************************************************/
-
-// FIXME: Implementation of this function is hidden from the static analyzer.
-// The analyzer is worried about the double release and suggests
-// refactoring the code into the typical non-owning container pattern.
-// Feel free to remove the #ifndef and address the warning!
-#ifndef __clang_analyzer__
+
+/*********************************************************************
+*********************************************************************/
OSReturn
OSKextReleaseKextWithLoadTag(uint32_t loadTag)
{
@@ -162,7 +146,6 @@
finish:
return result;
}
-#endif // __clang_analyzer__
/*********************************************************************
* Not to be called by the kext being unloaded!
@@ -207,12 +190,9 @@
#pragma mark MIG Functions & Wrappers
#endif
/*********************************************************************
-* IMPORTANT: vm_map_copyout_size() consumes the requestIn copy
-* object on success. Therefore once it has been invoked successfully,
-* this routine *must* return KERN_SUCCESS, regardless of our actual
-* result. Our contract with the caller is that requestIn must be
-* caller-deallocated if we return an error. We use op_result to return
-* the real result of our work.
+* IMPORTANT: Once we have done the vm_map_copyout(), we *must* return
+* KERN_SUCCESS or the kernel map gets messed up (reason as yet
+* unknown). We use op_result to return the real result of our work.
*********************************************************************/
kern_return_t
kext_request(
@@ -242,9 +222,9 @@
* just in case, or MIG will try to copy out bogus data.
*/
*op_result = KERN_FAILURE;
- *responseOut = 0;
+ *responseOut = NULL;
*responseLengthOut = 0;
- *logDataOut = 0;
+ *logDataOut = NULL;
*logDataLengthOut = 0;
/* Check for input. Don't discard what isn't there, though.
@@ -258,17 +238,17 @@
goto finish;
}
- result = vm_map_copyout_size(kernel_map, &map_addr, (vm_map_copy_t)requestIn, requestLengthIn);
+ /* Once we have done the vm_map_copyout(), we *must* return KERN_SUCCESS
+ * or the kernel map gets messed up (reason as yet unknown). We will use
+ * op_result to return the real result of our work.
+ */
+ result = vm_map_copyout(kernel_map, &map_addr, (vm_map_copy_t)requestIn);
if (result != KERN_SUCCESS) {
OSKextLog(/* kext */ NULL,
kOSKextLogErrorLevel |
kOSKextLogIPCFlag,
"vm_map_copyout() failed for request from user space.");
- /*
- * If we return an error it is our caller's responsibility to
- * deallocate the requestIn copy object, so do not deallocate it
- * here. See comment above.
- */
+ vm_map_copy_discard((vm_map_copy_t)requestIn);
goto finish;
}
request = CAST_DOWN(char *, map_addr);
@@ -287,7 +267,7 @@
}
if (isMkext) {
-#if defined(SECURE_KERNEL) || !CONFIG_KXLD
+#ifdef SECURE_KERNEL
// xxx - something tells me if we have a secure kernel we don't even
// xxx - want to log a message here. :-)
*op_result = KERN_NOT_SUPPORTED;
@@ -334,7 +314,7 @@
kOSKextLogIPCFlag,
"Failed to copy response to request from user space.");
*op_result = copyin_result; // xxx - should we map to our own code?
- *responseOut = 0;
+ *responseOut = NULL;
*responseLengthOut = 0;
goto finish;
}
@@ -354,7 +334,7 @@
kOSKextLogIPCFlag,
"Failed to copy log data for request from user space.");
*op_result = copyin_result; // xxx - should we map to our own code?
- *logDataOut = 0;
+ *logDataOut = NULL;
*logDataLengthOut = 0;
goto finish;
}
@@ -380,31 +360,21 @@
* Gets the vm_map for the current kext
*********************************************************************/
extern vm_offset_t segPRELINKTEXTB;
-extern vm_offset_t segLINKB;
extern unsigned long segSizePRELINKTEXT;
+extern int kth_started;
+extern vm_map_t g_kext_map;
vm_map_t
kext_get_vm_map(kmod_info_t *info)
{
vm_map_t kext_map = NULL;
- kc_format_t kcformat;
-
- if (PE_get_primary_kc_format(&kcformat) && kcformat == KCFormatFileset) {
- /* Check if the kext is from the boot KC */
- assert(segLINKB >= (segPRELINKTEXTB + segSizePRELINKTEXT));
- if ((info->address >= segPRELINKTEXTB) &&
- (info->address < segLINKB)) {
- kext_map = kernel_map;
- } else {
- kext_map = g_kext_map;
- }
+
+ /* Set the vm map */
+ if ((info->address >= segPRELINKTEXTB) &&
+ (info->address < (segPRELINKTEXTB + segSizePRELINKTEXT))) {
+ kext_map = kernel_map;
} else {
- if ((info->address >= segPRELINKTEXTB) &&
- (info->address < (segPRELINKTEXTB + segSizePRELINKTEXT))) {
- kext_map = kernel_map;
- } else {
- kext_map = g_kext_map;
- }
+ kext_map = g_kext_map;
}
return kext_map;
@@ -419,10 +389,10 @@
void
kext_weak_symbol_referenced(void)
{
- panic("A kext referenced an unresolved weak symbol");
-}
-
-const void * const gOSKextUnresolved = (const void *)&kext_weak_symbol_referenced;
+ panic("A kext referenced an unresolved weak symbol\n");
+}
+
+const void *gOSKextUnresolved = (const void *)&kext_weak_symbol_referenced;
#if PRAGMA_MARK
#pragma mark Kernel-Internal C Functions
@@ -483,36 +453,6 @@
return;
}
-void
-telemetry_backtrace_add_kexts(
- char *buf,
- size_t buflen,
- uintptr_t *frames,
- uint32_t framecnt)
-{
- __block size_t pos = 0;
-
- OSKext::foreachKextInBacktrace(frames, framecnt, OSKext::kPrintKextsLock,
- ^(OSKextLoadedKextSummary *summary, uint32_t index __unused){
- uuid_string_t uuid;
- uint64_t tmpAddr;
- uint64_t tmpSize;
-
- (void) uuid_unparse(summary->uuid, uuid);
-
-#if defined(__arm__) || defined(__arm64__)
- tmpAddr = summary->text_exec_address;
- tmpSize = summary->text_exec_size;
-#else
- tmpAddr = summary->address;
- tmpSize = summary->size;
-#endif
- tmpAddr -= vm_kernel_stext;
- pos += scnprintf(buf + pos, buflen - pos, "%s@%llx:%llx\n",
- uuid, tmpAddr, tmpAddr + tmpSize - 1);
- });
-}
-
/********************************************************************/
void kmod_dump_log(vm_offset_t *addr, unsigned int cnt, boolean_t doUnslide);
@@ -535,13 +475,6 @@
return OSKext::kextForAddress(addr);
}
-kern_return_t
-OSKextGetLoadedKextSummaryForAddress(
- const void * addr,
- OSKextLoadedKextSummary * summary)
-{
- return OSKext::summaryForAddressExt(addr, summary);
-}
/*********************************************************************
* Compatibility implementation for kmod_get_info() host_priv routine.