import the latest standalone libmalloc.

This commit is contained in:
christos 2016-01-13 21:42:18 +00:00
parent d1c4f2bedd
commit 478e07dd80
25 changed files with 5318 additions and 0 deletions

481
external/gpl2/libmalloc/dist/COPYING.LIB vendored Normal file
View File

@ -0,0 +1,481 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This 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.
This 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 this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@ -0,0 +1,2 @@
Find older changes in OChangeLog.

57
external/gpl2/libmalloc/dist/Makefile vendored Normal file
View File

@ -0,0 +1,57 @@
# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# 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., 675 Mass Ave,
# Cambridge, MA 02139, USA.
# Makefile for standalone distribution of malloc.
# Use this on System V.
#CPPFLAGS = -DUSG
.PHONY: all
all: libmalloc.a gmalloc.o
gmalloc = valloc.c malloc.c free.c cfree.c realloc.c calloc.c morecore.c memalign.c
sources = valloc.c malloc.c free.c cfree.c realloc.c calloc.c morecore.c memalign.c mcheck.c mtrace.c mstats.c vm-limit.c ralloc.c malloc-find.c
objects = valloc.o malloc.o free.o cfree.o realloc.o calloc.o morecore.o memalign.o mcheck.o mtrace.o mstats.o vm-limit.o ralloc.o malloc-find.o
headers = malloc.h
libmalloc.a: $(objects)
ar crv $@ $(objects)
ranlib $@
$(objects): $(headers)
gmalloc.c: gmalloc-head.c $(headers) $(gmalloc) Makefile
cat gmalloc-head.c $(headers) $(gmalloc) > $@-tmp
mv -f $@-tmp $@
# Make it unwritable to avoid accidentally changing the file,
# since it is generated and any changes would be lost.
chmod a-w $@
.c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -I. -c $< $(OUTPUT_OPTION)
.PHONY: clean realclean malloc-clean malloc-realclean
clean malloc-clean:
-rm -f libmalloc.a *.o core
realclean malloc-realclean: clean
-rm -f TAGS tags *~
# For inside the C library.
malloc.tar malloc.tar.Z: FORCE
$(MAKE) -C .. $@
FORCE:

34
external/gpl2/libmalloc/dist/OChangeLog vendored Normal file
View File

@ -0,0 +1,34 @@
**** All newer entries are in the C library ChangeLog file. ****
Thu Jul 11 18:15:04 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu)
* Merged with C library version, which now has its own subdir.
* malloc.h, *.c: Use ansideclisms and #ifdefs for portability both
in and out of the C library.
* Makefile: New makefile for malloc subdir in libc.
Has targets to create malloc.tar{,.Z} by ansidecl processing on srcs.
* malloc/Makefile: New file; Makefile for standalone distribution.
* malloc/README: New file; info for same.
Fri Apr 6 00:18:36 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
* Makefile: Add comments.
Thu Apr 5 23:08:14 1990 Mike Haertel (mike at albert.ai.mit.edu)
* mcheck.c (mcheck, checkhdr): Support user-supplied abort()
function.
* malloc.h: Declare __free().
* Makefile: New target libmalloc.a.
Thu Apr 5 21:56:03 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
* free.c (free): Split into free and __free.
* malloc.c (morecore): Call __free on oldinfo.
Local Variables:
mode: indented-text
left-margin: 8
fill-column: 76
version-control: never
End:

12
external/gpl2/libmalloc/dist/README vendored Normal file
View File

@ -0,0 +1,12 @@
This is the standalone distribution of GNU malloc.
GNU malloc is part of the GNU C Library, but is also distributed separately.
If you find bugs in GNU malloc, send reports to bug-glibc@prep.ai.mit.edu.
GNU malloc is free software. See the file COPYING.LIB for copying conditions.
The makefile builds libmalloc.a and gmalloc.o. If you are using GNU malloc
to replace your system's existing malloc package, it is important to make
sure you get all GNU functions, not some of the GNU functions and some from
the system library. gmalloc.o has all the functions in one file, so using
that will make sure you don't accidentally mix the two malloc packages.

41
external/gpl2/libmalloc/dist/calloc.c vendored Normal file
View File

@ -0,0 +1,41 @@
/* $NetBSD: calloc.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
/* Allocate an array of NMEMB elements each SIZE bytes long.
The entire array is initialized to zeros. */
__ptr_t
calloc (nmemb, size)
register __malloc_size_t nmemb;
register __malloc_size_t size;
{
register __ptr_t result = malloc (nmemb * size);
if (result != NULL)
(void) memset (result, 0, nmemb * size);
return result;
}

45
external/gpl2/libmalloc/dist/cfree.c vendored Normal file
View File

