diff options
| author | Paul Eggert | 2011-07-10 23:05:57 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-10 23:05:57 -0700 |
| commit | da85a02af7585384008d3ebec836a7b8571f175d (patch) | |
| tree | e6d4f34119ea1c45985eaed207ef6b47f650ea93 /src/buffer.c | |
| parent | 7f5515125fbc9b46454e1f84b7e3052a0a5326f0 (diff) | |
| parent | 4d45a8b7a237e1d33d0ae71d95a0ed7165ea6cda (diff) | |
| download | emacs-da85a02af7585384008d3ebec836a7b8571f175d.tar.gz emacs-da85a02af7585384008d3ebec836a7b8571f175d.zip | |
Merge from trunk.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 115 |
1 files changed, 47 insertions, 68 deletions
diff --git a/src/buffer.c b/src/buffer.c index 48dde18b02c..05e96e85112 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -4466,24 +4466,40 @@ static int mmap_initialized_p; | |||
| 4466 | #define MMAP_ALLOCATED_P(start, end) 1 | 4466 | #define MMAP_ALLOCATED_P(start, end) 1 |
| 4467 | #endif | 4467 | #endif |
| 4468 | 4468 | ||
| 4469 | /* Function prototypes. */ | 4469 | /* Perform necessary intializations for the use of mmap. */ |
| 4470 | 4470 | ||
| 4471 | static int mmap_free_1 (struct mmap_region *); | 4471 | static void |
| 4472 | static int mmap_enlarge (struct mmap_region *, int); | 4472 | mmap_init (void) |
| 4473 | static struct mmap_region *mmap_find (POINTER_TYPE *, POINTER_TYPE *); | 4473 | { |
| 4474 | static POINTER_TYPE *mmap_alloc (POINTER_TYPE **, size_t); | 4474 | #if MAP_ANON == 0 |
| 4475 | static POINTER_TYPE *mmap_realloc (POINTER_TYPE **, size_t); | 4475 | /* The value of mmap_fd is initially 0 in temacs, and -1 |
| 4476 | static void mmap_free (POINTER_TYPE **ptr); | 4476 | in a dumped Emacs. */ |
| 4477 | static void mmap_init (void); | 4477 | if (mmap_fd <= 0) |
| 4478 | { | ||
| 4479 | /* No anonymous mmap -- we need the file descriptor. */ | ||
| 4480 | mmap_fd = open ("/dev/zero", O_RDONLY); | ||
| 4481 | if (mmap_fd == -1) | ||
| 4482 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); | ||
| 4483 | } | ||
| 4484 | #endif /* MAP_ANON == 0 */ | ||
| 4485 | |||
| 4486 | if (mmap_initialized_p) | ||
| 4487 | return; | ||
| 4488 | mmap_initialized_p = 1; | ||
| 4478 | 4489 | ||
| 4490 | #if MAP_ANON != 0 | ||
| 4491 | mmap_fd = -1; | ||
| 4492 | #endif | ||
| 4493 | |||
| 4494 | mmap_page_size = getpagesize (); | ||
| 4495 | } | ||
| 4479 | 4496 | ||
| 4480 | /* Return a region overlapping address range START...END, or null if | 4497 | /* Return a region overlapping address range START...END, or null if |
| 4481 | none. END is not including, i.e. the last byte in the range | 4498 | none. END is not including, i.e. the last byte in the range |
| 4482 | is at END - 1. */ | 4499 | is at END - 1. */ |
| 4483 | 4500 | ||
| 4484 | static struct mmap_region * | 4501 | static struct mmap_region * |
| 4485 | mmap_find (start, end) | 4502 | mmap_find (POINTER_TYPE *start, POINTER_TYPE *end); |
| 4486 | POINTER_TYPE *start, *end; | ||
| 4487 | { | 4503 | { |
| 4488 | struct mmap_region *r; | 4504 | struct mmap_region *r; |
| 4489 | char *s = (char *) start, *e = (char *) end; | 4505 | char *s = (char *) start, *e = (char *) end; |
| @@ -4512,8 +4528,7 @@ mmap_find (start, end) | |||
| 4512 | the region. Value is non-zero if successful. */ | 4528 | the region. Value is non-zero if successful. */ |
| 4513 | 4529 | ||
| 4514 | static int | 4530 | static int |
| 4515 | mmap_free_1 (r) | 4531 | mmap_free_1 (struct mmap_region *r) |
| 4516 | struct mmap_region *r; | ||
| 4517 | { | 4532 | { |
| 4518 | if (r->next) | 4533 | if (r->next) |
| 4519 | r->next->prev = r->prev; | 4534 | r->next->prev = r->prev; |
| @@ -4536,9 +4551,7 @@ mmap_free_1 (r) | |||
| 4536 | Value is non-zero if successful. */ | 4551 | Value is non-zero if successful. */ |
| 4537 | 4552 | ||
| 4538 | static int | 4553 | static int |
| 4539 | mmap_enlarge (r, npages) | 4554 | mmap_enlarge (struct mmap_region *r, int npages) |
| 4540 | struct mmap_region *r; | ||
| 4541 | int npages; | ||
| 4542 | { | 4555 | { |
| 4543 | char *region_end = (char *) r + r->nbytes_mapped; | 4556 | char *region_end = (char *) r + r->nbytes_mapped; |
| 4544 | size_t nbytes; | 4557 | size_t nbytes; |
| @@ -4602,8 +4615,7 @@ mmap_enlarge (r, npages) | |||
| 4602 | when Emacs starts. */ | 4615 | when Emacs starts. */ |
| 4603 | 4616 | ||
| 4604 | void | 4617 | void |
| 4605 | mmap_set_vars (restore_p) | 4618 | mmap_set_vars (int restore_p) |
| 4606 | int restore_p; | ||
| 4607 | { | 4619 | { |
| 4608 | struct mmap_region *r; | 4620 | struct mmap_region *r; |
| 4609 | 4621 | ||
| @@ -4636,9 +4648,7 @@ mmap_set_vars (restore_p) | |||
| 4636 | return null. */ | 4648 | return null. */ |
| 4637 | 4649 | ||
| 4638 | static POINTER_TYPE * | 4650 | static POINTER_TYPE * |
| 4639 | mmap_alloc (var, nbytes) | 4651 | mmap_alloc (POINTER_TYPE **var, size_t nbytes) |
| 4640 | POINTER_TYPE **var; | ||
| 4641 | size_t nbytes; | ||
| 4642 | { | 4652 | { |
| 4643 | void *p; | 4653 | void *p; |
| 4644 | size_t map; | 4654 | size_t map; |
| @@ -4675,15 +4685,29 @@ mmap_alloc (var, nbytes) | |||
| 4675 | } | 4685 | } |
| 4676 | 4686 | ||
| 4677 | 4687 | ||
| 4688 | /* Free a block of relocatable storage whose data is pointed to by | ||
| 4689 | PTR. Store 0 in *PTR to show there's no block allocated. */ | ||
| 4690 | |||
| 4691 | static void | ||
| 4692 | mmap_free (POINTER_TYPE **var) | ||
| 4693 | { | ||
| 4694 | mmap_init (); | ||
| 4695 | |||
| 4696 | if (*var) | ||
| 4697 | { | ||
| 4698 | mmap_free_1 (MMAP_REGION (*var)); | ||
| 4699 | *var = NULL; | ||
| 4700 | } | ||
| 4701 | } | ||
| 4702 | |||
| 4703 | |||
| 4678 | /* Given a pointer at address VAR to data allocated with mmap_alloc, | 4704 | /* Given a pointer at address VAR to data allocated with mmap_alloc, |
| 4679 | resize it to size NBYTES. Change *VAR to reflect the new block, | 4705 | resize it to size NBYTES. Change *VAR to reflect the new block, |
| 4680 | and return this value. If more memory cannot be allocated, then | 4706 | and return this value. If more memory cannot be allocated, then |
| 4681 | leave *VAR unchanged, and return null. */ | 4707 | leave *VAR unchanged, and return null. */ |
| 4682 | 4708 | ||
| 4683 | static POINTER_TYPE * | 4709 | static POINTER_TYPE * |
| 4684 | mmap_realloc (var, nbytes) | 4710 | mmap_realloc (POINTER_TYPE **var, size_t nbytes) |
| 4685 | POINTER_TYPE **var; | ||
| 4686 | size_t nbytes; | ||
| 4687 | { | 4711 | { |
| 4688 | POINTER_TYPE *result; | 4712 | POINTER_TYPE *result; |
| 4689 | 4713 | ||
| @@ -4753,51 +4777,6 @@ mmap_realloc (var, nbytes) | |||
| 4753 | } | 4777 | } |
| 4754 | 4778 | ||
| 4755 | 4779 | ||
| 4756 | /* Free a block of relocatable storage whose data is pointed to by | ||
| 4757 | PTR. Store 0 in *PTR to show there's no block allocated. */ | ||
| 4758 | |||
| 4759 | static void | ||
| 4760 | mmap_free (var) | ||
| 4761 | POINTER_TYPE **var; | ||
| 4762 | { | ||
| 4763 | mmap_init (); | ||
| 4764 | |||
| 4765 | if (*var) | ||
| 4766 | { | ||
| 4767 | mmap_free_1 (MMAP_REGION (*var)); | ||
| 4768 | *var = NULL; | ||
| 4769 | } | ||
| 4770 | } | ||
| 4771 | |||
| 4772 | |||
| 4773 | /* Perform necessary intializations for the use of mmap. */ | ||
| 4774 | |||
| 4775 | static void | ||
| 4776 | mmap_init () | ||
| 4777 | { | ||
| 4778 | #if MAP_ANON == 0 | ||
| 4779 | /* The value of mmap_fd is initially 0 in temacs, and -1 | ||
| 4780 | in a dumped Emacs. */ | ||
| 4781 | if (mmap_fd <= 0) | ||
| 4782 | { | ||
| 4783 | /* No anonymous mmap -- we need the file descriptor. */ | ||
| 4784 | mmap_fd = open ("/dev/zero", O_RDONLY); | ||
| 4785 | if (mmap_fd == -1) | ||
| 4786 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); | ||
| 4787 | } | ||
| 4788 | #endif /* MAP_ANON == 0 */ | ||
| 4789 | |||
| 4790 | if (mmap_initialized_p) | ||
| 4791 | return; | ||
| 4792 | mmap_initialized_p = 1; | ||
| 4793 | |||
| 4794 | #if MAP_ANON != 0 | ||
| 4795 | mmap_fd = -1; | ||
| 4796 | #endif | ||
| 4797 | |||
| 4798 | mmap_page_size = getpagesize (); | ||
| 4799 | } | ||
| 4800 | |||
| 4801 | #endif /* USE_MMAP_FOR_BUFFERS */ | 4780 | #endif /* USE_MMAP_FOR_BUFFERS */ |
| 4802 | 4781 | ||
| 4803 | 4782 | ||