1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright 2018-2020 Alex Richardson <arichardson@FreeBSD.org> 5 * 6 * This software was developed by SRI International and the University of 7 * Cambridge Computer Laboratory (Department of Computer Science and 8 * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the 9 * DARPA SSITH research programme. 10 * 11 * This software was developed by SRI International and the University of 12 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 13 * ("CTSRD"), as part of the DARPA CRASH research programme. 14 * 15 * This work was supported by Innovate UK project 105694, "Digital Security by 16 * Design (DSbD) Technology Platform Prototype". 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions 20 * are met: 21 * 1. Redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer. 23 * 2. Redistributions in binary form must reproduce the above copyright 24 * notice, this list of conditions and the following disclaimer in the 25 * documentation and/or other materials provided with the distribution. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 */ 39 #pragma once 40 41 #include_next <sys/param.h> 42 43 #ifndef BLKDEV_IOSIZE 44 #define BLKDEV_IOSIZE PAGE_SIZE /* default block device I/O size */ 45 #endif 46 #ifndef DFLTPHYS 47 #define DFLTPHYS (64 * 1024) /* default max raw I/O transfer size */ 48 #endif 49 #ifndef MAXPHYS 50 #define MAXPHYS (128 * 1024) /* max raw I/O transfer size */ 51 #endif 52 #ifndef MAXDUMPPGS 53 #define MAXDUMPPGS (DFLTPHYS / PAGE_SIZE) 54 #endif 55 56 #ifndef MCLSHIFT 57 #define MCLSHIFT 11 /* convert bytes to mbuf clusters */ 58 #endif 59 60 #ifndef MCLBYTES 61 #define MCLBYTES (1 << MCLSHIFT) /* size of an mbuf cluster */ 62 #endif 63 64 #ifndef __PAST_END 65 #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) 66 #endif 67 68 #ifndef nitems 69 // https://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 70 #define nitems(x) \ 71 ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) 72 #endif 73 74 #ifndef rounddown 75 #define rounddown(x, y) (((x) / (y)) * (y)) 76 #endif 77 #ifndef rounddown2 78 #define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */ 79 #endif 80 #ifndef roundup 81 #define roundup(x, y) ((((x) + ((y)-1)) / (y)) * (y)) /* to any y */ 82 #endif 83 #ifndef roundup2 84 #define roundup2(x, y) \ 85 (((x) + ((y)-1)) & (~((y)-1))) /* if y is powers of two */ 86 #endif 87 #ifndef powerof2 88 #define powerof2(x) ((((x)-1) & (x)) == 0) 89 #endif 90