Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 568714
Collapse All | Expand All

(-)a/libsandbox/memory.c (-3 / +3 lines)
Lines 40-46 static int sb_munmap(void *addr, size_t length) Link Here
40
40
41
#define SB_MALLOC_TO_MMAP(ptr) ((void*)((uintptr_t)(ptr) - MIN_ALIGN))
41
#define SB_MALLOC_TO_MMAP(ptr) ((void*)((uintptr_t)(ptr) - MIN_ALIGN))
42
#define SB_MMAP_TO_MALLOC(ptr) ((void*)((uintptr_t)(ptr) + MIN_ALIGN))
42
#define SB_MMAP_TO_MALLOC(ptr) ((void*)((uintptr_t)(ptr) + MIN_ALIGN))
43
#define SB_MALLOC_TO_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr)))
43
#define SB_MALLOC_TO_MMAP_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr)))
44
44
45
void *malloc(size_t size)
45
void *malloc(size_t size)
46
{
46
{
Lines 57-63 void free(void *ptr) Link Here
57
{
57
{
58
	if (ptr == NULL)
58
	if (ptr == NULL)
59
		return;
59
		return;
60
	if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_SIZE(ptr)))
60
	if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_MMAP_SIZE(ptr)))
61
		sb_ebort("sandbox memory corruption with free(%p): %s\n",
61
		sb_ebort("sandbox memory corruption with free(%p): %s\n",
62
			ptr, strerror(errno));
62
			ptr, strerror(errno));
63
}
63
}
Lines 83-89 void *realloc(void *ptr, size_t size) Link Here
83
		return ptr;
83
		return ptr;
84
	}
84
	}
85
85
86
	old_malloc_size = SB_MALLOC_TO_SIZE(ptr);
86
	old_malloc_size = SB_MALLOC_TO_MMAP_SIZE(ptr) - MIN_ALIGN;
87
	/* Since mmap() is heavy, don't bother shrinking */
87
	/* Since mmap() is heavy, don't bother shrinking */
88
	if (size <= old_malloc_size)
88
	if (size <= old_malloc_size)
89
		return ptr;
89
		return ptr;

Return to bug 568714