2012-08-02 19 views
0

我正在製作一個解釋器,以雞計劃的形式進行內存分配。其基本思想是:如何獲取堆棧限制的特定於平臺的信息

int main() { 
    instruction instructions[] = { zero_root, print_root, hello_world, 
        hello_world, stop }; 

    top_ip.go = &instructions[0]; 

    setjmp(top); 

    (*top_ip.go)(top_ip); 

    return 0; 
} 
                  89,10-17  Bot 

/* The following function is machine dependent */ 
static bool is_time_to_gc(){ 
    /* Is allocated on the stack */ 
    char stack_top; 

    /* It's address is therefore the stack's top */ 
    return &stack_top >= STACK_LIMIT; 
} 

static void goto_next_instruction(struct instruction_pointer ip) { 
    ++ip.go; 

    if (is_time_to_gc()) { 
      /* 
      * Some complicated garbage collection stuff which I haven't 
      * completed yet. 
      */ 

      top_ip.go = ip.go; 
      longjmp(top, 0); 
    } 

    (*ip.go)(ip); 
} 

和樣本指令是:

static void hello_world(struct instruction_pointer ip) { 
    printf("Hello World!\n"); 

    goto_next_instruction(ip); 
} 

我需要知道的是STACK_LIMIT值應該是什麼(我還需要了解堆棧是向上還是向下發展。)如何獲得堆棧限制的平臺特定信息?

回答

1

man getrlimit。 還會檢查shell的限制,通常在/etc/login.conf (如果它是一個衍生產品,您可以通過鍵入limit來查看它們)。

:) 乾杯。