Re: 4k stacks

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

 



I've modified stack.c to handle 4k stacks. It can also provide information
for 8k stacks (fwiw) by changing STACK_GRANULARITY.

It found one stack with only 756 bytes left. I hope it's just due to a
greedy boot-time function as I'm not running anything particularly exotic.
(CIFS & Reiser4). 

Unfortunately I don't have any more time to experiment: I'm leaving for
a week.

Andrew Wade
//
//  This needs the kernel stack-poison patch to run. 
//  Merry Christmas from [email protected]
//  Released under GPL
//  Modified by [email protected]
//

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

// Alignment/size of i386 stacks:
#define STACK_GRANULARITY 4096

// skip these many bytes:
#define THREAD_INFO_SIZE 52

int main()
{
    size_t i;
    int fd;
    char *buf;
    if((fd = open("/dev/mem", O_RDONLY)) < 0)
    {
        fprintf(stderr, "Can't open device file for reading\n");
        exit(EXIT_FAILURE);
    }
    if((buf = malloc(STACK_GRANULARITY)) == NULL)
    {
        fprintf(stderr, "Can't allocate memory\n");
        exit(EXIT_FAILURE);
    }

    while(read(fd, buf, STACK_GRANULARITY) == STACK_GRANULARITY)
    {
        if(buf[THREAD_INFO_SIZE] == 'Q')
        {
            for(i=THREAD_INFO_SIZE; i < STACK_GRANULARITY; i++)
                if(buf[i] != 'Q')
                     break;
            if(i > THREAD_INFO_SIZE + 4)	// Could be a word of 'QQQQ'
                printf("Available Stack bytes = %5u\n", i - THREAD_INFO_SIZE);
        }
    }
    free(buf);
    close(fd);
    return 0;
}


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux