Change 29928 by [EMAIL PROTECTED] on 2007/01/22 23:12:43

        Integrate:
        [ 27626]
        Subject: re-[PATCH] Re: [PATCH] Poison now in two different flavours!
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Date: Sun, 26 Mar 2006 14:53:56 +0300
        Message-ID: <[EMAIL PROTECTED]>
        
        [ 27774]
        Newxz() can use calloc() rather than malloc(), as the implementation
        of calloc() may know that it has fresh pages from the OS, and so
        doesn't need to zero them itself. Plus our object code should be
        slightly smaller.
        
        [ 28265]
        Document PoisonFree() instead of documenting Poison() twice.
        
        plus revert change 26776 now that PERL_MEM_LOG is merged:
        [ 26776]
        Steve Hay notes that there's a reference PERL_MEM_LOG here, which is
        inconsistent as PERL_MEM_LOG isn't (yet) merged to maint.

Affected files ...

... //depot/maint-5.8/perl/handy.h#44 integrate
... //depot/maint-5.8/perl/pod/perlapi.pod#85 integrate
... //depot/maint-5.8/perl/pod/perlclib.pod#3 integrate
... //depot/maint-5.8/perl/pod/perldebguts.pod#5 edit
... //depot/maint-5.8/perl/pod/perlhack.pod#23 integrate
... //depot/maint-5.8/perl/pp_ctl.c#150 integrate
... //depot/maint-5.8/perl/scope.c#57 integrate
... //depot/maint-5.8/perl/util.c#124 integrate

Differences ...

==== //depot/maint-5.8/perl/handy.h#44 (text) ====
Index: perl/handy.h
--- perl/handy.h#43~29809~      2007-01-14 05:47:07.000000000 -0800
+++ perl/handy.h        2007-01-22 15:12:43.000000000 -0800
@@ -617,10 +617,22 @@
 =for apidoc Am|void|StructCopy|type src|type dest|type
 This is an architecture-independent macro to copy one structure to another.
 
+=for apidoc Am|void|PoisonWith|void* dest|int nitems|type|U8 byte
+
+Fill up memory with a byte pattern (a byte repeated over and over
+again) that hopefully catches attempts to access uninitialized memory.
+
+=for apidoc Am|void|PoisonNew|void* dest|int nitems|type
+
+PoisonWith(0xAB) for catching access to allocated but uninitialized memory.
+
+=for apidoc Am|void|PoisonFree|void* dest|int nitems|type
+
+PoisonWith(0xEF) for catching access to freed memory.
+
 =for apidoc Am|void|Poison|void* dest|int nitems|type
 
-Fill up memory with a pattern (byte 0xAB over and over again) that
-hopefully catches attempts to access uninitialized memory.
+PoisonWith(0xEF) for catching access to freed memory.
 
 =cut */
 
@@ -705,8 +717,7 @@
 
 #define Newx(v,n,t)    (v = (MEM_WRAP_CHECK_(n,t) 
MEM_LOG_ALLOC(n,t,(t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))))
 #define Newxc(v,n,t,c) (v = (MEM_WRAP_CHECK_(n,t) 
MEM_LOG_ALLOC(n,t,(c*)safemalloc((MEM_SIZE)((n)*sizeof(t))))))
-#define Newxz(v,n,t)   (v = (MEM_WRAP_CHECK_(n,t) 
MEM_LOG_ALLOC(n,t,(t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))))), \
-                       memzero((char*)(v), (n)*sizeof(t))
+#define Newxz(v,n,t)   (v = (MEM_WRAP_CHECK_(n,t) 
MEM_LOG_ALLOC(n,t,(t*)safecalloc((n),sizeof(t)))))
 /* pre 5.9.x compatibility */
 #define New(x,v,n,t)   Newx(v,n,t)
 #define Newc(x,v,n,t,c)        Newxc(v,n,t,c)
@@ -737,7 +748,10 @@
 #define ZeroD(d,n,t)   (MEM_WRAP_CHECK_(n,t) memzero((char*)(d), (n) * 
