Subject: Re: kernel stack overflow detection
To: None <eeh@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 06/27/2002 04:11:47
From: eeh@netbsd.org
Subject: Re: kernel stack overflow detection
Date: 26 Jun 2002 18:56:30 -0000

> #define	KSTACK_SIZE	(USPACE - sizeof(struct user))
> 
> then do:
> 
> +	ip = (u_int32_t *)KSTACK_END(p);
> +	end = (u_int32_t *)((caddr_t)KSTACK_END(p) + KSTACK_SIZE); 
> +	for (; ip < end; ip++) {
> +		*ip = KSTACK_MAGIC;
> +	}
> 
> Now, isn't there some danger that due to rounding
> (KSTACK_END(p) + KSTACK_SIZE) may fall off the end of a page?

i think it's safe since the end of page is aligned.
but, yes, following can be better. thanks.
#define	KSTACK_SIZE (USPACE - ALIGN(sizeof(struct user)))

> Will this also work with machines which have stacks that grow
> up instead of stacks that grow down?

such a machine will need a grow-up version of kstack_check_magic().
is there any such archs in tree now?
the name KSTACK_END might not be so good for such archs...

---
YAMAMOTO Takashi<yamt@mwd.biglobe.ne.jp>