@ -0,0 +1,45 @@
/* $NetBSD: cfree.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
#ifdef _LIBC
#include <ansidecl.h>
#include <gnu-stabs.h>
#undef cfree
function_alias(cfree, free, void, (ptr),
DEFUN(cfree, (ptr), PTR ptr))
#else
void
cfree (ptr)
__ptr_t ptr;
{
free (ptr);
}
#endif

212
external/gpl2/libmalloc/dist/free.c vendored Normal file
View File

@ -0,0 +1,212 @@
/* $NetBSD: free.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Free a block of memory allocated by `malloc'.
Copyright 1990, 1991, 1992, 1994 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
/* Debugging hook for free. */
void (*__free_hook) __P ((__ptr_t __ptr));
/* List of blocks allocated by memalign. */
struct alignlist *_aligned_blocks = NULL;
/* Return memory to the heap.
Like `free' but don't call a __free_hook if there is one. */
void
_free_internal (ptr)
__ptr_t ptr;
{
int type;
__malloc_size_t block, blocks;
register __malloc_size_t i;
struct list *prev, *next;
block = BLOCK (ptr);
type = _heapinfo[block].busy.type;
switch (type)
{
case 0:
/* Get as many statistics as early as we can. */
--_chunks_used;
_bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE;
_bytes_free += _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 = _heapindex;
if (i > block)
while (i > block)
i = _heapinfo[i].free.prev;
else
{
do
i = _heapinfo[i].free.next;
while (i > 0 && i < block);
i = _heapinfo[i].free.prev;
}
/* Determine how to link this block into the free list. */
if (block == i + _heapinfo[i].free.size)
{
/* Coalesce this block with its predecessor. */
_heapinfo[i].free.size += _heapinfo[block].busy.info.size;
block = i;
}
else
{
/* Really link this block back into the free list. */
_heapinfo[block].free.size = _heapinfo[block].busy.info.size;
_heapinfo[block].free.next = _heapinfo[i].free.next;
_heapinfo[block].free.prev = i;
_heapinfo[i].free.next = block;
_heapinfo[_heapinfo[block].free.next].free.prev = block;
++_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 + _heapinfo[block].free.size == _heapinfo[block].free.next)
{
_heapinfo[block].free.size
+= _heapinfo[_heapinfo[block].free.next].free.size;
_heapinfo[block].free.next
= _heapinfo[_heapinfo[block].free.next].free.next;
_heapinfo[_heapinfo[block].free.next].free.prev = block;
--_chunks_free;
}
/* Now see if we can return stuff to the system. */
blocks = _heapinfo[block].free.size;
if (blocks >= FINAL_FREE_BLOCKS && block + blocks == _heaplimit
&& (*__morecore) (0) == ADDRESS (block + blocks))
{
register __malloc_size_t bytes = blocks * BLOCKSIZE;
_heaplimit -= blocks;
(*__morecore) (-bytes);
_heapinfo[_heapinfo[block].free.prev].free.next
= _heapinfo[block].free.next;
_heapinfo[_heapinfo[block].free.next].free.prev
= _heapinfo[block].free.prev;
block = _heapinfo[block].free.prev;
--_chunks_free;
_bytes_free -= bytes;
}
/* Set the next search to begin at this block. */
_heapindex = block;
break;
default:
/* Do some of the statistics. */
--_chunks_used;
_bytes_used -= 1 << type;
++_chunks_free;
_bytes_free += 1 << type;
/* Get the address of the first free fragment in this block. */
prev = (struct list *) ((char *) ADDRESS (block) +
(_heapinfo[block].busy.info.frag.first << type));
if (_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 < (__malloc_size_t) (BLOCKSIZE >> type); ++i)
next = next->next;
prev->prev->next = next;
if (next != NULL)
next->prev = prev->prev;
_heapinfo[block].busy.type = 0;
_heapinfo[block].busy.info.size = 1;
/* Keep the statistics accurate. */
++_chunks_used;
_bytes_used += BLOCKSIZE;
_chunks_free -= BLOCKSIZE >> type;
_bytes_free -= BLOCKSIZE;
free (ADDRESS (block));
}
else if (_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;
++_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;
_heapinfo[block].busy.info.frag.nfree = 1;
_heapinfo[block].busy.info.frag.first = (unsigned long int)
((unsigned long int) ((char *) ptr - (char *) NULL)
% BLOCKSIZE >> type);
prev->next = _fraghead[type].next;
prev->prev = &_fraghead[type];
prev->prev->next = prev;
if (prev->next != NULL)
prev->next->prev = prev;
}
break;
}
}
/* Return memory to the heap. */
void
free (ptr)
__ptr_t ptr;
{
register struct alignlist *l;
if (ptr == NULL)
return;
for (l = _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 (__free_hook != NULL)
(*__free_hook) (ptr);
else
_free_internal (ptr);
}

View File

@ -0,0 +1,41 @@
/* $NetBSD: getpagesize.h,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Emulate getpagesize on systems that lack it. */
#ifndef HAVE_GETPAGESIZE
#ifdef VMS
#define getpagesize() 512
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef _SC_PAGESIZE
#define getpagesize() sysconf(_SC_PAGESIZE)
#else
#include <sys/param.h>
#ifdef EXEC_PAGESIZE
#define getpagesize() EXEC_PAGESIZE
#else
#ifdef NBPG
#define getpagesize() NBPG * CLSIZE
#ifndef CLSIZE
#define CLSIZE 1
#endif /* no CLSIZE */
#else /* no NBPG */
#ifdef NBPC
#define getpagesize() NBPC
#else /* no NBPC */
#ifdef PAGESIZE
#define getpagesize() PAGESIZE
#endif
#endif /* NBPC */
#endif /* no NBPG */
#endif /* no EXEC_PAGESIZE */
#endif /* no _SC_PAGESIZE */
#endif /* not HAVE_GETPAGESIZE */

View File

@ -0,0 +1,8 @@
/* $NetBSD: gmalloc-head.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */
#define _MALLOC_INTERNAL
/* The malloc headers and source files from the C library follow here. */

1352
external/gpl2/libmalloc/dist/gmalloc.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,61 @@
/* $NetBSD: malloc-find.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Find the starting address of a malloc'd block, from anywhere inside it.
Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
/* Given an address in the middle of a malloc'd object,
return the address of the beginning of the object. */
__ptr_t
malloc_find_object_address (ptr)
__ptr_t ptr;
{
__malloc_size_t block = BLOCK (ptr);
int type = _heapinfo[block].busy.type;
if (type == 0)
{
/* The object is one or more entire blocks. */
__malloc_ptrdiff_t sizevalue = _heapinfo[block].busy.info.size;
if (sizevalue < 0)
/* This is one of the blocks after the first. SIZEVALUE
says how many blocks to go back to find the first. */
block += sizevalue;
/* BLOCK is now the first block of the object.
Its start is the start of the object. */
return ADDRESS (block);
}
else
{
/* Get the size of fragments in this block. */
__malloc_size_t size = 1 << type;
/* Turn off the low bits to find the start address of the fragment. */
return _heapbase + (((char *) ptr - _heapbase) & ~(size - 1));
}
}

377
external/gpl2/libmalloc/dist/malloc.c vendored Normal file
View File

@ -0,0 +1,377 @@
/* $NetBSD: malloc.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Memory allocator `malloc'.
Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
/* How to really get more memory. */
__ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore;
/* Debugging hook for `malloc'. */
__ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
/* Pointer to the base of the first block. */
char *_heapbase;
/* Block information table. Allocated with align/__free (not malloc/free). */
malloc_info *_heapinfo;
/* Number of info entries. */
static __malloc_size_t heapsize;
/* Search index in the info table. */
__malloc_size_t _heapindex;
/* Limit of valid info table indices. */
__malloc_size_t _heaplimit;
/* Free lists for each fragment size. */
struct list _fraghead[BLOCKLOG];
/* Instrumentation. */
__malloc_size_t _chunks_used;
__malloc_size_t _bytes_used;
__malloc_size_t _chunks_free;
__malloc_size_t _bytes_free;
/* Are you experienced? */
int __malloc_initialized;
void (*__malloc_initialize_hook) __P ((void));
void (*__after_morecore_hook) __P ((void));
/* Aligned allocation. */
static __ptr_t align __P ((__malloc_size_t));
static __ptr_t
align (size)
__malloc_size_t size;
{
__ptr_t result;
unsigned long int adj;
result = (*__morecore) (size);
adj = (unsigned long int) ((unsigned long int) ((char *) result -
(char *) NULL)) % BLOCKSIZE;
if (adj != 0)
{
adj = BLOCKSIZE - adj;
(void) (*__morecore) (adj);
result = (char *) result + adj;
}
if (__after_morecore_hook)
(*__after_morecore_hook) ();
return result;
}
/* Set everything up and remember that we have. */
static int initialize __P ((void));
static int
initialize ()
{
if (__malloc_initialize_hook)
(*__malloc_initialize_hook) ();
heapsize = HEAP / BLOCKSIZE;
_heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
if (_heapinfo == NULL)
return 0;
memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
_heapinfo[0].free.size = 0;
_heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
_heapindex = 0;
_heapbase = (char *) _heapinfo;
/* Account for the _heapinfo block itself in the statistics. */
_bytes_used = heapsize * sizeof (malloc_info);
_chunks_used = 1;
__malloc_initialized = 1;
return 1;
}
/* Get neatly aligned memory, initializing or
growing the heap info table as necessary. */
static __ptr_t morecore __P ((__malloc_size_t));
static __ptr_t
morecore (size)
__malloc_size_t size;
{
__ptr_t result;
malloc_info *newinfo, *oldinfo;
__malloc_size_t newsize;
result = align (size);
if (result == NULL)
return NULL;
/* Check if we need to grow the info table. */
if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize)
{
newsize = heapsize;
while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize)
newsize *= 2;
newinfo = (malloc_info *) align (newsize * sizeof (malloc_info));
if (newinfo == NULL)
{
(*__morecore) (-size);
return NULL;
}
memcpy (newinfo, _heapinfo, heapsize * sizeof (malloc_info));
memset (&newinfo[heapsize], 0,
(newsize - heapsize) * sizeof (malloc_info));
oldinfo = _heapinfo;
newinfo[BLOCK (oldinfo)].busy.type = 0;
newinfo[BLOCK (oldinfo)].busy.info.size
= BLOCKIFY (heapsize * sizeof (malloc_info));
_heapinfo = newinfo;
/* Account for the _heapinfo block itself in the statistics. */
_bytes_used += newsize * sizeof (malloc_info);
++_chunks_used;
_free_internal (oldinfo);
heapsize = newsize;
}
_heaplimit = BLOCK ((char *) result + size);
return result;
}
/* Allocate memory from the heap. */
__ptr_t
malloc (size)
__malloc_size_t size;
{
__ptr_t result;
__malloc_size_t block, blocks, lastblocks, start;
register __malloc_size_t i;
struct list *next;
/* ANSI C allows `malloc (0)' to either return NULL, or to return a
valid address you can realloc and free (though not dereference).
It turns out that some extant code (sunrpc, at least Ultrix's version)
expects `malloc (0)' to return non-NULL and breaks otherwise.
Be compatible. */
#if 0
if (size == 0)
return NULL;
#endif
if (__malloc_hook != NULL)
return (*__malloc_hook) (size);
if (!__malloc_initialized)
if (!initialize ())
return NULL;
if (size < sizeof (struct list))
size = sizeof (struct list);
#ifdef SUNOS_LOCALTIME_BUG
if (size < 16)
size = 16;
#endif
/* Determine the allocation policy based on the request size. */
if (size <= BLOCKSIZE / 2)
{
/* Small allocation to receive a fragment of a block.
Determine the logarithm to base two of the fragment size. */
register __malloc_size_t log = 1;
--size;
while ((size /= 2) != 0)
++log;
/* Look in the fragment lists for a
free fragment of the desired size. */
next = _fraghead[log].next;
if (next != NULL)
{
/* There are free fragments of this size.
Pop a fragment out of the fragment list and return it.
Update the block's nfree and first counters. */
result = (__ptr_t) next;
next->prev->next = next->next;
if (next->next != NULL)
next->next->prev = next->prev;
block = BLOCK (result);
if (--_heapinfo[block].busy.info.frag.nfree != 0)
_heapinfo[block].busy.info.frag.first = (unsigned long int)
((unsigned long int) ((char *) next->next - (char *) NULL)
% BLOCKSIZE) >> log;
/* Update the statistics. */
++_chunks_used;
_bytes_used += 1 << log;
--_chunks_free;
_bytes_free -= 1 << log;
}
else
{
/* No free fragments of the desired size, so get a new block
and break it into fragments, returning the first. */
result = malloc (BLOCKSIZE);
if (result == NULL)
return NULL;
/* Link all fragments but the first into the free list. */
for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> log); ++i)
{
next = (struct list *) ((char *) result + (i << log));
next->next = _fraghead[log].next;
next->prev = &_fraghead[log];
next->prev->next = next;
if (next->next != NULL)
next->next->prev = next;
}
/* Initialize the nfree and first counters for this block. */
block = BLOCK (result);
_heapinfo[block].busy.type = log;
_heapinfo[block].busy.info.frag.nfree = i - 1;
_heapinfo[block].busy.info.frag.first = i - 1;
_chunks_free += (BLOCKSIZE >> log) - 1;
_bytes_free += BLOCKSIZE - (1 << log);
_bytes_used -= BLOCKSIZE - (1 << log);
}
}
else
{
/* Large allocation to receive one or more blocks.
Search the free list in a circle starting at the last place visited.
If we loop completely around without finding a large enough
space we will have to get more memory from the system. */
blocks = BLOCKIFY (size);
start = block = _heapindex;
while (_heapinfo[block].free.size < blocks)
{
block = _heapinfo[block].free.next;
if (block == start)
{
/* Need to get more from the system. Check to see if
the new core will be contiguous with the final free
block; if so we don't need to get as much. */
block = _heapinfo[0].free.prev;
lastblocks = _heapinfo[block].free.size;
if (_heaplimit != 0 && block + lastblocks == _heaplimit &&
(*__morecore) (0) == ADDRESS (block + lastblocks) &&
(morecore ((blocks - lastblocks) * BLOCKSIZE)) != NULL)
{
/* Which block we are extending (the `final free
block' referred to above) might have changed, if
it got combined with a freed info table. */
block = _heapinfo[0].free.prev;
_heapinfo[block].free.size += (blocks - lastblocks);
_bytes_free += (blocks - lastblocks) * BLOCKSIZE;
continue;
}
result = morecore (blocks * BLOCKSIZE);
if (result == NULL)
return NULL;
block = BLOCK (result);
_heapinfo[block].busy.type = 0;
_heapinfo[block].busy.info.size = blocks;
++_chunks_used;
_bytes_used += blocks * BLOCKSIZE;
return result;
}
}
/* At this point we have found a suitable free list entry.
Figure out how to remove what we need from the list. */
result = ADDRESS (block);
if (_heapinfo[block].free.size > blocks)
{
/* The block we found has a bit left over,
so relink the tail end back into the free list. */
_heapinfo[block + blocks].free.size
= _heapinfo[block].free.size - blocks;
_heapinfo[block + blocks].free.next
= _heapinfo[block].free.next;
_heapinfo[block + blocks].free.prev
= _heapinfo[block].free.prev;
_heapinfo[_heapinfo[block].free.prev].free.next
= _heapinfo[_heapinfo[block].free.next].free.prev
= _heapindex = block + blocks;
}
else
{
/* The block exactly matches our requirements,
so just remove it from the list. */
_heapinfo[_heapinfo[block].free.next].free.prev
= _heapinfo[block].free.prev;
_heapinfo[_heapinfo[block].free.prev].free.next
= _heapindex = _heapinfo[block].free.next;
--_chunks_free;
}
_heapinfo[block].busy.type = 0;
_heapinfo[block].busy.info.size = blocks;
++_chunks_used;
_bytes_used += blocks * BLOCKSIZE;
_bytes_free -= blocks * BLOCKSIZE;
/* Mark all the blocks of the object just allocated except for the
first with a negative number so you can find the first block by
adding that adjustment. */
while (--blocks > 0)
_heapinfo[block + blocks].busy.info.size = -blocks;
}
return result;
}
#ifndef _LIBC
/* On some ANSI C systems, some libc functions call _malloc, _free
and _realloc. Make them use the GNU functions. */
__ptr_t
_malloc (size)
__malloc_size_t size;
{
return malloc (size);
}
void
_free (ptr)
__ptr_t ptr;
{
free (ptr);
}
__ptr_t
_realloc (ptr, size)
__ptr_t ptr;
__malloc_size_t size;
{
return realloc (ptr, size);
}
#endif

