aboutsummaryrefslogtreecommitdiffstats
path: root/src/ralloc.c
diff options
context:
space:
mode:
authorBill Wohler2014-02-23 18:04:35 -0800
committerBill Wohler2014-02-23 18:04:35 -0800
commit3e93bafb95608467e438ba7f725fd1f020669f8c (patch)
treef2f90109f283e06a18caea3cb2a2623abcfb3a92 /src/ralloc.c
parent791c0d7634e44bb92ca85af605be84ff2ae08963 (diff)
parente918e27fdf331e89268fc2c9d7cf838d3ecf7aa7 (diff)
downloademacs-3e93bafb95608467e438ba7f725fd1f020669f8c.tar.gz
emacs-3e93bafb95608467e438ba7f725fd1f020669f8c.zip
Merge from trunk; up to 2014-02-23T23:41:17Z!lekktu@gmail.com.
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index 13fd65cbb0c..c82cd4548d2 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1,5 +1,5 @@
1/* Block-relocating memory allocator. 1/* Block-relocating memory allocator.
2 Copyright (C) 1993, 1995, 2000-2013 Free Software Foundation, Inc. 2 Copyright (C) 1993, 1995, 2000-2014 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -43,8 +43,6 @@ extern size_t __malloc_extra_blocks;
43#else /* not emacs */ 43#else /* not emacs */
44 44
45#include <stddef.h> 45#include <stddef.h>
46
47#include <unistd.h>
48#include <malloc.h> 46#include <malloc.h>
49 47
50#endif /* not emacs */ 48#endif /* not emacs */
@@ -87,7 +85,7 @@ static int extra_bytes;
87/* Macros for rounding. Note that rounding to any value is possible 85/* Macros for rounding. Note that rounding to any value is possible
88 by changing the definition of PAGE. */ 86 by changing the definition of PAGE. */
89#define PAGE (getpagesize ()) 87#define PAGE (getpagesize ())
90#define ROUNDUP(size) (((size_t) (size) + page_size - 1) \ 88#define PAGE_ROUNDUP(size) (((size_t) (size) + page_size - 1) \
91 & ~((size_t) (page_size - 1))) 89 & ~((size_t) (page_size - 1)))
92 90
93#define MEM_ALIGN sizeof (double) 91#define MEM_ALIGN sizeof (double)
@@ -283,7 +281,7 @@ obtain (void *address, size_t size)
283 Get some extra, so we can come here less often. */ 281 Get some extra, so we can come here less often. */
284 282
285 get = size + extra_bytes - already_available; 283 get = size + extra_bytes - already_available;
286 get = (char *) ROUNDUP ((char *) last_heap->end + get) 284 get = (char *) PAGE_ROUNDUP ((char *) last_heap->end + get)
287 - (char *) last_heap->end; 285 - (char *) last_heap->end;
288 286
289 if (real_morecore (get) != last_heap->end) 287 if (real_morecore (get) != last_heap->end)
@@ -346,7 +344,7 @@ relinquish (void)
346 else 344 else
347 { 345 {
348 excess = ((char *) last_heap->end 346 excess = ((char *) last_heap->end
349 - (char *) ROUNDUP ((char *) last_heap->end - excess)); 347 - (char *) PAGE_ROUNDUP ((char *) last_heap->end - excess));
350 /* If the system doesn't want that much memory back, leave 348 /* If the system doesn't want that much memory back, leave
351 the end of the last heap unchanged to reflect that. This 349 the end of the last heap unchanged to reflect that. This
352 can occur if break_value is still within the original 350 can occur if break_value is still within the original
@@ -770,9 +768,9 @@ r_alloc_sbrk (ptrdiff_t size)
770 not always find a space which is contiguous to the previous. */ 768 not always find a space which is contiguous to the previous. */
771 void *new_bloc_start; 769 void *new_bloc_start;
772 heap_ptr h = first_heap; 770 heap_ptr h = first_heap;
773 size_t get = ROUNDUP (size); 771 size_t get = PAGE_ROUNDUP (size);
774 772
775 address = (void *) ROUNDUP (virtual_break_value); 773 address = (void *) PAGE_ROUNDUP (virtual_break_value);
776 774
777 /* Search the list upward for a heap which is large enough. */ 775 /* Search the list upward for a heap which is large enough. */
778 while ((char *) h->end < (char *) MEM_ROUNDUP ((char *) address + get)) 776 while ((char *) h->end < (char *) MEM_ROUNDUP ((char *) address + get))
@@ -780,7 +778,7 @@ r_alloc_sbrk (ptrdiff_t size)
780 h = h->next; 778 h = h->next;
781 if (h == NIL_HEAP) 779 if (h == NIL_HEAP)
782 break; 780 break;
783 address = (void *) ROUNDUP (h->start); 781 address = (void *) PAGE_ROUNDUP (h->start);
784 } 782 }
785 783
786 /* If not found, obtain more space. */ 784 /* If not found, obtain more space. */
@@ -792,9 +790,9 @@ r_alloc_sbrk (ptrdiff_t size)
792 return 0; 790 return 0;
793 791
794 if (first_heap == last_heap) 792 if (first_heap == last_heap)
795 address = (void *) ROUNDUP (virtual_break_value); 793 address = (void *) PAGE_ROUNDUP (virtual_break_value);
796 else 794 else
797 address = (void *) ROUNDUP (last_heap->start); 795 address = (void *) PAGE_ROUNDUP (last_heap->start);
798 h = last_heap; 796 h = last_heap;
799 } 797 }
800 798
@@ -1056,7 +1054,7 @@ r_alloc_check (void)
1056 for (h = first_heap; h; h = h->next) 1054 for (h = first_heap; h; h = h->next)
1057 { 1055 {
1058 assert (h->prev == ph); 1056 assert (h->prev == ph);
1059 assert ((void *) ROUNDUP (h->end) == h->end); 1057 assert ((void *) PAGE_ROUNDUP (h->end) == h->end);
1060#if 0 /* ??? The code in ralloc.c does not really try to ensure 1058#if 0 /* ??? The code in ralloc.c does not really try to ensure
1061 the heap start has any sort of alignment. 1059 the heap start has any sort of alignment.
1062 Perhaps it should. */ 1060 Perhaps it should. */
@@ -1192,7 +1190,7 @@ r_alloc_init (void)
1192 if (break_value == NULL) 1190 if (break_value == NULL)
1193 emacs_abort (); 1191 emacs_abort ();
1194 1192
1195 extra_bytes = ROUNDUP (50000); 1193 extra_bytes = PAGE_ROUNDUP (50000);
1196#endif 1194#endif
1197 1195
1198#ifdef DOUG_LEA_MALLOC 1196#ifdef DOUG_LEA_MALLOC
@@ -1214,7 +1212,7 @@ r_alloc_init (void)
1214#endif 1212#endif
1215 1213
1216#ifndef SYSTEM_MALLOC 1214#ifndef SYSTEM_MALLOC
1217 first_heap->end = (void *) ROUNDUP (first_heap->start); 1215 first_heap->end = (void *) PAGE_ROUNDUP (first_heap->start);
1218 1216
1219 /* The extra call to real_morecore guarantees that the end of the 1217 /* The extra call to real_morecore guarantees that the end of the
1220 address space is a multiple of page_size, even if page_size is 1218 address space is a multiple of page_size, even if page_size is