Shared Lib Question (ISC)
Jim Balter
jim at segue.segue.com
Sat May 18 18:03:09 AEST 1991
In article <19261 at rpp386.cactus.org> jfh at rpp386.cactus.org (John F Haugh II) writes:
>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.
As I've already pointed out, this requires that every library routine that ever
might call [a routine that ever might call ...] (I meant to imply this closure,
Dan) malloc must also be a wrapper that passes the malloc arena pointer to the
real routine, which must in turn pass the arena pointer to any other real
routine that ever might call [a real routine that ever might call ...] real
malloc. Whether this is "implemented well" is certainly a matter of opinion.
Passing this arena pointer around violates all reasonable coupling rules.
Better to pass a pointer to a structure containing all global data,
in a hidden register if possible, else as the first or last (by convention)
arg to every routine.
>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[]
Better to have a wrapper for every function and pass one pointer
for every function than to try to guess ahead of time which functions
might lead to a call to malloc and which functions might lead to
a reference to _iob. Of course, this requires a single structure
definition that contains the malloc arena as well as _iob and any
other globals that might be needed, which is grossly bad coupling,
although you could build the structure up cleanly from pieces in
various modules, avoiding the need to couple all this disparate info.
>[ Hint: How does the system get errno out of the kernel and
> into the user space, if it is a user space global variable? ]
Here's where DMR's bad CS becomes evident; system call interfaces should
have taken a pointer through which to store the error number (or an error
structure, for more detailed info), instead of the global errno hack.
>"If liberals interpreted the 2nd Amendment the same way they interpret the
> rest of the Constitution, gun ownership would be mandatory."
Foo on political propaganda in technical newsgroups.
More information about the Comp.unix.internals
mailing list