blob: 50a822c78dc81951683f024eb67b697656ebd37c [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 Żenczykowski730a3862020-01-27 01:10:48 -080028/*
29 * Map structure to be used by Android eBPF C programs. The Android eBPF loader
30 * uses this structure from eBPF object to create maps at boot time.
31 *
32 * The eBPF C program should define structure in the maps section using
33 * SEC("maps") otherwise it will be ignored by the eBPF loader.
34 *
35 * For example:
36 * const struct bpf_map_def SEC("maps") mymap { .type=... , .key_size=... }
37 *
38 * See 'bpf_helpers.h' for helpful macros for eBPF program use.
39 */
40struct bpf_map_def {
41 enum bpf_map_type type;
42 unsigned int key_size;
43 unsigned int value_size;
44 unsigned int max_entries;
45 unsigned int map_flags;
46
47 // The following are not supported by the Android bpfloader:
48 // unsigned int inner_map_idx;
49 // unsigned int numa_node;
Maciej Żenczykowski83f29772020-01-27 03:11:51 -080050
51 unsigned int uid; // uid_t
52 unsigned int gid; // gid_t
53 unsigned int mode; // mode_t
Maciej Żenczykowski730a3862020-01-27 01:10:48 -080054};
Connor O'Brien3278a162020-02-13 21:45:22 -080055
56struct bpf_prog_def {
57 unsigned int uid;
58 unsigned int gid;
Maciej Żenczykowski07375e22020-02-19 14:23:59 -080059
Maciej Żenczykowskifd59a4a2021-03-02 18:37:33 -080060 // kernelVersion() must be >= min_kver and < max_kver
61 unsigned int min_kver;
62 unsigned int max_kver;
Maciej Żenczykowskiaa295c82020-06-16 17:02:48 -070063
Maciej Żenczykowskifd59a4a2021-03-02 18:37:33 -080064 bool optional; // program section (ie. function) may fail to load, continue onto next func.
Connor O'Brien3278a162020-02-13 21:45:22 -080065};