diff options
author | nobody <> | 2004-10-18 08:06:33 +0000 |
---|---|---|
committer | nobody <> | 2004-10-18 08:06:33 +0000 |
commit | 4dcf8bca5382f997a23a3ed1ba352745600e2477 (patch) | |
tree | 121248599854507bb9b8bbb87e27f8d2cd27c8ef /mmalloc/mfree.c | |
parent | 2b10a680d703ca8950444b0d6a5394f11f6b05c8 (diff) | |
download | binutils-4dcf8bca5382f997a23a3ed1ba352745600e2477.zip binutils-4dcf8bca5382f997a23a3ed1ba352745600e2477.tar.gz binutils-4dcf8bca5382f997a23a3ed1ba352745600e2477.tar.bz2 |
This commit was manufactured by cvs2svn to create tag 'drow_intercu-drow_intercu-merge-20040915
merge-20040915'.
Sprout from gdb_6_3-branch 2004-10-18 08:06:32 UTC nobody 'This commit was manufactured by cvs2svn to create branch 'gdb_6_3-branch'.'
Cherrypick from master 2004-09-15 00:00:05 UTC Alan Modra <amodra@gmail.com> 'daily update':
ChangeLog
Makefile.in
Makefile.tpl
bfd/ChangeLog
bfd/Makefile.am
bfd/Makefile.in
bfd/aclocal.m4
bfd/aout-target.h
bfd/aout-tic30.c
bfd/bfd-in.h
bfd/bfd-in2.h
bfd/bfd.c
bfd/binary.c
bfd/coff-rs6000.c
bfd/coff64-rs6000.c
bfd/coffcode.h
bfd/config.bfd
bfd/configure
bfd/configure.in
bfd/cpu-i386.c
bfd/doc/ChangeLog
bfd/doc/Makefile.am
bfd/doc/Makefile.in
bfd/dwarf2.c
bfd/ecoff.c
bfd/elf-bfd.h
bfd/elf-eh-frame.c
bfd/elf-hppa.h
bfd/elf-m10300.c
bfd/elf.c
bfd/elf32-arm.h
bfd/elf32-cris.c
bfd/elf32-frv.c
bfd/elf32-hppa.c
bfd/elf32-i370.c
bfd/elf32-i386.c
bfd/elf32-m32r.c
bfd/elf32-m68k.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-sh-symbian.c
bfd/elf32-sh.c
bfd/elf32-sh64.c
bfd/elf32-sparc.c
bfd/elf32-vax.c
bfd/elf32-xstormy16.c
bfd/elf32-xtensa.c
bfd/elf64-alpha.c
bfd/elf64-hppa.c
bfd/elf64-mips.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-sh64.c
bfd/elf64-sparc.c
bfd/elf64-x86-64.c
bfd/elfarm-nabi.c
bfd/elflink.c
bfd/elfxx-ia64.c
bfd/elfxx-mips.c
bfd/elfxx-target.h
bfd/hash.c
bfd/i386msdos.c
bfd/ieee.c
bfd/ihex.c
bfd/libaout.h
bfd/libbfd-in.h
bfd/libbfd.h
bfd/libecoff.h
bfd/linker.c
bfd/mach-o.c
bfd/mmo.c
bfd/nlm-target.h
bfd/oasys.c
bfd/opncls.c
bfd/pe-i386.c
bfd/pef.c
bfd/pei-i386.c
bfd/po/SRC-POTFILES.in
bfd/po/bfd.pot
bfd/ppcboot.c
bfd/reloc.c
bfd/simple.c
bfd/som.c
bfd/srec.c
bfd/syms.c
bfd/targets.c
bfd/tekhex.c
bfd/versados.c
bfd/version.h
bfd/vms.c
bfd/xcoff-target.h
bfd/xcofflink.c
bfd/xsym.c
bfd/xtensa-isa.c
bfd/xtensa-modules.c
config.guess
config/ChangeLog
config/gettext.m4
configure
configure.in
gdb/ChangeLog
gdb/MAINTAINERS
gdb/Makefile.in
gdb/ada-exp.y
gdb/ada-lang.c
gdb/ada-lang.h
gdb/ada-lex.l
gdb/ada-typeprint.c
gdb/ada-valprint.c
gdb/aix-thread.c
gdb/alphanbsd-tdep.c
gdb/amd64-nat.h
gdb/amd64bsd-nat.c
gdb/amd64fbsd-nat.c
gdb/amd64nbsd-nat.c
gdb/amd64obsd-nat.c
gdb/breakpoint.c
gdb/bsd-kvm.c
gdb/config.in
gdb/config/alpha/alpha-linux.mh
gdb/config/arm/linux.mh
gdb/config/djgpp/fnchange.lst
gdb/config/frv/tm-frv.h
gdb/config/i386/fbsd.mh
gdb/config/i386/fbsd64.mh
gdb/config/i386/linux.mh
gdb/config/i386/linux64.mh
gdb/config/i386/nbsd64.mh
gdb/config/i386/nbsdaout.mh
gdb/config/i386/nbsdelf.mh
gdb/config/i386/nm-fbsd.h
gdb/config/i386/nm-fbsd64.h
gdb/config/i386/nm-i386.h
gdb/config/i386/nm-linux.h
gdb/config/i386/nm-nbsdaout.h
gdb/config/i386/nm-obsd.h
gdb/config/i386/obsd.mh
gdb/config/i386/obsd64.mh
gdb/config/i386/obsdaout.mh
gdb/config/ia64/linux.mh
gdb/config/ia64/nm-linux.h
gdb/config/m68k/linux.mh
gdb/config/m88k/obsd.mh
gdb/config/mips/linux.mh
gdb/config/nm-linux.h
gdb/config/nm-lynx.h
gdb/config/pa/hpux1020.mh
gdb/config/pa/hpux11.mh
gdb/config/pa/hpux11w.mh
gdb/config/pa/linux.mh
gdb/config/powerpc/linux.mh
gdb/config/powerpc/nbsd.mh
gdb/config/powerpc/ppc64-linux.mh
gdb/config/s390/s390.mh
gdb/config/sparc/fbsd.mh
gdb/config/sparc/linux.mh
gdb/config/sparc/linux64.mh
gdb/config/sparc/nbsd64.mh
gdb/config/sparc/nbsd64.mt
gdb/config/sparc/nbsdaout.mh
gdb/config/sparc/nbsdelf.mh
gdb/config/sparc/obsd.mt
gdb/config/sparc/obsd64.mt
gdb/config/vax/nbsdaout.mh
gdb/config/vax/nbsdelf.mh
gdb/config/vax/obsd.mh
gdb/configure
gdb/configure.in
gdb/configure.tgt
gdb/corelow.c
gdb/cris-tdep.c
gdb/defs.h
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/doc/gdbint.texinfo
gdb/doc/stabs.texinfo
gdb/dwarf2read.c
gdb/event-top.c
gdb/exec.c
gdb/fbsd-proc.c
gdb/fork-child.c
gdb/frv-tdep.c
gdb/gdb_indent.sh
gdb/gdb_thread_db.h
gdb/gdbcmd.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/configure
gdb/gdbserver/configure.in
gdb/gdbserver/linux-i386-low.c
gdb/gdbserver/linux-low.c
gdb/gdbserver/linux-x86-64-low.c
gdb/gdbserver/proc-service.c
gdb/gdbserver/remote-utils.c
gdb/gdbserver/thread-db.c
gdb/gdbtypes.h
gdb/gnu-nat.c
gdb/go32-nat.c
gdb/hppa-tdep.c
gdb/hppah-nat.c
gdb/hpux-thread.c
gdb/i386-nat.c
gdb/i386-tdep.c
gdb/i386bsd-nat.c
gdb/i386fbsd-nat.c
gdb/i386gnu-nat.c
gdb/i386nbsd-nat.c
gdb/ia64-linux-nat.c
gdb/inf-child.c
gdb/inf-ptrace.c
gdb/infcall.c
gdb/infptrace.c
gdb/infrun.c
gdb/inftarg.c
gdb/infttrace.c
gdb/jv-exp.y
gdb/language.c
gdb/lin-lwp.c
gdb/linux-nat.c
gdb/linux-proc.c
gdb/m32r-tdep.c
gdb/m88kbsd-nat.c
gdb/maint.c
gdb/minsyms.c
gdb/mips-tdep.c
gdb/monitor.c
gdb/nto-procfs.c
gdb/objfiles.c
gdb/ppc-bdm.c
gdb/procfs.c
gdb/regcache.c
gdb/remote-e7000.c
gdb/remote-m32r-sdi.c
gdb/remote-mips.c
gdb/remote-rdi.c
gdb/remote-rdp.c
gdb/remote-sds.c
gdb/remote-sim.c
gdb/remote-st.c
gdb/remote-vx.c
gdb/remote.c
gdb/rs6000-nat.c
gdb/rs6000-tdep.c
gdb/sh-tdep.c
gdb/sh-tdep.h
gdb/sol-thread.c
gdb/solib-sunos.c
gdb/source.c
gdb/sparc-linux-tdep.c
gdb/sparc-nat.c
gdb/sparc-nat.h
gdb/sparc64-linux-tdep.c
gdb/sparc64nbsd-nat.c
gdb/sparc64nbsd-tdep.c
gdb/sparc64obsd-tdep.c
gdb/sparcnbsd-nat.c
gdb/symfile.c
gdb/symtab.c
gdb/target.c
gdb/target.h
gdb/testsuite/ChangeLog
gdb/testsuite/Makefile.in
gdb/testsuite/config/gdbserver.exp
gdb/testsuite/configure
gdb/testsuite/configure.in
gdb/testsuite/gdb.asm/asm-source.exp
gdb/testsuite/gdb.base/bigcore.c
gdb/testsuite/gdb.base/bigcore.exp
gdb/testsuite/gdb.base/constvars.exp
gdb/testsuite/gdb.base/overlays.exp
gdb/testsuite/gdb.base/sigstep.exp
gdb/testsuite/gdb.base/volatile.exp
gdb/testsuite/gdb.mi/gdb701.c
gdb/testsuite/gdb.threads/bp_in_thread.exp
gdb/testsuite/gdb.threads/pthread_cond_wait.exp
gdb/testsuite/gdb.threads/watchthreads.exp
gdb/thread-db.c
gdb/top.c
gdb/tui/tui-wingeneral.c
gdb/utils.c
gdb/uw-thread.c
gdb/v850ice.c
gdb/valarith.c
gdb/vaxbsd-nat.c
gdb/version.in
gdb/win32-nat.c
gdb/wince.c
gdb/xstormy16-tdep.c
include/ChangeLog
include/bfdlink.h
include/elf/ChangeLog
include/elf/arm.h
include/elf/common.h
include/elf/dwarf2.h
include/elf/x86-64.h
include/elf/xtensa.h
include/opcode/ChangeLog
include/opcode/arm.h
include/opcode/crx.h
include/xtensa-config.h
include/xtensa-isa-internal.h
include/xtensa-isa.h
install-sh
intl/ChangeLog
intl/Makefile.in
intl/acconfig.h
intl/aclocal.m4
intl/bindtextdom.c
intl/cat-compat.c
intl/config.in
intl/configure
intl/configure.in
intl/dcgettext.c
intl/dgettext.c
intl/explodename.c
intl/finddomain.c
intl/gettext.c
intl/gettext.h
intl/gettextP.h
intl/hash-string.h
intl/intl-compat.c
intl/intlh.inst.in
intl/l10nflist.c
intl/libgettext.h
intl/libintl.glibc
intl/linux-msg.sed
intl/loadinfo.h
intl/loadmsgcat.c
intl/localealias.c
intl/po2tbl.sed.in
intl/textdomain.c
intl/xopen-msg.sed
ltcf-c.sh
ltcf-cxx.sh
ltconfig
mmalloc/COPYING.LIB
mmalloc/ChangeLog
mmalloc/MAINTAINERS
mmalloc/Makefile.in
mmalloc/TODO
mmalloc/acinclude.m4
mmalloc/aclocal.m4
mmalloc/attach.c
mmalloc/configure
mmalloc/configure.in
mmalloc/detach.c
mmalloc/keys.c
mmalloc/mcalloc.c
mmalloc/mfree.c
mmalloc/mm.c
mmalloc/mmalloc.c
mmalloc/mmalloc.h
mmalloc/mmalloc.texi
mmalloc/mmap-sup.c
mmalloc/mmcheck.c
mmalloc/mmemalign.c
mmalloc/mmprivate.h
mmalloc/mmstats.c
mmalloc/mmtrace.awk
mmalloc/mmtrace.c
mmalloc/mrealloc.c
mmalloc/mvalloc.c
mmalloc/sbrk-sup.c
opcodes/ChangeLog
opcodes/Makefile.am
opcodes/Makefile.in
opcodes/aclocal.m4
opcodes/arm-dis.c
opcodes/arm-opc.h
opcodes/configure
opcodes/crx-dis.c
opcodes/crx-opc.c
opcodes/pdp11-dis.c
opcodes/po/POTFILES.in
opcodes/po/opcodes.pot
opcodes/ppc-opc.c
opcodes/xtensa-dis.c
sim/common/ChangeLog
sim/common/cgen-defs.h
sim/mips/ChangeLog
sim/mips/m16.igen
sim/ppc/ChangeLog
sim/ppc/config.in
sim/ppc/configure
sim/ppc/configure.in
sim/ppc/emul_netbsd.c
Cherrypick from cygnus 1999-05-03 07:29:11 UTC Richard Henderson <rth@redhat.com> '19990502 sourceware import':
ylwrap
Delete:
config/codeset.m4
config/gcc-lib-path.m4
config/gettext-sister.m4
config/glibc21.m4
config/iconv.m4
config/intdiv0.m4
config/inttypes-pri.m4
config/inttypes.m4
config/inttypes_h.m4
config/lcmessage.m4
config/lib-ld.m4
config/lib-link.m4
config/lib-prefix.m4
config/mh-x86omitfp
config/nls.m4
config/po.m4
config/stdint_h.m4
config/uintmax_t.m4
config/ulonglong.m4
config/warnings.m4
gdb/config/m32r/linux.mh
gdb/config/m32r/linux.mt
gdb/config/m32r/nm-linux.h
gdb/fbsd-nat.c
gdb/fbsd-nat.h
gdb/i386bsd-nat.h
gdb/m32r-linux-nat.c
gdb/m32r-linux-tdep.c
gdb/m32r-tdep.h
gdb/testsuite/gdb.asm/m32r-linux.inc
gdb/testsuite/gdb.dwarf2/Makefile.in
gdb/testsuite/gdb.dwarf2/dw2-basic.S
gdb/testsuite/gdb.dwarf2/dw2-basic.exp
gdb/testsuite/gdb.dwarf2/dw2-intercu.S
gdb/testsuite/gdb.dwarf2/dw2-intercu.exp
gdb/testsuite/gdb.dwarf2/file1.txt
gdb/testsuite/gdb.dwarf2/main.c
gdb/testsuite/gdb.java/jprint.exp
gdb/testsuite/gdb.java/jprint.java
gdb/testsuite/gdb.threads/watchthreads.c
Diffstat (limited to 'mmalloc/mfree.c')
-rw-r--r-- | mmalloc/mfree.c | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/mmalloc/mfree.c b/mmalloc/mfree.c new file mode 100644 index 0000000..c509ac6 --- /dev/null +++ b/mmalloc/mfree.c @@ -0,0 +1,247 @@ +/* Free a block of memory allocated by `mmalloc'. + Copyright 1990, 1991, 1992 Free Software Foundation + + Written May 1989 by Mike Haertel. + Heavily modified Mar 1992 by Fred Fish. (fnf@cygnus.com) + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + + The author may be reached (Email) at the address mike@ai.mit.edu, + or (US mail) as Mike Haertel c/o Free Software Foundation. */ + +#include "mmprivate.h" + +/* Return memory to the heap. + Like `mfree' but don't call a mfree_hook if there is one. */ + +void +__mmalloc_free (mdp, ptr) + struct mdesc *mdp; + PTR ptr; +{ + int type; + size_t block, blocks; + register size_t i; + struct list *prev, *next; + + block = BLOCK (ptr); + + type = mdp -> heapinfo[block].busy.type; + switch (type) + { + case 0: + /* Get as many statistics as early as we can. */ + mdp -> heapstats.chunks_used--; + mdp -> heapstats.bytes_used -= + mdp -> heapinfo[block].busy.info.size * BLOCKSIZE; + mdp -> heapstats.bytes_free += + mdp -> heapinfo[block].busy.info.size * BLOCKSIZE; + + /* Find the free cluster previous to this one in the free list. + Start searching at the last block referenced; this may benefit + programs with locality of allocation. */ + i = mdp -> heapindex; + if (i > block) + { + while (i > block) + { + i = mdp -> heapinfo[i].free.prev; + } + } + else + { + do + { + i = mdp -> heapinfo[i].free.next; + } + while ((i != 0) && (i < block)); + i = mdp -> heapinfo[i].free.prev; + } + + /* Determine how to link this block into the free list. */ + if (block == i + mdp -> heapinfo[i].free.size) + { + /* Coalesce this block with its predecessor. */ + mdp -> heapinfo[i].free.size += + mdp -> heapinfo[block].busy.info.size; + block = i; + } + else + { + /* Really link this block back into the free list. */ + mdp -> heapinfo[block].free.size = + mdp -> heapinfo[block].busy.info.size; + mdp -> heapinfo[block].free.next = mdp -> heapinfo[i].free.next; + mdp -> heapinfo[block].free.prev = i; + mdp -> heapinfo[i].free.next = block; + mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev = block; + mdp -> heapstats.chunks_free++; + } + + /* Now that the block is linked in, see if we can coalesce it + with its successor (by deleting its successor from the list + and adding in its size). */ + if (block + mdp -> heapinfo[block].free.size == + mdp -> heapinfo[block].free.next) + { + mdp -> heapinfo[block].free.size + += mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.size; + mdp -> heapinfo[block].free.next + = mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.next; + mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev = block; + mdp -> heapstats.chunks_free--; + } + + /* Now see if we can return stuff to the system. */ + blocks = mdp -> heapinfo[block].free.size; + if (blocks >= FINAL_FREE_BLOCKS && block + blocks == mdp -> heaplimit + && mdp -> morecore (mdp, 0) == ADDRESS (block + blocks)) + { + register size_t bytes = blocks * BLOCKSIZE; + mdp -> heaplimit -= blocks; + mdp -> morecore (mdp, -bytes); + mdp -> heapinfo[mdp -> heapinfo[block].free.prev].free.next + = mdp -> heapinfo[block].free.next; + mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev + = mdp -> heapinfo[block].free.prev; + block = mdp -> heapinfo[block].free.prev; + mdp -> heapstats.chunks_free--; + mdp -> heapstats.bytes_free -= bytes; + } + + /* Set the next search to begin at this block. */ + mdp -> heapindex = block; + break; + + default: + /* Do some of the statistics. */ + mdp -> heapstats.chunks_used--; + mdp -> heapstats.bytes_used -= 1 << type; + mdp -> heapstats.chunks_free++; + mdp -> heapstats.bytes_free += 1 << type; + + /* Get the address of the first free fragment in this block. */ + prev = (struct list *) + ((char *) ADDRESS(block) + + (mdp -> heapinfo[block].busy.info.frag.first << type)); + + if (mdp -> heapinfo[block].busy.info.frag.nfree == + (BLOCKSIZE >> type) - 1) + { + /* If all fragments of this block are free, remove them + from the fragment list and free the whole block. */ + next = prev; + for (i = 1; i < (size_t) (BLOCKSIZE >> type); ++i) + { + next = next -> next; + } + prev -> prev -> next = next; + if (next != NULL) + { + next -> prev = prev -> prev; + } + mdp -> heapinfo[block].busy.type = 0; + mdp -> heapinfo[block].busy.info.size = 1; + + /* Keep the statistics accurate. */ + mdp -> heapstats.chunks_used++; + mdp -> heapstats.bytes_used += BLOCKSIZE; + mdp -> heapstats.chunks_free -= BLOCKSIZE >> type; + mdp -> heapstats.bytes_free -= BLOCKSIZE; + + mfree ((PTR) mdp, (PTR) ADDRESS(block)); + } + else if (mdp -> heapinfo[block].busy.info.frag.nfree != 0) + { + /* If some fragments of this block are free, link this + fragment into the fragment list after the first free + fragment of this block. */ + next = (struct list *) ptr; + next -> next = prev -> next; + next -> prev = prev; + prev -> next = next; + if (next -> next != NULL) + { + next -> next -> prev = next; + } + ++mdp -> heapinfo[block].busy.info.frag.nfree; + } + else + { + /* No fragments of this block are free, so link this + fragment into the fragment list and announce that + it is the first free fragment of this block. */ + prev = (struct list *) ptr; + mdp -> heapinfo[block].busy.info.frag.nfree = 1; + mdp -> heapinfo[block].busy.info.frag.first = + RESIDUAL (ptr, BLOCKSIZE) >> type; + prev -> next = mdp -> fraghead[type].next; + prev -> prev = &mdp -> fraghead[type]; + prev -> prev -> next = prev; + if (prev -> next != NULL) + { + prev -> next -> prev = prev; + } + } + break; + } +} + +/* Return memory to the heap. */ + +void +mfree (md, ptr) + PTR md; + PTR ptr; +{ + struct mdesc *mdp; + register struct alignlist *l; + + if (ptr != NULL) + { + mdp = MD_TO_MDP (md); + for (l = mdp -> aligned_blocks; l != NULL; l = l -> next) + { + if (l -> aligned == ptr) + { + l -> aligned = NULL; /* Mark the slot in the list as free. */ + ptr = l -> exact; + break; + } + } + if (mdp -> mfree_hook != NULL) + { + (*mdp -> mfree_hook) (md, ptr); + } + else + { + __mmalloc_free (mdp, ptr); + } + } +} + +/* When using this package, provide a version of malloc/realloc/free built + on top of it, so that if we use the default sbrk() region we will not + collide with another malloc package trying to do the same thing, if + the application contains any "hidden" calls to malloc/realloc/free (such + as inside a system library). */ + +void +free (ptr) + PTR ptr; +{ + mfree ((PTR) NULL, ptr); +} |