www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/10/29/17:08:13

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3BDDD2F5.4D609543@phekda.freeserve.co.uk>
Date: Mon, 29 Oct 2001 22:06:45 +0000
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: DJGPP workers <djgpp-workers AT delorie DOT com>
Subject: Patch for develop.txi: BSS and restarted programs
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Below is a patch for develop.txi in the knowledge base, which describes
what to do about BSS and restarting programs (aka Emacs ;) ) restarting.
I've been wondering about this for a while - my /dev/{zero,full} patches
need updating to cope with restarting programs. BTW what does BSS stand?

OK to commit?

Thanks, bye, Rich =]

-- 
Richard Dawe
http://www.phekda.freeserve.co.uk/richdawe/

Index: src/docs/kb/develop.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/develop.txi,v
retrieving revision 1.5
diff -p -c -3 -r1.5 develop.txi
*** src/docs/kb/develop.txi     2001/03/31 13:44:50     1.5
--- src/docs/kb/develop.txi     2001/10/29 22:03:05
*************** functions, it should include @file{libc/
*** 77,82 ****
--- 77,127 ----
  @sc{gs} register instead of @sc{fs}, to avoid clobbering @sc{fs} which
  might be used by the application.
  
+ @subsection BSS and restarted programs
+ @cindex BSS and restarted programs
+ 
+ Uninitialised static and global data is placed in the section @dfn{bss}.
+ The BSS is zeroed by the start-up code.  It would seem that one can rely
+ on uninitialised static and global variables being initialised to zero.
+ Unfortunately it is possible that the start-up code is not called.
+ This happens where programs are restarted --- Emacs is one example.
+ 
+ Fortunately there is a way that library code can detect a restart.
+ The variable @code{__bss_count} contains a counter of the number of
times
+ that the program has been started.  A routine using BSS can store
+ @code{__bss_count} and then check whether it needs to initialise its
data
+ by comparing @code{__bss_count} with its stored value. Here is an
example:
+ 
+ @example
+ #include <string.h>
+ #include <libc/bss.h>
+ 
+ extern int do_something_interesting (const int n);
+ 
+ static int my_bss_count = -1;
+ static int my_array[20];
+ 
+ int
+ myfunc (const int n)
+ @{
+   if (my_bss_count != __bss_count)
+     @{
+       my_bss_count = __bss_count;
+       memset(my_array, 0, sizeof(my_array));
+     @}
+ 
+   if (n >= 20)
+     return 0;
+ 
+   if (!my_array[n])
+     my_array[n] = do_something_interesting(n);
+ 
+   return(my_array[n]);
+ @}
+ @end example
+ 
+ For more details see @file{src/libc/crt0/crt1.c} in the DJGPP libc
sources.
+ 
  @section Texinfo documentation
  
  @subsection Formatting

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019