Loading...
--- xnu/xnu-1504.7.4/libkern/c++/OSRuntime.cpp
+++ xnu/xnu-2050.9.2/libkern/c++/OSRuntime.cpp
@@ -225,6 +225,41 @@
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
@@ -249,9 +284,7 @@
section != 0;
section = nextsect(segment, section)) {
- if (strncmp(section->sectname, SECT_DESTRUCTOR,
- sizeof(SECT_DESTRUCTOR)) == 0) {
-
+ if (sectionIsDestructor(section)) {
structor_t * destructors = (structor_t *)section->addr;
if (destructors) {
@@ -422,9 +455,7 @@
section != NULL;
section = nextsect(segment, section)) {
- if (strncmp(section->sectname, SECT_CONSTRUCTOR,
- sizeof(SECT_CONSTRUCTOR)) == 0) {
-
+ if (sectionIsConstructor(section)) {
structor_t * constructors = (structor_t *)section->addr;
if (constructors) {
@@ -517,6 +548,7 @@
// 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.");
}