sizeof(t)),d)
 #endif
 
-#define Poison(d,n,t)  (MEM_WRAP_CHECK_(n,t) (void)memset((char*)(d), 0xAB, 
(n) * sizeof(t)))
+#define PoisonWith(d,n,t,b)    (MEM_WRAP_CHECK_(n,t) (void)memset((char*)(d), 
(U8)(b), (n) * sizeof(t)))
+#define PoisonNew(d,n,t)       PoisonWith(d,n,t,0xAB)
+#define PoisonFree(d,n,t)      PoisonWith(d,n,t,0xEF)
+#define Poison(d,n,t)          PoisonFree(d,n,t)
 
 #ifdef USE_STRUCT_COPY
 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))

==== //depot/maint-5.8/perl/pod/perlapi.pod#85 (text+w) ====
Index: perl/pod/perlapi.pod
--- perl/pod/perlapi.pod#84~29912~      2007-01-21 15:33:27.000000000 -0800
+++ perl/pod/perlapi.pod        2007-01-22 15:12:43.000000000 -0800
@@ -2004,14 +2004,34 @@
 =item Poison
 X<Poison>
 
-Fill up memory with a pattern (byte 0xAB over and over again) that
-hopefully catches attempts to access uninitialized memory.
+PoisonWith(0xEF) for catching access to freed memory.
 
        void    Poison(void* dest, int nitems, type)
 
 =for hackers
 Found in file handy.h
 
+=item PoisonNew
+X<PoisonNew>
+
+PoisonWith(0xAB) for catching access to allocated but uninitialized memory.
+
+       void    PoisonNew(void* dest, int nitems, type)
+
+=for hackers
+Found in file handy.h
+
+=item PoisonWith
+X<PoisonWith>
+
+Fill up memory with a byte pattern (a byte repeated over and over
+again) that hopefully catches attempts to access uninitialized memory.
+
+       void    PoisonWith(void* dest, int nitems, type, U8 byte)
+
+=for hackers
+Found in file handy.h
+
 =item Renew
 X<Renew>
 

==== //depot/maint-5.8/perl/pod/perlclib.pod#3 (text) ====
Index: perl/pod/perlclib.pod
--- perl/pod/perlclib.pod#2~25572~      2005-09-22 09:46:28.000000000 -0700
+++ perl/pod/perlclib.pod       2007-01-22 15:12:43.000000000 -0800
@@ -138,9 +138,12 @@
 numbers), and also hopefully surprising enough as integers, so that
 any code attempting to use the data without forethought will break
 sooner rather than later.  Poisoning can be done using the Poison()
-macro, which has similar arguments as Zero():
+macros, which have similar arguments as Zero():
 
-    Poison(dst, n, t)
+    PoisonWith(dst, n, t, b)    scribble memory with byte b
+    PoisonNew(dst, n, t)        equal to PoisonWith(dst, n, t, 0xAB)
+    PoisonFree(dst, n, t)       equal to PoisonWith(dst, n, t, 0xEF)
+    Poison(dst, n, t)           equal to PoisonFree(dst, n, t)
 
 =head2 Character Class Tests
 

==== //depot/maint-5.8/perl/pod/perldebguts.pod#5 (text) ====
Index: perl/pod/perldebguts.pod
--- perl/pod/perldebguts.pod#4~26776~   2006-01-10 10:28:31.000000000 -0800
+++ perl/pod/perldebguts.pod    2007-01-22 15:12:43.000000000 -0800
@@ -753,7 +753,8 @@
 (it was available only if Perl was built with C<-DDEBUGGING>).
 The switch was used to track Perl's memory allocations and possible
 memory leaks.  These days the use of malloc debugging tools like
-F<Purify> or F<valgrind> is suggested instead.
+F<Purify> or F<valgrind> is suggested instead.  See also
+L<perlhack/PERL_MEM_LOG>.
 
 One way to find out how much memory is being used by Perl data
 structures is to install the Devel::Size module from CPAN: it gives

