xref: /linux/tools/testing/selftests/bpf/progs/test_obj_id.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
125763b3cSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2bd4aed0eSJiong Wang /* Copyright (c) 2017 Facebook
3bd4aed0eSJiong Wang  */
4bd4aed0eSJiong Wang #include <stddef.h>
5bd4aed0eSJiong Wang #include <linux/bpf.h>
63e689141SToke Høiland-Jørgensen #include <bpf/bpf_helpers.h>
7*c8ed6685SAndrii Nakryiko #include "bpf_misc.h"
8bd4aed0eSJiong Wang 
91639b17cSAndrii Nakryiko struct {
101639b17cSAndrii Nakryiko 	__uint(type, BPF_MAP_TYPE_ARRAY);
111639b17cSAndrii Nakryiko 	__uint(max_entries, 1);
121639b17cSAndrii Nakryiko 	__type(key, __u32);
131639b17cSAndrii Nakryiko 	__type(value, __u64);
141639b17cSAndrii Nakryiko } test_map_id SEC(".maps");
15bd4aed0eSJiong Wang 
162c2837b0SAndrii Nakryiko SEC("raw_tp/sys_enter")
test_obj_id(void * ctx)172c2837b0SAndrii Nakryiko int test_obj_id(void *ctx)
18bd4aed0eSJiong Wang {
19bd4aed0eSJiong Wang 	__u32 key = 0;
20bd4aed0eSJiong Wang 	__u64 *value;
21bd4aed0eSJiong Wang 
22bd4aed0eSJiong Wang 	value = bpf_map_lookup_elem(&test_map_id, &key);
23*c8ed6685SAndrii Nakryiko 	__sink(value);
24bd4aed0eSJiong Wang 
252c2837b0SAndrii Nakryiko 	return 0;
26bd4aed0eSJiong Wang }
27