Shared Lib Question (ISC)

John F Haugh II jfh at rpp386.cactus.org
Mon May 13 04:14:47 AEST 1991


In article <1991May10.192648.3147 at Think.COM> barmar at think.com writes:
>In article <19255 at rpp386.cactus.org> jfh at rpp386.cactus.org (John F Haugh II) writes:
>>  Name a single library function
>>which cannot be implemented well without global variables.
>
>Malloc() needs a global variable that points to the arena.
>
>Stdio uses the global variables stdin, stdout, and stderr.
>
>Errno is a global variable, and some library routines set it.

The key word was "well", not "at all".  malloc() can be
implemented as a function which is bound static and has
a single pointer to all the private data that it requires.
It then calls the real routine which takes a pointer to
the arena glarp and size of the desired object.

Likewise for the stdio library.  Functions which have
implied (FILE *) objects can be re-implemented as wrappers
for the versions which require the explicit argument.  The
FILE _iob[] 

Given that the functions were =designed= with the notion
of shared global data, I don't see any reason not to cheat
and leave certain parts =out= of the shared library.

I'll leave errno as an exercise for the reader.

[ Hint: How does the system get errno out of the kernel and
  into the user space, if it is a user space global variable? ]
-- 
John F. Haugh II        | Distribution to  | UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 255-8251 | GEnie PROHIBITED :-) |  Domain: jfh at rpp386.cactus.org
"If liberals interpreted the 2nd Amendment the same way they interpret the
 rest of the Constitution, gun ownership would be mandatory."



More information about the Comp.unix.internals mailing list