76 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.4 * Copyright (c) 2023 Tejun Heo <tj@kernel.org>5 * Copyright (c) 2023 David Vernet <dvernet@meta.com>6 */7#ifndef __SCHED_EXT_COMMON_H8#define __SCHED_EXT_COMMON_H9 10#ifdef __KERNEL__11#error "Should not be included by BPF programs"12#endif13 14#include <stdarg.h>15#include <stdio.h>16#include <stdlib.h>17#include <stdint.h>18#include <errno.h>19 20typedef uint8_t u8;21typedef uint16_t u16;22typedef uint32_t u32;23typedef uint64_t u64;24typedef int8_t s8;25typedef int16_t s16;26typedef int32_t s32;27typedef int64_t s64;28 29#define SCX_BUG(__fmt, ...) \30 do { \31 fprintf(stderr, "[SCX_BUG] %s:%d", __FILE__, __LINE__); \32 if (errno) \33 fprintf(stderr, " (%s)\n", strerror(errno)); \34 else \35 fprintf(stderr, "\n"); \36 fprintf(stderr, __fmt __VA_OPT__(,) __VA_ARGS__); \37 fprintf(stderr, "\n"); \38 \39 exit(EXIT_FAILURE); \40 } while (0)41 42#define SCX_BUG_ON(__cond, __fmt, ...) \43 do { \44 if (__cond) \45 SCX_BUG((__fmt) __VA_OPT__(,) __VA_ARGS__); \46 } while (0)47 48/**49 * RESIZE_ARRAY - Convenience macro for resizing a BPF array50 * @__skel: the skeleton containing the array51 * @elfsec: the data section of the BPF program in which the array exists52 * @arr: the name of the array53 * @n: the desired array element count54 *55 * For BPF arrays declared with RESIZABLE_ARRAY(), this macro performs two56 * operations. It resizes the map which corresponds to the custom data57 * section that contains the target array. As a side effect, the BTF info for58 * the array is adjusted so that the array length is sized to cover the new59 * data section size. The second operation is reassigning the skeleton pointer60 * for that custom data section so that it points to the newly memory mapped61 * region.62 */63#define RESIZE_ARRAY(__skel, elfsec, arr, n) \64 do { \65 size_t __sz; \66 bpf_map__set_value_size((__skel)->maps.elfsec##_##arr, \67 sizeof((__skel)->elfsec##_##arr->arr[0]) * (n)); \68 (__skel)->elfsec##_##arr = \69 bpf_map__initial_value((__skel)->maps.elfsec##_##arr, &__sz); \70 } while (0)71 72#include "user_exit_info.h"73#include "compat.h"74 75#endif /* __SCHED_EXT_COMMON_H */76