diff options
Diffstat (limited to 'src/gmalloc.c')
| -rw-r--r-- | src/gmalloc.c | 71 |
1 files changed, 21 insertions, 50 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index 0df050e127a..bc1d85ac5fb 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declarations for `malloc' and friends. | 1 | /* Declarations for `malloc' and friends. |
| 2 | Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004, | 2 | Copyright (C) 1990-1993, 1995-1996, 1999, 2002-2007, 2013 Free |
| 3 | 2005, 2006, 2007 Free Software Foundation, Inc. | 3 | Software Foundation, Inc. |
| 4 | Written May 1989 by Mike Haertel. | 4 | Written May 1989 by Mike Haertel. |
| 5 | 5 | ||
| 6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
| @@ -14,16 +14,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 14 | General Public License for more details. | 14 | General Public License for more details. |
| 15 | 15 | ||
| 16 | You should have received a copy of the GNU General Public | 16 | You should have received a copy of the GNU General Public |
| 17 | License along with this library; see the file COPYING. If | 17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 18 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | 18 | ||
| 21 | The author may be reached (Email) at the address mike@ai.mit.edu, | 19 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 22 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 20 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 23 | 21 | ||
| 24 | #ifdef HAVE_CONFIG_H | ||
| 25 | #include <config.h> | 22 | #include <config.h> |
| 26 | #endif | ||
| 27 | 23 | ||
| 28 | #ifdef HAVE_PTHREAD | 24 | #ifdef HAVE_PTHREAD |
| 29 | #define USE_PTHREAD | 25 | #define USE_PTHREAD |
| @@ -38,6 +34,10 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 38 | #include <pthread.h> | 34 | #include <pthread.h> |
| 39 | #endif | 35 | #endif |
| 40 | 36 | ||
| 37 | #ifdef WINDOWSNT | ||
| 38 | #include <w32heap.h> /* for sbrk */ | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifdef __cplusplus | 41 | #ifdef __cplusplus |
| 42 | extern "C" | 42 | extern "C" |
| 43 | { | 43 | { |
| @@ -290,9 +290,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 290 | General Public License for more details. | 290 | General Public License for more details. |
| 291 | 291 | ||
| 292 | You should have received a copy of the GNU General Public | 292 | You should have received a copy of the GNU General Public |
| 293 | License along with this library; see the file COPYING. If | 293 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 294 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 295 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 296 | 294 | ||
| 297 | The author may be reached (Email) at the address mike@ai.mit.edu, | 295 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 298 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 296 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| @@ -462,7 +460,7 @@ get_contiguous_space (ptrdiff_t size, void *position) | |||
| 462 | /* This is called when `_heapinfo' and `heapsize' have just | 460 | /* This is called when `_heapinfo' and `heapsize' have just |
| 463 | been set to describe a new info table. Set up the table | 461 | been set to describe a new info table. Set up the table |
| 464 | to describe itself and account for it in the statistics. */ | 462 | to describe itself and account for it in the statistics. */ |
| 465 | static inline void | 463 | static void |
| 466 | register_heapinfo (void) | 464 | register_heapinfo (void) |
| 467 | { | 465 | { |
| 468 | size_t block, blocks; | 466 | size_t block, blocks; |
| @@ -970,9 +968,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 970 | General Public License for more details. | 968 | General Public License for more details. |
| 971 | 969 | ||
| 972 | You should have received a copy of the GNU General Public | 970 | You should have received a copy of the GNU General Public |
| 973 | License along with this library; see the file COPYING. If | 971 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 974 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 975 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 976 | 972 | ||
| 977 | The author may be reached (Email) at the address mike@ai.mit.edu, | 973 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 978 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 974 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| @@ -1284,14 +1280,14 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 1284 | General Public License for more details. | 1280 | General Public License for more details. |
| 1285 | 1281 | ||
| 1286 | You should have received a copy of the GNU General Public | 1282 | You should have received a copy of the GNU General Public |
| 1287 | License along with this library; see the file COPYING. If | 1283 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 1288 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 1289 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 1290 | 1284 | ||
| 1291 | The author may be reached (Email) at the address mike@ai.mit.edu, | 1285 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 1292 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 1286 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 1293 | 1287 | ||
| 1288 | #ifndef min | ||
| 1294 | #define min(A, B) ((A) < (B) ? (A) : (B)) | 1289 | #define min(A, B) ((A) < (B) ? (A) : (B)) |
| 1290 | #endif | ||
| 1295 | 1291 | ||
| 1296 | /* On Cygwin the dumped emacs may try to realloc storage allocated in | 1292 | /* On Cygwin the dumped emacs may try to realloc storage allocated in |
| 1297 | the static heap. We just malloc space in the new heap and copy the | 1293 | the static heap. We just malloc space in the new heap and copy the |
| @@ -1483,9 +1479,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 1483 | General Public License for more details. | 1479 | General Public License for more details. |
| 1484 | 1480 | ||
| 1485 | You should have received a copy of the GNU General Public | 1481 | You should have received a copy of the GNU General Public |
| 1486 | License along with this library; see the file COPYING. If | 1482 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 1487 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 1488 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 1489 | 1483 | ||
| 1490 | The author may be reached (Email) at the address mike@ai.mit.edu, | 1484 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 1491 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 1485 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| @@ -1516,9 +1510,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| 1516 | GNU General Public License for more details. | 1510 | GNU General Public License for more details. |
| 1517 | 1511 | ||
| 1518 | You should have received a copy of the GNU General Public License | 1512 | You should have received a copy of the GNU General Public License |
| 1519 | along with the GNU C Library; see the file COPYING. If not, write to | 1513 | along with the GNU C Library. If not, see <http://www.gnu.org/licenses/>. */ |
| 1520 | the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, | ||
| 1521 | MA 02110-1301, USA. */ | ||
| 1522 | 1514 | ||
| 1523 | /* uClibc defines __GNU_LIBRARY__, but it is not completely | 1515 | /* uClibc defines __GNU_LIBRARY__, but it is not completely |
| 1524 | compatible. */ | 1516 | compatible. */ |
| @@ -1562,9 +1554,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 1562 | General Public License for more details. | 1554 | General Public License for more details. |
| 1563 | 1555 | ||
| 1564 | You should have received a copy of the GNU General Public | 1556 | You should have received a copy of the GNU General Public |
| 1565 | License along with this library; see the file COPYING. If | 1557 | License along with this library. If not, see <http://www.gnu.org/licenses/>. */ |
| 1566 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 1567 | Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 1568 | 1558 | ||
| 1569 | void *(*__memalign_hook) (size_t size, size_t alignment); | 1559 | void *(*__memalign_hook) (size_t size, size_t alignment); |
| 1570 | 1560 | ||
| @@ -1618,7 +1608,7 @@ memalign (size_t alignment, size_t size) | |||
| 1618 | break; | 1608 | break; |
| 1619 | if (l == NULL) | 1609 | if (l == NULL) |
| 1620 | { | 1610 | { |
| 1621 | l = malloc (sizeof (struct alignlist)); | 1611 | l = malloc (sizeof *l); |
| 1622 | if (l != NULL) | 1612 | if (l != NULL) |
| 1623 | { | 1613 | { |
| 1624 | l->next = _aligned_blocks; | 1614 | l->next = _aligned_blocks; |
| @@ -1641,14 +1631,6 @@ memalign (size_t alignment, size_t size) | |||
| 1641 | return result; | 1631 | return result; |
| 1642 | } | 1632 | } |
| 1643 | 1633 | ||
| 1644 | #ifndef ENOMEM | ||
| 1645 | #define ENOMEM 12 | ||
| 1646 | #endif | ||
| 1647 | |||
| 1648 | #ifndef EINVAL | ||
| 1649 | #define EINVAL 22 | ||
| 1650 | #endif | ||
| 1651 | |||
| 1652 | int | 1634 | int |
| 1653 | posix_memalign (void **memptr, size_t alignment, size_t size) | 1635 | posix_memalign (void **memptr, size_t alignment, size_t size) |
| 1654 | { | 1636 | { |
| @@ -1682,18 +1664,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 1682 | General Public License for more details. | 1664 | General Public License for more details. |
| 1683 | 1665 | ||
| 1684 | You should have received a copy of the GNU General Public | 1666 | You should have received a copy of the GNU General Public |
| 1685 | License along with this library; see the file COPYING. If | 1667 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 1686 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 1687 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 1688 | 1668 | ||
| 1689 | The author may be reached (Email) at the address mike@ai.mit.edu, | 1669 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 1690 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 1670 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 1691 | 1671 | ||
| 1692 | /* Emacs defines GMALLOC_INHIBIT_VALLOC to avoid this definition | ||
| 1693 | on MSDOS, where it conflicts with a system header file. */ | ||
| 1694 | |||
| 1695 | #ifndef GMALLOC_INHIBIT_VALLOC | ||
| 1696 | |||
| 1697 | /* Allocate SIZE bytes on a page boundary. */ | 1672 | /* Allocate SIZE bytes on a page boundary. */ |
| 1698 | extern void *valloc (size_t); | 1673 | extern void *valloc (size_t); |
| 1699 | 1674 | ||
| @@ -1714,8 +1689,6 @@ valloc (size_t size) | |||
| 1714 | return memalign (pagesize, size); | 1689 | return memalign (pagesize, size); |
| 1715 | } | 1690 | } |
| 1716 | 1691 | ||
| 1717 | #endif /* Not ELIDE_VALLOC. */ | ||
| 1718 | |||
| 1719 | #ifdef GC_MCHECK | 1692 | #ifdef GC_MCHECK |
| 1720 | 1693 | ||
| 1721 | /* Standard debugging hooks for `malloc'. | 1694 | /* Standard debugging hooks for `malloc'. |
| @@ -1733,9 +1706,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 1733 | General Public License for more details. | 1706 | General Public License for more details. |
| 1734 | 1707 | ||
| 1735 | You should have received a copy of the GNU General Public | 1708 | You should have received a copy of the GNU General Public |
| 1736 | License along with this library; see the file COPYING. If | 1709 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 1737 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 1738 | Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 1739 | 1710 | ||
| 1740 | The author may be reached (Email) at the address mike@ai.mit.edu, | 1711 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 1741 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 1712 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| @@ -1813,7 +1784,7 @@ mallochook (size_t size) | |||
| 1813 | struct hdr *hdr; | 1784 | struct hdr *hdr; |
| 1814 | 1785 | ||
| 1815 | __malloc_hook = old_malloc_hook; | 1786 | __malloc_hook = old_malloc_hook; |
| 1816 | hdr = malloc (sizeof (struct hdr) + size + 1); | 1787 | hdr = malloc (sizeof *hdr + size + 1); |
| 1817 | __malloc_hook = mallochook; | 1788 | __malloc_hook = mallochook; |
| 1818 | if (hdr == NULL) | 1789 | if (hdr == NULL) |
| 1819 | return NULL; | 1790 | return NULL; |
| @@ -1844,7 +1815,7 @@ reallochook (void *ptr, size_t size) | |||
| 1844 | __free_hook = old_free_hook; | 1815 | __free_hook = old_free_hook; |
| 1845 | __malloc_hook = old_malloc_hook; | 1816 | __malloc_hook = old_malloc_hook; |
| 1846 | __realloc_hook = old_realloc_hook; | 1817 | __realloc_hook = old_realloc_hook; |
| 1847 | hdr = realloc (hdr, sizeof (struct hdr) + size + 1); | 1818 | hdr = realloc (hdr, sizeof *hdr + size + 1); |
| 1848 | __free_hook = freehook; | 1819 | __free_hook = freehook; |
| 1849 | __malloc_hook = mallochook; | 1820 | __malloc_hook = mallochook; |
| 1850 | __realloc_hook = reallochook; | 1821 | __realloc_hook = reallochook; |