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 * $FreeBSD$ 40 */ 41 #pragma once 42 43 #include_next <sys/param.h> 44 45 #ifndef BLKDEV_IOSIZE 46 #define BLKDEV_IOSIZE PAGE_SIZE /* default block device I/O size */ 47 #endif 48 #ifndef DFLTPHYS 49 #define DFLTPHYS (64 * 1024) /* default max raw I/O transfer size */ 50 #endif 51 #ifndef MAXPHYS 52 #define MAXPHYS (128 * 1024) /* max raw I/O transfer size */ 53 #endif 54 #ifndef MAXDUMPPGS 55 #define MAXDUMPPGS (DFLTPHYS / PAGE_SIZE) 56 #endif 57 58 #ifndef MCLSHIFT 59 #define MCLSHIFT 11 /* convert bytes to mbuf clusters */ 60 #endif 61 62 #ifndef MCLBYTES 63 #define MCLBYTES (1 << MCLSHIFT) /* size of an mbuf cluster */ 64 #endif 65 66 #ifndef __PAST_END 67 #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) 68 #endif 69 70 #ifndef nitems 71 // https://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 72 #define nitems(x) \ 73 ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) 74 #endif 75 76 #ifndef rounddown 77 #define rounddown(x, y) (((x) / (y)) * (y)) 78 #endif 79 #ifndef rounddown2 80 #define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */ 81 #endif 82 #ifndef roundup 83 #define roundup(x, y) ((((x) + ((y)-1)) / (y)) * (y)) /* to any y */ 84 #endif 85 #ifndef roundup2 86 #define roundup2(x, y) \ 87 (((x) + ((y)-1)) & (~((y)-1))) /* if y is powers of two */ 88 #endif 89 #ifndef powerof2 90 #define powerof2(x) ((((x)-1) & (x)) == 0) 91 #endif 92