Re: Call a Function in Shared Memory?

From: Nils O. Selåsdal (NOS_at_Utel.no)
Date: 09/27/04


Date: 27 Sep 2004 22:07:19 +0200

On Sun, 26 Sep 2004 10:37:48 -0700, Paul Pluzhnikov wrote:

> Barry Margolin <barmar@alum.mit.edu> writes:
>
>> > No dynamic linker I know of places anything in (SysV or POSIX)
>> > shared memory.
>>
>> It mmaps the shared library file [...]
>
> Indeed, but it mmap()s it with MAP_PRIVATE, *not* MAP_SHARED,
> as can be seen in strace/truss output:
>
> open("/lib/libc.so.6", O_RDONLY) = 3
> read(3, "\177ELF [...]
> old_mmap(NULL, 1201988, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40034000
> old_mmap(0x4014f000, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x11a000) = 0x4014f000
> old_mmap(0x40156000, 14148, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40156000
> close(3) = 0
>
> It (almost) might as well malloc() that memory.
No. These are likely copy on write protected. And you don't write to code
sections. It could also be that the code could not be loaded at it's
compile time address, in which case the code must be modified though.