[BusyBox] Implement fork using longjmp [PATCH]

Shaun Jackman sjackman at gmail.com
Tue Mar 8 18:26:21 UTC 2005


On Fri, 4 Mar 2005 19:05:20 +0100, Bastian Blank <waldi at debian.org> wrote:
> On Fri, Mar 04, 2005 at 09:27:50AM -0800, Shaun Jackman wrote:
> > .... but these both use somewhat esoteric features of the language and
> > implementation. Once the jmp_buf is stored on the stack, it is still
> > necessary to store a global reference to it so that the exit macro
> > knows where to longjmp. If you have a helper function maintaining a
> > list of jmp_buf buffers pointers anyways, it may as well allocate the
> > memory for them as well.
> 
> Why not safe the old value in a local variable and the new in a general?
> exit will than jump to the actual position and restore the global
> value.

Good idea! I've modified my patch to do just that. fork and exit are
implemented purely with macros, and wait is implemented as a macro
that calls a helper function. This implementation uses the
Declarations in Expressions feature of GCC and so requires GCC. Nested
forks now work.

Cheers,
Shaun

2005-03-03  Shaun Jackman  <sjackman at gmail.com>

	* include/libbb.h (bb_fork_jmp_buf, bb_fork_pid, bb_exit_pid,
	bb_exit_status): New global variables.
	(bb_waitpid): New function.
	(bb_fork, bb_exit, fork, exit, _exit, wait, waitpid): New macro.
	* libbb/Makefile.in (LIBBB_SRC): Add fork.c
	* libbb/fork.c: New file.
	* shell/lash.c (run_command): Do not call close_all after forking
	if CONFIG_FEATURE_IMPLEMENT_FORK_USING_LONGJMP is used.
	* sysdeps/linux/Config.in: Add CONFIG_FEATURE_IMPLEMENT_FORK_USING_LONGJMP.

$ diffstat busybox-1.00-fork.diff
 include/libbb.h         |   37 +++++++++++++++++++++++++++++++++++++
 libbb/Makefile.in       |    2 +-
 libbb/fork.c            |   43 +++++++++++++++++++++++++++++++++++++++++++
 shell/lash.c            |    2 ++
 sysdeps/linux/Config.in |    9 +++++++++
 5 files changed, 92 insertions(+), 1 deletion(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: busybox-1.00-fork.diff
Type: text/x-patch
Size: 5603 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20050308/273e9652/attachment.bin 


More information about the busybox mailing list