[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shared Libs



Chris Ridd wrote:

> Wouldn't the lib then have to keep 'n' data sections corresponding to the
> 'n' processes currently using the library.

Sure, most library modules will want to use some static variables(*),
which must be allocated in different data sections for different pro-
cesses. So the trap code should pass the proper base address of a mo-
dules' data section before jumping to a function within that module.
All functions must access their static variables relative to that base
address. I believe register a5 would be most appropriate to pass the
base address. :-)

Theoretically the trap code could even move data sections to different
locations after initialisation. Of course, in this case something like
first_time:
	lea	a5@(200),a0	| start of structure foo
	movl	a0,a5@(400)
	...
next_time:
	movl	a5@(400),a0
	movl	a0@,d0		| foo.size
	...
would be illegal in a library function.


(*) Some of the libc functions requiring static variables would be:
    asctime(), ctermid(), ctime(), cuserid(), getgrgid(), getgrnam(),
    getlogin(), getpwnam(), getpwuid(), gmtime(), localeconv(),
    localtime(), setlocale(), tmpnam() and ttyname()
    which traditionally return a pointer to static storage. Other
    functions, like strtok(), want to maintain internal information
    between subsequent calls.


Waldi