Loading...
libkern/c++/OSRuntime.cpp xnu-3248.50.21 xnu-1504.9.17
--- xnu/xnu-3248.50.21/libkern/c++/OSRuntime.cpp
+++ xnu/xnu-1504.9.17/libkern/c++/OSRuntime.cpp
@@ -33,7 +33,6 @@
 #include <libkern/c++/OSKext.h>
 #include <libkern/c++/OSLib.h>
 #include <libkern/c++/OSSymbol.h>
-#include <IOKit/IOKitDebug.h>
 
 #include <sys/cdefs.h>
 
@@ -74,6 +73,7 @@
         }                                                     \
     } while (0)
 
+
 #if PRAGMA_MARK
 #pragma mark kern_os Allocator Package
 #endif /* PRAGMA_MARK */
@@ -104,7 +104,7 @@
         return (0);
     }
 
-    mem = (struct _mhead *)kalloc_tag_bt(memsize, VM_KERN_MEMORY_LIBKERN);
+    mem = (struct _mhead *)kalloc(memsize);
     if (!mem) {
         return (0);
     }
@@ -172,7 +172,7 @@
     }
 
     nmemsize = sizeof (*nmem) + nsize ;
-    nmem = (struct _mhead *) kalloc_tag_bt(nmemsize, VM_KERN_MEMORY_LIBKERN);
+    nmem = (struct _mhead *) kalloc(nmemsize);
     if (!nmem){
         kern_os_free(addr);
         return (0);
@@ -225,41 +225,6 @@
 typedef void (*structor_t)(void);
 
 /*********************************************************************
-*********************************************************************/
-static boolean_t
-sectionIsDestructor(kernel_section_t * section)
-{
-    boolean_t result;
-
-    result = !strncmp(section->sectname, SECT_MODTERMFUNC,
-        sizeof(SECT_MODTERMFUNC) - 1);
-#if !__LP64__
-    result = result || !strncmp(section->sectname, SECT_DESTRUCTOR, 
-        sizeof(SECT_DESTRUCTOR) - 1);
-#endif
-
-    return result;
-}
-
-/*********************************************************************
-*********************************************************************/
-static boolean_t
-sectionIsConstructor(kernel_section_t * section)
-{
-    boolean_t result;
-
-    result = !strncmp(section->sectname, SECT_MODINITFUNC,
-        sizeof(SECT_MODINITFUNC) - 1);
-#if !__LP64__
-    result = result || !strncmp(section->sectname, SECT_CONSTRUCTOR, 
-        sizeof(SECT_CONSTRUCTOR) - 1);
-#endif
-
-    return result;
-}
-
-
-/*********************************************************************
 * OSRuntimeUnloadCPPForSegment()
 *
 * Given a pointer to a mach object segment, iterate the segment to
@@ -284,7 +249,9 @@
          section != 0;
          section = nextsect(segment, section)) {
 
-        if (sectionIsDestructor(section)) {
+        if (strncmp(section->sectname, SECT_DESTRUCTOR, 
+            sizeof(SECT_DESTRUCTOR)) == 0) {
+
             structor_t * destructors = (structor_t *)section->addr;
 
             if (destructors) {
@@ -412,7 +379,7 @@
     kernel_segment_command_t * segment         = NULL;  // do not free
     kernel_segment_command_t * failure_segment = NULL;  // do not free
 
-    if (!kmodInfo || !kmodInfo->address) {
+    if (!kmodInfo || !kmodInfo->address || !kmodInfo->name) {
         result = kOSKextReturnInvalidArgument;
         goto finish;
     }
@@ -455,7 +422,9 @@
              section != NULL;
              section = nextsect(segment, section)) {
 
-            if (sectionIsConstructor(section)) {
+            if (strncmp(section->sectname, SECT_CONSTRUCTOR, 
+                sizeof(SECT_CONSTRUCTOR)) == 0) {
+
                 structor_t * constructors = (structor_t *)section->addr;
 
                 if (constructors) {
@@ -537,15 +506,17 @@
 
 /*********************************************************************
 *********************************************************************/
+extern lck_spin_t  gOSObjectTrackLock;
 extern lck_grp_t * IOLockGroup;
 extern kmod_info_t g_kernel_kmod_info;
 
 void OSlibkernInit(void)
 {
+    lck_spin_init(&gOSObjectTrackLock, IOLockGroup, LCK_ATTR_NULL);
+ 
     // This must be called before calling OSRuntimeInitializeCPP.
     OSMetaClassBase::initialize();
     
-    g_kernel_kmod_info.address = (vm_address_t) &_mh_execute_header;
     if (kOSReturnSuccess != OSRuntimeInitializeCPP(&g_kernel_kmod_info, 0)) {
         panic("OSRuntime: C++ runtime failed to initialize.");
     }
@@ -565,9 +536,6 @@
 *********************************************************************/
 void *
 operator new(size_t size)
-#if __cplusplus >= 201103L
-								noexcept
-#endif
 {
     void * result;
 
@@ -577,9 +545,6 @@
 
 void
 operator delete(void * addr)
-#if __cplusplus >= 201103L
-								noexcept
-#endif
 {
     kern_os_free(addr);
     return;
@@ -587,9 +552,6 @@
 
 void *
 operator new[](unsigned long sz)
-#if __cplusplus >= 201103L
-								noexcept
-#endif
 {
     if (sz == 0) sz = 1;
     return kern_os_malloc(sz);
@@ -597,9 +559,6 @@
 
 void
 operator delete[](void * ptr)
-#if __cplusplus >= 201103L
-								noexcept
-#endif
 {
     if (ptr) {
         kern_os_free(ptr);