Mercurial > emacs
comparison src/ralloc.c @ 31525:5b50ac5d207d
(mmap_enlarge): Don't return 0 if successful.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sun, 10 Sep 2000 11:17:26 +0000 |
parents | 92dec3ff92a1 |
children | f0f7e75e83c4 |
comparison
equal
deleted
inserted
replaced
31524:3935d834ff04 | 31525:5b50ac5d207d |
---|---|
1387 struct mmap_region *r; | 1387 struct mmap_region *r; |
1388 int npages; | 1388 int npages; |
1389 { | 1389 { |
1390 char *region_end = (char *) r + r->nbytes_mapped; | 1390 char *region_end = (char *) r + r->nbytes_mapped; |
1391 size_t nbytes; | 1391 size_t nbytes; |
1392 int success = 1; | 1392 int success = 0; |
1393 | 1393 |
1394 if (npages < 0) | 1394 if (npages < 0) |
1395 { | 1395 { |
1396 /* Unmap pages at the end of the region. */ | 1396 /* Unmap pages at the end of the region. */ |
1397 nbytes = - npages * page_size; | 1397 nbytes = - npages * page_size; |
1398 if (munmap (region_end - nbytes, nbytes) == -1) | 1398 if (munmap (region_end - nbytes, nbytes) == -1) |
1399 { | 1399 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); |
1400 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); | |
1401 success = 0; | |
1402 } | |
1403 else | 1400 else |
1404 r->nbytes_mapped -= nbytes; | 1401 { |
1402 r->nbytes_mapped -= nbytes; | |
1403 success = 1; | |
1404 } | |
1405 } | 1405 } |
1406 else if (npages > 0) | 1406 else if (npages > 0) |
1407 { | 1407 { |
1408 struct mmap_region *r2; | |
1409 | |
1408 nbytes = npages * page_size; | 1410 nbytes = npages * page_size; |
1409 | 1411 |
1410 /* Try to map additional pages at the end of the region. We | 1412 /* Try to map additional pages at the end of the region. We |
1411 cannot do this if the address range is already occupied by | 1413 cannot do this if the address range is already occupied by |
1412 something else because mmap deletes any previous mapping. | 1414 something else because mmap deletes any previous mapping. |
1413 I'm not sure this is worth doing, let's see. */ | 1415 I'm not sure this is worth doing, let's see. */ |
1414 if (mmap_find (region_end, region_end + nbytes)) | 1416 r2 = mmap_find (region_end, region_end + nbytes); |
1415 success = 0; | 1417 if (r2 == NULL) |
1416 else | |
1417 { | 1418 { |
1418 POINTER_TYPE *p; | 1419 POINTER_TYPE *p; |
1419 | 1420 |
1420 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, | 1421 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, |
1421 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0); | 1422 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0); |
1422 if (p == MAP_FAILED) | 1423 if (p == MAP_FAILED) |
1423 { | 1424 fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); |
1424 fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); | |
1425 success = 0; | |
1426 } | |
1427 else if (p != (POINTER_TYPE *) region_end) | 1425 else if (p != (POINTER_TYPE *) region_end) |
1428 { | 1426 { |
1429 /* Kernels are free to choose a different address. In | 1427 /* Kernels are free to choose a different address. In |
1430 that case, unmap what we've mapped above; we have | 1428 that case, unmap what we've mapped above; we have |
1431 no use for it. */ | 1429 no use for it. */ |
1432 if (munmap (p, nbytes) == -1) | 1430 if (munmap (p, nbytes) == -1) |
1433 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); | 1431 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); |
1434 success = 0; | |
1435 } | 1432 } |
1436 else | 1433 else |
1437 r->nbytes_mapped += nbytes; | 1434 { |
1438 } | 1435 r->nbytes_mapped += nbytes; |
1439 | 1436 success = 1; |
1440 success = 0; | 1437 } |
1438 } | |
1441 } | 1439 } |
1442 | 1440 |
1443 return success; | 1441 return success; |
1444 } | 1442 } |
1445 | 1443 |