Hi,

gcl use the attached program, extracted from configure.in, to
calculateĀ mem_top, mem_range, stack_address, stack_direction and
page_width for that package. (Unfortunately I don't understand parts of
the code)

Unfortunately some values are wrong for GNU/Hurd. In order to hardcode
them (to see if the application packages like maxima can run properly)
I need to know the correct/safe (maybe empirical) values.

On Hurd:
page_width=12
stack_direction=-1
stack_address=0xfffffff
mem_top=0x80000000
mem_range=0x40000000

Empirically, with a max memory of 1980 MiB, that gives
mem_top=0x7bc00000 (Using this value does not change anything when
building maxima, it hangs with a corrupt stack/memory corruption/other)

Are the other calculated values correct?

On Linux (amd64):
page_width=12
stack_direction=-1
stack_address=0x7fff2fffffff
mem_top=0x8000000000000000
mem_range=0x40000000
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

void *foo()
{
  int ii;
  return (void *)&ii;
}

uint check_page_width()
{
  int min_pagewidth=12; 
  size_t i=getpagesize(),j;

  for (j=0;i>>=1;j++);
  j=j<min_pagewidth ? min_pagewidth : j;
  return j;
}

int check_stack_direction()
{
  char *b;
  if ((long) &b > (long) foo())
    return -1;
  else
    return 1;
}

ulong check_stack_address()
{
  void *v;
  unsigned long i,j,m;

  j=1;
  m = check_page_width();
  j<<=m;
  j<<=16;
  i=(unsigned long)&v;
  if ((long)foo()>i) i-=j;
  j--;
  i+=j;
  i&=~j;
  return i-1;
}

ulong check_mem_top()
{
  unsigned long i,j,k,l,m,n;

  for (i=2,k=1;i;k=i,i<<=1);
  l = check_stack_address();
  n = check_stack_direction();
  l=n==1 ? (l<k ? k-1 : -1) : l;
  for (i=j=k;j && i<l;j>>=1,i|=j);
  if (j<(k>>3)) i=0;
  j=1;
  m = check_page_width();
  j<<=m;
  j<<=4;
  j--;
  i+=j;
  i&=~j;
  return i;
}

ulong check_mem_range()
{
  unsigned long j, mem_top=check_mem_top();
  mem_top=0x80000000;
  for (j=1;j && !(j& mem_top);j<<=1);
  return j>>1;
}

int main()
{
  fprintf(stdout,"page_width=%u\n", check_page_width());
  fprintf(stdout,"stack_direction=%d\n", check_stack_direction());
  fprintf(stdout,"stack_address=0x%lx\n", check_stack_address());
  fprintf(stdout,"mem_top=0x%lx\n", check_mem_top());
  fprintf(stdout,"mem_range=0x%lx\n", check_mem_range());
  
  return 0;
}

Reply via email to