get the debugging methods to build

This commit is contained in:
tg 2008-11-12 05:32:34 +00:00
parent 1211cf79cc
commit c3e17d8f0b
1 changed files with 21 additions and 22 deletions

View File

@ -1,6 +1,6 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.5 2008/11/12 05:27:01 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.6 2008/11/12 05:32:34 tg Exp $");
/* mksh integration of aalloc */ /* mksh integration of aalloc */
@ -79,13 +79,12 @@ static void track_check(void);
#undef AALLOC_INITSZ #undef AALLOC_INITSZ
#define AALLOC_INITSZ pagesz #define AALLOC_INITSZ pagesz
static size_t pagesz; static size_t pagesz;
#define AALLOC_ACCESS(bp, n, p) mprotect((bp), (bp)->endp - (bp), (p)) #define AALLOC_ALLOW(bp) mprotect((bp), (bp)->endp - (char *)(bp), \
#define AALLOC_ALLOW(bp) \ PROT_READ | PROT_WRITE)
AALLOC_ACCESS((bp), (bp)->endp - (bp), PROT_READ | PROT_WRITE); #define AALLOC_DENY(bp) mprotect((bp), (bp)->endp - (char *)(bp), \
#define AALLOC_DENY(bp) \ PROT_NONE)
AALLOC_ACCESS((bp), (bp)->endp - (bp), PROT_NONE) #define AALLOC_PEEK(bp) mprotect((bp), sizeof (struct TArea), \
#define AALLOC_PEEK(bp) \ PROT_READ | PROT_WRITE)
AALLOC_ACCESS((bp), sizeof (struct TArea), PROT_READ | PROT_WRITE)
#else #else
#define AALLOC_ALLOW(bp) /* nothing */ #define AALLOC_ALLOW(bp) /* nothing */
#define AALLOC_DENY(bp) /* nothing */ #define AALLOC_DENY(bp) /* nothing */
@ -179,8 +178,8 @@ anew(void)
ap->bp.pv = (char *)bp; ap->bp.pv = (char *)bp;
ap->bp.iv ^= gcookie; ap->bp.iv ^= gcookie;
#ifdef AALLOC_TRACK #ifdef AALLOC_TRACK
ap->prev.pv = track; ap->prev.pv = (char *)track;
ap->prev.iv ^= track_cookie; ap->prev.iv ^= gcookie;
ap->ocookie = bp->cookie ^ gcookie; ap->ocookie = bp->cookie ^ gcookie;
track = ap; track = ap;
#endif #endif
@ -246,25 +245,25 @@ track_check(void)
while (track) { while (track) {
ap = track; ap = track;
ap->ocookie ^= track_cookie; ap->ocookie ^= gcookie;
ap->prev.iv ^= track_cookie; ap->prev.iv ^= gcookie;
if ((ap->prev.iv & PVMASK) || !ap->ocookie) { if ((ap->prev.iv & PVMASK) || !ap->ocookie) {
/* buffer overflow or something? */ /* buffer overflow or something? */
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:" AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
" %p, %08X, %08X", ap, ap->prev.pv, " %p, %08tX, %08tX", ap, ap->prev.pv,
ap->bp.iv, ap->ocookie); ap->bp.iv, ap->ocookie);
return; return;
} }
if (!(bp = check_bp(ap, "atexit:track_check", tp->ocookie))) if (!(bp = check_bp(ap, "atexit:track_check", ap->ocookie)))
goto track_next; goto track_next;
if (bp->last == &bp->storage) { if (bp->last == (char *)&bp->storage) {
AALLOC_WARN("leaking empty area %p (%p %tu)", ap, AALLOC_WARN("leaking empty area %p (%p %tu)", ap,
bp, bp->endp - bp); bp, bp->endp - (char *)bp);
} else } else
adelete_leak(ap, bp); adelete_leak(ap, bp);
free(bp); free(bp);
track_next: track_next:
track = ap->prev.pv; track = (PArea)ap->prev.pv;
free(ap); free(ap);
} }
} }
@ -304,7 +303,7 @@ adelete(PArea *pap)
#ifdef AALLOC_TRACK #ifdef AALLOC_TRACK
if (track == *pap) { if (track == *pap) {
(*pap)->prev.iv ^= gcookie; (*pap)->prev.iv ^= gcookie;
track = (*pap)->prev.pv; track = (PArea)((*pap)->prev.pv);
goto adelete_tracked; goto adelete_tracked;
} }
/* find the TArea whose prev is *pap */ /* find the TArea whose prev is *pap */
@ -312,16 +311,16 @@ adelete(PArea *pap)
while (tp) { while (tp) {
TPtr lp; TPtr lp;
lp.iv = tp->prev.iv ^ gcookie; lp.iv = tp->prev.iv ^ gcookie;
if ((lp.iv & PVMASK) || !lp->ocookie) { if ((lp.iv & PVMASK) || !tp->ocookie) {
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:" AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
" %p, %08X, %08X", tp, tp->prev.pv, " %p, %08tX, %08tX", tp, tp->prev.pv,
tp->bp.iv, tp->ocookie); tp->bp.iv, tp->ocookie);
tp = NULL; tp = NULL;
break; break;
} }
if (lp.pv == *pap) if (lp.pv == (char *)*pap)
break; break;
tp = lp.pv; tp = (PArea)lp.pv;
} }
if (tp) if (tp)
tp->prev.iv = (*pap)->prev.iv; /* decouple *pap */ tp->prev.iv = (*pap)->prev.iv; /* decouple *pap */