Blame SOURCES/ElectricFence-2.2.2-malloc_usable_size.patch

15f68b
diff -up ElectricFence-2.2.2/efence.c\~ ElectricFence-2.2.2/efence.c
15f68b
--- ElectricFence-2.2.2/efence.c~	2012-03-12 22:48:22.634989256 +0100
15f68b
+++ ElectricFence-2.2.2/efence.c	2012-03-12 23:05:00.545522379 +0100
15f68b
@@ -865,6 +865,41 @@ free(void * address)
15f68b
 	release();
15f68b
 }
15f68b
 
15f68b
+extern C_LINKAGE size_t
15f68b
+malloc_usable_size(void * address)
15f68b
+{
15f68b
+	Slot *	slot;
15f68b
+
15f68b
+	lock();
15f68b
+
15f68b
+	if ( !noAllocationListProtection )
15f68b
+		Page_AllowAccess(allocationList, allocationListSize);
15f68b
+
15f68b
+	slot = slotForUserAddress(address);
15f68b
+
15f68b
+	if ( !slot )
15f68b
+		EF_Abort("free(%a): address not from malloc().", address);
15f68b
+
15f68b
+	if ( slot->mode != ALLOCATED ) {
15f68b
+		if ( internalUse && slot->mode == INTERNAL_USE )
15f68b
+			/* Do nothing. */;
15f68b
+		else {
15f68b
+			EF_Abort(
15f68b
+			 "free(%a): malloc_usable_size on freed block."
15f68b
+			,address);
15f68b
+		}
15f68b
+	}
15f68b
+
15f68b
+	size_t ret = slot->userSize;
15f68b
+
15f68b
+	if ( !noAllocationListProtection )
15f68b
+		Page_DenyAccess(allocationList, allocationListSize);
15f68b
+
15f68b
+	release();
15f68b
+
15f68b
+	return ret;
15f68b
+}
15f68b
+
15f68b
 extern C_LINKAGE void *
15f68b
 realloc(void * oldBuffer, size_t newSize)
15f68b
 {
15f68b
15f68b
Diff finished.  Mon Mar 12 23:06:53 2012