=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|Poison|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 */
#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)))
=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>
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
=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
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
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;
}
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;
}
# define SvARENA_CHAIN(sv) ((sv)->sv_u.svu_rv)
/* Whilst I'd love to do this, it seems that things like to check on
unreferenced scalars
-# define POSION_SV_HEAD(sv) Poison(sv, 1, struct STRUCT_SV)
+# define POSION_SV_HEAD(sv) PoisonNew(sv, 1, struct STRUCT_SV)
*/
-# define POSION_SV_HEAD(sv) Poison(&SvANY(sv), 1, void *), \
- Poison(&SvREFCNT(sv), 1, U32)
+# define POSION_SV_HEAD(sv) PoisonNew(&SvANY(sv), 1, void *), \
+ PoisonNew(&SvREFCNT(sv), 1, U32)
#else
# define SvARENA_CHAIN(sv) SvANY(sv)
# define POSION_SV_HEAD(sv)
PERL_SET_THX(my_perl);
# ifdef DEBUGGING
- Poison(my_perl, 1, PerlInterpreter);
+ PoisonNew(my_perl, 1, PerlInterpreter);
PL_op = NULL;
PL_curcop = NULL;
PL_markstack = 0;
PERL_SET_THX(my_perl);
# ifdef DEBUGGING
- Poison(my_perl, 1, PerlInterpreter);
+ PoisonNew(my_perl, 1, PerlInterpreter);
PL_op = NULL;
PL_curcop = NULL;
PL_markstack = 0;
#endif
#ifdef PERL_POISON
- Poison(((char *)ptr), size, char);
+ PoisonNew(((char *)ptr), size, char);
#endif
#ifdef PERL_TRACK_MEMPOOL
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
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
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;