296
external/gpl2/libmalloc/dist/malloc.h vendored Normal file
View File

@ -0,0 +1,296 @@
/* $NetBSD: malloc.h,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Declarations for `malloc' and friends.
Copyright 1990, 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_H
#define _MALLOC_H 1
#ifdef _MALLOC_INTERNAL
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG)
#include <string.h>
#else
#ifndef memset
#define memset(s, zero, n) bzero ((s), (n))
#endif
#ifndef memcpy
#define memcpy(d, s, n) bcopy ((s), (d), (n))
#endif
#endif
#if defined (__GNU_LIBRARY__) || (defined (__STDC__) && __STDC__)
#include <limits.h>
#else
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#endif /* _MALLOC_INTERNAL. */
#ifdef __cplusplus
extern "C"
{
#endif
#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
#undef __P
#define __P(args) args
#undef __ptr_t
#define __ptr_t void *
#else /* Not C++ or ANSI C. */
#undef __P
#define __P(args) ()
#undef const
#define const
#undef __ptr_t
#define __ptr_t char *
#endif /* C++ or ANSI C. */
#if defined (__STDC__) && __STDC__
#include <stddef.h>
#define __malloc_size_t size_t
#define __malloc_ptrdiff_t ptrdiff_t
#else
#define __malloc_size_t unsigned int
#define __malloc_ptrdiff_t int
#endif
#ifndef NULL
#define NULL 0
#endif
/* Allocate SIZE bytes of memory. */
extern __ptr_t malloc __P ((__malloc_size_t __size));
/* Re-allocate the previously allocated block
in __ptr_t, making the new block SIZE bytes long. */
extern __ptr_t realloc __P ((__ptr_t __ptr, __malloc_size_t __size));
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
extern __ptr_t calloc __P ((__malloc_size_t __nmemb, __malloc_size_t __size));
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
extern void free __P ((__ptr_t __ptr));
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
extern __ptr_t memalign __P ((__malloc_size_t __alignment,
__malloc_size_t __size));
/* Allocate SIZE bytes on a page boundary. */
extern __ptr_t valloc __P ((__malloc_size_t __size));
#ifdef _MALLOC_INTERNAL
/* The allocator divides the heap into blocks of fixed size; large
requests receive one or more whole blocks, and small requests
receive a fragment of a block. Fragment sizes are powers of two,
and all fragments of a block are the same size. When all the
fragments in a block have been freed, the block itself is freed. */
#define INT_BIT (CHAR_BIT * sizeof(int))
#define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
#define BLOCKSIZE (1 << BLOCKLOG)
#define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
/* Determine the amount of memory spanned by the initial heap table
(not an absolute limit). */
#define HEAP (INT_BIT > 16 ? 4194304 : 65536)
/* Number of contiguous free blocks allowed to build up at the end of
memory before they will be returned to the system. */
#define FINAL_FREE_BLOCKS 8
/* Data structure giving per-block information. */
typedef union
{
/* Heap information for a busy block. */
struct
{
/* Zero for a large (multiblock) object, or positive giving the
logarithm to the base two of the fragment size. */
int type;
union
{
struct
{
__malloc_size_t nfree; /* Free frags in a fragmented block. */
__malloc_size_t first; /* First free fragment of the block. */
} frag;
/* For a large object, in its first block, this has the number
of blocks in the object. In the other blocks, this has a
negative number which says how far back the first block is. */
__malloc_ptrdiff_t size;
} info;
} busy;
/* Heap information for a free block
(that may be the first of a free cluster). */
struct
{
__malloc_size_t size; /* Size (in blocks) of a free cluster. */
__malloc_size_t next; /* Index of next free cluster. */
__malloc_size_t prev; /* Index of previous free cluster. */
} free;
} malloc_info;
/* Pointer to first block of the heap. */
extern char *_heapbase;
/* Table indexed by block number giving per-block information. */
extern malloc_info *_heapinfo;
/* Address to block number and vice versa. */
#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
#define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase))
/* Current search index for the heap table. */
extern __malloc_size_t _heapindex;
/* Limit of valid info table indices. */
extern __malloc_size_t _heaplimit;
/* Doubly linked lists of free fragments. */
struct list
{
struct list *next;
struct list *prev;
};
/* Free list headers for each fragment size. */
extern struct list _fraghead[];
/* List of blocks allocated with `memalign' (or `valloc'). */
struct alignlist
{
struct alignlist *next;
__ptr_t aligned; /* The address that memaligned returned. */
__ptr_t exact; /* The address that malloc returned. */
};
extern struct alignlist *_aligned_blocks;
/* Instrumentation. */
extern __malloc_size_t _chunks_used;
extern __malloc_size_t _bytes_used;
extern __malloc_size_t _chunks_free;
extern __malloc_size_t _bytes_free;
/* Internal version of `free' used in `morecore' (malloc.c). */
extern void _free_internal __P ((__ptr_t __ptr));
#endif /* _MALLOC_INTERNAL. */
/* Given an address in the middle of a malloc'd object,
return the address of the beginning of the object. */
extern __ptr_t malloc_find_object_address __P ((__ptr_t __ptr));
/* Underlying allocation function; successive calls should
return contiguous pieces of memory. */
extern __ptr_t (*__morecore) __P ((__malloc_ptrdiff_t __size));
/* Default value of `__morecore'. */
extern __ptr_t __default_morecore __P ((__malloc_ptrdiff_t __size));
/* If not NULL, this function is called after each time
`__morecore' is called to increase the data size. */
extern void (*__after_morecore_hook) __P ((void));
/* Nonzero if `malloc' has been called and done its initialization. */
extern int __malloc_initialized;
/* Hooks for debugging versions. */
extern void (*__malloc_initialize_hook) __P ((void));
extern void (*__free_hook) __P ((__ptr_t __ptr));
extern __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
extern __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size));
extern __ptr_t (*__memalign_hook) __P ((__malloc_size_t __size,
__malloc_size_t __alignment));
/* Return values for `mprobe': these are the kinds of inconsistencies that
`mcheck' enables detection of. */
enum mcheck_status
{
MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */
MCHECK_OK, /* Block is fine. */
MCHECK_FREE, /* Block freed twice. */
MCHECK_HEAD, /* Memory before the block was clobbered. */
MCHECK_TAIL /* Memory after the block was clobbered. */
};
/* Activate a standard collection of debugging hooks. This must be called
before `malloc' is ever called. ABORTFUNC is called with an error code
(see enum above) when an inconsistency is detected. If ABORTFUNC is
null, the standard function prints on stderr and then calls `abort'. */
extern int mcheck __P ((void (*__abortfunc) __P ((enum mcheck_status))));
/* Check for aberrations in a particular malloc'd block. You must have
called `mcheck' already. These are the same checks that `mcheck' does
when you free or reallocate a block. */
extern enum mcheck_status mprobe __P ((__ptr_t __ptr));
/* Activate a standard collection of tracing hooks. */
extern void mtrace __P ((void));
extern void muntrace __P ((void));
/* Statistics available to the user. */
struct mstats
{
__malloc_size_t bytes_total; /* Total size of the heap. */
__malloc_size_t chunks_used; /* Chunks allocated by the user. */
__malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */
__malloc_size_t chunks_free; /* Chunks in the free list. */
__malloc_size_t bytes_free; /* Byte total of chunks in the free list. */
};
/* Pick up the current statistics. */
extern struct mstats mstats __P ((void));
/* Call WARNFUN with a warning message when memory usage is high. */
extern void memory_warnings __P ((__ptr_t __start,
void (*__warnfun) __P ((const char *))));
/* Relocating allocator. */
/* Allocate SIZE bytes, and store the address in *HANDLEPTR. */
extern __ptr_t r_alloc __P ((__ptr_t *__handleptr, __malloc_size_t __size));
/* Free the storage allocated in HANDLEPTR. */
extern void r_alloc_free __P ((__ptr_t *__handleptr));
/* Adjust the block at HANDLEPTR to be SIZE bytes long. */
extern __ptr_t r_re_alloc __P ((__ptr_t *__handleptr, __malloc_size_t __size));
#ifdef __cplusplus
}
#endif
#endif /* malloc.h */

