RE: [PATCH] guard page for stacks that grow upwards

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> But the ia64 grows-up case is tested?

Yes. The attached hacky test program reports that the RSE stack
stomps over the mmap'd segment w/o this patch. With it the
program dies with a SIGBUS. Should be easy to adapt to
test on pa-risc (hint, hint to parisc people).

>> The #ifdefs are ugly - suggestions welcome on how to make
>> the code prettier.
>
> One thing I've considered is to get rid of the CONFIG_STACK_GROWSUP
> crap entirely in code, and instead just make the VM_GROWSUP #define be
> 0 for architectures that don't want it. The compiler should then just
> automatically remove all the code that says
>
>   if (vma->vm_flags & VM_GROWSUP) {
>     ...
>
> and the code would look more straightforward. Hmm?

You'd also need some stub declaration for expand_upwards().
But overall that would look cleaner.

-Tony
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

void watch(long depth, char *map)
{
	int i;

	for (i = 0; i < 0x10000; i++) {
		if (map[i]) {
			printf("Found %x at %p\n", map[i], &map[i]);
			exit(1);
		}
	}
	if (++depth % 5000 == 0)
		printf("now at stack depth %ld\n", depth);
	watch(depth, map);

	/* won't get here .. but stop compiler from doing tail recursion */
	for (i = 0; i < 0x10000; i++) {
		if (map[i]) {
			printf("Found %x at %p\n", map[i], &map[i]);
			exit(1);
		}
	}
}
	
main()
{
	char *p;

	p = mmap((void *)0x6008000000000000, 0x10000, PROT_READ|PROT_WRITE,
		MAP_ANONYMOUS|MAP_PRIVATE, -1, 0L);

	printf("%p\n", p);
	memset(p, '\0', 0x10000);

	watch(0, p);

	return 0;
}

[Index of Archives]     [Linux Kernel]     [Sparc Linux]     [DCCP]     [Linux ARM]     [Yosemite News]     [Linux SCSI]     [Linux x86_64]     [Linux for Ham Radio]

  Powered by Linux