lkml.org 
[lkml]   [2005]   [Dec]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: 4k stacks
Date
From
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 rjohnson@analogic.com
// Released under GPL
// Modified by andrew.j.wade@gmail.com
//

#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;
}
\
 
 \ /
  Last update: 2005-12-26 09:46    [from the cache]
©2003-2011 Jasper Spaans