Page 1 of 1

Problem when loading several libraries, wich use libraries.

Posted: Sun Apr 15, 2012 2:10 pm
by hidnplayr
I first discovered the problem when writing 'synergyc' application for net branch, some time ago.
This program uses several libraries (console, libini and network library).
Network library uses libini, wich in turn uses libio.

The problem is that libio in libini doesnt load correctly (and perhaps others too).
Thus, when calling ini_get_str, my program crashes because libini trys to call [file.open] (libio) but its value is -1.

Back when i first discovered the problem, I discussed it with diamond, who blamed the problem on a design flaw IIRC.
Since he is no longer here, but the problem is, somebody else will need to fix it.

Does anybody here have more information or insight about this problem ?

Re: Problem when loading several libraries, wich use librari

Posted: Sun Apr 15, 2012 4:16 pm
by Mario
LibINI uses its own copy of LibIO. Thus, for example, Tinypad has two copies LibIO.

How do you use LibIO?

Re: Problem when loading several libraries, wich use librari

Posted: Sun Apr 15, 2012 4:22 pm
by hidnplayr
If what I remember is correct, it has to do with lib_init being called multiple times for the same library.
I do not think it's a kernel problem.

BUT.. I havent investigated any of these claims as of yet,
I was hoping somebody here knows more about the dll loading mechanism then I currently do.. :)

The program synergyc does not use libio itself.
BTW: I tought that the dll's are only loaded in memory once ?

Re: Problem when loading several libraries, wich use librari

Posted: Sun Apr 15, 2012 5:17 pm
by Mario
DLL is loaded into memory only once:
1) if the path to the file system is the same.
2) if the library does not change the memory in its own area, where it has its own code.

LibIO and LibINI violate Rule 2. For this reason, the kernel makes a copy of these libraries for each application.

lib_init is actually a very harmful thing. And for example in box_lib is imitation - you did it. For this reason, the mechanism of the DLL into the kernel does not duplicate Box_Lib.

Re: Problem when loading several libraries, wich use librari

Posted: Sun Apr 15, 2012 5:49 pm
by hidnplayr
Mario wrote:DLL is loaded into memory only once:
1) if the path to the file system is the same.
2) if the library does not change the memory in its own area, where it has its own code.

LibIO and LibINI violate Rule 2. For this reason, the kernel makes a copy of these libraries for each application.

lib_init is actually a very harmful thing. And for example in box_lib is imitation - you did it. For this reason, the mechanism of the DLL into the kernel does not duplicate Box_Lib.
So every library, wich uses another library suffers the problem (2) ?

Re: Problem when loading several libraries, wich use librari

Posted: Sun Apr 15, 2012 6:19 pm
by Mario
If the library does not need a call to lib_init, then the question is not relevant.

Re: Problem when loading several libraries, wich use librari

Posted: Thu Apr 19, 2012 6:36 pm
by hidnplayr
Here is some debugging output I generated.

The way I see it, libini tries to read proc addresses from libio twice. There is no error checking mechanism and on the second call of dll.link, proc addresses get screwed up ?

Re: Problem when loading several libraries, wich use librari

Posted: Thu Apr 19, 2012 10:57 pm
by Mario
This is very strange behavior. Most recently, I used LibINI for @PANEL (SVN r.2619 and following) and it is no have problem.
Maybe it makes sense to try a macro SVN_Kolibri\programs\develop\libraries\box_lib\load_lib.mac ?