[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] mintlib and shareable libraries
Le Fri, 13 Feb 2004 21:25:01 +0100
Arnaud BERCEGEAY <arnaud.bercegeay@free.fr> a écrit:
> A process (let's call it p1) call one of the library (slb/ldg) function.
> This function call malloc(), mintlib (within the ldg/slb) will perform a
> big Malloc(), and the area returned by malloc() will be a small part of
> the big Malloc.
> Who own this Malloc ? Is it the process that has called this library
> function (p1) ?
With real shared library support, the memory is owned by the process. You
must view the library as just a bunch of extra functions for your program.
When you have dynamic linking, the .text section of a library is shared
between all programs (and may be present at different adresses for each
program) hence the code must be fully PC-independent (-fPIC switch for
gcc). The .data and .bss sections of the library are attached to the
program that run it, and each program has private .data and .bss library
stuff (is it clear ?):
An example with 2 processes:
p1(text,data,bss) + lib(text1,data1,bss1)
p2(text,data,bss) + lib(text2,data2,bss2)
text1 and text2 once the library is loaded, lies in only one physical
memory space. However, p1 may see it at 0x00120000, and p2 may see it at
0x00140000. data1 and bss1 come from the library file, and are given to
p1. The functions from the library access data1 and bss1.
Same for data2 and bss2, given to p2.
> Later, another process (p2) call the same library fuction, which one
> call once more malloc(). The area returned by this malloc will be
> another part of the Malloc() allocated in the previous call.
> At this moment, the 2nd process (p2) is working on a memory area owned
> by the 1st process. Right ?
If it is the case, it is a wrong working.
> Later, if process 1 ended, mint will automatically free the memory
> allocated by this process, and so the big Malloc() of the library will
> be free-ed... and p2 will work on a memory that may be allocated by
> another process at any time.
Or just bus error if you have memory protection (or right virtual memory
support, where memory is only readable/writable when allocated).
> Am i right ?
Yes. If you want functional shared libraries, we need first virtual memory
support in the kernel.
--
Patrice Mandin
WWW: http://membres.lycos.fr/pmandin/
Programmeur Linux, Atari
Spécialité: Développement, jeux