[PATCH 0/2] first stab at NOFORK applet support
Denis Vlasenko
vda at ilport.com.ua
Fri May 5 06:37:22 UTC 2006
Hi Rob,
I looked at implementing NOFORK as discussed a while ago.
Two following patches are a RFC. They add a bss_size field
to struct BB_applet and global bss_buffer, which is
memset(bss_buffer, 0 applet->bss_size);
just before applet invocation. This allows for repeated calls
of an applet from e.g. shell with correctly zeroed-out bss.
Also patches convert one applet (sed) so that it has neither
initialized data section nor bss section. #defines in quickshell.h
are provided to make it easier.
Conversion goes like this:
1) Remove 'static' keyword, bracket all bss variables in
BEGIN_BSS/END_BSS (this places them in struct BSS_DATA).
check with "make objsizes" that you didn't miss anything.
2) Either globally s/var/B.var/g or add line
#define var B.var
for each variable
3) edit line
APPLET_DATA_SIZE(sed, <bss_size>, <data_size>)
in quickshell.h. Set bss_size to something greater
or equal [*] to total size of sed's bss.
4) add line
CHECK_BSS_SIZE(sed);
at the beginning of sed_main()
(its's a compile check, no code generated)
This will make sed use bss_buffer for all bss variables.
Initialized data is not yet handled. To be done
after this RFC will be discussed.
[*] Why? Because it is impractical to move struct BSS_DATA
definition out of sed.c into something.h and just use
sizeof(struct BSS_DATA_sed). Too many applets have
local structs and local vars with names which will
pollute namespace. This will wreak havoc.
Just entering bss size by hand in quickshell.h
is a bit awkward, but at least I make compiler
check that entered value is not less than sizeof(BSS_SIZE_sed),
preventing a "bss is not entirely cleared" bug.
CHECK_BSS_SIZE(sed) does that check. Spesifying
too big a value is harmless (will memset a few extra bytes)
Please comment...
--
vda
More information about the busybox
mailing list