jcs's openbsd hax
openbsd

- fix bug wrt posix_memalign(3) of blocks between half a page and a page - document posix_memalign() does not play nice with reacallocarray(3) and freezero(3)

otto 48c91247 f360c371

+18 -8
+9 -4
lib/libc/stdlib/malloc.c
··· 1 - /* $OpenBSD: malloc.c,v 1.224 2017/04/22 09:12:49 otto Exp $ */ 1 + /* $OpenBSD: malloc.c,v 1.225 2017/05/13 07:11:29 otto Exp $ */ 2 2 /* 3 3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> 4 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> ··· 1974 1974 } 1975 1975 1976 1976 static void * 1977 - omemalign(struct dir_info *pool, size_t alignment, size_t sz, int zero_fill, void *f) 1977 + omemalign(struct dir_info *pool, size_t alignment, size_t sz, int zero_fill, 1978 + void *f) 1978 1979 { 1979 1980 size_t psz; 1980 1981 void *p; 1981 1982 1983 + /* If between half a page and a page, avoid MALLOC_MOVE. */ 1984 + if (sz > MALLOC_MAXCHUNK && sz < MALLOC_PAGESIZE) 1985 + sz = MALLOC_PAGESIZE; 1982 1986 if (alignment <= MALLOC_PAGESIZE) { 1983 1987 /* 1984 - * max(size, alignment) is enough to assure the requested alignment, 1985 - * since the allocator always allocates power-of-two blocks. 1988 + * max(size, alignment) is enough to assure the requested 1989 + * alignment, since the allocator always allocates 1990 + * power-of-two blocks. 1986 1991 */ 1987 1992 if (sz < alignment) 1988 1993 sz = alignment;
+9 -4
lib/libc/stdlib/posix_memalign.3
··· 1 - .\" $OpenBSD: posix_memalign.3,v 1.3 2012/06/18 17:03:52 matthew Exp $ 1 + .\" $OpenBSD: posix_memalign.3,v 1.4 2017/05/13 07:11:29 otto Exp $ 2 2 .\" Copyright (C) 2006 Jason Evans <jasone@FreeBSD.org>. 3 3 .\" All rights reserved. 4 4 .\" ··· 28 28 .\" 29 29 .\" $FreeBSD: src/lib/libc/stdlib/posix_memalign.3,v 1.3 2007/03/28 04:32:51 jasone Exp $ 30 30 .\" 31 - .Dd $Mdocdate: June 18 2012 $ 31 + .Dd $Mdocdate: May 13 2017 $ 32 32 .Dt POSIX_MEMALIGN 3 33 33 .Os 34 34 .Sh NAME ··· 56 56 Memory that is allocated via 57 57 .Fn posix_memalign 58 58 can be used as an argument in subsequent calls to 59 - .Xr realloc 3 59 + .Xr realloc 3 , 60 + .Xr reallocarray 3 61 + and 62 + .Xr free 3 , 63 + but not 64 + .Xr recallocarray 3 60 65 and 61 - .Xr free 3 . 66 + .Xr freezero 3 . 62 67 .Sh RETURN VALUES 63 68 The 64 69 .Fn posix_memalign