diff options
| author | Eli Zaretskii | 2014-06-02 20:08:50 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2014-06-02 20:08:50 +0300 |
| commit | 0dd0ad374ba839a268e864512886aebbe5d49dca (patch) | |
| tree | a8b0dd9a8d5cad951b554b37de0d1b960dd98b37 /src/w32heap.c | |
| parent | 7973d8d5facf11b6408f8e17c9ad11efc7ff6eba (diff) | |
| download | emacs-0dd0ad374ba839a268e864512886aebbe5d49dca.tar.gz emacs-0dd0ad374ba839a268e864512886aebbe5d49dca.zip | |
Minor improvement of sbrk emulation on MS-Windows.
src/w32heap.c (malloc_after_dump, realloc_after_dump): Update the
emulated break value only if it goes up.
(sbrk): Add assertion that the INCREMENT argument is strictly
zero. Improve and correct the commentary.
Diffstat (limited to 'src/w32heap.c')
| -rw-r--r-- | src/w32heap.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/w32heap.c b/src/w32heap.c index 523df909165..c0a17551d27 100644 --- a/src/w32heap.c +++ b/src/w32heap.c | |||
| @@ -299,9 +299,14 @@ malloc_after_dump (size_t size) | |||
| 299 | /* Use the new private heap. */ | 299 | /* Use the new private heap. */ |
| 300 | void *p = HeapAlloc (heap, 0, size); | 300 | void *p = HeapAlloc (heap, 0, size); |
| 301 | 301 | ||
| 302 | /* After dump, keep track of the last allocated byte for sbrk(0). */ | 302 | /* After dump, keep track of the "brk value" for sbrk(0). */ |
| 303 | if (p) | 303 | if (p) |
| 304 | data_region_end = p + size - 1; | 304 | { |
| 305 | unsigned char *new_brk = (unsigned char *)p + size; | ||
| 306 | |||
| 307 | if (new_brk > data_region_end) | ||
| 308 | data_region_end = new_brk; | ||
| 309 | } | ||
| 305 | else | 310 | else |
| 306 | errno = ENOMEM; | 311 | errno = ENOMEM; |
| 307 | return p; | 312 | return p; |
| @@ -391,9 +396,14 @@ realloc_after_dump (void *ptr, size_t size) | |||
| 391 | else | 396 | else |
| 392 | errno = ENOMEM; | 397 | errno = ENOMEM; |
| 393 | } | 398 | } |
| 394 | /* After dump, keep track of the last allocated byte for sbrk(0). */ | 399 | /* After dump, keep track of the "brk value" for sbrk(0). */ |
| 395 | if (p) | 400 | if (p) |
| 396 | data_region_end = p + size - 1; | 401 | { |
| 402 | unsigned char *new_brk = (unsigned char *)p + size; | ||
| 403 | |||
| 404 | if (new_brk > data_region_end) | ||
| 405 | data_region_end = new_brk; | ||
| 406 | } | ||
| 397 | return p; | 407 | return p; |
| 398 | } | 408 | } |
| 399 | 409 | ||
| @@ -497,10 +507,11 @@ getpagesize (void) | |||
| 497 | void * | 507 | void * |
| 498 | sbrk (ptrdiff_t increment) | 508 | sbrk (ptrdiff_t increment) |
| 499 | { | 509 | { |
| 500 | /* The data_region_end address is the one of the last byte | 510 | /* data_region_end is the address beyond the last allocated byte. |
| 501 | allocated. The sbrk() function is not emulated at all, except | 511 | The sbrk() function is not emulated at all, except for a 0 value |
| 502 | for a 0 value of its parameter. This is needed by the emacs lisp | 512 | of its parameter. This is needed by the Emacs Lisp function |
| 503 | function `memory-limit'. */ | 513 | `memory-limit'. */ |
| 514 | eassert (increment == 0); | ||
| 504 | return data_region_end; | 515 | return data_region_end; |
| 505 | } | 516 | } |
| 506 | 517 | ||