Page 1 of 1

A question about dlopen implementation

Posted: Tue Dec 11, 2012 2:06 am
by alix
Hello,

While designing my shared library facilities a question came to my mind about dlopen. Until now i'm managing a list of shared libraries and i map them to process space if they are needed (ELF relocation, etc...) The virtual layout of a process is the following:

[KERNEL_SPACE(<=512MB): PROCESS_CODE+HEAP--->................<---PROCESS_STACK:LIB1,LIB2...]

Is dlopen is expected to open a library and make it available in the process heap? I would be surprised if it is not the case.

Re: A question about dlopen implementation

Posted: Tue Dec 11, 2012 10:23 am
by bluemoon

Code: Select all

man dlopen

     dlopen() examines the file specified by path.  If the file is compatible with the current
     process and has not already been loaded into the current process, it is loaded and linked.  After being
     linked, if it contains any initializer functions, they are called, before dlopen() returns.  dlopen()
     can load dynamic libraries and bundles.  It returns a handle that can be used with dlsym() and
     dlclose().  A second call to dlopen() with the same path will return the same handle, but the internal
     reference count for the handle will be incremented.  Therefore all dlopen() calls should be balanced
     with a dlclose() call.
The exact memory address for the loaded module is open to implementation.