lua-users home
lua-l archive

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


On Wed, 14 Apr 2010, Robert G. Jakabosky wrote:
>
> Using the jmp_buf hacks or assembly code, allows the program to allocate the
> stacks using malloc() or mmap().

You can use alloca() or C99 variable-length arrays to move the stack to
the heap. For example (assuming the stack grows downwards),

	#define STACKSIZE (16*1024)
	#define SLOP 16

	void newstack(void f(void)) {
		vois *osp = &f;
		void *nsp = malloc(STACKSIZE) + STACKSIZE - SLOP;
		void *dummy = alloca(osp - nsp);
		f(); // runs with its stack on the heap
	}

alloca() is just a way of subtracting some number from the stack pointer.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.