217
external/gpl2/libmalloc/dist/mcheck.c vendored Normal file
View File

@ -0,0 +1,217 @@
/* $NetBSD: mcheck.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Standard debugging hooks for `malloc'.
Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#include <stdio.h>
#endif
/* Old hook values. */
static void (*old_free_hook) __P ((__ptr_t ptr));
static __ptr_t (*old_malloc_hook) __P ((__malloc_size_t size));
static __ptr_t (*old_realloc_hook) __P ((__ptr_t ptr, __malloc_size_t size));
/* Function to call when something awful happens. */
static void (*abortfunc) __P ((enum mcheck_status));
/* Arbitrary magical numbers. */
#define MAGICWORD 0xfedabeeb
#define MAGICFREE 0xd8675309
#define MAGICBYTE ((char) 0xd7)
#define MALLOCFLOOD ((char) 0x93)
#define FREEFLOOD ((char) 0x95)
struct hdr
{
__malloc_size_t size; /* Exact size requested by user. */
unsigned long int magic; /* Magic number to check header integrity. */
};
#if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG)
#define flood memset
#else
static void flood __P ((__ptr_t, int, __malloc_size_t));
static void
flood (ptr, val, size)
__ptr_t ptr;
int val;
__malloc_size_t size;
{
char *cp = ptr;
while (size--)
*cp++ = val;
}
#endif
static enum mcheck_status checkhdr __P ((const struct hdr *));
static enum mcheck_status
checkhdr (hdr)
const struct hdr *hdr;
{
enum mcheck_status status;
switch (hdr->magic)
{
default:
status = MCHECK_HEAD;
break;
case MAGICFREE:
status = MCHECK_FREE;
break;
case MAGICWORD:
if (((char *) &hdr[1])[hdr->size] != MAGICBYTE)
status = MCHECK_TAIL;
else
status = MCHECK_OK;
break;
}
if (status != MCHECK_OK)
(*abortfunc) (status);
return status;
}
static void freehook __P ((__ptr_t));
static void
freehook (ptr)
__ptr_t ptr;
{
struct hdr *hdr = ((struct hdr *) ptr) - 1;
checkhdr (hdr);
hdr->magic = MAGICFREE;
flood (ptr, FREEFLOOD, hdr->size);
__free_hook = old_free_hook;
free (hdr);
__free_hook = freehook;
}
static __ptr_t mallochook __P ((__malloc_size_t));
static __ptr_t
mallochook (size)
__malloc_size_t size;
{
struct hdr *hdr;
__malloc_hook = old_malloc_hook;
hdr = (struct hdr *) malloc (sizeof (struct hdr) + size + 1);
__malloc_hook = mallochook;
if (hdr == NULL)
return NULL;
hdr->size = size;
hdr->magic = MAGICWORD;
((char *) &hdr[1])[size] = MAGICBYTE;
flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size);
return (__ptr_t) (hdr + 1);
}
static __ptr_t reallochook __P ((__ptr_t, __malloc_size_t));
static __ptr_t
reallochook (ptr, size)
__ptr_t ptr;
__malloc_size_t size;
{
struct hdr *hdr = ((struct hdr *) ptr) - 1;
__malloc_size_t osize = hdr->size;
checkhdr (hdr);
if (size < osize)
flood ((char *) ptr + size, FREEFLOOD, osize - size);
__free_hook = old_free_hook;
__malloc_hook = old_malloc_hook;
__realloc_hook = old_realloc_hook;
hdr = (struct hdr *) realloc ((__ptr_t) hdr, sizeof (struct hdr) + size + 1);
__free_hook = freehook;
__malloc_hook = mallochook;
__realloc_hook = reallochook;
if (hdr == NULL)
return NULL;
hdr->size = size;
hdr->magic = MAGICWORD;
((char *) &hdr[1])[size] = MAGICBYTE;
if (size > osize)
flood ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize);
return (__ptr_t) (hdr + 1);
}
static void
mabort (status)
enum mcheck_status status;
{
const char *msg;
switch (status)
{
case MCHECK_OK:
msg = "memory is consistent, library is buggy";
break;
case MCHECK_HEAD:
msg = "memory clobbered before allocated block";
break;
case MCHECK_TAIL:
msg = "memory clobbered past end of allocated block";
break;
case MCHECK_FREE:
msg = "block freed twice";
break;
default:
msg = "bogus mcheck_status, library is buggy";
break;
}
#ifdef __GNU_LIBRARY__
__libc_fatal (msg);
#else
fprintf (stderr, "mcheck: %s\n", msg);
fflush (stderr);
abort ();
#endif
}
static int mcheck_used = 0;
int
mcheck (func)
void (*func) __P ((enum mcheck_status));
{
abortfunc = (func != NULL) ? func : &mabort;
/* These hooks may not be safely inserted if malloc is already in use. */
if (!__malloc_initialized && !mcheck_used)
{
old_free_hook = __free_hook;
__free_hook = freehook;
old_malloc_hook = __malloc_hook;
__malloc_hook = mallochook;
old_realloc_hook = __realloc_hook;
__realloc_hook = reallochook;
mcheck_used = 1;
}
return mcheck_used ? 0 : -1;
}
enum mcheck_status
mprobe (__ptr_t ptr)
{
return mcheck_used ? checkhdr (ptr) : MCHECK_DISABLED;
}

