1dcc6ef16SKonstantin Belousov /*-
2dcc6ef16SKonstantin Belousov * Copyright (c) 2020 The FreeBSD Foundation
3dcc6ef16SKonstantin Belousov *
4dcc6ef16SKonstantin Belousov * This software was developed by Konstantin Belousov
5dcc6ef16SKonstantin Belousov * under sponsorship from the FreeBSD Foundation.
6dcc6ef16SKonstantin Belousov *
7dcc6ef16SKonstantin Belousov * Redistribution and use in source and binary forms, with or without
8dcc6ef16SKonstantin Belousov * modification, are permitted provided that the following conditions
9dcc6ef16SKonstantin Belousov * are met:
10dcc6ef16SKonstantin Belousov * 1. Redistributions of source code must retain the above copyright
11dcc6ef16SKonstantin Belousov * notice, this list of conditions and the following disclaimer.
12dcc6ef16SKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright
13dcc6ef16SKonstantin Belousov * notice, this list of conditions and the following disclaimer in the
14dcc6ef16SKonstantin Belousov * documentation and/or other materials provided with the distribution.
15dcc6ef16SKonstantin Belousov *
16dcc6ef16SKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17dcc6ef16SKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18dcc6ef16SKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19dcc6ef16SKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20dcc6ef16SKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21dcc6ef16SKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22dcc6ef16SKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23dcc6ef16SKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24dcc6ef16SKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25dcc6ef16SKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26dcc6ef16SKonstantin Belousov * SUCH DAMAGE.
27dcc6ef16SKonstantin Belousov */
28dcc6ef16SKonstantin Belousov
29dcc6ef16SKonstantin Belousov #include <sys/param.h>
30dcc6ef16SKonstantin Belousov #include <stdlib.h>
31dcc6ef16SKonstantin Belousov
32dcc6ef16SKonstantin Belousov void *
memalign(size_t align,size_t size)33dcc6ef16SKonstantin Belousov memalign(size_t align, size_t size)
34dcc6ef16SKonstantin Belousov {
35*2c709ee7SPaul Floyd /*
36*2c709ee7SPaul Floyd * glibc allows align == 0, but that is not valid for roundup.
37*2c709ee7SPaul Floyd * Just pass through to malloc in that case.
38*2c709ee7SPaul Floyd */
39*2c709ee7SPaul Floyd if (align != 0)
40dcc6ef16SKonstantin Belousov return (aligned_alloc(align, roundup(size, align)));
41*2c709ee7SPaul Floyd else
42*2c709ee7SPaul Floyd return (malloc(size));
43dcc6ef16SKonstantin Belousov }
44