[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] Re: How does linking work under Solaris?
From: |
Casper Dik |
Subject: |
[Help-smalltalk] Re: How does linking work under Solaris? |
Date: |
Wed, 06 Dec 2000 13:56:21 +0100 |
>Casper,
>
>Thanks for your response. I know that MAP_FIXED is dangerous; in fact the
>starting address is picked by autoconf and not encoded in the program.
>This approach fails only under Solaris -- Linux, HP/UX, and Windows
>support it. The address picked by autoconf on my user's system is around
>0xef7....
>
>What I still don't understand is: why isn't the memory where libc is
>loaded protected? If I mmap an already mapped address, or if I mmap
>below the brk address, the mmap fails. Why isn't the same with libc?
AFAIK, mmap has no restrictions on where you map:
The mapping established by mmap() replaces any previous map-
pings for those whole pages containing any part of the
address space of the process starting at pa and continuing
for len bytes.
I ran a program that checked this and I was able to overlay
mappings in brk, stack and libc.
If mmap() doesn't allow this in some implementation, then that's
arguably a bug:
When MAP_FIXED is set in the flags argument, the implementation is
informed that the value of pa must be addr, exactly. If MAP_FIXED
is set, mmap() may return MAP_FAILED and set errno to [EINVAL]. If
a MAP_FIXED request is successful, the mapping established by
mmap() replaces any previous mappings for the process' pages in the
range [pa, pa + len).
While MAP_FIXED requests may return EINVAL if the addr parameter isn't
suitable, there's a strong implication that replacing mappings doesn't
require you to call munmap() first.
(And such behaviour is clearly standard conformant).
If autoconf returns the e7xxx value, then that is a problem in
the auto configuration: such a value is very application and even
hardware/OS release dependent (and in some cases even patch revision
dependent). A small program that tests for mappings may not
have as many libraries loaded and will find a higher available address
than a more complicated application that links the world.
If a user increses his/her default stack limit from 8MB to a shigher value,
the mapping will shift yet again.
There is no way you can find a piece of the memory map that is safe to use;
if you must, use a lower address, close to the brk.
Casper