View File

@ -0,0 +1,186 @@
/* $NetBSD: mem-limits.h,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Includes for memory limit warnings.
Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef MSDOS
#include <dpmi.h>
#endif
/* Some systems need this before <sys/resource.h>. */
#include <sys/types.h>
#ifdef _LIBC
#include <sys/resource.h>
#define BSD4_2 /* Tell code below to use getrlimit. */
#else
#if defined (__osf__) && (defined (__mips) || defined (mips) || defined(__alpha))
#include <sys/time.h>
#include <sys/resource.h>
#endif
#ifdef __bsdi__
#define BSD4_2
#endif
#ifndef BSD4_2
#ifndef USG
#ifndef MSDOS
#ifndef WINDOWSNT
#include <sys/vlimit.h>
#endif /* not WINDOWSNT */
#endif /* not MSDOS */
#endif /* not USG */
#else /* if BSD4_2 */
#include <sys/time.h>
#include <sys/resource.h>
#endif /* BSD4_2 */
#endif /* _LIBC */
#ifdef emacs
/* The important properties of this type are that 1) it's a pointer, and
2) arithmetic on it should work as if the size of the object pointed
to has a size of 1. */
#ifdef __STDC__
typedef void *POINTER;
#else
typedef char *POINTER;
#endif
typedef unsigned long SIZE;
#ifdef NULL
#undef NULL
#endif
#define NULL ((POINTER) 0)
extern POINTER start_of_data ();
#ifdef DATA_SEG_BITS
#define EXCEEDS_LISP_PTR(ptr) \
(((EMACS_UINT) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
#else
#define EXCEEDS_LISP_PTR(ptr) ((EMACS_UINT) (ptr) >> VALBITS)
#endif
#ifdef BSD
#ifndef DATA_SEG_BITS
extern char etext;
#define start_of_data() &etext
#endif
#endif
#else /* Not emacs */
extern char etext;
#define start_of_data() &etext
#endif /* Not emacs */
/* start of data space; can be changed by calling malloc_init */
static POINTER data_space_start;
/* Number of bytes of writable memory we can expect to be able to get */
static unsigned int lim_data;
#ifdef NO_LIM_DATA
static void
get_lim_data ()
{
lim_data = -1;
}
#else /* not NO_LIM_DATA */
#ifdef USG
static void
get_lim_data ()
{
extern long ulimit ();
lim_data = -1;
/* Use the ulimit call, if we seem to have it. */
#if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
lim_data = ulimit (3, 0);
#endif
/* If that didn't work, just use the macro's value. */
#ifdef ULIMIT_BREAK_VALUE
if (lim_data == -1)
lim_data = ULIMIT_BREAK_VALUE;
#endif
lim_data -= (long) data_space_start;
}
#else /* not USG */
#ifdef WINDOWSNT
static void
get_lim_data ()
{
extern unsigned long data_region_size;
lim_data = data_region_size;
}
#else
#if !defined (BSD4_2) && !defined (__osf__)
#ifdef MSDOS
void
get_lim_data ()
{
_go32_dpmi_meminfo info;
_go32_dpmi_get_free_memory_information (&info);
lim_data = info.available_memory;
}
#else /* not MSDOS */
static void
get_lim_data ()
{
lim_data = vlimit (LIM_DATA, -1);
}
#endif /* not MSDOS */
#else /* BSD4_2 */
static void
get_lim_data ()
{
struct rlimit XXrlimit;
getrlimit (RLIMIT_DATA, &XXrlimit);
#ifdef RLIM_INFINITY
lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
#else
lim_data = XXrlimit.rlim_cur; /* soft limit */
#endif
}
#endif /* BSD4_2 */
#endif /* not WINDOWSNT */
#endif /* not USG */
#endif /* not NO_LIM_DATA */

68
external/gpl2/libmalloc/dist/memalign.c vendored Normal file
View File

@ -0,0 +1,68 @@
/* $NetBSD: memalign.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
__ptr_t (*__memalign_hook) __P ((size_t __size, size_t __alignment));
__ptr_t
memalign (alignment, size)
__malloc_size_t alignment;
__malloc_size_t size;
{
__ptr_t result;
unsigned long int adj;
if (__memalign_hook)
return (*__memalign_hook) (alignment, size);
size = ((size + alignment - 1) / alignment) * alignment;
result = malloc (size);
if (result == NULL)
return NULL;
adj = (unsigned long int) ((unsigned long int) ((char *) result -
(char *) NULL)) % alignment;
if (adj != 0)
{
struct alignlist *l;
for (l = _aligned_blocks; l != NULL; l = l->next)
if (l->aligned == NULL)
/* This slot is free. Use it. */
break;
if (l == NULL)
{
l = (struct alignlist *) malloc (sizeof (struct alignlist));
if (l == NULL)
{
free (result);
return NULL;
}
l->next = _aligned_blocks;
_aligned_blocks = l;
}
l->exact = result;
result = l->aligned = (char *) result + alignment - adj;
}
return result;
}

