Sign in to follow this  
raven_arkadon

shared libraries - how are they done?

Recommended Posts

raven_arkadon    122
ok, heres my problem: how do shared libraries access their data (on assembly level)? currently i know the following: in object/executable files there are sections, some (or all?) of these are mapped to segments. for each segmnent there is a segment descriptor. some segment descriptors are call gate descriptors - which specify an entry point for a far call to some segment. ok, so i have my executable. when i execute it, a code, data and bss segment is created. (am i right that those segment descriptors are stored in the local descriptor table?). the descriptor for the code segment is loaded into cs, the data section is loaded into ds. in case i want to use a different segment as the data segment i either load another segment into ds or i use a segment override prefix. ok, no problem here (i think). but: when i dynamically load a library, new segmnets are created (code, data). so when i want to call a library function, i use a far call for calling it. a far call does some security checking, and if it passes these checks it simply sets cs and eip according to the operands. what about the data section? how does the library access its data section? a far call does not change the ds register (of course it doesnt). so am i right that the called function of the library needs to adjust ds first (otherwise it would mess up "my" data)? or is there some special trick (relative addressing or so) so that the shared lib can access its data? also: if a shared library has global variables, what happens if multiple processes require the same library? are the globals shared among all processes? or does each process get its own copy of the globals? one person once said, that all processes share the same globals, UNTIL one process changes something, then a copy of the modified globals is created (copy on write). is that true? of course there are different ways how it can be done. so lets just say im talking about x86 architecture and windows dlls, or libraries in elf format. ive been looking for that information for quite some time, but i couldnt find anything that answered my questions :( about 95% of the stuff i found about shared libs was how to create them and how to install them, but noone answered how it all works internally. (oh, and why this is game related? cause i want to write a byte code interpreter for a game - and some kind of shared library stuff would be quite nice - but id first like to know how its done on real machines before i write my version) thx for help in advance (if you know some good links on this topic plz let me know)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this