• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2022 Google LLC
4  */
5 
6 #ifndef TEST_FUSE__BPF__H
7 #define TEST_FUSE__BPF__H
8 
9 #define __EXPORTED_HEADERS__
10 #define __KERNEL__
11 
12 #ifdef __ANDROID__
13 #include <stdint.h>
14 #endif
15 
16 #include <uapi/linux/types.h>
17 #include <uapi/linux/bpf.h>
18 #include <uapi/linux/android_fuse.h>
19 #include <uapi/linux/fuse.h>
20 #include <uapi/linux/errno.h>
21 
22 #define SEC(NAME) __section(NAME)
23 
24 struct fuse_bpf_map {
25 	int map_type;
26 	size_t key_size;
27 	size_t value_size;
28 	int max_entries;
29 };
30 
31 static void *(*bpf_map_lookup_elem)(struct fuse_bpf_map *map, void *key)
32 	= (void *) 1;
33 
34 static void *(*bpf_map_update_elem)(struct fuse_bpf_map *map, void *key,
35 				    void *value, int flags)
36 	= (void *) 2;
37 
38 static long (*bpf_trace_printk)(const char *fmt, __u32 fmt_size, ...)
39 	= (void *) 6;
40 
41 static long (*bpf_get_current_pid_tgid)()
42 	= (void *) 14;
43 
44 static long (*bpf_get_current_uid_gid)()
45 	= (void *) 15;
46 
47 #define bpf_printk(fmt, ...)					\
48 	({			                                \
49 		char ____fmt[] = fmt;                           \
50 		bpf_trace_printk(____fmt, sizeof(____fmt),      \
51 					##__VA_ARGS__);		\
52 	})
53 
strcmp(const char * a,const char * b)54 SEC("dummy") inline int strcmp(const char *a, const char *b)
55 {
56 	int i;
57 
58 	for (i = 0; i < __builtin_strlen(b) + 1; ++i)
59 		if (a[i] != b[i])
60 			return -1;
61 
62 	return 0;
63 }
64 
65 #endif
66