54
external/gpl2/libmalloc/dist/morecore.c vendored Normal file
View File

@ -0,0 +1,54 @@
/* $NetBSD: morecore.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with the GNU C Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
#ifndef __GNU_LIBRARY__
#define __sbrk sbrk
#endif
#ifdef __GNU_LIBRARY__
/* It is best not to declare this and cast its result on foreign operating
systems with potentially hostile include files. */
extern __ptr_t __sbrk __P ((int increment));
#endif
#ifndef NULL
#define NULL 0
#endif
/* Allocate INCREMENT more bytes of data space,
and return the start of data space, or NULL on errors.
If INCREMENT is negative, shrink data space. */
__ptr_t
__default_morecore (increment)
#ifdef __STDC__
ptrdiff_t increment;
#else
int increment;
#endif
{
__ptr_t result = (__ptr_t) __sbrk ((int) increment);
if (result == (__ptr_t) -1)
return NULL;
return result;
}

41
external/gpl2/libmalloc/dist/mstats.c vendored Normal file
View File

@ -0,0 +1,41 @@
/* $NetBSD: mstats.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Access the statistics maintained by `malloc'.
Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
struct mstats
mstats ()
{
struct mstats result;
result.bytes_total = (char *) (*__morecore) (0) - _heapbase;
result.chunks_used = _chunks_used;
result.bytes_used = _bytes_used;
result.chunks_free = _chunks_free;
result.bytes_free = _bytes_free;
return result;
}

50
external/gpl2/libmalloc/dist/mtrace.awk vendored Normal file
View File

@ -0,0 +1,50 @@
#
# Awk program to analyze mtrace.c output.
#
{
if ($1 == "@") {
where = " (" $2 ")"
n = 3
} else {
where = ""
n = 1
}
if ($n == "+") {
if (allocated[$(n+1)] != "")
print "+", $(n+1), "Alloc", NR, "duplicate:", allocated[$(n+1)], wherewas[$(n+1)], where;
else {
wherewas[$(n+1)] = where;
allocated[$(n+1)] = $(n+2);
}
} else if ($n == "-") {
if (allocated[$(n+1)] != "") {
wherewas[$(n+1)] = "";
allocated[$(n+1)] = "";
if (allocated[$(n+1)] != "")
print "DELETE FAILED", $(n+1), allocated[$(n+1)];
} else
print "-", $(n+1), "Free", NR, "was never alloc'd", where;
} else if ($n == "<") {
if (allocated[$(n+1)] != "") {
wherewas[$(n+1)] = "";
allocated[$(n+1)] = "";
} else
print "-", $(n+1), "Realloc", NR, "was never alloc'd", where;
} else if ($n == ">") {
if (allocated[$(n+1)] != "")
print "+", $(n+1), "Realloc", NR, "duplicate:", allocated[$(n+1)], where;
else {
wherewas[$(n+1)] = $(n+2);
allocated[$(n+1)] = $(n+2);
}
} else if ($n == "=") {
# Ignore "= Start"
} else if ($n == "!") {
# Ignore failed realloc attempts for now
}
}
END {
for (x in allocated)
if (allocated[x] != "")
print "+", x, allocated[x], wherewas[x];
}

189
external/gpl2/libmalloc/dist/mtrace.c vendored Normal file
View File

@ -0,0 +1,189 @@
/* $NetBSD: mtrace.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* More debugging hooks for `malloc'.
Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
Written April 2, 1991 by John Gilmore of Cygnus Support.
Based on mcheck.c by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
#include <stdio.h>
#ifndef __GNU_LIBRARY__
extern char *getenv ();
#else
#include <stdlib.h>
#endif
static FILE *mallstream;
static char mallenv[]= "MALLOC_TRACE";
static char mallbuf[BUFSIZ]; /* Buffer for the output. */
/* Address to breakpoint on accesses to... */
__ptr_t mallwatch;
/* File name and line number information, for callers that had
the foresight to call through a macro. */
char *_mtrace_file;
int _mtrace_line;
/* Old hook values. */
static void (*tr_old_free_hook) __P ((__ptr_t ptr));
static __ptr_t (*tr_old_malloc_hook) __P ((__malloc_size_t size));
static __ptr_t (*tr_old_realloc_hook) __P ((__ptr_t ptr, __malloc_size_t size));
/* This function is called when the block being alloc'd, realloc'd, or
freed has an address matching the variable "mallwatch". In a debugger,
set "mallwatch" to the address of interest, then put a breakpoint on
tr_break. */
void tr_break __P ((void));
void
tr_break ()
{
}
static void tr_where __P ((void));
static void
tr_where ()
{
if (_mtrace_file)
{
fprintf (mallstream, "@ %s:%d ", _mtrace_file, _mtrace_line);
_mtrace_file = NULL;
}
}
static void tr_freehook __P ((__ptr_t));
static void
tr_freehook (ptr)
__ptr_t ptr;
{
tr_where ();
fprintf (mallstream, "- %p\n", ptr); /* Be sure to print it first. */
if (ptr == mallwatch)
tr_break ();
__free_hook = tr_old_free_hook;
free (ptr);
__free_hook = tr_freehook;
}
static __ptr_t tr_mallochook __P ((__malloc_size_t));
static __ptr_t
tr_mallochook (size)
__malloc_size_t size;
{
__ptr_t hdr;
__malloc_hook = tr_old_malloc_hook;
hdr = (__ptr_t) malloc (size);
__malloc_hook = tr_mallochook;
tr_where ();
/* We could be printing a NULL here; that's OK. */
fprintf (mallstream, "+ %p %lx\n", hdr, (unsigned long)size);
if (hdr == mallwatch)
tr_break ();
return hdr;
}
static __ptr_t tr_reallochook __P ((__ptr_t, __malloc_size_t));
static __ptr_t
tr_reallochook (ptr, size)
__ptr_t ptr;
__malloc_size_t size;
{
__ptr_t hdr;
if (ptr == mallwatch)
tr_break ();
__free_hook = tr_old_free_hook;
__malloc_hook = tr_old_malloc_hook;
__realloc_hook = tr_old_realloc_hook;
hdr = (__ptr_t) realloc (ptr, size);
__free_hook = tr_freehook;
__malloc_hook = tr_mallochook;
__realloc_hook = tr_reallochook;
tr_where ();
if (hdr == NULL)
/* Failed realloc. */
fprintf (mallstream, "! %p %lx\n", ptr, (unsigned long)size);
else
fprintf (mallstream, "< %p\n> %p %lx\n", ptr, hdr, (unsigned long)size);
if (hdr == mallwatch)
tr_break ();
return hdr;
}
/* We enable tracing if either the environment variable MALLOC_TRACE
is set, or if the variable mallwatch has been patched to an address
that the debugging user wants us to stop on. When patching mallwatch,
don't forget to set a breakpoint on tr_break! */
void
mtrace ()
{
char *mallfile;
/* Don't panic if we're called more than once. */
if (mallstream != NULL)
return;
mallfile = getenv (mallenv);
if (mallfile != NULL || mallwatch != NULL)
{
mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "w");
if (mallstream != NULL)
{
/* Be sure it doesn't malloc its buffer! */
setbuf (mallstream, mallbuf);
fprintf (mallstream, "= Start\n");
tr_old_free_hook = __free_hook;
__free_hook = tr_freehook;
tr_old_malloc_hook = __malloc_hook;
__malloc_hook = tr_mallochook;
tr_old_realloc_hook = __realloc_hook;
__realloc_hook = tr_reallochook;
}
}
}
void
muntrace ()
{
if (mallstream == NULL)
return;
fprintf (mallstream, "= End\n");
fclose (mallstream);
mallstream = NULL;
__free_hook = tr_old_free_hook;
__malloc_hook = tr_old_malloc_hook;
__realloc_hook = tr_old_realloc_hook;
}

