From 8cc7fdb8340386c9dbc9af796edbd77c28240db6 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 7 Apr 2009 19:43:28 +0000 Subject: [PATCH] "evil" workaround to the alignment issues: embed an ALLOC_ITEM into struct env (other structures defined have no "foreign type with pos- sible alignment constraints" members) and take care of it while dea- ling in a struct env instance --- check.t | 4 ++-- main.c | 24 ++++++++++++++++++------ sh.h | 7 ++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/check.t b/check.t index bc32908..7841176 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.269 2009/04/06 08:33:36 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.270 2009/04/07 19:43:26 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -7,7 +7,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R37 2009/04/05 + @(#)MIRBSD KSH R37 2009/04/07 description: Check version of shell. stdin: diff --git a/main.c b/main.c index 7459c8b..3323246 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.124 2009/04/05 12:35:31 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.125 2009/04/07 19:43:27 tg Exp $"); extern char **environ; @@ -620,15 +620,23 @@ void newenv(int type) { struct env *ep; + char *cp; - ep = alloc(sizeof (struct env), ATEMP); - ep->type = type; - ep->flags = 0; + /* + * struct env includes ALLOC_ITEM for alignment constraints + * so first get the actually used memory, then assign it + */ + cp = alloc(sizeof (struct env) - ALLOC_SIZE, ATEMP); + ep = (void *)(cp - ALLOC_SIZE); /* undo what alloc() did */ + /* initialise public members of struct env (not the ALLOC_ITEM) */ ainit(&ep->area); + ep->oenv = e; ep->loc = e->loc; ep->savefd = NULL; - ep->oenv = e; ep->temps = NULL; + ep->type = type; + ep->flags = 0; + /* jump buffer is invalid because flags == 0 */ e = ep; } @@ -636,6 +644,7 @@ void quitenv(struct shf *shf) { struct env *ep = e; + char *cp; int fd; if (ep->oenv && ep->oenv->loc != ep->loc) @@ -684,7 +693,10 @@ quitenv(struct shf *shf) reclaim(); e = e->oenv; - afree(ep, ATEMP); + + /* free the struct env - tricky due to the ALLOC_ITEM inside */ + cp = (void *)ep; + afree(cp + ALLOC_SIZE, ATEMP); } /* Called after a fork to cleanup stuff left over from parents environment */ diff --git a/sh.h b/sh.h index c9db78d..7c8c1c4 100644 --- a/sh.h +++ b/sh.h @@ -102,9 +102,9 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.292 2009/04/07 18:56:51 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.293 2009/04/07 19:43:28 tg Exp $"); #endif -#define MKSH_VERSION "R37 2009/04/05" +#define MKSH_VERSION "R37 2009/04/07" #ifndef MKSH_INCLUDES_ONLY @@ -445,10 +445,11 @@ EXTERN Area aperm; /* permanent object space */ * parsing & execution environment */ extern struct env { + ALLOC_ITEM __alloc_i; /* internal, do not touch */ Area area; /* temporary allocation area */ + struct env *oenv; /* link to previous environment */ struct block *loc; /* local variables and functions */ short *savefd; /* original redirected fds */ - struct env *oenv; /* link to previous environment */ struct temp *temps; /* temp files */ sigjmp_buf jbuf; /* long jump back to env creator */ short type; /* environment type - see below */