#pragma once
#ifdef __BPF__
#include <vmlinux.h>
#include <bpf_arena_common.h>
#include <bpf_arena_spin_lock.h>
#include <asm-generic/errno.h>
#ifndef __BPF_FEATURE_ADDR_SPACE_CAST
#error "Arena allocators require bpf_addr_space_cast feature"
#endif
#define arena_stdout(fmt, ...) bpf_stream_printk(1, (fmt), ##__VA_ARGS__)
#define arena_stderr(fmt, ...) bpf_stream_printk(2, (fmt), ##__VA_ARGS__)
#ifndef __maybe_unused
#define __maybe_unused __attribute__((__unused__))
#endif
#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
#define ARENA_PAGES (1UL << (32 - __builtin_ffs(__PAGE_SIZE) + 1))
struct {
__uint(type, BPF_MAP_TYPE_ARENA);
__uint(map_flags, BPF_F_MMAPABLE);
__uint(max_entries, ARENA_PAGES);
#if defined(__TARGET_ARCH_arm64) || defined(__aarch64__)
__ulong(map_extra, (1ull << 32));
#else
__ulong(map_extra, (1ull << 44));
#endif
} arena __weak SEC(".maps");
extern const volatile u32 zero;
extern volatile u64 asan_violated;
int arena_fls(__u64 word);
void __arena *arena_malloc(size_t size);
void arena_free(void __arena *ptr);
#define arena_subprog_init() do { asm volatile ("" :: "r"(&arena)); } while (0)
#else
#include <stdint.h>
#define __arena
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
#define arena_spinlock_t int
#endif
struct arena_get_info_args {
void __arena *arena_base;
};
struct arena_alloc_reserve_args {
u64 nr_pages;
};
#define ARENA_RESERVE_PAGES_DFL (8)