1088
external/gpl2/libmalloc/dist/ralloc.c vendored Normal file

File diff suppressed because it is too large Load Diff

221
external/gpl2/libmalloc/dist/realloc.c vendored Normal file
View File

@ -0,0 +1,221 @@
/* $NetBSD: realloc.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Change the size of a block allocated by `malloc'.
Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
#if (defined (MEMMOVE_MISSING) || \
!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG))
/* Snarfed directly from Emacs src/dispnew.c:
XXX Should use system bcopy if it handles overlap. */
#ifndef emacs
/* Like bcopy except never gets confused by overlap. */
static void
safe_bcopy (from, to, size)
char *from, *to;
int size;
{
if (size <= 0 || from == to)
return;
/* If the source and destination don't overlap, then bcopy can
handle it. If they do overlap, but the destination is lower in
memory than the source, we'll assume bcopy can handle that. */
if (to < from || from + size <= to)
bcopy (from, to, size);
/* Otherwise, we'll copy from the end. */
else
{
register char *endf = from + size;
register char *endt = to + size;
/* If TO - FROM is large, then we should break the copy into
nonoverlapping chunks of TO - FROM bytes each. However, if
TO - FROM is small, then the bcopy function call overhead
makes this not worth it. The crossover point could be about
anywhere. Since I don't think the obvious copy loop is too
bad, I'm trying to err in its favor. */
if (to - from < 64)
{
do
*--endt = *--endf;
while (endf != from);
}
else
{
for (;;)
{
endt -= (to - from);
endf -= (to - from);
if (endt < to)
break;
bcopy (endf, endt, to - from);
}
/* If SIZE wasn't a multiple of TO - FROM, there will be a
little left over. The amount left over is
(endt + (to - from)) - to, which is endt - from. */
bcopy (from, to, endt - from);
}
}
}
#endif /* Not emacs. */
#define memmove(to, from, size) safe_bcopy ((from), (to), (size))
#endif
#define min(A, B) ((A) < (B) ? (A) : (B))
/* Debugging hook for realloc. */
__ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size));
/* Resize the given region to the new size, returning a pointer
to the (possibly moved) region. This is optimized for speed;
some benchmarks seem to indicate that greater compactness is
achieved by unconditionally allocating and copying to a
new region. This module has incestuous knowledge of the
internals of both free and malloc. */
__ptr_t
realloc (ptr, size)
__ptr_t ptr;
__malloc_size_t size;
{
__ptr_t result;
int type;
__malloc_size_t block, blocks, oldlimit;
if (size == 0)
{
free (ptr);
return malloc (0);
}
else if (ptr == NULL)
return malloc (size);
if (__realloc_hook != NULL)
return (*__realloc_hook) (ptr, size);
block = BLOCK (ptr);
type = _heapinfo[block].busy.type;
switch (type)
{
case 0:
/* Maybe reallocate a large block to a small fragment. */
if (size <= BLOCKSIZE / 2)
{
result = malloc (size);
if (result != NULL)
{
memcpy (result, ptr, size);
_free_internal (ptr);
return result;
}
}
/* The new size is a large allocation as well;
see if we can hold it in place. */
blocks = BLOCKIFY (size);
if (blocks < _heapinfo[block].busy.info.size)
{
/* The new size is smaller; return
excess memory to the free list. */
_heapinfo[block + blocks].busy.type = 0;
_heapinfo[block + blocks].busy.info.size
= _heapinfo[block].busy.info.size - blocks;
_heapinfo[block].busy.info.size = blocks;
/* We have just created a new chunk by splitting a chunk in two.
Now we will free this chunk; increment the statistics counter
so it doesn't become wrong when _free_internal decrements it. */
++_chunks_used;
_free_internal (ADDRESS (block + blocks));
result = ptr;
}
else if (blocks == _heapinfo[block].busy.info.size)
/* No size change necessary. */
result = ptr;
else
{
/* Won't fit, so allocate a new region that will.
Free the old region first in case there is sufficient
adjacent free space to grow without moving. */
blocks = _heapinfo[block].busy.info.size;
/* Prevent free from actually returning memory to the system. */
oldlimit = _heaplimit;
_heaplimit = 0;
_free_internal (ptr);
_heaplimit = oldlimit;
result = malloc (size);
if (result == NULL)
{
/* Now we're really in trouble. We have to unfree
the thing we just freed. Unfortunately it might
have been coalesced with its neighbors. */
if (_heapindex == block)
(void) malloc (blocks * BLOCKSIZE);
else
{
__ptr_t previous = malloc ((block - _heapindex) * BLOCKSIZE);
(void) malloc (blocks * BLOCKSIZE);
_free_internal (previous);
}
return NULL;
}
if (ptr != result)
memmove (result, ptr, blocks * BLOCKSIZE);
}
break;
default:
/* Old size is a fragment; type is logarithm
to base two of the fragment size. */
if (size > (__malloc_size_t) (1 << (type - 1)) &&
size <= (__malloc_size_t) (1 << type))
/* The new size is the same kind of fragment. */
result = ptr;
else
{
/* The new size is different; allocate a new space,
and copy the lesser of the new size and the old. */
result = malloc (size);
if (result == NULL)
return NULL;
memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type));
free (ptr);
}
break;
}
return result;
}

