On 6/29/05, Russell Shaw <[EMAIL PROTECTED]> wrote:
> Alloca is like creating a stack variable, except it just gives you some
> generic bytes that don't mean anything. Exiting the local scope will
> trash the local variables and anything done with alloca(). You'll need
> to store some information in a global variable. This C exceptions method
> stores things as a linked list in nested stack frames and keeps a pointer
> to the list in a global variable. Well worth studying:
>
> http://ldeniau.home.cern.ch/ldeniau/html/exception/exception.html
Thanks! That linked was a very good reference. Here's the new and
improved vfork macro. It works nicely! If anyone's curious enough, I
can post the exit and waitpid macros that accompany it. I'm using
these macros to implement a Busybox system that does not need a fork
system call.
Thanks for all your help, Daniel and Russell! Cheers,
Shaun
struct vfork_context {
struct vfork_context *prev;
jmp_buf jmp;
} *vfork_context;
# define vfork() ({ \
int setjmp_ret; \
struct vfork_context *c = alloca(sizeof *c); \
c->prev = vfork_context; \
vfork_context = c; \
if( (setjmp_ret = setjmp(c->jmp)) != 0 ) \
vfork_context = vfork_context->prev; \
setjmp_ret; \
})