Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 471020 | Differences between
and this patch

Collapse All | Expand All

(-)a/include/sys/cdefs.h (+18 lines)
Lines 15-18 rtld_hidden_proto (__chk_fail) Link Here
15
15
16
#endif
16
#endif
17
17
18
/* Align a value by rounding down to closest size.
19
   e.g. Using size of 4096, we get this behavior:
20
	{4095, 4096, 4097} = {0, 4096, 4096}.  */
21
#define ALIGN_DOWN(base, size)	((base) & ~((size) - 1))
22
23
/* Align a value by rounding up to closest size.
24
   e.g. Using size of 4096, we get this behavior:
25
	{4095, 4096, 4097} = {4096, 4096, 8192}.  */
26
#define ALIGN_UP(base, size)	ALIGN_DOWN((base) + (size) - 1, (size))
27
28
/* Same as ALIGN_DOWN(), but automatically casts when base is a pointer.  */
29
#define PTR_ALIGN_DOWN(base, size) \
30
  (void *) ALIGN_DOWN ((uintptr_t) (base), (size))
31
32
/* Same as ALIGN_DOWN_UP(), but automatically casts when base is a pointer.  */
33
#define PTR_ALIGN_UP(base, size) \
34
  (void *) ALIGN_UP ((uintptr_t) (base), (size))
35
18
#endif
36
#endif
(-)a/locale/locarchive.h (+2 lines)
Lines 81-89 struct locrecent Link Here
81
struct locarhandle
81
struct locarhandle
82
{
82
{
83
  int fd;
83
  int fd;
84
  void *mmap_base;
84
  void *addr;
85
  void *addr;
85
  size_t mmaped;
86
  size_t mmaped;
86
  size_t reserved;
87
  size_t reserved;
88
  size_t mmap_len;
87
};
89
};
88
90
89
91
(-)a/locale/programs/locarchive.c (-17 / +46 lines)
Lines 37-42 Link Here
37
#include <stdint.h>
37
#include <stdint.h>
38
#include <sys/mman.h>
38
#include <sys/mman.h>
39
#include <sys/param.h>
39
#include <sys/param.h>
40
#include <sys/shm.h>
40
#include <sys/stat.h>
41
#include <sys/stat.h>
41
42
42
#include "../../crypt/md5.h"
43
#include "../../crypt/md5.h"
Lines 79-99 static const char *locnames[] = Link Here
79
   mapping affects the address selection.  So do this mapping from the
80
   mapping affects the address selection.  So do this mapping from the
80
   actual file, even though it's only a dummy to reserve address space.  */
81
   actual file, even though it's only a dummy to reserve address space.  */
81
static void *
82
static void *
82
prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags)
83
prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
84
		       void **mmap_base, size_t *mmap_len)
83
{
85
{
84
  if (total < RESERVE_MMAP_SIZE)
86
  if (total < RESERVE_MMAP_SIZE)
85
    {
87
    {
86
      void *p = mmap64 (NULL, RESERVE_MMAP_SIZE, PROT_NONE, MAP_SHARED, fd, 0);
88
      void *p = mmap64 (NULL, RESERVE_MMAP_SIZE, PROT_NONE, MAP_SHARED, fd, 0);
87
      if (p != MAP_FAILED)
89
      if (p != MAP_FAILED)
88
        {
90
	{
89
          *reserved = RESERVE_MMAP_SIZE;
91
	  /* Some arches require fixed mappings to be aligned higher than
90
          *xflags = MAP_FIXED;
92
	     pagesize, and SHMLBA represents that size.  */
91
          return p;
93
	  void *aligned_p = PTR_ALIGN_UP (p, SHMLBA);
92
        }
94
	  size_t align_adjust = aligned_p - p;
95
	  *mmap_base = p;
96
	  *mmap_len = RESERVE_MMAP_SIZE;
97
	  assert (align_adjust < RESERVE_MMAP_SIZE);
98
	  *reserved = RESERVE_MMAP_SIZE - align_adjust;
99
	  *xflags = MAP_FIXED;
100
	  return aligned_p;
101
	}
93
    }
102
    }
94
103
95
  *reserved = total;
104
  *reserved = total;
96
  *xflags = 0;
105
  *xflags = 0;
106
  *mmap_base = NULL;
107
  *mmap_len = 0;
97
  return NULL;
108
  return NULL;
98
}
109
}
99
110
Lines 151-159 create_archive (const char *archivefname, struct locarhandle *ah) Link Here
151
      error (EXIT_FAILURE, errval, _("cannot resize archive file"));
162
      error (EXIT_FAILURE, errval, _("cannot resize archive file"));
152
    }
163
    }
153
164
154
  size_t reserved;
165
  size_t reserved, mmap_len;
155
  int xflags;
166
  int xflags;
156
  void *p = prepare_address_space (fd, total, &reserved, &xflags);
167
  void *mmap_base;
168
  void *p = prepare_address_space (fd, total, &reserved, &xflags, &mmap_base,
169
				   &mmap_len);
157
170
158
  /* Map the header and all the administration data structures.  */
171
  /* Map the header and all the administration data structures.  */
159
  p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
172
  p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
Lines 199-204 create_archive (const char *archivefname, struct locarhandle *ah) Link Here
199
    }
212
    }
200
213
201
  ah->fd = fd;
214
  ah->fd = fd;
215
  ah->mmap_base = mmap_base;
