1 /*
2 * Copyright (c) 2015-2021 Dmitry V. Levin <ldv@strace.io>
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 #include "defs.h"
9
10 #include DEF_MPERS_TYPE(struct_sock_fprog)
11
12 #include <linux/filter.h>
13 typedef struct sock_fprog struct_sock_fprog;
14
15 #include MPERS_DEFS
16 #include "bpf_fprog.h"
17
18 MPERS_PRINTER_DECL(unsigned int, get_sock_fprog_size, void)
19 {
20 return sizeof(struct_sock_fprog);
21 }
22
23 MPERS_PRINTER_DECL(bool, fetch_bpf_fprog, struct tcb *const tcp,
24 const kernel_ulong_t addr, void *const p)
25 {
26 struct bpf_fprog *pfp = p;
27 struct_sock_fprog mfp;
28
29 if ((sizeof(*pfp) == sizeof(mfp))
30 && (offsetof(struct bpf_fprog, filter) ==
31 offsetof(struct_sock_fprog, filter)))
32 return !umove_or_printaddr(tcp, addr, pfp);
33
34 if (umove_or_printaddr(tcp, addr, &mfp))
35 return false;
36
37 pfp->len = mfp.len;
38 pfp->filter =
39 #ifndef IN_MPERS
40 (uintptr_t)
41 #endif
42 mfp.filter;
43 return true;
44 }