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