Maciej Żenczykowski | 730a386 | 2020-01-27 01:10:48 -0800 | [diff] [blame] | 1 | /* |
| 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 Żenczykowski | 56bf76b | 2020-02-18 14:44:06 -0800 | [diff] [blame] | 25 | // Pull in AID_* constants from //system/core/libcutils/include/private/android_filesystem_config.h |
Maciej Żenczykowski | 56bf76b | 2020-02-18 14:44:06 -0800 | [diff] [blame] | 26 | #include <private/android_filesystem_config.h> |
Maciej Żenczykowski | 6f87896 | 2020-01-27 02:58:29 -0800 | [diff] [blame] | 27 | |
Maciej Żenczykowski | 9217eee | 2021-03-03 05:28:52 -0800 | [diff] [blame] | 28 | /****************************************************************************** |
| 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 Żenczykowski | 0bf9219 | 2021-07-01 14:49:00 -0700 | [diff] [blame^] | 45 | // We currently default to v0.1 format |
Maciej Żenczykowski | 9217eee | 2021-03-03 05:28:52 -0800 | [diff] [blame] | 46 | #ifndef BPFLOADER_VERSION |
Maciej Żenczykowski | 0bf9219 | 2021-07-01 14:49:00 -0700 | [diff] [blame^] | 47 | #define BPFLOADER_VERSION 1u |
Maciej Żenczykowski | 9217eee | 2021-03-03 05:28:52 -0800 | [diff] [blame] | 48 | #endif |
| 49 | |
| 50 | // These are the values used if these fields are missing |
Maciej Żenczykowski | a21256d | 2021-07-02 00:40:55 -0700 | [diff] [blame] | 51 | #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 Żenczykowski | 9217eee | 2021-03-03 05:28:52 -0800 | [diff] [blame] | 53 | #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 Żenczykowski | 730a386 | 2020-01-27 01:10:48 -0800 | [diff] [blame] | 56 | /* |
| 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 | */ |
| 68 | struct 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 Żenczykowski | 83f2977 | 2020-01-27 03:11:51 -0800 | [diff] [blame] | 78 | |
| 79 | unsigned int uid; // uid_t |
| 80 | unsigned int gid; // gid_t |
| 81 | unsigned int mode; // mode_t |
Maciej Żenczykowski | 9217eee | 2021-03-03 05:28:52 -0800 | [diff] [blame] | 82 | |
| 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 Żenczykowski | 730a386 | 2020-01-27 01:10:48 -0800 | [diff] [blame] | 88 | }; |
Connor O'Brien | 3278a16 | 2020-02-13 21:45:22 -0800 | [diff] [blame] | 89 | |
| 90 | struct bpf_prog_def { |
| 91 | unsigned int uid; |
| 92 | unsigned int gid; |
Maciej Żenczykowski | 07375e2 | 2020-02-19 14:23:59 -0800 | [diff] [blame] | 93 | |
Maciej Żenczykowski | fd59a4a | 2021-03-02 18:37:33 -0800 | [diff] [blame] | 94 | // kernelVersion() must be >= min_kver and < max_kver |
| 95 | unsigned int min_kver; |
| 96 | unsigned int max_kver; |
Maciej Żenczykowski | aa295c8 | 2020-06-16 17:02:48 -0700 | [diff] [blame] | 97 | |
Maciej Żenczykowski | fd59a4a | 2021-03-02 18:37:33 -0800 | [diff] [blame] | 98 | bool optional; // program section (ie. function) may fail to load, continue onto next func. |
Maciej Żenczykowski | 9217eee | 2021-03-03 05:28:52 -0800 | [diff] [blame] | 99 | |
| 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'Brien | 3278a16 | 2020-02-13 21:45:22 -0800 | [diff] [blame] | 105 | }; |