blob: 0034a354ff1a8fca8eb24b7e5bbbcf496010cb70 [file] [log] [blame]
Maciej Żenczykowski730a3862020-01-27 01:10:48 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19/* This file is separate because it's included both by eBPF programs (via include
20 * in bpf_helpers.h) and directly by the boot time bpfloader (Loader.cpp).
21 */
22
23#include <linux/bpf.h>
24
Maciej Żenczykowski56bf76b2020-02-18 14:44:06 -080025// Pull in AID_* constants from //system/core/libcutils/include/private/android_filesystem_config.h
Maciej Żenczykowski56bf76b2020-02-18 14:44:06 -080026#include <private/android_filesystem_config.h>
Maciej Żenczykowski6f878962020-01-27 02:58:29 -080027
Maciej Żenczykowski9217eee2021-03-03 05:28:52 -080028/******************************************************************************
29 * *
30 * ! ! ! W A R N I N G ! ! ! *
31 * *
32 * CHANGES TO THESE STRUCTURE DEFINITIONS OUTSIDE OF AOSP/MASTER *WILL* BREAK *
33 * MAINLINE MODULE COMPATIBILITY *
34 * *
35 * AND THUS MAY RESULT IN YOUR DEVICE BRICKING AT SOME ARBITRARY POINT IN *
36 * THE FUTURE *
37 * *
38 * (and even in aosp/master you may only append new fields at the very end, *
39 * you may *never* delete fields, change their types, ordering, insert in *
40 * the middle, etc. If a mainline module using the old definition has *
41 * already shipped (which happens roughly monthly), then it's set in stone) *
42 * *
43 ******************************************************************************/
44
Maciej Żenczykowski0bf92192021-07-01 14:49:00 -070045// We currently default to v0.1 format
Maciej Żenczykowski9217eee2021-03-03 05:28:52 -080046#ifndef BPFLOADER_VERSION
Maciej Żenczykowski0bf92192021-07-01 14:49:00 -070047#define BPFLOADER_VERSION 1u
Maciej Żenczykowski9217eee2021-03-03 05:28:52 -080048#endif
49
50// These are the values used if these fields are missing
Maciej Żenczykowskia21256d2021-07-02 00:40:55 -070051#define DEFAULT_BPFLOADER_MIN_VER 0u // v0.0 (this is inclusive ie. >= v0.0)
52#define DEFAULT_BPFLOADER_MAX_VER 0x10000u // v1.0 (this is exclusive ie. < v1.0)
Maciej Żenczykowski9217eee2021-03-03 05:28:52 -080053#define DEFAULT_SIZEOF_BPF_MAP_DEF 32 // v0.0 struct: enum + alignment padding + 7 uint
54#define DEFAULT_SIZEOF_BPF_PROG_DEF 20 // v0.0 struct: 4 uint + bool + alignment padding
55
Maciej Żenczykowski730a3862020-01-27 01:10:48 -080056/*
57 * Map structure to be used by Android eBPF C programs. The Android eBPF loader
58 * uses this structure from eBPF object to create maps at boot time.
59 *
60 * The eBPF C program should define structure in the maps section using
61 * SEC("maps") otherwise it will be ignored by the eBPF loader.
62 *
63 * For example:
64 * const struct bpf_map_def SEC("maps") mymap { .type=... , .key_size=... }
65 *
66 * See 'bpf_helpers.h' for helpful macros for eBPF program use.
67 */
68struct bpf_map_def {
69 enum bpf_map_type type;
70 unsigned int key_size;
71 unsigned int value_size;
72 unsigned int max_entries;
73 unsigned int map_flags;
74
75 // The following are not supported by the Android bpfloader:
76 // unsigned int inner_map_idx;
77 // unsigned int numa_node;
Maciej Żenczykowski83f29772020-01-27 03:11:51 -080078
79 unsigned int uid; // uid_t
80 unsigned int gid; // gid_t
81 unsigned int mode; // mode_t
Maciej Żenczykowski9217eee2021-03-03 05:28:52 -080082
83#if BPFLOADER_VERSION >= 1u
84 // The following fields were added in version 0.1
85 unsigned int bpfloader_min_ver; // if missing, defaults to 0, ie. v0.0
86 unsigned int bpfloader_max_ver; // if missing, defaults to 0x10000, ie. v1.0
87#endif
Maciej Żenczykowski730a3862020-01-27 01:10:48 -080088};
Connor O'Brien3278a162020-02-13 21:45:22 -080089
90struct bpf_prog_def {
91 unsigned int uid;
92 unsigned int gid;
Maciej Żenczykowski07375e22020-02-19 14:23:59 -080093
Maciej Żenczykowskifd59a4a2021-03-02 18:37:33 -080094 // kernelVersion() must be >= min_kver and < max_kver
95 unsigned int min_kver;
96 unsigned int max_kver;
Maciej Żenczykowskiaa295c82020-06-16 17:02:48 -070097
Maciej Żenczykowskifd59a4a2021-03-02 18:37:33 -080098 bool optional; // program section (ie. function) may fail to load, continue onto next func.
Maciej Żenczykowski9217eee2021-03-03 05:28:52 -080099
100#if BPFLOADER_VERSION >= 1u
101 // The following fields were added in version 0.1
102 unsigned int bpfloader_min_ver; // if missing, defaults to 0, ie. v0.0
103 unsigned int bpfloader_max_ver; // if missing, defaults to 0x10000, ie. v1.0
104#endif
Connor O'Brien3278a162020-02-13 21:45:22 -0800105};