Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: gcc question



>>>>> "Fredric" == Fredric Fredricson <Fredric.Fredriksson@example.com> writes:

    Fredric> It is not malloc(3) but sbrk(2) that malloc(3) use to
    Fredric> request new pages from the kernel that matters.

No, because GNU malloc (some version of which is used in all Linux
systems AFAIK) breaks up the memory it gets from sbrk() into
reasonably-sized pieces.  In old GNU malloc, you only get all the raw
memory as returned by sbrk if you are allocating more memory than the
malloc BLOCKSIZE, which is 2048 bytes on 32 bit systems.  I don't know
what Doug Lea malloc does, though.

    Fredric> If you allocate, say, 80 bytes using malloc and start to
    Fredric> use the returned pointer to write to memory outside these
    Fredric> 80 bytes you will probably corrupt malloc(3)s data
    Fredric> structures before you try to access data outside the
    Fredric> allocated memory for the process and get a SIGSEGV.

This actually is not true under the old GNU malloc, since it keeps its
data structures in separately allocated memory.  Again, I don't know
about the strategy followed by new GNU (Doug Lea) malloc, I don't have
a copy of the source on my system at the moment.

Of course, since C structures often contain pointers, and in many
cases function pointers, you don't need to corrupt malloc internal
data structures to generate SIGBUS and SIGSEGV errors before
overrunning the allocated memory.


-- 
University of Tsukuba                Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Institute of Policy and Planning Sciences       Tel/fax: +81 (298) 53-5091
_________________  _________________  _________________  _________________
What are those straight lines for?  "XEmacs rules."
-------------------------------------------------------------------
Next Technical Meeting: January 14 (Fri) 19:00
* Topic: "glibc - current status and future developments"
* Guest Speaker: Ulrich Drepper (Cygnus Solutions)
* Place: Oracle Japan HQ 12F Seminar Room (New Otani Garden Court)
-------------------------------------------------------------------
more info: http://www.tlug.gr.jp        Sponsor: Global Online Japan


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links