216
  ah->mmap_len = mmap_len;
202
  ah->addr = p;
217
  ah->addr = p;
203
  ah->mmaped = total;
218
  ah->mmaped = total;
204
  ah->reserved = reserved;
219
  ah->reserved = reserved;
Lines 271-278 file_data_available_p (struct locarhandle *ah, uint32_t offset, uint32_t size) Link Here
271
  if (st.st_size > ah->reserved)
286
  if (st.st_size > ah->reserved)
272
    return false;
287
    return false;
273
288
274
  const size_t pagesz = getpagesize ();
289
  size_t start = ah->mmaped & ~(SHMLBA - 1);
275
  size_t start = ah->mmaped & ~(pagesz - 1);
276
  void *p = mmap64 (ah->addr + start, st.st_size - start,
290
  void *p = mmap64 (ah->addr + start, st.st_size - start,
277
		    PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
291
		    PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
278
		    ah->fd, start);
292
		    ah->fd, start);
Lines 332-341 enlarge_archive (struct locarhandle *ah, const struct locarhead *head) Link Here
332
		       MAP_SHARED | MAP_FIXED, ah->fd, 0);
346
		       MAP_SHARED | MAP_FIXED, ah->fd, 0);
333
  else
347
  else
334
    {
348
    {
335
      munmap (ah->addr, ah->reserved);
349
      if (ah->mmap_base)
350
	munmap (ah->mmap_base, ah->mmap_len);
351
      else
352
	munmap (ah->addr, ah->reserved);
336
      ah->addr = mmap64 (NULL, st.st_size, PROT_READ | PROT_WRITE,
353
      ah->addr = mmap64 (NULL, st.st_size, PROT_READ | PROT_WRITE,
337
			 MAP_SHARED, ah->fd, 0);
354
			 MAP_SHARED, ah->fd, 0);
338
      ah->reserved = st.st_size;
355
      ah->reserved = st.st_size;
356
      ah->mmap_base = NULL;
357
      ah->mmap_len = 0;
339
      head = ah->addr;
358
      head = ah->addr;
340
    }
359
    }
341
  if (ah->addr == MAP_FAILED)
360
  if (ah->addr == MAP_FAILED)
Lines 401-409 enlarge_archive (struct locarhandle *ah, const struct locarhead *head) Link Here
401
      error (EXIT_FAILURE, errval, _("cannot resize archive file"));
420
      error (EXIT_FAILURE, errval, _("cannot resize archive file"));
402
    }
421
    }
403
422
404
  size_t reserved;
423
  size_t reserved, mmap_len;
405
  int xflags;
424
  int xflags;
406
  void *p = prepare_address_space (fd, total, &reserved, &xflags);
425
  void *mmap_base;
426
  void *p = prepare_address_space (fd, total, &reserved, &xflags, &mmap_base,
427
				   &mmap_len);
407
428
408
  /* Map the header and all the administration data structures.  */
429
  /* Map the header and all the administration data structures.  */
409
  p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
430
  p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
Lines 423-428 enlarge_archive (struct locarhandle *ah, const struct locarhead *head) Link Here
423
    }
444
    }
424
445
425
  new_ah.mmaped = total;
446
  new_ah.mmaped = total;
447
  new_ah.mmap_base = mmap_base;
448
  new_ah.mmap_len = mmap_len;
426
  new_ah.addr = p;
449
  new_ah.addr = p;
427
  new_ah.fd = fd;
450
  new_ah.fd = fd;
428
  new_ah.reserved = reserved;
451
  new_ah.reserved = reserved;
Lines 606-614 open_archive (struct locarhandle *ah, bool readonly) Link Here
606
  ah->fd = fd;
629
  ah->fd = fd;
607
  ah->mmaped = st.st_size;
630
  ah->mmaped = st.st_size;
608
631
609
  size_t reserved;
632
  size_t reserved, mmap_len;
610
  int xflags;
633
  int xflags;
611
  void *p = prepare_address_space (fd, st.st_size, &reserved, &xflags);
634
  void *mmap_base;
635
  void *p = prepare_address_space (fd, st.st_size, &reserved, &xflags,
636
				   &mmap_base, &mmap_len);
612
637
613
  /* Map the entire file.  We might need to compare the category data
638
  /* Map the entire file.  We might need to compare the category data
614
     in the file with the newly added data.  */
639
     in the file with the newly added data.  */
Lines 620-625 open_archive (struct locarhandle *ah, bool readonly) Link Here
620
      error (EXIT_FAILURE, errno, _("cannot map archive header"));
645
      error (EXIT_FAILURE, errno, _("cannot map archive header"));
621
    }
646
    }
622
  ah->reserved = reserved;
647
  ah->reserved = reserved;
648
  ah->mmap_base = mmap_base;
649
  ah->mmap_len = mmap_len;
623
}
650
}
624
651
625
652
Lines 628-634 close_archive (struct locarhandle *ah) Link Here
628
{
655
{
629
  if (ah->fd != -1)
656
  if (ah->fd != -1)
630
    {
657
    {
631
      munmap (ah->addr, ah->reserved);
658
      if (ah->mmap_base)
659
	munmap (ah->mmap_base, ah->mmap_len);
660
      else
661
	munmap (ah->addr, ah->reserved);
632
      close (ah->fd);
662
      close (ah->fd);
633
    }
663
    }
634
}
664
}
635
- 

Return to bug 471020