Path: blob/main/tools/build/cross-build/include/common/sys/param.h
39587 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright 2018-2020 Alex Richardson <[email protected]>4*5* This software was developed by SRI International and the University of6* Cambridge Computer Laboratory (Department of Computer Science and7* Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the8* DARPA SSITH research programme.9*10* This software was developed by SRI International and the University of11* Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)12* ("CTSRD"), as part of the DARPA CRASH research programme.13*14* This work was supported by Innovate UK project 105694, "Digital Security by15* Design (DSbD) Technology Platform Prototype".16*17* Redistribution and use in source and binary forms, with or without18* modification, are permitted provided that the following conditions19* are met:20* 1. Redistributions of source code must retain the above copyright21* notice, this list of conditions and the following disclaimer.22* 2. Redistributions in binary form must reproduce the above copyright23* notice, this list of conditions and the following disclaimer in the24* documentation and/or other materials provided with the distribution.25*26* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND27* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE30* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL31* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS32* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)33* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT34* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY35* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF36* SUCH DAMAGE.37*/38#pragma once3940#include_next <sys/param.h>4142#ifndef BLKDEV_IOSIZE43#define BLKDEV_IOSIZE PAGE_SIZE /* default block device I/O size */44#endif45#ifndef DFLTPHYS46#define DFLTPHYS (64 * 1024) /* default max raw I/O transfer size */47#endif48#ifndef MAXPHYS49#define MAXPHYS (128 * 1024) /* max raw I/O transfer size */50#endif51#ifndef MAXDUMPPGS52#define MAXDUMPPGS (DFLTPHYS / PAGE_SIZE)53#endif5455#ifndef MCLSHIFT56#define MCLSHIFT 11 /* convert bytes to mbuf clusters */57#endif5859#ifndef MCLBYTES60#define MCLBYTES (1 << MCLSHIFT) /* size of an mbuf cluster */61#endif6263#ifndef __PAST_END64#define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset])65#endif6667#ifndef nitems68// https://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#159882769#define nitems(x) \70((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))71#endif7273#ifndef rounddown74#define rounddown(x, y) (((x) / (y)) * (y))75#endif76#ifndef rounddown277#define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */78#endif79#ifndef roundup80#define roundup(x, y) ((((x) + ((y)-1)) / (y)) * (y)) /* to any y */81#endif82#ifndef roundup283#define roundup2(x, y) \84(((x) + ((y)-1)) & (~((y)-1))) /* if y is powers of two */85#endif86#ifndef powerof287#define powerof2(x) ((((x)-1) & (x)) == 0)88#endif899091