48
external/gpl2/libmalloc/dist/valloc.c vendored Normal file
View File

@ -0,0 +1,48 @@
/* $NetBSD: valloc.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Allocate memory on a page boundary.
Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This 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.
This 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 this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, 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. */
#if defined (__GNU_LIBRARY__) || defined (_LIBC)
#include <stddef.h>
#include <sys/cdefs.h>
extern size_t __getpagesize __P ((void));
#else
#include "getpagesize.h"
#define __getpagesize() getpagesize()
#endif
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
static __malloc_size_t pagesize;
__ptr_t
valloc (size)
__malloc_size_t size;
{
if (pagesize == 0)
pagesize = __getpagesize ();
return memalign (pagesize, size);
}

137
external/gpl2/libmalloc/dist/vm-limit.c vendored Normal file
View File

@ -0,0 +1,137 @@
/* $NetBSD: vm-limit.c,v 1.1.1.1 2016/01/13 21:42:18 christos Exp $ */
/* Functions for memory limit warnings.
Copyright (C) 1990, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef emacs
#include <config.h>
#include "lisp.h"
#endif
#ifndef emacs
#include <stddef.h>
typedef size_t SIZE;
typedef void *POINTER;
#define EXCEEDS_LISP_PTR(x) 0
#endif
#include "mem-limits.h"
/*
Level number of warnings already issued.
0 -- no warnings issued.
1 -- 75% warning already issued.
2 -- 85% warning already issued.
3 -- 95% warning issued; keep warning frequently.
*/
static int warnlevel;
/* Function to call to issue a warning;
0 means don't issue them. */
static void (*warn_function) ();
/* Get more memory space, complaining if we're near the end. */
static void
check_memory_limits ()
{
extern POINTER (*__morecore) ();
register POINTER cp;
unsigned long five_percent;
unsigned long data_size;
if (lim_data == 0)
get_lim_data ();
five_percent = lim_data / 20;
/* Find current end of memory and issue warning if getting near max */
cp = (char *) (*__morecore) (0);
data_size = (char *) cp - (char *) data_space_start;
if (warn_function)
switch (warnlevel)
{
case 0:
if (data_size > five_percent * 15)
{
warnlevel++;
(*warn_function) ("Warning: past 75% of memory limit");
}
break;
case 1:
if (data_size > five_percent * 17)
{
warnlevel++;
(*warn_function) ("Warning: past 85% of memory limit");
}
break;
case 2:
if (data_size > five_percent * 19)
{
warnlevel++;
(*warn_function) ("Warning: past 95% of memory limit");
}
break;
default:
(*warn_function) ("Warning: past acceptable memory limits");
break;
}
/* If we go down below 70% full, issue another 75% warning
when we go up again. */
if (data_size < five_percent * 14)
warnlevel = 0;
/* If we go down below 80% full, issue another 85% warning
when we go up again. */
else if (warnlevel > 1 && data_size < five_percent * 16)
warnlevel = 1;
/* If we go down below 90% full, issue another 95% warning
when we go up again. */
else if (warnlevel > 2 && data_size < five_percent * 18)
warnlevel = 2;
if (EXCEEDS_LISP_PTR (cp))
(*warn_function) ("Warning: memory in use exceeds lisp pointer size");
}
/* Cause reinitialization based on job parameters;
also declare where the end of pure storage is. */
void
memory_warnings (start, warnfun)
POINTER start;
void (*warnfun) ();
{
extern void (* __after_morecore_hook) (); /* From gmalloc.c */
if (start)
data_space_start = start;
else
data_space_start = start_of_data ();
warn_function = warnfun;
__after_morecore_hook = check_memory_limits;
}