Loading...
libkern/c++/OSRuntime.cpp xnu-201.14 xnu-792.6.22
--- xnu/xnu-201.14/libkern/c++/OSRuntime.cpp
+++ xnu/xnu-792.6.22/libkern/c++/OSRuntime.cpp
@@ -44,13 +44,6 @@
 extern int debug_iomalloc_size;
 #endif
 
-#define	MDECL(reqlen)					\
-typedef union {						\
-	struct	_mhead hdr;				\
-	char	_m[(reqlen) + sizeof (struct _mhead)];	\
-} hdr_t;						\
-hdr_t
-
 struct _mhead {
 	size_t	mlen;
 	char	dat[0];
@@ -59,13 +52,13 @@
 void *kern_os_malloc(
 	size_t		size)
 {
-	MDECL(size)	*mem;
-	size_t		memsize = sizeof (*mem);
+	struct _mhead	*mem;
+	size_t		memsize = sizeof (*mem) + size ;
 
 	if (size == 0)
 		return (0);
 
-	mem = (hdr_t *)kalloc(memsize);
+	mem = (struct _mhead *)kalloc(memsize);
 	if (!mem)
 		return (0);
 
@@ -73,10 +66,10 @@
 	debug_iomalloc_size += memsize;
 #endif
 
-	mem->hdr.mlen = memsize;
-	(void) memset(mem->hdr.dat, 0, size);
-
-	return  (mem->hdr.dat);
+	mem->mlen = memsize;
+	bzero( mem->dat, size);
+
+	return  (mem->dat);
 }
 
 void kern_os_free(
@@ -96,7 +89,7 @@
 #if 0
 	memset((vm_offset_t)hdr, 0xbb, hdr->mlen);
 #else
-	kfree((vm_offset_t)hdr, hdr->mlen);
+	kfree(hdr, hdr->mlen);
 #endif
 }
 
@@ -105,7 +98,7 @@
 	size_t		nsize)
 {
 	struct _mhead	*ohdr;
-	MDECL(nsize)	*nmem;
+	struct _mhead	*nmem;
 	size_t		nmemsize, osize;
 
 	if (!addr)
@@ -121,8 +114,8 @@
 		return (0);
 	}
 
-	nmemsize = sizeof (*nmem);
-	nmem = (hdr_t *) kalloc(nmemsize);
+	nmemsize = sizeof (*nmem) + nsize ;
+	nmem = (struct _mhead *) kalloc(nmemsize);
 	if (!nmem){
 		kern_os_free(addr);
 		return (0);
@@ -132,14 +125,14 @@
 	debug_iomalloc_size += (nmemsize - ohdr->mlen);
 #endif
 
-	nmem->hdr.mlen = nmemsize;
+	nmem->mlen = nmemsize;
 	if (nsize > osize)
-		(void) memset(&nmem->hdr.dat[osize], 0, nsize - osize);
-	(void) memcpy(nmem->hdr.dat, ohdr->dat,
+		(void) memset(&nmem->dat[osize], 0, nsize - osize);
+	(void) memcpy(nmem->dat, ohdr->dat,
 					(nsize > osize) ? osize : nsize);
-	kfree((vm_offset_t)ohdr, ohdr->mlen);
-
-	return (nmem->hdr.dat);
+	kfree(ohdr, ohdr->mlen);
+
+	return (nmem->dat);
 }
 
 size_t kern_os_malloc_size(
@@ -154,11 +147,19 @@
 	return( hdr->mlen - sizeof (struct _mhead));
 }
 
+#if __GNUC__ >= 3
+void __cxa_pure_virtual( void )	{ panic(__FUNCTION__); }
+#else
 void __pure_virtual( void )	{ panic(__FUNCTION__); }
+#endif
 
 typedef void (*structor_t)(void);
 
-void OSRuntimeUnloadCPPForSegment(struct segment_command * segment) {
+// Given a pointer to a 32 bit mach object segment, iterate the segment to
+// obtain a 32 bit destructor section for C++ objects, and call each of the
+// destructors there.
+void
+OSRuntimeUnloadCPPForSegment(struct segment_command * segment) {
 
     struct section * section;
 
@@ -182,6 +183,7 @@
     return;
 }
 
+// This function will only operate on 32 bit kmods
 void OSRuntimeUnloadCPP(kmod_info_t *ki, void *)
 {
     if (ki && ki->address) {
@@ -224,6 +226,7 @@
 }
 
 // Functions used by the extenTools/kmod library project
+// This function will only operate on 32 bit kmods
 kern_return_t OSRuntimeInitializeCPP(kmod_info_t *ki, void *)
 {
     struct mach_header *header;
@@ -331,8 +334,6 @@
     void * result;
 
     result = (void *) kern_os_malloc( size);
-    if( result)
-	bzero( result, size);
     return( result);
 }