zero-size malloc and ps: kvm_getprocs: Bad address

Matthew Dillon dillon at apollo.backplane.com
Sun May 24 10:12:51 PDT 2009


    We currently return an invalid non-NULL pointer, ZERO_LENGTH_PTR,
    which I have set to ((void *)-8).

    We can change ZERO_LENGTH_PTR to be whatever we want, including
    making it a pointer to valid memory like the address of a dummy
    global.

    It might be better to fix kvm_getprocs, though, to not try to do a
    useracc test on a zero-length allocation.  But I leave it up to you
    guys.

					-Matt
					Matthew Dillon 
					<dillon at backplane.com>

diff --git a/lib/libc/stdlib/nmalloc.c b/lib/libc/stdlib/nmalloc.c
index faa1e5c..29c1c4f 100644
--- a/lib/libc/stdlib/nmalloc.c
+++ b/lib/libc/stdlib/nmalloc.c
@@ -183,7 +183,7 @@ typedef struct slglobaldata {
  */
 #define WEIRD_ADDR      0xdeadc0de
 #define MAX_COPY        sizeof(weirdary)
-#define ZERO_LENGTH_PTR	((void *)-8)
+#define ZERO_LENGTH_PTR	((void *)&nmalloc_dummy_storage)
 
 #define BIGHSHIFT	10			/* bigalloc hash table */
 #define BIGHSIZE	(1 << BIGHSHIFT)
@@ -219,6 +219,7 @@ static struct slglobaldata	SLGlobalData[SLGD_MAX];
 static bigalloc_t bigalloc_array[BIGHSIZE];
 static spinlock_t bigspin_array[BIGXSIZE];
 static int malloc_panic;
+static int nmalloc_dummy_storage;
 
 static const int32_t weirdary[16] = {
 	WEIRD_ADDR, WEIRD_ADDR, WEIRD_ADDR, WEIRD_ADDR,





More information about the Bugs mailing list