leave at least a working tree, with zero-penalty -DAALLOC_NO_COOKIES
XXX cookies are still broken? cost for aalloc.c: data -= (4, 0, 4, 0); text += (1665, ?, 2115, 2217)
This commit is contained in:
parent
079e86501a
commit
d099b00b53
4
Build.sh
4
Build.sh
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.371 2008/11/11 23:20:08 tg Exp $'
|
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.372 2008/11/12 07:36:18 tg Exp $'
|
||||||
#-
|
#-
|
||||||
# Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
|
# Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
|
||||||
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI
|
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI
|
||||||
@ -251,7 +251,7 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
SRCS="alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
|
SRCS="aalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
|
||||||
SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c"
|
SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c"
|
||||||
|
|
||||||
if test x"$srcdir" = x"."; then
|
if test x"$srcdir" = x"."; then
|
||||||
|
3
Makefile
3
Makefile
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/Makefile,v 1.66 2008/11/12 04:59:42 tg Exp $
|
# $MirOS: src/bin/mksh/Makefile,v 1.67 2008/11/12 07:36:18 tg Exp $
|
||||||
#-
|
#-
|
||||||
# use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff
|
# use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ SRCS= aalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c \
|
|||||||
. if ${DEBUGLIBS:L} == "yes"
|
. if ${DEBUGLIBS:L} == "yes"
|
||||||
CPPFLAGS+= -DMKSH_AFREE_DEBUG # MirOS development version
|
CPPFLAGS+= -DMKSH_AFREE_DEBUG # MirOS development version
|
||||||
. endif
|
. endif
|
||||||
|
CPPFLAGS+= -DAALLOC_NO_COOKIES # for now… aalloc cookies are broken
|
||||||
CPPFLAGS+= -DMKSH_ASSUME_UTF8 \
|
CPPFLAGS+= -DMKSH_ASSUME_UTF8 \
|
||||||
-DHAVE_ATTRIBUTE=1 -DHAVE_ATTRIBUTE_BOUNDED=1 \
|
-DHAVE_ATTRIBUTE=1 -DHAVE_ATTRIBUTE_BOUNDED=1 \
|
||||||
-DHAVE_ATTRIBUTE_USED=1 -DHAVE_SYS_PARAM_H=1 \
|
-DHAVE_ATTRIBUTE_USED=1 -DHAVE_SYS_PARAM_H=1 \
|
||||||
|
62
aalloc.c
62
aalloc.c
@ -1,6 +1,6 @@
|
|||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.22 2008/11/12 07:02:47 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.23 2008/11/12 07:36:19 tg Exp $");
|
||||||
|
|
||||||
/* mksh integration of aalloc */
|
/* mksh integration of aalloc */
|
||||||
|
|
||||||
@ -68,9 +68,11 @@ struct TArea {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static TCookie gcookie;
|
static TCookie global_cookie;
|
||||||
#ifdef AALLOC_NO_COOKIES
|
#ifdef AALLOC_NO_COOKIES
|
||||||
static TCookie fake_cookie;
|
#define gcookie 0
|
||||||
|
#else
|
||||||
|
#define gcookie global_cookie
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AALLOC_TRACK
|
#ifdef AALLOC_TRACK
|
||||||
@ -154,17 +156,14 @@ anew(void)
|
|||||||
(unsigned long)sizeof (struct TBlock));
|
(unsigned long)sizeof (struct TBlock));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AALLOC_NO_COOKIES
|
if (!global_cookie) {
|
||||||
#define gcookie fake_cookie
|
|
||||||
#endif
|
|
||||||
if (!gcookie) {
|
|
||||||
size_t v;
|
size_t v;
|
||||||
|
|
||||||
/* ensure unaligned cookie */
|
/* ensure unaligned cookie */
|
||||||
do {
|
do {
|
||||||
gcookie = AALLOC_RANDOM();
|
global_cookie = AALLOC_RANDOM();
|
||||||
v = AALLOC_RANDOM() & 7;
|
v = AALLOC_RANDOM() & 7;
|
||||||
} while (!(gcookie & PVMASK) || !v);
|
} while (!(global_cookie & PVMASK) || !v);
|
||||||
/* randomise seed afterwards */
|
/* randomise seed afterwards */
|
||||||
while (v--)
|
while (v--)
|
||||||
AALLOC_RANDOM();
|
AALLOC_RANDOM();
|
||||||
@ -172,7 +171,6 @@ anew(void)
|
|||||||
atexit(track_check);
|
atexit(track_check);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#undef gcookie
|
|
||||||
|
|
||||||
ap = NULL; safe_realloc(ap, sizeof (struct TArea));
|
ap = NULL; safe_realloc(ap, sizeof (struct TArea));
|
||||||
bp = NULL; safe_realloc(bp, AALLOC_INITSZ);
|
bp = NULL; safe_realloc(bp, AALLOC_INITSZ);
|
||||||
@ -255,35 +253,40 @@ check_bp(PArea ap, const char *funcname, TCookie ocookie)
|
|||||||
static void
|
static void
|
||||||
track_check(void)
|
track_check(void)
|
||||||
{
|
{
|
||||||
PArea ap;
|
PArea tp;
|
||||||
|
TPtr lp;
|
||||||
PBlock bp;
|
PBlock bp;
|
||||||
|
|
||||||
while (track) {
|
while (track) {
|
||||||
ap = track;
|
tp = track;
|
||||||
ap->ocookie ^= gcookie;
|
tp->ocookie ^= gcookie;
|
||||||
ap->prev.iv ^= gcookie;
|
lp.iv = tp->prev.iv ^ gcookie;
|
||||||
if ((ap->prev.iv & PVMASK) || (ap->ocookie & PVMASK)) {
|
if ((lp.iv & PVMASK)
|
||||||
|
#ifndef AALLOC_NO_COOKIES
|
||||||
|
|| !(tp->ocookie & PVMASK)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
/* 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, %p, %p; exiting", ap, ap->prev.pv,
|
" %p, %p, %p; exiting", tp, lp.pv, tp->bp.pv,
|
||||||
ap->bp.pv, (void *)ap->ocookie);
|
(void *)tp->ocookie);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(bp = check_bp(ap, "atexit:track_check", ap->ocookie)))
|
if (!(bp = check_bp(tp, "atexit:track_check", tp->ocookie)))
|
||||||
goto track_next;
|
goto track_next;
|
||||||
if (bp->last != (char *)&bp->storage)
|
if (bp->last != (char *)&bp->storage)
|
||||||
#ifdef MKSH_VERSION /* allowed to leak silently */
|
#ifdef MKSH_VERSION /* allowed to leak silently */
|
||||||
adelete_leak(ap, bp, false, "at exit");
|
adelete_leak(tp, bp, false, "at exit");
|
||||||
#else
|
#else
|
||||||
adelete_leak(ap, bp, true, "at exit");
|
adelete_leak(tp, bp, true, "at exit");
|
||||||
else
|
else
|
||||||
AALLOC_WARN("leaking empty area %p (%p %lu)", ap,
|
AALLOC_WARN("leaking empty area %p (%p %lu)", tp,
|
||||||
bp, (unsigned long)(bp->endp - (char *)bp));
|
bp, (unsigned long)(bp->endp - (char *)bp));
|
||||||
#endif
|
#endif
|
||||||
free(bp);
|
free(bp);
|
||||||
track_next:
|
track_next:
|
||||||
track = (PArea)ap->prev.pv;
|
track = (PArea)lp.pv;
|
||||||
free(ap);
|
free(tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -311,6 +314,7 @@ adelete(PArea *pap)
|
|||||||
{
|
{
|
||||||
#ifdef AALLOC_TRACK
|
#ifdef AALLOC_TRACK
|
||||||
PArea tp;
|
PArea tp;
|
||||||
|
TPtr lp;
|
||||||
#endif
|
#endif
|
||||||
PBlock bp;
|
PBlock bp;
|
||||||
|
|
||||||
@ -330,12 +334,16 @@ adelete(PArea *pap)
|
|||||||
/* find the TArea whose prev is *pap */
|
/* find the TArea whose prev is *pap */
|
||||||
tp = track;
|
tp = track;
|
||||||
while (tp) {
|
while (tp) {
|
||||||
TPtr lp;
|
|
||||||
lp.iv = tp->prev.iv ^ gcookie;
|
lp.iv = tp->prev.iv ^ gcookie;
|
||||||
if ((lp.iv & PVMASK) || (tp->ocookie & PVMASK)) {
|
if ((lp.iv & PVMASK)
|
||||||
|
#ifndef AALLOC_NO_COOKIES
|
||||||
|
|| !((tp->ocookie ^ gcookie) & PVMASK)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
/* buffer overflow or something? */
|
||||||
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
|
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
|
||||||
" %p, %p, %p", tp, tp->prev.pv, tp->bp.pv,
|
" %p, %p, %p; exiting", tp, lp.pv, tp->bp.pv,
|
||||||
(void *)tp->ocookie);
|
(void *)(tp->ocookie ^ gcookie));
|
||||||
tp = NULL;
|
tp = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user