==== //depot/maint-5.8/perl/pod/perlhack.pod#23 (text) ====
Index: perl/pod/perlhack.pod
--- perl/pod/perlhack.pod#22~29135~     2006-10-29 11:31:39.000000000 -0800
+++ perl/pod/perlhack.pod       2007-01-22 15:12:43.000000000 -0800
@@ -2709,8 +2709,9 @@
 
 =item *
 
-If you see in a debugger a memory area mysteriously full of 0xabababab,
-you may be seeing the effect of the Poison() macro, see L<perlclib>.
+If you see in a debugger a memory area mysteriously full of 0xABABABAB
+or 0xEFEFEFEF, you may be seeing the effect of the Poison() macros,
+see L<perlclib>.
 
 =back
 

==== //depot/maint-5.8/perl/pp_ctl.c#150 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#149~29925~    2007-01-22 14:10:59.000000000 -0800
+++ perl/pp_ctl.c       2007-01-22 15:12:43.000000000 -0800
@@ -327,7 +327,7 @@
        void *tmp = INT2PTR(char*,*p);
        Safefree(tmp);
        if (*p)
-           Poison(*p, 1, sizeof(*p));
+           PoisonFree(*p, 1, sizeof(*p));
 #else
        Safefree(INT2PTR(char*,*p));
 #endif

==== //depot/maint-5.8/perl/scope.c#57 (text) ====
Index: perl/scope.c
--- perl/scope.c#56~29920~      2007-01-22 11:20:43.000000000 -0800
+++ perl/scope.c        2007-01-22 15:12:43.000000000 -0800
@@ -91,7 +91,7 @@
     Newx(si->si_cxstack, cxitems, PERL_CONTEXT);
     /* Without any kind of initialising PUSHSUBST()
      * in pp_subst() will read uninitialised heap. */
-    Poison(si->si_cxstack, cxitems, PERL_CONTEXT);
+    PoisonNew(si->si_cxstack, cxitems, PERL_CONTEXT);
     return si;
 }
 
@@ -103,7 +103,7 @@
     Renew(cxstack, cxstack_max + 1, PERL_CONTEXT);     /* XXX should fix CXINC 
macro */
     /* Without any kind of initialising deep enough recursion
      * will end up reading uninitialised PERL_CONTEXTs. */
-    Poison(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
+    PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
     return cxstack_ix + 1;
 }
 

==== //depot/maint-5.8/perl/util.c#124 (text) ====
Index: perl/util.c
--- perl/util.c#123~29920~      2007-01-22 11:20:43.000000000 -0800
+++ perl/util.c 2007-01-22 15:12:43.000000000 -0800
@@ -98,7 +98,7 @@
 #endif
 
 #ifdef PERL_POISON
-       Poison(((char *)ptr), size, char);
+       PoisonNew(((char *)ptr), size, char);
 #endif
 
 #ifdef PERL_TRACK_MEMPOOL
@@ -164,7 +164,7 @@
        if (header->size > size) {
            const MEM_SIZE freed_up = header->size - size;
            char *start_of_freed = ((char *)where) + size;
-           Poison(start_of_freed, freed_up, char);
+           PoisonFree(start_of_freed, freed_up, char);
        }
        header->size = size;
 #  endif
@@ -189,7 +189,7 @@
        if (header->size < size) {
            const MEM_SIZE fresh = size - header->size;
            char *start_of_fresh = ((char *)ptr) + size;
-           Poison(start_of_fresh, fresh, char);
+           PoisonNew(start_of_fresh, fresh, char);
        }
 #  endif
 
@@ -238,7 +238,7 @@
            header->next->prev = header->prev;
            header->prev->next = header->next;
 #  ifdef PERL_POISON
-           Poison(where, header->size, char);
+           PoisonNew(where, header->size, char);
 #  endif
            /* Trigger the duplicate free warning.  */
            header->next = NULL;
End of Patch.

Reply via email to